argos/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts

193 lines
6.2 KiB
TypeScript
Raw Normal View History

2018-10-05 17:00:54 +02:00
import { DataSource } from '@angular/cdk/table';
2018-11-27 18:33:17 +01:00
import { Component, OnInit, ViewChild } from '@angular/core';
2019-01-18 18:03:45 +01:00
import { MatDialog, MatPaginator, MatSort } from '@angular/material';
2018-11-27 18:33:17 +01:00
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs';
2018-11-27 18:33:17 +01:00
import { takeUntil } from 'rxjs/operators';
2019-01-18 18:03:45 +01:00
import { BaseComponent } from '../../../core/common/base/base.component';
import { DmpListingModel } from '../../../core/model/dmp/dmp-listing';
import { DmpCriteria } from '../../../core/query/dmp/dmp-criteria';
import { DmpService } from '../../../core/services/dmp/dmp.service';
import { EnumUtils } from '../../../core/services/utilities/enum-utils.service';
import { DataTableRequest } from '../../../core/model/data-table/data-table-request';
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
import { DmpInvitationDialogComponent } from '../invitation/dmp-invitation.component';
import { DmpCriteriaComponent } from './criteria/dmp-criteria.component';
import { ProjectListingModel } from '../../../core/model/project/project-listing';
2017-12-14 18:13:28 +01:00
@Component({
2018-10-05 17:00:54 +02:00
selector: 'app-dmp-listing-component',
templateUrl: 'dmp-listing.component.html',
styleUrls: ['./dmp-listing.component.scss'],
2017-12-14 18:13:28 +01:00
})
2019-01-18 18:03:45 +01:00
export class DmpListingComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
2017-12-14 18:13:28 +01:00
2018-10-05 17:00:54 +02:00
@ViewChild(MatPaginator) _paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
2019-01-18 18:03:45 +01:00
@ViewChild(DmpCriteriaComponent) criteria: DmpCriteriaComponent;
2018-10-05 17:00:54 +02:00
breadCrumbs: Observable<BreadcrumbItem[]> = Observable.of([]);
2019-01-18 18:03:45 +01:00
dataSource: DmpDataSource | null;
displayedColumns: String[] = ['name', 'project', 'status', 'creationTime', 'organisations', 'version', 'datasets', 'actions'];
2018-10-05 17:00:54 +02:00
itemId: string;
projectId: string;
showProject: boolean;
titlePrefix: string;
constructor(
2019-01-18 18:03:45 +01:00
private dmpService: DmpService,
2018-10-05 17:00:54 +02:00
private router: Router,
private route: ActivatedRoute,
2019-01-18 18:03:45 +01:00
private dialog: MatDialog,
public enumUtils: EnumUtils
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
}
ngOnInit() {
2018-11-27 18:33:17 +01:00
this.route.params
.pipe(takeUntil(this._destroyed))
.subscribe(async params => {
let projectLabel;
if (params['projectId']) {
this.projectId = params['projectId'];
this.showProject = false;
const project: ProjectListingModel = {
2019-01-18 18:03:45 +01:00
id: this.projectId
}
2018-11-27 18:33:17 +01:00
this.criteria.setCriteria({ like: null, projects: [project], groupIds: null, allVersions: false });
this.refresh();
projectLabel = this.route.snapshot.queryParams.projectLabel;
this.breadCrumbs = Observable.of([{ parentComponentName: 'ProjectEditorComponent', label: projectLabel, url: '/projects/edit/' + this.projectId }]);
this.criteria.setRefreshCallback(() => this.refresh());
} else {
this.itemId = params['groupId'];
this.showProject = true;
const breadCrumbs = [];
2018-10-05 17:00:54 +02:00
2018-11-27 18:33:17 +01:00
if (this.itemId) {
const dmplabel = this.route.snapshot.queryParams.groupLabel;
breadCrumbs.push(
2019-01-18 18:03:45 +01:00
{ parentComponentName: null, label: 'DMPs', url: '/plans' },
2018-11-27 18:33:17 +01:00
);
}
2019-01-18 18:03:45 +01:00
//else breadCrumbs.push({ parentComponentName: null, label: 'DMPs', url: "/plans" })
2018-11-27 18:33:17 +01:00
this.breadCrumbs = Observable.of(breadCrumbs);
2018-10-05 17:00:54 +02:00
2018-11-27 18:33:17 +01:00
this.criteria.setCriteria(this.getDefaultCriteria());
this.refresh();
this.criteria.setRefreshCallback(() => this.refresh());
}
2018-10-05 17:00:54 +02:00
2018-11-27 18:33:17 +01:00
if (this.projectId != null) {
if (projectLabel !== undefined) {
this.titlePrefix = 'for ' + projectLabel;
}
2018-10-05 17:00:54 +02:00
}
2018-11-27 18:33:17 +01:00
});
2018-10-05 17:00:54 +02:00
}
refresh() {
2019-01-18 18:03:45 +01:00
this.dataSource = new DmpDataSource(this.dmpService, this._paginator, this.sort, this.criteria, this.itemId);
2018-10-05 17:00:54 +02:00
}
rowClick(rowId: String) {
2019-01-18 18:03:45 +01:00
this.router.navigate(['/plans/edit/' + rowId]);
2018-10-05 17:00:54 +02:00
}
addDataset(rowId: String) {
this.router.navigate(['/datasets/new/' + rowId]);
}
showDatasets(rowId: String, rowLabel: String) {
this.router.navigate(['/datasets/dmp/' + rowId, { dmpLabel: rowLabel }]);
}
viewVersions(rowId: String, rowLabel: String) {
2019-01-18 18:03:45 +01:00
this.router.navigate(['/plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
2018-10-05 17:00:54 +02:00
}
2019-01-18 18:03:45 +01:00
getDefaultCriteria(): DmpCriteria {
const defaultCriteria = new DmpCriteria();
2018-10-05 17:00:54 +02:00
return defaultCriteria;
}
openShareDialog(rowId: any, rowName: any) {
2019-01-18 18:03:45 +01:00
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
// height: '250px',
// width: '700px',
2018-10-05 17:00:54 +02:00
data: {
dmpId: rowId,
dmpName: rowName
}
});
}
2017-12-14 18:13:28 +01:00
}
2019-01-18 18:03:45 +01:00
export class DmpDataSource extends DataSource<DmpListingModel> {
2017-12-14 18:13:28 +01:00
2018-10-05 17:00:54 +02:00
totalCount = 0;
2019-01-18 18:03:45 +01:00
2018-10-05 17:00:54 +02:00
constructor(
2019-01-18 18:03:45 +01:00
private _service: DmpService,
2018-10-05 17:00:54 +02:00
private _paginator: MatPaginator,
private _sort: MatSort,
2019-01-18 18:03:45 +01:00
private _criteria: DmpCriteriaComponent,
2018-10-05 17:00:54 +02:00
private itemId
) {
super();
}
2019-01-18 18:03:45 +01:00
connect(): Observable<DmpListingModel[]> {
2018-10-05 17:00:54 +02:00
const displayDataChanges = [
this._paginator.page
];
return Observable.merge(...displayDataChanges)
.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]; }
2019-01-18 18:03:45 +01:00
const request = new DataTableRequest<DmpCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
2018-10-05 17:00:54 +02:00
request.criteria = this._criteria.formGroup.value;
if (this.itemId) {
request.criteria.groupIds = [this.itemId];
request.criteria.allVersions = true;
}
return this._service.getPaged(request, "listing");
2018-10-05 17:00:54 +02:00
})
/*.catch((error: any) => {
this._snackBar.openFromComponent(SnackBarNotificationComponent, {
data: { message: 'GENERAL.SNACK-BAR.FORMS-BAD-REQUEST', language: this._languageService },
duration: 3000,
extraClasses: ['snackbar-warning']
});
return Observable.of(null);
})*/
.map(result => {
2019-01-18 18:03:45 +01:00
result.data = result.data;
2018-10-05 17:00:54 +02:00
return result;
})
.map(result => {
return result;
})
.map(result => {
if (!result) { return []; }
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
return result.data.map(item => {
item['datasets'].map(dmp => {
dmp.url = 'datasets/edit/' + dmp.url;
dmp.all = 'datasets/dmp/' + item.id;
return dmp;
});
return item;
});
});
}
disconnect() {
}
2017-12-14 18:13:28 +01:00
}