Skip to content

Commit

Permalink
fix #22 #28
Browse files Browse the repository at this point in the history
"
  • Loading branch information
joelclems committed Jun 30, 2020
1 parent ddacb48 commit f2b691d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
10 changes: 10 additions & 0 deletions frontend/app/class/monitoring-object-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export class MonitoringObjectBase {
);
}


childrenTypes(configParam: string = null): Array<string> {
let childrenTypes = this.configParam('children_types') || [];

Expand All @@ -168,6 +169,15 @@ export class MonitoringObjectBase {
return childrenTypes || [];
}

uniqueChildrenType() {
const childrenTypes = this.configParam('children_types') || [];

if (childrenTypes.length === 1) {
return childrenTypes[0]
}
}


parentType() {
return this.configParam('parent_type');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
height: 39px;
}

.float-left, .float-right {
.float-right {
margin-left: 5px;
}

form:invalid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ <h3>
</div>

<form [formGroup]="objForm">
<p style="color:red" *ngIf="obj.config['geometry_type'] && !objForm.value.geometry">
Veuillez saisir une géométrie sur la carte
<p class="alert alert-danger" *ngIf="obj.config['geometry_type'] && !objForm.value.geometry">
<span class="material-icons">
warning
</span>
<span>
Veuillez saisir une géométrie sur la carte
</span>
</p>

<!-- composant choix de site select + filtre -->
Expand All @@ -80,9 +85,29 @@ <h3>
></pnx-dynamic-form-generator>

<div>

<button
*ngIf="!bChainInput && !obj.id && obj.uniqueChildrenType()"
class="btn btn-success float-right"
(click)="bAddChildren=true; onSubmit();"
[disabled]="!objForm.valid"
>
<span
[ngClass]="{ 'hide-spinner': !bSaveSpinner }"
class="spinner-border spinner-border-sm float-right"
role="status"
aria-hidden="true"
></span>

<span
>Enregister et saisir les {{obj.uniqueChildrenType()}}s</span
>
</button>


<button
class="btn btn-success float-right"
(click)="onSubmit(bChainInput)"
(click)="onSubmit()"
[disabled]="!objForm.valid"
>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ export class MonitoringFormComponent implements OnInit {
this.objForm.patchValue(defaultValues);
}

navigateToAddChildren() {
this.bEditChange.emit(false);
this._router.navigate([
"/",
this._configService.frontendModuleMonitoringUrl(),
"create_object",
this.obj.modulePath,
this.obj.uniqueChildrenType(),
this.obj.id,
]);
}

navigateToDetail() {
this.bEditChange.emit(false);
this._router.navigate([
"/",
this._configService.frontendModuleMonitoringUrl(),
"object",
this.obj.modulePath,
this.obj.objectType,
this.obj.id,
]);
}

navigateToParent() {
this.bEditChange.emit(false);
if (this.obj.objectType.includes("module")) {
Expand Down Expand Up @@ -198,9 +222,9 @@ export class MonitoringFormComponent implements OnInit {
return bCreation && bChoixSite && this.bChainInput;
}

onSubmit(addNew = false) {
this.bSaveSpinner = !addNew;
this.bSaveAddSpinner = addNew;
onSubmit() {
this.bSaveSpinner = !this.bChainInput;
this.bSaveAddSpinner = this.bChainInput;

// cas choix site
if (this.testChoixSite()) {
Expand All @@ -220,10 +244,12 @@ export class MonitoringFormComponent implements OnInit {
);
this.bSaveSpinner = this.bSaveAddSpinner = false;
this.objChanged.emit(this.obj);
if (addNew) {
if (this.bChainInput) {
this.resetObjForm();
} else if (this.bAddChildren){
this.navigateToAddChildren()
} else {
this.navigateToParent();
this.navigateToDetail();
}
});
}
Expand All @@ -246,7 +272,6 @@ export class MonitoringFormComponent implements OnInit {
this.obj.delete().subscribe((objData) => {
this.bDeleteSpinner = this.bDeleteModal = false;
this.objChanged.emit(this.obj);
// this.bEditChange.emit(false);
this.navigateToParent();
});
}
Expand Down

0 comments on commit f2b691d

Please sign in to comment.