You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
5.2 KiB
TypeScript
160 lines
5.2 KiB
TypeScript
import { DataSource } from '@angular/cdk/table';
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { MatPaginator, MatSnackBar, MatSort, PageEvent } from '@angular/material';
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { Observable } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
import { BaseComponent } from '../../core/common/base/base.component';
|
|
import { DatasetProfileCriteria } from '../../models/criteria/dataset-profile/DatasetProfileCriteria';
|
|
import { DataManagementPlanModel } from '../../models/data-managemnt-plans/DataManagementPlanModel';
|
|
import { DataTableRequest } from '../../models/data-table/DataTableRequest';
|
|
import { DatasetListingModel } from '../../models/datasets/DatasetListingModel';
|
|
import { DataManagementPlanService } from '../../services/data-management-plan/data-management-plan.service';
|
|
import { DatasetProfileAdmin } from '../../services/datasetProfileAdmin/datasetProfileAfmin.service';
|
|
import { DatasetProfileCriteriaComponent } from '../../shared/components/criteria/dataset-profile/dataset-profile.component';
|
|
|
|
@Component({
|
|
selector: 'app-dataset-profile-admin-listing-component',
|
|
templateUrl: 'dataset-profile-admin-listing.component.html',
|
|
styleUrls: ['./dataset-profile-admin-listing.component.scss'],
|
|
providers: [DatasetProfileAdmin, DataManagementPlanService]
|
|
})
|
|
export class DatasetProfileAdminListingComponent extends BaseComponent implements OnInit {
|
|
|
|
@ViewChild(MatPaginator) _paginator: MatPaginator;
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
@ViewChild(DatasetProfileCriteriaComponent) criteria: DatasetProfileCriteriaComponent;
|
|
|
|
|
|
dataSource: DatasetDataSource | null;
|
|
displayedColumns: String[] = ['label', 'description', 'created', 'actions'];
|
|
pageEvent: PageEvent;
|
|
titlePrefix: String;
|
|
dmpId: String;
|
|
|
|
statuses = [
|
|
{ value: '0', viewValue: 'Active' },
|
|
{ value: '1', viewValue: 'Inactive' }
|
|
];
|
|
|
|
constructor(
|
|
private datasetService: DatasetProfileAdmin,
|
|
private router: Router,
|
|
private languageService: TranslateService,
|
|
public snackBar: MatSnackBar,
|
|
public route: ActivatedRoute,
|
|
public dataManagementPlanService: DataManagementPlanService
|
|
) {
|
|
super();
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
this.route.params
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe((params: Params) => {
|
|
this.dmpId = params['dmpId'];
|
|
if (this.dmpId != null) { this.setDmpTitle(this.dmpId); }
|
|
this.criteria.setCriteria(this.getDefaultCriteria(this.dmpId));
|
|
this.refresh();
|
|
this.criteria.setRefreshCallback(() => this.refresh());
|
|
});
|
|
}
|
|
|
|
setDmpTitle(dmpId: String) {
|
|
this.dataManagementPlanService.getSingle(dmpId).map(data => data as DataManagementPlanModel)
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(data => {
|
|
this.titlePrefix = data.label;
|
|
});
|
|
}
|
|
|
|
refresh() {
|
|
this.dataSource = new DatasetDataSource(this.datasetService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria);
|
|
}
|
|
|
|
rowClick(rowId: String) {
|
|
this.router.navigate(['dataset-profile/' + rowId]);
|
|
}
|
|
|
|
getDefaultCriteria(dmpId: String): DatasetProfileCriteria {
|
|
const defaultCriteria = new DatasetProfileCriteria();
|
|
|
|
return defaultCriteria;
|
|
}
|
|
|
|
clone(id: string) {
|
|
this.router.navigate(['dataset-profile/clone/' + id]);
|
|
}
|
|
|
|
// makeItPublic(id: String) {
|
|
// debugger;
|
|
// this.datasetService.makeDatasetPublic(id).pipe(takeUntil(this._destroyed)).subscribe();
|
|
// }
|
|
|
|
}
|
|
|
|
export class DatasetDataSource extends DataSource<DatasetListingModel> {
|
|
|
|
totalCount = 0;
|
|
isLoadingResults = false;
|
|
|
|
constructor(
|
|
private _service: DatasetProfileAdmin,
|
|
private _paginator: MatPaginator,
|
|
private _sort: MatSort,
|
|
private _languageService: TranslateService,
|
|
private _snackBar: MatSnackBar,
|
|
private _criteria: DatasetProfileCriteriaComponent
|
|
) {
|
|
super();
|
|
|
|
}
|
|
|
|
connect(): Observable<DatasetListingModel[]> {
|
|
const displayDataChanges = [
|
|
this._paginator.page
|
|
//this._sort.matSortChange
|
|
];
|
|
|
|
return Observable.merge(...displayDataChanges)
|
|
.startWith(null)
|
|
.switchMap(() => {
|
|
setTimeout(() => {
|
|
this.isLoadingResults = true;
|
|
});
|
|
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<DatasetProfileCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
|
request.criteria = this._criteria.criteria;
|
|
return this._service.getPaged(request);
|
|
})
|
|
/*.catch((error: any) => {
|
|
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);
|
|
})*/
|
|
.map(result => {
|
|
setTimeout(() => {
|
|
this.isLoadingResults = false;
|
|
});
|
|
return result;
|
|
})
|
|
.map(result => {
|
|
if (!result) { return []; }
|
|
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
return result.data;
|
|
});
|
|
}
|
|
|
|
disconnect() {
|
|
// No-op
|
|
}
|
|
}
|