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

Fix #212

parent a1a7abb6
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)">
......
......@@ -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;
}
}
}
}
}
......@@ -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
......
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