diff --git a/angular/src/app/_components/list/list.component.html b/angular/src/app/_components/list/list.component.html index 5ce0655..e166b63 100644 --- a/angular/src/app/_components/list/list.component.html +++ b/angular/src/app/_components/list/list.component.html @@ -90,11 +90,11 @@ - + - + diff --git a/angular/src/app/_components/list/list.component.ts b/angular/src/app/_components/list/list.component.ts index f9bd4dd..4028c61 100644 --- a/angular/src/app/_components/list/list.component.ts +++ b/angular/src/app/_components/list/list.component.ts @@ -8,8 +8,9 @@ import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-funct import {ListUpdateElementFunctionType} from "@app/_components/list/list-update-element-function-type"; import {FilterBarComponent} from "@app/_components/filter-bar/filter-bar.component"; import { Router } from '@angular/router'; -import {interval, Subscription} from "rxjs"; +import {interval, Observable, Subscription} from "rxjs"; import {AbstractDataFormComponent} from "@app/_components/_abstract/abstract-data-form-component"; +import {TranslateService} from "@ngx-translate/core"; @Component({ selector: 'app-list', @@ -23,8 +24,8 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { @Input() public onSortFunction?: Function; @Input() public onNavigateToDetailsFunction!: Function; @Input() public getCustomDetailLinkFunction!: Function; - @Input() public onRemoveItemFunction!: Function; - @Input() public onEditFunction!: Function; + @Input() public deleteItemFunction?: (id: string) => Observable; + @Input() public onEditItemFunction!: Function; @Input() public onDownloadFunction!: Function; @Input() public onRowSelectedFunction!: Function; @Input() public onUpdateBooleanStateFunction!: ListUpdateElementFunctionType; @@ -83,6 +84,7 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { constructor( protected appHelperService: AppHelperService, private router: Router, + protected translateService: TranslateService ) { this.searchable = true; this.showPosition = true; @@ -105,12 +107,12 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { if (this.showPosition) { this.listColDefinitions.unshift(ListComponent.getDefaultColPosition()); } - if (this.showEditButton) { - this.listColDefinitions.unshift(ListComponent.getDefaultColEditBtn()); - } - if (this.showRemoveButton) { + if (this.deleteItemFunction && this.showRemoveButton) { this.listColDefinitions.unshift(ListComponent.getDefaultRemoveBtn()); } + if (this.dataFormComponent && this.showEditButton) { + this.listColDefinitions.unshift(ListComponent.getDefaultColEditBtn()); + } if (this.showDetailButton) { const url = this.getCustomDetailLinkFunction !== undefined ? '' : this.router.routerState.snapshot.url; this.listColDefinitions.unshift(ListComponent.getDefaultColDetailBtnLink(url)); @@ -431,17 +433,41 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { ); } - public onEditData(element: any) { - // Create a new object instead of modifying the existing one - this.dataFormComponentData = { - ...this.dataFormComponentData, - data: element - }; - this.appHelperService.openModal( - this.dataFormComponent, - this.dataFormComponentData, - this.getData - ); + public onEditItem(element: any) { + if (this.onEditItemFunction) { + this.onEditItemFunction(element); + } else { + // Default edit + // Create a new object instead of modifying the existing one + this.dataFormComponentData = { + ...this.dataFormComponentData, + data: element + }; + this.appHelperService.openModal( + this.dataFormComponent, + this.dataFormComponentData, + this.getData + ); + } + } + + public onDeleteItem(element: any) { + const deleteFunction = this.deleteItemFunction; + if (deleteFunction) { + this.translateService.get('basic.delete_confirm_related').subscribe((confirmMessage: string) => { + if (confirm(confirmMessage)) { + deleteFunction(element.dbId).subscribe({ + next: () => { + this.getData(); + }, + error: (error: any) => { + console.error('Delete error:', error); + alert('Error while deleting dataset (there might be related data)'); + } + }); + } + }); + } } public getFilterJsonString(): any { diff --git a/angular/src/app/_views/location/location-list/location-list.component.html b/angular/src/app/_views/location/location-list/location-list.component.html index 0bf66eb..e12af86 100644 --- a/angular/src/app/_views/location/location-list/location-list.component.html +++ b/angular/src/app/_views/location/location-list/location-list.component.html @@ -2,6 +2,7 @@ Observable { + return (id: string) => this.locationService.locationsIdDelete(id); + } } diff --git a/angular/src/app/_views/shipping-company/shipping-company-list/shipping-company-list.component.html b/angular/src/app/_views/shipping-company/shipping-company-list/shipping-company-list.component.html index 4184e43..a4a1ea8 100644 --- a/angular/src/app/_views/shipping-company/shipping-company-list/shipping-company-list.component.html +++ b/angular/src/app/_views/shipping-company/shipping-company-list/shipping-company-list.component.html @@ -2,6 +2,7 @@ Observable { + return (id: string) => this.shippingCompanyService.shippingCompaniesIdDelete(id); + } + getCustomDetailLink(element: LocationJsonld) { return ROUTE_SHIPPING_COMPANIES + '/' + this.appHelperService.extractId(element?.id); } diff --git a/angular/src/app/_views/trip/trip-list/trip-list.component.html b/angular/src/app/_views/trip/trip-list/trip-list.component.html index 4b6c65f..3806ec5 100644 --- a/angular/src/app/_views/trip/trip-list/trip-list.component.html +++ b/angular/src/app/_views/trip/trip-list/trip-list.component.html @@ -1,8 +1,8 @@
diff --git a/angular/src/app/_views/trip/trip-list/trip-list.component.ts b/angular/src/app/_views/trip/trip-list/trip-list.component.ts index 23d43fb..6f6b267 100644 --- a/angular/src/app/_views/trip/trip-list/trip-list.component.ts +++ b/angular/src/app/_views/trip/trip-list/trip-list.component.ts @@ -6,6 +6,7 @@ import {TripService} from "@app/core/api/v1"; import {AppHelperService} from "@app/_helpers/app-helper.service"; import {FilterBarComponent} from "@app/_components/filter-bar/filter-bar.component"; import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; +import {Observable} from "rxjs"; @Component({ selector: 'app-trip-list', @@ -116,4 +117,7 @@ export class TripListComponent { ); } + get deleteItemFunction(): (id: string) => Observable { + return (id: string) => this.tripService.tripsIdDelete(id); + } } diff --git a/angular/src/app/_views/trip/trip-location-list/trip-location-list.component.html b/angular/src/app/_views/trip/trip-location-list/trip-location-list.component.html index b7fecb1..9ad12b9 100644 --- a/angular/src/app/_views/trip/trip-location-list/trip-location-list.component.html +++ b/angular/src/app/_views/trip/trip-location-list/trip-location-list.component.html @@ -1,10 +1,11 @@
\ No newline at end of file diff --git a/angular/src/app/_views/trip/trip-location-list/trip-location-list.component.ts b/angular/src/app/_views/trip/trip-location-list/trip-location-list.component.ts index 3531e82..b537191 100644 --- a/angular/src/app/_views/trip/trip-location-list/trip-location-list.component.ts +++ b/angular/src/app/_views/trip/trip-location-list/trip-location-list.component.ts @@ -7,6 +7,7 @@ import {FilterBarComponent} from "@app/_components/filter-bar/filter-bar.compone import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type"; import {TripLocationFormComponent} from "@app/_views/trip/trip-location-form/trip-location-form.component"; import {map, tap} from "rxjs/operators"; +import {Observable} from "rxjs"; @Component({ selector: 'app-trip-location-list', @@ -23,7 +24,7 @@ export class TripLocationListComponent { protected dataFormComponentData: any; constructor( - private tripLocationService: TripLocationService, + public tripLocationService: TripLocationService, protected appHelperService: AppHelperService, ) { this.listColDefinitions = [ @@ -124,4 +125,8 @@ export class TripLocationListComponent { }) ); } + + get deleteItemFunction(): (id: string) => Observable { + return (id: string) => this.tripLocationService.tripLocationsIdDelete(id); + } } diff --git a/angular/src/app/_views/vessel/vessel-list/vessel-list.component.html b/angular/src/app/_views/vessel/vessel-list/vessel-list.component.html index d98a3c0..7e08431 100644 --- a/angular/src/app/_views/vessel/vessel-list/vessel-list.component.html +++ b/angular/src/app/_views/vessel/vessel-list/vessel-list.component.html @@ -2,6 +2,7 @@ Observable { + return (id: string) => this.vesselService.vesselsIdDelete(id); + } + getCustomDetailLink(element: ZoneJsonld) { return ROUTE_VESSELS + '/' + this.appHelperService.extractId(element?.id); } diff --git a/angular/src/app/_views/zone/zone-list/zone-list.component.html b/angular/src/app/_views/zone/zone-list/zone-list.component.html index 9b90230..7c6cdfb 100644 --- a/angular/src/app/_views/zone/zone-list/zone-list.component.html +++ b/angular/src/app/_views/zone/zone-list/zone-list.component.html @@ -2,6 +2,7 @@ Observable { + return (id: string) => this.zoneService.zonesIdDelete(id); + } + getCustomDetailLink(element: ZoneJsonld) { return ROUTE_ZONES + '/' + this.appHelperService.extractId(element?.id); }