From 0677268673444569327b7ffec4016eb4f173281a Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Fri, 17 May 2019 16:06:18 +0200 Subject: [PATCH] Fix #197 --- .../services/formulaire/formulaire.service.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 6b747b16d..7aad1ab1c 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -459,8 +459,9 @@ export class FormulaireService extends Observable { * @param f fichier session * @param formInfos infos sur les modules de calcul @see DialogLoadSessionComponent.calculators */ - public loadSession(f: File, formInfos: any[]): Promise<any> { - return this.readSingleFile(f).then(s => { + public async loadSession(f: File, formInfos: any[]): Promise<any> { + try { + const s = await this.readSingleFile(f); const uids: string[] = []; formInfos.forEach((fi) => { if (fi.selected) { @@ -469,19 +470,22 @@ export class FormulaireService extends Observable { }); const newNubs = Session.getInstance().unserialise(s, uids); // for each new Nub, create the related form, set its title - newNubs.forEach((nn) => { + for (let i = 0; i < newNubs.length; i++) { + const nn = newNubs[i]; let title; if (nn.meta && nn.meta.title) { title = nn.meta.title; } // pre-fill language cache (for LinkedValues labels for ex.) - this.loadLocalisation(nn.nub.calcType); // async - this.createFormulaire(nn.nub.calcType, nn.nub, title); // async - }); - }).catch(err => { + await this.loadLocalisation(nn.nub.calcType); + await this.createFormulaire(nn.nub.calcType, nn.nub, title); // await guarantees loading order + } + return s; + + } catch (err) { // forward errors to caller, to avoid "Uncaught (in promise)…" throw err; - }); + } } /** -- GitLab