2018-01-30 10:35:26 +01:00
|
|
|
import { DataTableRequest } from '../../models/data-table/DataTableRequest';
|
|
|
|
import { DataManagementPlanListingModel } from '../../models/data-managemnt-plans/DataManagementPlanListingModel';
|
2018-05-28 11:50:42 +02:00
|
|
|
import { InvitationComponent } from '../../shared/components/invitation/invitation.component';
|
2018-01-30 10:35:26 +01:00
|
|
|
import { DataManagementPlanCriteria } from '../../models/criteria/data-management-plan/DataManagementPlanCriteria';
|
|
|
|
import {
|
|
|
|
DataManagementPlanCriteriaComponent,
|
|
|
|
} from '../../shared/components/criteria/data-management-plan/dmp-criteria.component';
|
|
|
|
import { DataManagementPlanService } from '../../services/data-management-plan/data-management-plan.service';
|
2017-12-14 18:13:28 +01:00
|
|
|
import { Component, ViewChild, OnInit, AfterViewInit } from "@angular/core";
|
2018-01-05 16:40:19 +01:00
|
|
|
import { MatPaginator, MatSort, MatSnackBar, MatDialog } from "@angular/material";
|
2018-06-27 12:29:21 +02:00
|
|
|
import { Router, ActivatedRoute, ActivatedRouteSnapshot } from "@angular/router";
|
2017-12-14 18:13:28 +01:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
|
|
|
import { DataSource } from "@angular/cdk/table";
|
|
|
|
import { Observable } from "rxjs/Observable";
|
2018-05-14 08:44:35 +02:00
|
|
|
import { DataManagementPlanRoutes } from '../../dmps/dmps.routes';
|
|
|
|
import { DatasetRoutes } from '../../datasets/dataset.routes';
|
|
|
|
import { ProjectModel } from '../../models/projects/ProjectModel';
|
2018-06-27 12:29:21 +02:00
|
|
|
import { IBreadCrumbComponent } from '../../shared/components/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { BreadcrumbItem } from '../../shared/components/breadcrumb/definition/breadcrumb-item';
|
2017-12-14 18:13:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dmp-listing-component',
|
|
|
|
templateUrl: 'dmp-listing.component.html',
|
2017-12-19 08:31:02 +01:00
|
|
|
styleUrls: ['./dmp-listing.component.scss'],
|
2017-12-14 18:13:28 +01:00
|
|
|
})
|
2018-06-27 12:29:21 +02:00
|
|
|
export class DataManagementPlanListingComponent implements OnInit, IBreadCrumbComponent {
|
|
|
|
|
2018-02-02 16:24:06 +01:00
|
|
|
|
2017-12-14 18:13:28 +01:00
|
|
|
|
|
|
|
@ViewChild(MatPaginator) _paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
@ViewChild(DataManagementPlanCriteriaComponent) criteria: DataManagementPlanCriteriaComponent;
|
|
|
|
|
2018-06-27 12:29:21 +02:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]> = Observable.of([]);
|
2017-12-14 18:13:28 +01:00
|
|
|
dataSource: DataManagementPlanDataSource | null;
|
2018-02-02 12:09:38 +01:00
|
|
|
displayedColumns: String[] = ['name', 'project', 'creationTime', 'organisations', 'version', 'numOfDatasets', 'actions'];
|
2018-02-08 09:42:02 +01:00
|
|
|
itemId: string;
|
2018-03-21 14:15:06 +01:00
|
|
|
projectId: string;
|
|
|
|
showProject: boolean;
|
2018-06-05 10:18:01 +02:00
|
|
|
titlePrefix: string;
|
2017-12-14 18:13:28 +01:00
|
|
|
constructor(
|
2017-12-19 08:31:02 +01:00
|
|
|
private dataManagementPlanService: DataManagementPlanService,
|
2017-12-14 18:13:28 +01:00
|
|
|
private router: Router,
|
2018-02-08 09:42:02 +01:00
|
|
|
private route: ActivatedRoute,
|
2017-12-14 18:13:28 +01:00
|
|
|
private languageService: TranslateService,
|
|
|
|
public snackBar: MatSnackBar,
|
2018-01-05 16:40:19 +01:00
|
|
|
public dialog: MatDialog
|
2017-12-14 18:13:28 +01:00
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-06-27 12:29:21 +02:00
|
|
|
this.route.params.subscribe(async params => {
|
|
|
|
let projectLabel;
|
2018-03-21 14:15:06 +01:00
|
|
|
if (params["projectId"]) {
|
|
|
|
this.projectId = params["projectId"];
|
|
|
|
this.showProject = false;
|
|
|
|
let project = new ProjectModel();
|
|
|
|
project.id = this.projectId;
|
|
|
|
this.criteria.setCriteria({ like: null, projects: [project], groupIds: null, allVersions: false })
|
|
|
|
this.refresh();
|
2018-06-27 12:29:21 +02:00
|
|
|
projectLabel = this.route.snapshot.queryParams.projectLabel
|
|
|
|
this.breadCrumbs = Observable.of([{ parentComponentName: "ProjectEditorComponent", label: projectLabel, url: "/projects/edit/" + this.projectId }, { parentComponentName: null, label: 'DMPs', url: "/dmps/project/" + this.projectId, params: { projectLabel: projectLabel } }])
|
2018-03-21 14:15:06 +01:00
|
|
|
this.criteria.setRefreshCallback(() => this.refresh());
|
|
|
|
} else {
|
|
|
|
this.itemId = params['groupId'];
|
2018-03-28 15:24:47 +02:00
|
|
|
this.showProject = true;
|
2018-06-27 12:29:21 +02:00
|
|
|
let breadCrumbs = [];
|
|
|
|
if (this.itemId) breadCrumbs.push({ parentComponentName: null, label: 'DMPs For ' + this.itemId, url: "/dmps/viewversions/" + this.itemId })
|
|
|
|
else breadCrumbs.push({ parentComponentName: null, label: 'DMPs', url: "/dmps" })
|
|
|
|
this.breadCrumbs = Observable.of(breadCrumbs)
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-03-21 14:15:06 +01:00
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria());
|
|
|
|
this.refresh();
|
|
|
|
this.criteria.setRefreshCallback(() => this.refresh());
|
|
|
|
}
|
2018-06-05 10:18:01 +02:00
|
|
|
|
|
|
|
if (this.projectId != null)
|
2018-06-27 12:29:21 +02:00
|
|
|
if (projectLabel != undefined)
|
|
|
|
this.titlePrefix = "for " + projectLabel;
|
2018-02-08 09:42:02 +01:00
|
|
|
})
|
|
|
|
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
2018-02-08 09:42:02 +01:00
|
|
|
this.dataSource = new DataManagementPlanDataSource(this.dataManagementPlanService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria, this.itemId);
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rowClick(rowId: String) {
|
2018-01-30 10:35:26 +01:00
|
|
|
this.router.navigate(['/dmps/edit/' + rowId]);
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|
|
|
|
|
2018-01-17 12:57:41 +01:00
|
|
|
addDataset(rowId: String) {
|
2018-01-30 10:35:26 +01:00
|
|
|
this.router.navigate(['/datasets/new/' + rowId]);
|
2018-01-17 12:57:41 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 14:15:06 +01:00
|
|
|
showDatasets(rowId: String, rowLabel: String) {
|
|
|
|
this.router.navigate(['/datasets/dmp/' + rowId, { dmpLabel: rowLabel }]);
|
2018-01-17 12:57:41 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 09:42:02 +01:00
|
|
|
viewVersions(rowId: String) {
|
|
|
|
this.router.navigate(['/dmps/viewversions/' + rowId]);
|
|
|
|
}
|
|
|
|
|
2017-12-14 18:13:28 +01:00
|
|
|
getDefaultCriteria(): DataManagementPlanCriteria {
|
|
|
|
const defaultCriteria = new DataManagementPlanCriteria();
|
|
|
|
return defaultCriteria;
|
|
|
|
}
|
2018-01-05 16:40:19 +01:00
|
|
|
|
2018-01-11 17:19:15 +01:00
|
|
|
openShareDialog(rowId: any, rowName: any) {
|
2018-01-05 16:40:19 +01:00
|
|
|
let dialogRef = this.dialog.open(InvitationComponent, {
|
|
|
|
height: '200px',
|
|
|
|
width: '700px',
|
|
|
|
data: {
|
2018-01-11 17:19:15 +01:00
|
|
|
dmpId: rowId,
|
|
|
|
dmpName: rowName
|
2018-01-05 16:40:19 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export class DataManagementPlanDataSource extends DataSource<DataManagementPlanListingModel> {
|
|
|
|
|
|
|
|
totalCount = 0;
|
|
|
|
isLoadingResults = false;
|
|
|
|
constructor(
|
|
|
|
private _service: DataManagementPlanService,
|
|
|
|
private _paginator: MatPaginator,
|
|
|
|
private _sort: MatSort,
|
|
|
|
private _languageService: TranslateService,
|
|
|
|
private _snackBar: MatSnackBar,
|
2018-02-08 09:42:02 +01:00
|
|
|
private _criteria: DataManagementPlanCriteriaComponent,
|
|
|
|
private itemId
|
2017-12-14 18:13:28 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(): Observable<DataManagementPlanListingModel[]> {
|
|
|
|
const displayDataChanges = [
|
|
|
|
this._paginator.page
|
|
|
|
];
|
|
|
|
|
|
|
|
return Observable.merge(...displayDataChanges)
|
|
|
|
.startWith(null)
|
|
|
|
.switchMap(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.isLoadingResults = true;
|
|
|
|
});
|
|
|
|
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
|
2018-02-02 16:24:06 +01:00
|
|
|
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<DataManagementPlanCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
2017-12-18 14:45:36 +01:00
|
|
|
request.criteria = this._criteria.criteria;
|
2018-02-08 09:42:02 +01:00
|
|
|
if (this.itemId) {
|
|
|
|
request.criteria.groupIds = [this.itemId];
|
|
|
|
request.criteria.allVersions = true;
|
|
|
|
}
|
2017-12-14 18:13:28 +01:00
|
|
|
return this._service.getPaged(request);
|
|
|
|
})
|
2018-01-30 10:35:26 +01:00
|
|
|
/*.catch((error: any) => {
|
2017-12-14 18:13:28 +01:00
|
|
|
this._snackBar.openFromComponent(SnackBarNotificationComponent, {
|
|
|
|
data: { message: 'GENERAL.SNACK-BAR.FORMS-BAD-REQUEST', language: this._languageService },
|
|
|
|
duration: 3000,
|
|
|
|
extraClasses: ['snackbar-warning']
|
|
|
|
});
|
|
|
|
return Observable.of(null);
|
2018-01-30 10:35:26 +01:00
|
|
|
})*/
|
2017-12-14 18:13:28 +01:00
|
|
|
.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() {
|
|
|
|
}
|
|
|
|
}
|