Skip to content
Snippets Groups Projects
Commit c48c05f8 authored by François Grand's avatar François Grand
Browse files

feat: load local session file by its URL

refs #476
parent dae50fed
No related branches found
No related tags found
1 merge request!159Resolve "URL de routeur "/loadsession" pour charger un exemple"
Pipeline #139738 failed
......@@ -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,
......
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");
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment