diff --git a/src/app/app.component.ts b/src/app/app.component.ts index cf38a7c63c4c1ed2c88e78b66a39f8533855b5d4..59d238cf1e0804dcf833355354bd55cc00271940 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -535,7 +535,14 @@ export class AppComponent implements OnInit, OnDestroy, Observer { const list = []; for (const c of this._calculators) { const uid = c["uid"]; + const nub = Session.getInstance().findNubByUid(uid); list.push({ + "children": nub.getChildren().map((child) => { + return child.uid; + }), + "requires": nub.getTargettedNubs().map((req) => { + return req.uid; + }), "selected": form ? (uid === form.uid) : true, "title": c["title"], "uid": uid diff --git a/src/app/components/dialog-save-session/dialog-save-session.component.html b/src/app/components/dialog-save-session/dialog-save-session.component.html index f207e5b27df91dbe679139a0f09ea4b2640369cb..d4f2324cc1b63149ee0bd5c0b87cf7594a254054 100644 --- a/src/app/components/dialog-save-session/dialog-save-session.component.html +++ b/src/app/components/dialog-save-session/dialog-save-session.component.html @@ -4,7 +4,8 @@ <div mat-dialog-content> <div class="cb-container"> - <mat-checkbox [name]="c.uid" *ngFor="let c of calculators" [(ngModel)]="c.selected"> + <mat-checkbox [name]="c.uid" *ngFor="let c of calculators" [(ngModel)]="c.selected" + (change)="checkLinkedParamsAndModelsDependencies()"> {{ c.title }} </mat-checkbox> </div> @@ -14,6 +15,20 @@ <button mat-raised-button (click)="selectNone()">{{ uitextNone }}</button> </div> + <div class="dependencies-problems" *ngIf="dependenciesProblems.length > 0"> + <mat-list role="list"> + <mat-list-item role="listitem" *ngFor="let dp of dependenciesProblems"> + <mat-icon color="warn">error_outline</mat-icon> {{ dp.message }} + </mat-list-item> + </mat-list> + <p> + <button mat-raised-button (click)="fixDependencies()" + [matBadge]="dependenciesProblems.length" matBadgeColor="warn"> + {{ uitextFixMissingDependencies }} + </button> + </p> + </div> + <mat-form-field> <input matInput required [placeholder]="uitextFilenameInput" [(ngModel)]="fileName" name="filename" #filename="ngModel" (keydown.enter)="onEnterPressed($event)"> diff --git a/src/app/components/dialog-save-session/dialog-save-session.component.scss b/src/app/components/dialog-save-session/dialog-save-session.component.scss index e612ad2cf5490552d96d024c1122ef4cd1bbfc1f..f9cad276513dfef8f4fd62cf8ecc57e177dc538b 100644 --- a/src/app/components/dialog-save-session/dialog-save-session.component.scss +++ b/src/app/components/dialog-save-session/dialog-save-session.component.scss @@ -17,3 +17,24 @@ mat-form-field { margin-right: 5px; } } + +.dependencies-problems { + + .mat-list-base { + padding-top: 0; + + .mat-list-item { + height: 32px; + font-size: .9em; + + ::ng-deep .mat-list-item-content { + padding-left: 0; + + mat-icon { + transform: scale(0.8); + margin-right: 5px; + } + } + } + } +} diff --git a/src/app/components/dialog-save-session/dialog-save-session.component.ts b/src/app/components/dialog-save-session/dialog-save-session.component.ts index 617557dcc9deb2849ba0a1bf06d77cf9c9490bf3..eac698d910b693c0bda270014b765531b4506702 100644 --- a/src/app/components/dialog-save-session/dialog-save-session.component.ts +++ b/src/app/components/dialog-save-session/dialog-save-session.component.ts @@ -13,24 +13,106 @@ export class DialogSaveSessionComponent { public fileName = "session"; + public dependenciesProblems: any[] = []; + constructor( public dialogRef: MatDialogRef<DialogSaveSessionComponent>, private intlService: I18nService, @Inject(MAT_DIALOG_DATA) public data: any ) { this.calculators = data.calculators; + // run dependency checking at first + this.checkLinkedParamsAndModelsDependencies(); } public selectAll() { for (const c of this.calculators) { c.selected = true; } + // re-run dependency checking + this.checkLinkedParamsAndModelsDependencies(); } public selectNone() { for (const c of this.calculators) { c.selected = false; } + // re-run dependency checking + this.checkLinkedParamsAndModelsDependencies(); + } + + /** + * Checks the dependencies between Nubs : + * - linked params depend on their targets + * - PabCloisons depend on their models + */ + public checkLinkedParamsAndModelsDependencies() { + console.log("CLPMD !", this.calculators); + this.dependenciesProblems = []; + // for all checked Nubs + this.calculators.forEach((c) => { + if (c.selected) { + // do all required nubs are checked ? + c.requires.forEach((r) => { + if (! this.isCalculatorOrParentSelected(r)) { + const realUid = this.getUidOrParentUid(r); + const depTitle = this.getTitleFromUid(realUid); + this.dependenciesProblems.push({ + requiring: c.title, + required: depTitle, + requiredUid: realUid, + message: c.title + " " + this.intlService.localizeText("INFO_REQUIRES") + " " + depTitle + }); + } + }); + } + }); + } + + public fixDependencies() { + for (const dp of this.dependenciesProblems) { + this.selectRequiredModule(dp.requiredUid); + } + } + + private isCalculatorOrParentSelected(uid: string): boolean { + let isSelected = false; + this.calculators.forEach((c) => { + if (c.uid === uid || c.children.includes(uid)) { + isSelected = c.selected; + } + }); + return isSelected; + } + + private getUidOrParentUid(uid: string): string { + let realUid: string; + this.calculators.forEach((c) => { + if (c.uid === uid || c.children.includes(uid)) { + realUid = c.uid; + } + }); + return realUid; + } + + private getTitleFromUid(uid: string): string { + let title: string; + this.calculators.forEach((c) => { + if (c.uid === uid) { + title = c.title; + } + }); + return title; + } + + private selectRequiredModule(uid: string) { + this.calculators.forEach((c) => { + if (c.uid === uid) { + c.selected = true; + } + }); + // re-run dependency checking + this.checkLinkedParamsAndModelsDependencies(); } public saveSession() { @@ -72,6 +154,10 @@ export class DialogSaveSessionComponent { return this.intlService.localizeText("INFO_DIALOG_SAVE_SESSION_FILENAME"); } + public get uitextFixMissingDependencies() { + return this.intlService.localizeText("INFO_DIALOG_FIX_MISSING_DEPENDENCIES"); + } + public onEnterPressed(event) { this.saveSession(); return false; // stops event propagation