Skip to content
Snippets Groups Projects
Commit 75137e4b authored by mathias.chouet's avatar mathias.chouet
Browse files

Fix #215

parent 37425d06
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,14 @@
</button>
</div>
<div class="format-problem" *ngIf="fileFormatVersionProblem">
<mat-list role="list">
<mat-list-item role="listitem">
<mat-icon color="warn">error_outline</mat-icon> {{ uitextFileFormatVersionProblem }}
</mat-list-item>
</mat-list>
</div>
<div class="dependencies-problems" *ngIf="dependenciesProblems.length > 0">
<mat-list role="list">
<mat-list-item role="listitem" *ngFor="let dp of dependenciesProblems">
......
......@@ -18,7 +18,11 @@ mat-form-field {
}
}
.dependencies-problems {
.format-problem {
margin-bottom: 1em;
}
.dependencies-problems, .format-problem {
.mat-list-base {
padding-top: 0;
......
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material";
import { Inject, Component } from "@angular/core";
import { config } from "jalhyd";
import { decode } from "he";
import { I18nService } from "../../services/internationalisation/internationalisation.service";
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
import { ServiceFactory } from "../../services/service-factory";
import { sprintf } from "sprintf-js";
@Component({
selector: "dialog-load-session",
templateUrl: "dialog-load-session.component.html",
......@@ -16,6 +19,10 @@ export class DialogLoadSessionComponent {
public calculators: any[] = [];
public fileFormatVersion: string;
public libFormatVersion: string;
public file: any;
public loadSessionForm: FormGroup;
......@@ -33,6 +40,7 @@ export class DialogLoadSessionComponent {
this.loadSessionForm = this.fb.group({
file: [null, Validators.required]
});
this.libFormatVersion = config.serialisation.fileFormatVersion;
}
public selectAll() {
......@@ -131,7 +139,8 @@ export class DialogLoadSessionComponent {
const formService = ServiceFactory.instance.formulaireService;
formService.calculatorInfosFromSessionFile(this.file).then(
calcInfos => {
this.calculators = calcInfos;
this.fileFormatVersion = calcInfos.formatVersion;
this.calculators = calcInfos.nubs;
for (const n of this.calculators) {
n.selected = true;
// if no title was given, generate a default one
......@@ -160,6 +169,10 @@ export class DialogLoadSessionComponent {
return ok;
}
public get fileFormatVersionProblem(): boolean {
return this.fileFormatVersion && (this.fileFormatVersion !== this.libFormatVersion);
}
public get uitextLoad() {
return this.intlService.localizeText("INFO_OPTION_LOAD");
}
......@@ -191,4 +204,12 @@ export class DialogLoadSessionComponent {
public get uitextEmptyCurrentSession() {
return this.intlService.localizeText("INFO_DIALOG_EMPTY_CURRENT_SESSION");
}
public get uitextFileFormatVersionProblem() {
return sprintf(
this.intlService.localizeText("INFO_DIALOG_FORMAT_VERSIONS_MISMATCH"),
this.fileFormatVersion,
this.libFormatVersion
);
}
}
......@@ -558,9 +558,13 @@ export class FormulaireService extends Observable {
* obtient des infos (nom, uid des modules de calcul, dépendances) d'un fichier session
* @param f fichier session
*/
public calculatorInfosFromSessionFile(f: File): Promise<any[]> {
public calculatorInfosFromSessionFile(f: File): Promise<{ nubs: any[], formatVersion: string }> {
return this.readSingleFile(f).then(s => {
const res: any[] = [];
// return value
const res: { nubs: any[], formatVersion: string } = {
nubs: [],
formatVersion: ""
};
const data = JSON.parse(s);
// liste des noms de modules de calcul
if (data.session && Array.isArray(data.session)) {
......@@ -601,9 +605,13 @@ export class FormulaireService extends Observable {
nubInfo.children.push(p.uid);
});
}
res.push(nubInfo);
res.nubs.push(nubInfo);
});
}
// version du format de fichier
if (data.header && data.header.format_version) {
res.formatVersion = data.header.format_version;
}
return res;
});
}
......
......@@ -60,6 +60,7 @@
"INFO_DIALOG_COMPUTED_VALUE_TITLE": "Edit initial value",
"INFO_DIALOG_EMPTY_CURRENT_SESSION": "Empty current session",
"INFO_DIALOG_FIX_MISSING_DEPENDENCIES": "Fix missing dependencies",
"INFO_DIALOG_FORMAT_VERSIONS_MISMATCH": "File format versions mismatch (file: %s, jalhyd: %s)",
"INFO_DIALOG_LOAD_SESSION_FILENAME": "Choose a file",
"INFO_DIALOG_LOAD_SESSION_TITLE": "Load calculator modules",
"INFO_DIALOG_PAB_NB": "Number of falls",
......
......@@ -60,6 +60,7 @@
"INFO_DIALOG_COMPUTED_VALUE_TITLE": "Modifier la valeur initiale",
"INFO_DIALOG_EMPTY_CURRENT_SESSION": "Vider la session courante",
"INFO_DIALOG_FIX_MISSING_DEPENDENCIES": "Résoudre les dépendances",
"INFO_DIALOG_FORMAT_VERSIONS_MISMATCH": "Mauvaise version du format de fichier (fichier: %s, jalhyd: %s)",
"INFO_DIALOG_LOAD_SESSION_FILENAME": "Choisir un fichier",
"INFO_DIALOG_LOAD_SESSION_TITLE": "Charger des modules de calcul",
"INFO_DIALOG_PAB_NB": "Nombre de chutes",
......
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