Merge "Add some confirm dialogs to scouting page to prevent dangerous actions."
diff --git a/scouting/www/app.ts b/scouting/www/app.ts
index 285d306..e22fad0 100644
--- a/scouting/www/app.ts
+++ b/scouting/www/app.ts
@@ -15,6 +15,12 @@
}
switchTabTo(tab: Tab) {
- this.tab = tab;
+ let shouldSwitch = true;
+ if (tab === 'ImportMatchList') {
+ shouldSwitch = window.confirm('Leave data scouting page?');
+ }
+ if (shouldSwitch) {
+ this.tab = tab;
+ }
}
}
diff --git a/scouting/www/import_match_list/import_match_list.component.ts b/scouting/www/import_match_list/import_match_list.component.ts
index b2b15e5..7ad4ab6 100644
--- a/scouting/www/import_match_list/import_match_list.component.ts
+++ b/scouting/www/import_match_list/import_match_list.component.ts
@@ -10,44 +10,48 @@
import ErrorResponse = error_response.scouting.webserver.requests.ErrorResponse;
@Component({
- selector: 'app-import-match-list',
- templateUrl: './import_match_list.ng.html',
- styleUrls: ['../common.css', './import_match_list.component.css']
+ selector: 'app-import-match-list',
+ templateUrl: './import_match_list.ng.html',
+ styleUrls: ['../common.css', './import_match_list.component.css']
})
export class ImportMatchListComponent {
- year: number = new Date().getFullYear();
- eventCode: string = '';
- progressMessage: string = '';
- errorMessage: string = '';
+ year: number = new Date().getFullYear();
+ eventCode: string = '';
+ progressMessage: string = '';
+ errorMessage: string = '';
- async importMatchList() {
- this.errorMessage = '';
-
- const builder = new flatbuffer_builder.Builder() as unknown as flatbuffers.Builder;
- const eventCode = builder.createString(this.eventCode);
- RefreshMatchList.startRefreshMatchList(builder);
- RefreshMatchList.addYear(builder, this.year);
- RefreshMatchList.addEventCode(builder, eventCode);
- builder.finish(RefreshMatchList.endRefreshMatchList(builder));
-
- this.progressMessage = 'Importing match list. Please be patient.';
-
- const buffer = builder.asUint8Array();
- const res = await fetch(
- '/requests/refresh_match_list', {method: 'POST', body: buffer});
-
- if (res.ok) {
- // We successfully submitted the data.
- this.progressMessage = 'Successfully imported match list.';
- } else {
- this.progressMessage = '';
- const resBuffer = await res.arrayBuffer();
- const fbBuffer = new ByteBuffer(new Uint8Array(resBuffer));
- const parsedResponse = ErrorResponse.getRootAsErrorResponse(
- fbBuffer as unknown as flatbuffers.ByteBuffer);
-
- const errorMessage = parsedResponse.errorMessage();
- this.errorMessage = `Received ${res.status} ${res.statusText}: "${errorMessage}"`;
- }
+ async importMatchList() {
+ if (!window.confirm('Actually import new matches?')) {
+ return;
}
+
+ this.errorMessage = '';
+
+ const builder = new flatbuffer_builder.Builder() as unknown as flatbuffers.Builder;
+ const eventCode = builder.createString(this.eventCode);
+ RefreshMatchList.startRefreshMatchList(builder);
+ RefreshMatchList.addYear(builder, this.year);
+ RefreshMatchList.addEventCode(builder, eventCode);
+ builder.finish(RefreshMatchList.endRefreshMatchList(builder));
+
+ this.progressMessage = 'Importing match list. Please be patient.';
+
+ const buffer = builder.asUint8Array();
+ const res = await fetch(
+ '/requests/refresh_match_list', {method: 'POST', body: buffer});
+
+ if (res.ok) {
+ // We successfully submitted the data.
+ this.progressMessage = 'Successfully imported match list.';
+ } else {
+ this.progressMessage = '';
+ const resBuffer = await res.arrayBuffer();
+ const fbBuffer = new ByteBuffer(new Uint8Array(resBuffer));
+ const parsedResponse = ErrorResponse.getRootAsErrorResponse(
+ fbBuffer as unknown as flatbuffers.ByteBuffer);
+
+ const errorMessage = parsedResponse.errorMessage();
+ this.errorMessage = `Received ${res.status} ${res.statusText}: "${errorMessage}"`;
+ }
+ }
}