diff --git a/src/app/app.module.ts b/src/app/app.module.ts index a76bf4558a49de10d0f8c1510f971f86e27a159a..04b1136704ce779478d47476dc196fe3852e4625 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -118,6 +118,7 @@ import { JalhydModelValidationStepDirective } from "./directives/jalhyd-model-validation.directive"; import { ImmediateErrorStateMatcher } from "./formulaire/immediate-error-state-matcher"; +import { LoadSessionURLComponent } from "./components/load-session-url/load-session-url.component"; const appRoutes: Routes = [ { path: "list/search", component: CalculatorListComponent }, @@ -126,6 +127,7 @@ const appRoutes: Routes = [ { path: "setup", component: ApplicationSetupComponent }, { path: "diagram", component: ModulesDiagramComponent }, { path: "properties", component: SessionPropertiesComponent }, + { path: "loadsession/:path", component: LoadSessionURLComponent }, { path: "**", redirectTo: "list", pathMatch: "full" } ]; @@ -217,6 +219,7 @@ const appRoutes: Routes = [ JalhydModelValidationStepDirective, JetResultsComponent, JetTrajectoryChartComponent, + LoadSessionURLComponent, LogComponent, LogDrawerComponent, LogEntryComponent, diff --git a/src/app/components/load-session-url/load-session-url.component.ts b/src/app/components/load-session-url/load-session-url.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..99c3bae84d35ac9708b732ad3656d82339cdcdbf --- /dev/null +++ b/src/app/components/load-session-url/load-session-url.component.ts @@ -0,0 +1,52 @@ +import { Component, forwardRef, Inject } from "@angular/core"; +import { ActivatedRoute } from "@angular/router"; +import { AppComponent } from "app/app.component"; +import { HttpService } from "app/services/http.service"; + +// load a session file by its URL (either local or remote) + +@Component({ + selector: "load-session-url", + template: "" +}) +export class LoadSessionURLComponent { + private path: string; + + constructor( + @Inject(forwardRef(() => AppComponent)) private appComponent: AppComponent, + private route: ActivatedRoute, + private httpService: HttpService + ) { + } + + ngOnInit() { + // get "path" argument from URL + const path = this.route.snapshot.params.path; + + if (path.startsWith("http")) { + // general URL path + } + else { + // local path + + // input URL example : http://localhost:4200/#/loadsession/app%2Fexamples%2Fpab-complete-chain.json + // extracted path : app/examples/pab-complete-chain.json + + this.loadLocalSession(path); + } + } + + /** + * load a locally stored session file + * @param path local path in the form eg. app/examples/pab-complete-chain.json + */ + private async loadLocalSession(path: string) { + try { + const d = await this.httpService.httpGetBlobRequestPromise(path); + const f: any = new Blob([d], { type: "application/json" }); + this.appComponent.loadSessionFile(f); + } catch (e) { + alert("ERROR: session " + path + " does not exist"); + } + } +}