+
+
+
+
+
+
+
+
diff --git a/frontend/app/components/monitoring-datatable/monitoring-datatable.component.ts b/frontend/app/components/monitoring-datatable/monitoring-datatable.component.ts
index 8784b6b35..efacdbc12 100644
--- a/frontend/app/components/monitoring-datatable/monitoring-datatable.component.ts
+++ b/frontend/app/components/monitoring-datatable/monitoring-datatable.component.ts
@@ -13,6 +13,8 @@ import { Router } from '@angular/router';
import { MonitoringObjectService } from './../../services/monitoring-object.service';
import { Subject } from 'rxjs';
import { catchError, map, tap, take, debounceTime } from 'rxjs/operators';
+import { CommonService } from '@geonature_common/service/common.service';
+import { ObjectService } from '../../services/object.service';
@Component({
selector: 'pnx-monitoring-datatable',
@@ -48,7 +50,15 @@ export class MonitoringDatatableComponent implements OnInit {
@ViewChild('actionsTemplate') actionsTemplate: TemplateRef
;
@ViewChild('hdrTpl') hdrTpl: TemplateRef;
- constructor(private _monitoring: MonitoringObjectService) {}
+ rowSelected;
+ bDeleteModal: boolean = false;
+ bDeleteSpinner: boolean = false;
+
+ constructor(
+ private _monitoring: MonitoringObjectService,
+ private _commonService: CommonService,
+ private _objectService: ObjectService
+ ) {}
ngOnInit() {
this.initDatatable();
@@ -234,4 +244,23 @@ export class MonitoringDatatableComponent implements OnInit {
return out;
};
}
+
+ msgToaster(action) {
+ // return `${action} ${this.obj.labelDu()} ${this.obj.description()} effectuée`.trim();
+ return `${action} effectuée`.trim();
+ }
+
+ onDelete(row) {
+ this._commonService.regularToaster('info', this.msgToaster('Suppression'));
+ this._objectService.changeDisplayingDeleteModal(this.bDeleteModal);
+ this._objectService.changeSelectRow({ rowSelected: row, objectType: this.child0.objectType });
+ this._objectService.currentDeleteModal.subscribe(
+ (deletedModal) => (this.bDeleteModal = deletedModal)
+ );
+ }
+
+ alertMessage(row) {
+ this.rowSelected = row;
+ this.bDeleteModal = true;
+ }
}
diff --git a/frontend/app/components/monitoring-object/monitoring-object.component.ts b/frontend/app/components/monitoring-object/monitoring-object.component.ts
index 80f28cb74..0e804c9e4 100644
--- a/frontend/app/components/monitoring-object/monitoring-object.component.ts
+++ b/frontend/app/components/monitoring-object/monitoring-object.component.ts
@@ -1,5 +1,15 @@
import { Observable, of, forkJoin } from 'rxjs';
-import { mergeMap, concatMap } from 'rxjs/operators';
+import {
+ mergeMap,
+ concatMap,
+ map,
+ tap,
+ take,
+ takeUntil,
+ distinctUntilChanged,
+ catchError,
+ skipWhile,
+} from 'rxjs/operators';
import { MonitoringObject } from '../../class/monitoring-object';
import { Component, OnInit } from '@angular/core';
@@ -13,6 +23,7 @@ import { DataUtilsService } from '../../services/data-utils.service';
import { AuthService, User } from '@geonature/components/auth/auth.service';
import { CommonService } from '@geonature_common/service/common.service';
import { MapService } from '@geonature_common/map/map.service';
+import { ObjectService } from '../../services/object.service';
import { Utils } from '../../utils/utils';
@Component({
@@ -41,6 +52,7 @@ export class MonitoringObjectComponent implements OnInit {
heightMap;
moduleSet = false;
+ bDeleteModal = false;
constructor(
private _route: ActivatedRoute,
@@ -50,7 +62,8 @@ export class MonitoringObjectComponent implements OnInit {
private _formBuilder: FormBuilder,
public mapservice: MapService,
private _auth: AuthService,
- private _commonService: CommonService
+ private _commonService: CommonService,
+ private _evtObjService: ObjectService
) {}
ngAfterViewInit() {
@@ -91,7 +104,7 @@ export class MonitoringObjectComponent implements OnInit {
.subscribe(() => {
this.obj.initTemplate(); // pour le html
- this.bEdit = this.checkEditParam ? true : false;
+ this.bEdit = this.checkEditParam == true ? true : false;
// si on est sur une création (pas d'id et id_parent ou pas de module_code pour module (root))
this.bEdit =
this.bEdit ||
@@ -105,6 +118,8 @@ export class MonitoringObjectComponent implements OnInit {
} else {
this.initObjectsStatus();
}
+
+ this.evenListnerTable();
});
}
@@ -231,7 +246,11 @@ export class MonitoringObjectComponent implements OnInit {
);
this.objForm = this._formBuilder.group({});
- this.checkEditParam = params.get('edit') ? true : false;
+ if (params.get('edit')) {
+ this.checkEditParam = Boolean(params.get('edit'));
+ } else {
+ this.checkEditParam = false;
+ }
// query param snapshot
// this.obj.parentId = params.get('parentId') && parseInt(params.get('parentId'));
@@ -281,4 +300,40 @@ export class MonitoringObjectComponent implements OnInit {
}
this.getModuleSet();
}
+
+ onDeleteFromTable(event) {
+ return this._objService
+ .dataMonitoringObjectService()
+ .deleteObject(this.obj.moduleCode, event.objectType, event.rowSelected.id);
+ }
+
+ evenListnerTable() {
+ const $displayModal = this._evtObjService.currentDeleteModal;
+ const $rowSelected = this._evtObjService.currentRowSelected;
+
+ $displayModal
+ .pipe(
+ distinctUntilChanged((prev, curr) => prev === curr),
+ tap((displayModal) => {
+ this.bDeleteModal = displayModal;
+ }),
+ concatMap(() => {
+ return $rowSelected;
+ }),
+ concatMap((rowSelected) => {
+ return this.onDeleteFromTable(rowSelected).pipe(
+ distinctUntilChanged((prev, curr) => prev.rowSelected === curr.rowSelected)
+ );
+ }),
+ catchError((err) => {
+ console.log(err);
+ this._evtObjService.changeDisplayingDeleteModal(false);
+ return of(null);
+ })
+ )
+ .subscribe((deletedObj) => {
+ this.initSites();
+ this._evtObjService.changeDisplayingDeleteModal(false);
+ });
+ }
}
diff --git a/frontend/app/components/monitoring-visits/monitoring-visits.component.html b/frontend/app/components/monitoring-visits/monitoring-visits.component.html
index 0cff88400..1b260163f 100644
--- a/frontend/app/components/monitoring-visits/monitoring-visits.component.html
+++ b/frontend/app/components/monitoring-visits/monitoring-visits.component.html
@@ -49,6 +49,8 @@
[obj]="visits"
(onDetailsRow)="seeDetails($event)"
(onEditEvent)="editChild($event)"
+ (onDeleteEvent)="onDelete($event)"
+ [bDeleteModalEmitter]="bDeleteModalEmitter"
>
();
+
private destroyed$: ReplaySubject = new ReplaySubject(1);
constructor(
@@ -73,7 +76,8 @@ export class MonitoringVisitsComponent extends MonitoringGeomComponent implement
private _formService: FormService,
private _configService: ConfigService,
public siteService: SitesService,
- protected _configJsonService: ConfigJsonService
+ protected _configJsonService: ConfigJsonService,
+ private _objServiceMonitoring: DataMonitoringObjectService
) {
super();
this.getAllItemsCallback = this.getVisits;
@@ -271,13 +275,14 @@ export class MonitoringVisitsComponent extends MonitoringGeomComponent implement
}
// TODO: voir s'il faut pouvoir supprimer les visites depuis l'entrée par sites
- // onDelete($event){
- // this._objServiceMonitoring
- // .deleteObject($event.rowSelected.module.module_code,$event.objectType, $event.rowSelected.id).subscribe(del =>{
- // this.bDeleteModalEmitter.emit(false);
- // this.initSiteVisit()
- // });
- // }
+ onDelete($event) {
+ this._objServiceMonitoring
+ .deleteObject($event.rowSelected.module.module_code, $event.objectType, $event.rowSelected.id)
+ .subscribe((del) => {
+ this.bDeleteModalEmitter.emit(false);
+ this.initSiteVisit();
+ });
+ }
partialfuncToFilt(
pageNumber: number,
diff --git a/frontend/app/services/monitoring-object.service.ts b/frontend/app/services/monitoring-object.service.ts
index cf20167b5..78d8100f1 100644
--- a/frontend/app/services/monitoring-object.service.ts
+++ b/frontend/app/services/monitoring-object.service.ts
@@ -282,6 +282,12 @@ export class MonitoringObjectService {
}
navigate(routeType, moduleCode, objectType, id, queryParams = {}) {
+ let editParams = '';
+ if ('edit' in queryParams && queryParams.edit == true) {
+ editParams = 'true';
+ delete queryParams.edit;
+ }
+
this._router.navigate(
[
this._configService.frontendModuleMonitoringUrl(),
@@ -289,6 +295,7 @@ export class MonitoringObjectService {
moduleCode,
objectType,
id,
+ { edit: editParams },
].filter((s) => !!s),
{
queryParams,
diff --git a/frontend/app/services/object.service.ts b/frontend/app/services/object.service.ts
index 1647cf9ba..119b2b73d 100644
--- a/frontend/app/services/object.service.ts
+++ b/frontend/app/services/object.service.ts
@@ -25,6 +25,12 @@ export class ObjectService {
private dataListOption = new ReplaySubject(1);
currentListOption = this.dataListOption.asObservable();
+ private rowSelected = new ReplaySubject