193 lines
6.2 KiB
TypeScript
193 lines
6.2 KiB
TypeScript
import { DataSource } from '@angular/cdk/table';
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { MatDialog, MatPaginator, MatSort } from '@angular/material';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
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';
|
|
|
|
@Component({
|
|
selector: 'app-dmp-listing-component',
|
|
templateUrl: 'dmp-listing.component.html',
|
|
styleUrls: ['./dmp-listing.component.scss'],
|
|
})
|
|
export class DmpListingComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
|
|
|
@ViewChild(MatPaginator) _paginator: MatPaginator;
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
@ViewChild(DmpCriteriaComponent) criteria: DmpCriteriaComponent;
|
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]> = Observable.of([]);
|
|
dataSource: DmpDataSource | null;
|
|
displayedColumns: String[] = ['name', 'project', 'status', 'creationTime', 'organisations', 'version', 'datasets', 'actions'];
|
|
itemId: string;
|
|
projectId: string;
|
|
showProject: boolean;
|
|
titlePrefix: string;
|
|
constructor(
|
|
private dmpService: DmpService,
|
|
private router: Router,
|
|
private route: ActivatedRoute,
|
|
private dialog: MatDialog,
|
|
public enumUtils: EnumUtils
|
|
) {
|
|
super();
|
|
}
|
|
|
|
ngOnInit() {
|
|
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 = {
|
|
id: this.projectId
|
|
}
|
|
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 = [];
|
|
|
|
if (this.itemId) {
|
|
const dmplabel = this.route.snapshot.queryParams.groupLabel;
|
|
breadCrumbs.push(
|
|
{ parentComponentName: null, label: 'DMPs', url: '/plans' },
|
|
);
|
|
}
|
|
//else breadCrumbs.push({ parentComponentName: null, label: 'DMPs', url: "/plans" })
|
|
this.breadCrumbs = Observable.of(breadCrumbs);
|
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria());
|
|
this.refresh();
|
|
this.criteria.setRefreshCallback(() => this.refresh());
|
|
}
|
|
|
|
if (this.projectId != null) {
|
|
if (projectLabel !== undefined) {
|
|
this.titlePrefix = 'for ' + projectLabel;
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
refresh() {
|
|
this.dataSource = new DmpDataSource(this.dmpService, this._paginator, this.sort, this.criteria, this.itemId);
|
|
}
|
|
|
|
rowClick(rowId: String) {
|
|
this.router.navigate(['/plans/edit/' + rowId]);
|
|
}
|
|
|
|
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) {
|
|
this.router.navigate(['/plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
|
}
|
|
|
|
getDefaultCriteria(): DmpCriteria {
|
|
const defaultCriteria = new DmpCriteria();
|
|
return defaultCriteria;
|
|
}
|
|
|
|
openShareDialog(rowId: any, rowName: any) {
|
|
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
|
|
// height: '250px',
|
|
// width: '700px',
|
|
data: {
|
|
dmpId: rowId,
|
|
dmpName: rowName
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export class DmpDataSource extends DataSource<DmpListingModel> {
|
|
|
|
totalCount = 0;
|
|
|
|
constructor(
|
|
private _service: DmpService,
|
|
private _paginator: MatPaginator,
|
|
private _sort: MatSort,
|
|
private _criteria: DmpCriteriaComponent,
|
|
private itemId
|
|
) {
|
|
super();
|
|
}
|
|
|
|
connect(): Observable<DmpListingModel[]> {
|
|
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]; }
|
|
const request = new DataTableRequest<DmpCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
|
request.criteria = this._criteria.formGroup.value;
|
|
if (this.itemId) {
|
|
request.criteria.groupIds = [this.itemId];
|
|
request.criteria.allVersions = true;
|
|
}
|
|
return this._service.getPaged(request, "listing");
|
|
})
|
|
/*.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 => {
|
|
result.data = result.data;
|
|
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() {
|
|
}
|
|
}
|