2019-09-23 10:17:03 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
import { DataSource } from '@angular/cdk/table';
|
2020-12-14 18:28:13 +01:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2021-06-22 12:00:58 +02:00
|
|
|
import { MatDialog } from '@angular/material';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatPaginator, PageEvent } from '@angular/material/paginator';
|
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
2021-06-22 12:00:58 +02:00
|
|
|
import { DmpStatus } from '@app/core/common/enum/dmp-status';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
|
|
import { DmpProfileListing } from '@app/core/model/dmp-profile/dmp-profile-listing';
|
|
|
|
import { DmpProfileCriteria } from '@app/core/query/dmp/dmp-profile-criteria';
|
|
|
|
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
|
2020-12-14 18:28:13 +01:00
|
|
|
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DmpProfileCriteriaComponent } from '@app/ui/admin/dmp-profile/listing/criteria/dmp-profile-criteria.component';
|
|
|
|
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { merge as observableMerge, Observable, of as observableOf } from 'rxjs';
|
|
|
|
import { map, startWith, switchMap, takeUntil } from 'rxjs/operators';
|
2021-06-22 12:00:58 +02:00
|
|
|
import { DialodConfirmationUploadDmpProfiles } from './criteria/dialog-confirmation-upload-profile/dialog-confirmation-upload-profiles.component';
|
2019-12-11 15:51:03 +01:00
|
|
|
|
2018-03-28 15:24:47 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-dmp-profile-listing-component',
|
|
|
|
templateUrl: 'dmp-profile-listing.component.html',
|
2019-01-18 18:03:45 +01:00
|
|
|
styleUrls: ['./dmp-profile-listing.component.scss']
|
2018-03-28 15:24:47 +02:00
|
|
|
})
|
2019-01-18 18:03:45 +01:00
|
|
|
export class DmpProfileListingComponent extends BaseComponent implements OnInit {
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
@ViewChild(MatPaginator, { static: true }) _paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
|
|
@ViewChild(DmpProfileCriteriaComponent, { static: true }) criteria: DmpProfileCriteriaComponent;
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
dataSource: DatasetDataSource | null;
|
|
|
|
displayedColumns: String[] = ['label', 'status', 'created'];
|
|
|
|
pageEvent: PageEvent;
|
|
|
|
titlePrefix: String;
|
|
|
|
dmpId: String;
|
2019-05-23 11:40:24 +02:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
statuses = [
|
2021-06-22 12:00:58 +02:00
|
|
|
{ value: '0', viewValue: 'DMP-PROFILE-LISTING.STATUS.ACTIVE' },// active
|
|
|
|
{ value: '1', viewValue: 'DMP-PROFILE-LISTING.STATUS.INACTIVE' }// inactive
|
2018-10-05 17:00:54 +02:00
|
|
|
];
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private languageService: TranslateService,
|
|
|
|
public snackBar: MatSnackBar,
|
|
|
|
public route: ActivatedRoute,
|
2020-12-14 18:28:13 +01:00
|
|
|
public dmpProfileService: DmpProfileService,
|
|
|
|
private httpClient: HttpClient,
|
2021-06-22 12:00:58 +02:00
|
|
|
private matomoService: MatomoService,
|
|
|
|
private dialog: MatDialog,
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
2018-11-27 18:33:17 +01:00
|
|
|
super();
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnInit() {
|
2020-12-14 18:28:13 +01:00
|
|
|
this.matomoService.trackPageView('Admin: DMP Templates');
|
2018-11-27 18:33:17 +01:00
|
|
|
this.route.params
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe((params: Params) => {
|
|
|
|
this.dmpId = params['dmpId'];
|
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria());
|
|
|
|
this.refresh();
|
|
|
|
this.criteria.setRefreshCallback(() => this.refresh());
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([{
|
2019-05-23 11:40:24 +02:00
|
|
|
parentComponentName: null,
|
|
|
|
label: this.languageService.instant('NAV-BAR.DMP-TEMPLATES'),
|
|
|
|
url: '/dmp-profiles'
|
|
|
|
}]);
|
2018-11-27 18:33:17 +01:00
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
refresh() {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dataSource = new DatasetDataSource(this.dmpProfileService, this._paginator, this.sort, this.criteria);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
rowClick(rowId: String) {
|
|
|
|
this.router.navigate(['dmp-profiles/' + rowId]);
|
|
|
|
}
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
getDefaultCriteria(): DmpProfileCriteria {
|
|
|
|
const defaultCriteria = new DmpProfileCriteria();
|
2018-10-05 17:00:54 +02:00
|
|
|
return defaultCriteria;
|
|
|
|
}
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
// makeItPublic(id: String) {
|
|
|
|
// debugger;
|
2018-11-27 18:33:17 +01:00
|
|
|
// this.datasetService.makeDatasetPublic(id).pipe(takeUntil(this._destroyed)).subscribe();
|
2018-10-05 17:00:54 +02:00
|
|
|
// }
|
2021-06-22 12:00:58 +02:00
|
|
|
|
|
|
|
parseStatus(value: number): string{
|
|
|
|
const stringVal = value.toString()
|
|
|
|
try{
|
|
|
|
return this.statuses.find(status => status.value === stringVal).viewValue;
|
|
|
|
}catch{
|
|
|
|
return stringVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
openDialog(): void {
|
|
|
|
const dialogRef = this.dialog.open(DialodConfirmationUploadDmpProfiles, {
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
message: this.languageService.instant('DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML-FILE-TITLE'),
|
|
|
|
confirmButton: this.languageService.instant('DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML'),
|
|
|
|
cancelButton: this.languageService.instant('DMP-PROFILE-LISTING.UPLOAD.UPLOAD-XML-FILE-CANCEL'),
|
|
|
|
name: '',
|
|
|
|
file: FileList,
|
|
|
|
sucsess: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(data => {
|
|
|
|
if (data && data.sucsess && data.name != null && data.file != null) {
|
|
|
|
this.dmpProfileService.uploadFile(data.file, data.name)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getStatusClass(status: number):string{
|
|
|
|
|
|
|
|
if(status === 1){//inactive
|
|
|
|
return 'status-chip-inactive'
|
|
|
|
}
|
|
|
|
if(status === 0){
|
|
|
|
return 'status-chip-active';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2018-03-28 15:24:47 +02:00
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
export class DatasetDataSource extends DataSource<DmpProfileListing> {
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
totalCount = 0;
|
|
|
|
|
|
|
|
constructor(
|
2019-01-18 18:03:45 +01:00
|
|
|
private _service: DmpProfileService,
|
2018-10-05 17:00:54 +02:00
|
|
|
private _paginator: MatPaginator,
|
|
|
|
private _sort: MatSort,
|
2019-01-18 18:03:45 +01:00
|
|
|
private _criteria: DmpProfileCriteriaComponent
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
connect(): Observable<DmpProfileListing[]> {
|
2018-10-05 17:00:54 +02:00
|
|
|
const displayDataChanges = [
|
|
|
|
this._paginator.page
|
|
|
|
//this._sort.matSortChange
|
|
|
|
];
|
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
return observableMerge(...displayDataChanges).pipe(
|
|
|
|
startWith(null),
|
|
|
|
switchMap(() => {
|
2018-10-05 17:00:54 +02:00
|
|
|
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]; }
|
2019-01-18 18:03:45 +01:00
|
|
|
const request = new DataTableRequest<DmpProfileCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
2018-10-05 17:00:54 +02:00
|
|
|
request.criteria = this._criteria.criteria;
|
|
|
|
return this._service.getPaged(request);
|
2019-09-23 10:17:03 +02:00
|
|
|
}),
|
2018-10-05 17:00:54 +02:00
|
|
|
/*.catch((error: any) => {
|
2018-03-28 15:24:47 +02:00
|
|
|
this._snackBar.openFromComponent(SnackBarNotificationComponent, {
|
|
|
|
data: { message: 'GENERAL.SNACK-BAR.FORMS-BAD-REQUEST', language: this._languageService },
|
|
|
|
duration: 3000,
|
|
|
|
extraClasses: ['snackbar-warning']
|
|
|
|
});
|
|
|
|
//this._criteria.criteria.onCallbackError(error);
|
|
|
|
return Observable.of(null);
|
|
|
|
})*/
|
2019-09-23 10:17:03 +02:00
|
|
|
map(result => {
|
2018-10-05 17:00:54 +02:00
|
|
|
return result;
|
2019-09-23 10:17:03 +02:00
|
|
|
}),
|
|
|
|
map(result => {
|
2018-10-05 17:00:54 +02:00
|
|
|
if (!result) { return []; }
|
|
|
|
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
|
|
return result.data;
|
2019-12-11 15:51:03 +01:00
|
|
|
}));
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
disconnect() {
|
|
|
|
// No-op
|
|
|
|
}
|
|
|
|
}
|