Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/delete from datatable #335

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/app/class/monitoring-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export class MonitoringObject extends MonitoringObjectBase {
.getObject(this.moduleCode, this.objectType, this.id, depth);
}),
mergeMap((postData) => {
if (!bFromCache) {
this._objService.setCache(this, postData);
}
// if (!bFromCache) {
// this._objService.setCache(this, postData);
// }
return this.init(postData);
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h2>Attention</h2>
class="nav-link link cell-link"
(click)="canCreateChild ? child0.navigateToAddChildren(null, row.id, obj.siteId) : null"
[matTooltip]="
canCreateChild ? 'Ajouter' + child0.child0().labelArtUndef(true) : toolTipNotAllowed
canCreateChild ? 'Ajouter ' + child0.child0().labelArtUndef(true) : toolTipNotAllowed
"
>
<i
Expand All @@ -74,7 +74,7 @@ <h2>Attention</h2>
class="nav-link link cell-link"
(click)="row.cruved['U'] ? child0.navigateToDetail(row.id, true) : null"
[matTooltip]="
row.cruved['U'] ? 'Editer' + child0.template.label_art_def : toolTipNotAllowed
row.cruved['U'] ? 'Editer ' + child0.template.label_art_def : toolTipNotAllowed
"
>
<i
Expand All @@ -91,7 +91,7 @@ <h2>Attention</h2>
class="nav-link link cell-link"
(click)="row.cruved['D'] ? alertMessage(row) : null"
[matTooltip]="
row.cruved['D'] ? 'Supprimer' + child0.template.label_art_def : toolTipNotAllowed
row.cruved['D'] ? 'Supprimer ' + child0.template.label_art_def : toolTipNotAllowed
"
>
<i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class MonitoringDatatableComponent implements OnInit {
@Input() columns;

@Input() sorts;

@Input() obj;
@Input() child0;
@Input() frontendModuleMonitoringUrl;
Expand All @@ -36,6 +35,7 @@ export class MonitoringDatatableComponent implements OnInit {

@Input() filters: Object;
@Output() onFilter = new EventEmitter<Object>();
@Output() onDeleteRow = new EventEmitter<Object>();

@Output() bEditChanged = new EventEmitter<boolean>();

Expand Down Expand Up @@ -243,12 +243,18 @@ export class MonitoringDatatableComponent implements OnInit {
}

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)
);
this._monitoring
.dataMonitoringObjectService()
.deleteObject(this.obj.moduleCode, this.child0.objectType, row.id)
.subscribe(() => {
this._commonService.regularToaster('info', this.msgToaster('Suppression'));

this.onDeleteRow.emit({
rowSelected: row,
objectType: this.child0.objectType,
});
this.bDeleteModal = false;
});
}

alertMessage(row) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@
<div class="mt-2">
<pnx-monitoring-datatable
*ngIf="childrenDataTable && childrenDataTable[child0.objectType]"
(bEditChanged)="onbEditChanged($event)"
(bEditChanged)="onbEditChanged($event)"
[rows]="childrenDataTable[child0.objectType]['rows']"
[columns]="childrenDataTable[child0.objectType]['columns']"
[frontendModuleMonitoringUrl]="frontendModuleMonitoringUrl"
(rowStatusChange)="onSelectedChildren(child0.objectType, $event)"
[(filters)]="filters"
(onFilter)="onFilterChange(child0.objectType, $event)"
(onDeleteRow)="onDeleteRowChange($event)"
[child0]="child0"
[obj]="obj"
[(obj)]="obj"
[sorts]="child0.configParam('sorts')"
[currentUser]="currentUser"
></pnx-monitoring-datatable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ export class MonitoringListComponent implements OnInit {
@Input() currentUser;
@Input() filters;
@Output() filtersChange: EventEmitter<Object> = new EventEmitter<Object>();

@Input() forceReload;
@Output() forceReloadChange = new EventEmitter<boolean>();

@Input() objectListType: string;
@Output() objectListTypeChange: EventEmitter<string> = new EventEmitter<string>();

@Input() selectedObject;
@Output() selectedObjectChange: EventEmitter<string> = new EventEmitter<string>();

@Output() onDeleteRow: EventEmitter<Object> = new EventEmitter<Object>();

activetab: string;
nbVisibleRows: Record<string, number> = {};
frontendModuleMonitoringUrl;
Expand Down Expand Up @@ -104,6 +110,10 @@ export class MonitoringListComponent implements OnInit {
this.nbVisibleRows[type] = nb_row;
}

onDeleteRowChange(event) {
this.onDeleteRow.emit(event);
}

changeActiveTab(typeObject, tab) {
this.activetab = this.children0Array[typeObject['index']];
// Réinitialisation des données selectés
Expand Down Expand Up @@ -135,6 +145,13 @@ export class MonitoringListComponent implements OnInit {
case 'obj':
this.initDataTable();
break;
case 'forceReload':
if (cur == true) {
this.initDataTable();
this.forceReload = false;
this.forceReloadChange.emit(false);
}
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ <h2>Chargement en cours</h2>
<pnx-monitoring-form [obj]="obj" (objChanged)="onObjChanged($event)" *ngIf="bEdit && obj?.bIsInitialized"
[(bEdit)]="bEdit" [objForm]="objForm" [currentUser]="currentUser"></pnx-monitoring-form>

<pnx-monitoring-lists [obj]="obj" [(bEdit)]="bEdit" [(filters)]="filters"
<pnx-monitoring-lists [(obj)]="obj" [(bEdit)]="bEdit" [(filters)]="filters"
[(objectListType)]="objectListType" *ngIf="!bEdit && obj && obj.bIsInitialized && moduleSet"
[(selectedObject)] = "selectedObject"
[(selectedObject)] = "selectedObject"
[(forceReload)] = "forceReload"
(onDeleteRow) = "onDeleteRowChange($event)"
[currentUser]="currentUser"></pnx-monitoring-lists>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class MonitoringObjectComponent implements OnInit {
pre_filters: Object = {};
selectedObject: Object = undefined;
objectListType: string;
forceReload: boolean = false;

backendUrl: string;
frontendModuleMonitoringUrl: string;
Expand Down Expand Up @@ -125,7 +126,6 @@ export class MonitoringObjectComponent implements OnInit {
(!this.obj.id && !!this.obj.parentId);
this.bLoadingModal = false; // fermeture du modal
this.obj.bIsInitialized = true; // obj initialisé
this.evenListnerTable();
});
}

Expand Down Expand Up @@ -279,37 +279,10 @@ export class MonitoringObjectComponent implements OnInit {
this.getModuleSet().subscribe();
}

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._evtObjService.changeDisplayingDeleteModal(false);
});
onDeleteRowChange(event) {
this.getDataObject().subscribe((obj) => {
this.forceReload = true;
this.onObjChanged(obj);
});
}
}
3 changes: 2 additions & 1 deletion frontend/app/services/data-monitoring-object.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ export class DataMonitoringObjectService {
* @param objectType le type de l'objet (site, visit, observation, ...)
* @param id l'identifiant de l'objet
*/
deleteObject(moduleCode, objectType, id) {
deleteObject(moduleCode, objectType, id): Observable<any> {
const url = this.urlMonitoring('object', moduleCode, objectType, id);

return this._cacheService.request('delete', url);
}

Expand Down
14 changes: 0 additions & 14 deletions frontend/app/services/object.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ export class ObjectService {
private dataListOption = new ReplaySubject<SelectObject[]>(1);
currentListOption = this.dataListOption.asObservable();

private rowSelected = new ReplaySubject<Object>(1);
currentRowSelected = this.rowSelected.asObservable();

private deleteModal = new ReplaySubject<boolean>(1);
currentDeleteModal = this.deleteModal.asObservable();

constructor() {
let storedObjectType = localStorage.getItem('storedObjectType');
let storedObjectTypeParent = localStorage.getItem('storedObjectTypeParent');
Expand Down Expand Up @@ -85,12 +79,4 @@ export class ObjectService {
changeListOption(newListOption: SelectObject[]) {
this.dataListOption.next(newListOption);
}

changeSelectRow(rowSelected) {
this.rowSelected.next(rowSelected);
}

changeDisplayingDeleteModal(isModal: boolean) {
this.deleteModal.next(isModal);
}
}
Loading