154 lines
5.2 KiB
TypeScript
154 lines
5.2 KiB
TypeScript
import { DataSource } from '@angular/cdk/table';
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
import { MatSort } from '@angular/material/sort';
|
|
import { DescriptionTemplateTypeService } from '@app/core/services/description-template-type/description-template-type.service';
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { merge as observableMerge, Observable, of } from 'rxjs';
|
|
import { map, startWith, switchMap, takeUntil } from 'rxjs/operators';
|
|
|
|
@Component({
|
|
selector: 'app-description-types',
|
|
templateUrl: './description-types.component.html',
|
|
styleUrls: ['./description-types.component.scss']
|
|
})
|
|
export class DescriptionTypesComponent extends BaseComponent implements OnInit {
|
|
|
|
@ViewChild(MatPaginator, { static: true }) _paginator: MatPaginator;
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
|
|
dataSource: DescriptionTypesDataSource | null;
|
|
displayedColumns: String[] = ['label', 'status', 'delete'];
|
|
|
|
constructor(
|
|
private descriptionTemplateTypeService: DescriptionTemplateTypeService,
|
|
private dialog: MatDialog,
|
|
private language: TranslateService,
|
|
private uiNotificationService: UiNotificationService
|
|
) {
|
|
super();
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.refresh();
|
|
}
|
|
|
|
refresh() {
|
|
this.dataSource = new DescriptionTypesDataSource(this.descriptionTemplateTypeService, this._paginator, this.sort/*, this.criteria*/);
|
|
}
|
|
|
|
deleteTemplate(id: string){
|
|
if(id){
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
restoreFocus: false,
|
|
data: {
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
isDeleteConfirmation: true
|
|
}
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
if (result) {
|
|
// this.descriptionTemplateTypeService.deleteType(id)
|
|
// .pipe(takeUntil(this._destroyed))
|
|
// .subscribe(
|
|
// complete => {
|
|
// this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Success);
|
|
// this.refresh();
|
|
// },
|
|
// error => {
|
|
// this.onCallbackError(error);
|
|
// if (error.error.statusCode == 674) {
|
|
// this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Error);
|
|
// } else {
|
|
// this.uiNotificationService.snackBarNotification(this.language.instant(error.message), SnackBarNotificationLevel.Error);
|
|
// }
|
|
// }
|
|
// );
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DESCRIPTION-TEMPLATE-TYPE-DELETE'), SnackBarNotificationLevel.Error);
|
|
this.refresh();
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
onCallbackError(errorResponse: HttpErrorResponse) {
|
|
this.uiNotificationService.snackBarNotification(errorResponse.message, SnackBarNotificationLevel.Warning);
|
|
}
|
|
|
|
getStatusClass(status: number): string {
|
|
|
|
if(status == 1){
|
|
return 'status-chip-finalized'
|
|
}
|
|
|
|
return 'status-chip-draft';
|
|
}
|
|
|
|
}
|
|
|
|
export interface DescriptionTemplateTypeListingModel {
|
|
id: string;
|
|
name: string;
|
|
status: number;
|
|
}
|
|
|
|
export class DescriptionTypesDataSource extends DataSource<DescriptionTemplateTypeListingModel> {
|
|
|
|
totalCount = 0;
|
|
|
|
constructor(
|
|
private _service: DescriptionTemplateTypeService,
|
|
private _paginator: MatPaginator,
|
|
private _sort: MatSort//,
|
|
//private _criteria: DmpProfileCriteriaComponent
|
|
) {
|
|
super();
|
|
|
|
}
|
|
|
|
connect(): Observable<DescriptionTemplateTypeListingModel[]> {
|
|
const displayDataChanges = [
|
|
this._paginator.page
|
|
//this._sort.matSortChange
|
|
];
|
|
|
|
// return observableMerge(...displayDataChanges).pipe(
|
|
// startWith(null),
|
|
// switchMap(() => {
|
|
// // const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
|
|
// // let fields: Array<string> = new Array();
|
|
// // if (this._sort.active) { fields = this._sort.direction === 'asc' ? ['+' + this._sort.active] : ['-' + this._sort.active]; }
|
|
// // const request = new DataTableRequest<DmpProfileCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
|
// // request.criteria = this._criteria.criteria;
|
|
// // return this._service.getPaged(request);
|
|
|
|
// return this._service.getTypes();
|
|
// }),
|
|
// map(result => {
|
|
// return result;
|
|
// }),
|
|
// map(result => {
|
|
// // if (!result) { return []; }
|
|
// // if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
// // return result.data;
|
|
// return result;
|
|
// }));
|
|
|
|
return of([{id: '1234', name: 'Dataset', status: 0}]);
|
|
}
|
|
|
|
disconnect() {
|
|
// No-op
|
|
}
|
|
}
|