|
|
|
@@ -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<any>; |
|
|
|
@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 { |
|
|
|
|