Skip to content

Commit

Permalink
Load scenario names from files
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccollum-woolpert committed Mar 25, 2024
1 parent d773ccf commit 9385267
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ export class BaseStorageApiSaveLoadDialogComponent implements OnChanges, OnDestr
@Input() saving = false;
@Input() scenario: OptimizeToursRequest;
@Input() solution: OptimizeToursResponse;
@Output() loadScenario = new EventEmitter<Scenario>();
@Output() loadScenario = new EventEmitter<{
scenario: Scenario;
scenarioName: string;
}>();
@Output() loadSolution = new EventEmitter<{
scenario: Scenario;
solution: Solution;
scenarioName: string;
}>();

closed = new Subject<void>();
Expand Down Expand Up @@ -264,6 +268,7 @@ export class BaseStorageApiSaveLoadDialogComponent implements OnChanges, OnDestr
this.loadSolution.emit({
scenario: result.scenario,
solution: result.solution,
scenarioName: result.name.replace(/\.[^/.]+$/, ''),
});
}

Expand All @@ -272,7 +277,10 @@ export class BaseStorageApiSaveLoadDialogComponent implements OnChanges, OnDestr
this.validationError();
return;
}
this.loadScenario.emit(result.fileContent);
this.loadScenario.emit({
scenario: result.fileContent,
scenarioName: result.name.replace(/\.[^/.]+$/, ''),
});
}

confirmDelete(selection: SearchResult): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="d-flex flex-row align-items-center">
<div class="d-flex flex-row align-items-center ml-3">
<mat-icon class="blue-svg-icon pb-2" svgIcon="dataset"></mat-icon>
<mat-form-field class="ml-1 scenario-input" appearance="standard">
<input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.scenario-input {
width: 11rem;
width: 14rem;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { selectScenarioName } from '../../selectors/dispatcher.selectors';
import { saveScenarioName } from '../../actions/dispatcher.actions';
Expand All @@ -12,11 +12,12 @@ import { saveScenarioName } from '../../actions/dispatcher.actions';
export class DatasetComponentComponent implements OnInit {
scenarioName: string;

constructor(private store: Store) {}
constructor(private store: Store, private detectRef: ChangeDetectorRef) {}

ngOnInit(): void {
this.store.select(selectScenarioName).subscribe((value) => {
this.scenarioName = value;
this.detectRef.markForCheck();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ export class StorageApiSaveLoadDialogComponent implements OnInit {
});
}

loadScenario(scenario: Scenario): void {
this.dialogRef.close({ scenario: this.dispatcherService.objectToScenario(scenario) });
loadScenario(content: { scenario: Scenario; scenarioName: string }): void {
this.dialogRef.close({
scenario: this.dispatcherService.objectToScenario(content.scenario),
scenarioName: content.scenarioName,
});
}

loadSolution(content: { scenario: Scenario; solution: Solution }): void {
loadSolution(content: { scenario: Scenario; solution: Solution; scenarioName: String }): void {

Check failure on line 70 in application/frontend/src/app/core/containers/storage-api-save-load-dialog/storage-api-save-load-dialog.component.ts

View workflow job for this annotation

GitHub Actions / check-frontend

Don't use `String` as a type. Use string instead
this.dialogRef.close({
scenario: this.dispatcherService.objectToScenario(content.scenario),
solution: this.dispatcherService.objectToSolution(content.solution, { json: true }),
scenarioName: content.scenarioName,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export class UploadDialogComponent {
zipMissingScenario: boolean;
zipMissingSolution: boolean;

selectedFilename: string;

resolvingPlaceIds = false;
placeIdProgress = 0;
placeIdError: string;
Expand Down Expand Up @@ -123,6 +125,7 @@ export class UploadDialogComponent {
this.dialogRef.close({
uploadType: this.scenarioSolutionPair ? UploadType.ScenarioSolutionPair : UploadType.Scenario,
content: this.scenarioSolutionPair ? this.scenarioSolutionPair : this.scenario,
scenarioName: this.selectedFilename,
});
}

Expand Down Expand Up @@ -150,6 +153,8 @@ export class UploadDialogComponent {
return;
}

this.selectedFilename = file.name.replace(/\.[^/.]+$/, '');

this.validatingUpload = true;

// First check if the file is valid JSON
Expand Down
11 changes: 9 additions & 2 deletions application/frontend/src/app/core/effects/storage-api.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export class StorageApiEffects {
return dialogRef.afterClosed();
}),
mergeMap(
(dialogResult: { scenario: IOptimizeToursRequest; solution?: IOptimizeToursResponse }) => {
(dialogResult: {
scenario: IOptimizeToursRequest;
solution?: IOptimizeToursResponse;
scenarioName: string;
}) => {
if (!dialogResult) {
return EMPTY;
}
Expand All @@ -38,7 +42,10 @@ export class StorageApiEffects {
const { shipments, vehicles, normalizedScenario } =
this.normalizationService.normalizeScenario(scenario, requestTime);
const actions: Action[] = [
DispatcherActions.uploadScenarioSuccess({ scenario: normalizedScenario }),
DispatcherActions.uploadScenarioSuccess({
scenario: normalizedScenario,
scenarioName: dialogResult.scenarioName,
}),
];
if (solution) {
const requestedShipmentIds = shipments.filter((s) => !s.ignore).map((s) => s.id);
Expand Down
12 changes: 9 additions & 3 deletions application/frontend/src/app/core/effects/upload.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class UploadEffects {
})
.afterClosed()
),
mergeMap((dialogResult: { uploadType: UploadType; content: any }) => {
mergeMap((dialogResult: { uploadType: UploadType; content: any; scenarioName: string }) => {
const actions: Action[] = [UploadActions.closeDialog()];
if (dialogResult) {
switch (dialogResult.uploadType) {
Expand All @@ -92,7 +92,10 @@ export class UploadEffects {
);

actions.push(
DispatcherActions.uploadScenarioSuccess({ scenario: normalizedScenario })
DispatcherActions.uploadScenarioSuccess({
scenario: normalizedScenario,
scenarioName: dialogResult.scenarioName,
})
);
break;
}
Expand All @@ -106,7 +109,10 @@ export class UploadEffects {
const requestedVehicleIds = vehicles.filter((v) => !v.ignore).map((v) => v.id);

actions.push(
DispatcherActions.uploadScenarioSuccess({ scenario: normalizedScenario })
DispatcherActions.uploadScenarioSuccess({
scenario: normalizedScenario,
scenarioName: dialogResult.scenarioName,
})
);
actions.push(
DispatcherApiActions.applySolution({
Expand Down

0 comments on commit 9385267

Please sign in to comment.