blob: 85620f106cd47f60a4781e977e0b5a6d0d071fdd [file] [log] [blame]
Philipp Schradercf915462022-03-16 23:42:22 -07001import {Component, ElementRef, ViewChild} from '@angular/core';
Alex Perryb3168082022-01-22 13:36:13 -08002
Milo Lin26b2cbb2022-03-26 17:35:20 -07003type Tab =
4 | 'MatchList'
5 | 'Notes'
6 | 'Entry'
7 | 'ImportMatchList'
8 | 'ShiftSchedule';
Ravago Jones2813c032022-03-16 23:44:11 -07009type TeamInMatch = {
Philipp Schrader817cce32022-03-26 15:00:00 -070010 teamNumber: number;
11 matchNumber: number;
12 compLevel: string;
Ravago Jones2813c032022-03-16 23:44:11 -070013};
Philipp Schrader72beced2022-03-07 05:29:52 -080014
Alex Perryb3168082022-01-22 13:36:13 -080015@Component({
16 selector: 'my-app',
17 templateUrl: './app.ng.html',
Philipp Schrader817cce32022-03-26 15:00:00 -070018 styleUrls: ['./common.css'],
Alex Perryb3168082022-01-22 13:36:13 -080019})
20export class App {
Philipp Schrader817cce32022-03-26 15:00:00 -070021 selectedTeamInMatch: TeamInMatch = {
22 teamNumber: 1,
23 matchNumber: 1,
24 compLevel: 'qm',
25 };
Ravago Jones2813c032022-03-16 23:44:11 -070026 tab: Tab = 'MatchList';
Philipp Schrader72beced2022-03-07 05:29:52 -080027
Ravago Jones2813c032022-03-16 23:44:11 -070028 @ViewChild('block_alerts') block_alerts: ElementRef;
Philipp Schradercf915462022-03-16 23:42:22 -070029
Alex Perryd3ccac92022-03-12 13:48:04 -080030 constructor() {
31 window.addEventListener('beforeunload', (e) => {
Philipp Schradercf915462022-03-16 23:42:22 -070032 if (!this.block_alerts.nativeElement.checked) {
Ravago Jones2813c032022-03-16 23:44:11 -070033 // Based on
34 // https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#example
Philipp Schradercf915462022-03-16 23:42:22 -070035 // This combination ensures a dialog will be shown on most browsers.
36 e.preventDefault();
37 e.returnValue = '';
38 }
Alex Perryd3ccac92022-03-12 13:48:04 -080039 });
40 }
41
Philipp Schrader72beced2022-03-07 05:29:52 -080042 tabIs(tab: Tab) {
43 return this.tab == tab;
44 }
45
Ravago Jones2813c032022-03-16 23:44:11 -070046 selectTeamInMatch(teamInMatch: TeamInMatch) {
47 this.selectedTeamInMatch = teamInMatch;
48 this.switchTabTo('Entry');
49 }
50
51 switchTabToGuarded(tab: Tab) {
Alex Perry19a87962022-03-12 13:36:10 -080052 let shouldSwitch = true;
Philipp Schrader5f190012022-03-15 23:29:09 -070053 if (this.tab !== tab) {
54 if (!this.block_alerts.nativeElement.checked) {
55 shouldSwitch = window.confirm('Leave current page?');
56 }
Alex Perry19a87962022-03-12 13:36:10 -080057 }
58 if (shouldSwitch) {
Ravago Jones2813c032022-03-16 23:44:11 -070059 this.switchTabTo(tab);
Alex Perry19a87962022-03-12 13:36:10 -080060 }
Philipp Schrader72beced2022-03-07 05:29:52 -080061 }
Ravago Jones2813c032022-03-16 23:44:11 -070062
63 private switchTabTo(tab: Tab) {
64 this.tab = tab;
65 }
Alex Perryb3168082022-01-22 13:36:13 -080066}