diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 6b747b16dc300f89cf84befc1a8317d8f702fa79..7aad1ab1c4ca587de14733a3ac818de7f363cf80 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; - }); + } } /**