2017-12-18 11:01:22 +01:00
|
|
|
import { Component, ViewChild, OnInit, AfterViewInit, ViewEncapsulation } from "@angular/core";
|
2018-02-14 11:38:19 +01:00
|
|
|
import { MatPaginator, MatSort, MatSnackBar, MatDialog, MatChipList, MatChip } from "@angular/material";
|
2017-12-18 11:01:22 +01:00
|
|
|
import { Router, ActivatedRoute, Params } 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";
|
2017-12-18 11:01:22 +01:00
|
|
|
import { JsonSerializer } from "../../utilities/JsonSerializer";
|
|
|
|
import { FormGroup } from "@angular/forms";
|
|
|
|
import { SnackBarNotificationComponent } from "../../shared/components/notificaiton/snack-bar-notification.component";
|
|
|
|
import { BaseErrorModel } from "../../models/error/BaseErrorModel";
|
2017-12-14 18:13:28 +01:00
|
|
|
import { DataManagementPlanService } from "../../services/data-management-plan/data-management-plan.service";
|
2017-12-18 11:01:22 +01:00
|
|
|
import { DataManagementPlanModel } from "../../models/data-managemnt-plans/DataManagementPlanModel";
|
|
|
|
import { ExternalSourcesService } from "../../services/external-sources/external-sources.service";
|
2017-12-18 12:24:12 +01:00
|
|
|
import { ExternalSourcesItemModel } from "../../models/external-sources/ExternalSourcesItemModel";
|
2017-12-21 10:16:46 +01:00
|
|
|
import { RequestItem } from "../../models/criteria/RequestItem";
|
|
|
|
import { DatasetProfileCriteria } from "../../models/criteria/dataset/DatasetProfileCriteria";
|
|
|
|
import { DataManagementPlanCriteriaComponent } from "../../shared/components/criteria/data-management-plan/dmp-criteria.component";
|
|
|
|
import { DatasetProfileModel } from "../../models/datasets/DatasetProfileModel";
|
2017-12-21 10:39:17 +01:00
|
|
|
import { AutoCompleteConfiguration } from "../../shared/components/autocomplete/AutoCompleteConfiguration";
|
|
|
|
import { ProjectCriteria } from "../../models/criteria/project/ProjectCriteria";
|
|
|
|
import { ProjectService } from "../../services/project/project.service";
|
2018-01-23 14:46:38 +01:00
|
|
|
import { DmpUsersModel } from "@app/models/dmpUsers/DmpUsersModel";
|
2018-02-05 10:44:40 +01:00
|
|
|
import { AddResearchersComponent } from "@app/add-researchers/add-researchers.component";
|
2018-02-05 11:34:25 +01:00
|
|
|
import { ViewContainerRef } from '@angular/core';
|
|
|
|
import { TdDialogService } from '@covalent/core';
|
2018-02-08 09:50:39 +01:00
|
|
|
import { AvailableProfilesComponent } from "@app/available-profiles/available-profiles.component";
|
2018-02-14 11:38:19 +01:00
|
|
|
import { AutoCompleteChipConfiguration } from "@app/shared/components/autocompleteChips/AutoCompleteChipConfiguration";
|
2017-12-14 18:13:28 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dmp-editor-component',
|
|
|
|
templateUrl: 'dmp-editor.component.html',
|
2017-12-18 11:01:22 +01:00
|
|
|
styleUrls: ['./dmp-editor.component.scss'],
|
2017-12-21 10:39:17 +01:00
|
|
|
providers: [DataManagementPlanService, ExternalSourcesService, ProjectService],
|
2017-12-18 11:01:22 +01:00
|
|
|
encapsulation: ViewEncapsulation.None
|
2017-12-14 18:13:28 +01:00
|
|
|
})
|
2017-12-18 11:01:22 +01:00
|
|
|
export class DataManagementPlanEditorComponent implements AfterViewInit {
|
|
|
|
|
2017-12-21 10:16:46 +01:00
|
|
|
|
2017-12-18 11:01:22 +01:00
|
|
|
isNew = true;
|
|
|
|
dataManagementPlan: DataManagementPlanModel;
|
|
|
|
formGroup: FormGroup = null;
|
|
|
|
|
|
|
|
filteringOrganisationsAsync: boolean = false;
|
|
|
|
filteringResearchersAsync: boolean = false;
|
2017-12-20 17:50:16 +01:00
|
|
|
filteredProfilesAsync: boolean = false;
|
2017-12-18 12:24:12 +01:00
|
|
|
filteredOrganisations: ExternalSourcesItemModel[];
|
|
|
|
filteredResearchers: ExternalSourcesItemModel[];
|
2017-12-21 10:16:46 +01:00
|
|
|
filteredProfiles: DatasetProfileModel[];
|
2017-12-14 18:13:28 +01:00
|
|
|
|
2017-12-21 10:39:17 +01:00
|
|
|
projectAutoCompleteConfiguration: AutoCompleteConfiguration;
|
2018-02-14 11:38:19 +01:00
|
|
|
projectAutoCompleteConfigurationTest: AutoCompleteChipConfiguration;
|
2018-01-23 12:56:43 +01:00
|
|
|
createNewVersion;
|
2018-01-23 14:46:38 +01:00
|
|
|
associatedUsers: Array<DmpUsersModel>
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-14 18:13:28 +01:00
|
|
|
constructor(
|
2017-12-18 11:01:22 +01:00
|
|
|
private dataManagementPlanService: DataManagementPlanService,
|
2017-12-21 10:39:17 +01:00
|
|
|
private projectService: ProjectService,
|
2017-12-18 11:01:22 +01:00
|
|
|
private externalSourcesService: ExternalSourcesService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
public snackBar: MatSnackBar,
|
|
|
|
public router: Router,
|
|
|
|
public language: TranslateService,
|
2018-02-05 10:44:40 +01:00
|
|
|
private _service: DataManagementPlanService,
|
2018-02-05 11:34:25 +01:00
|
|
|
public dialog: MatDialog,
|
|
|
|
private _dialogService: TdDialogService,
|
|
|
|
private _viewContainerRef: ViewContainerRef
|
2017-12-14 18:13:28 +01:00
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-18 11:01:22 +01:00
|
|
|
ngAfterViewInit() {
|
|
|
|
this.route.params.subscribe((params: Params) => {
|
|
|
|
const itemId = params['id'];
|
2017-12-14 18:13:28 +01:00
|
|
|
|
2017-12-21 10:39:17 +01:00
|
|
|
let projectRequestItem: RequestItem<ProjectCriteria> = new RequestItem();
|
|
|
|
projectRequestItem.criteria = new ProjectCriteria();
|
2017-12-22 14:46:36 +01:00
|
|
|
this.projectAutoCompleteConfiguration = new AutoCompleteConfiguration(this.projectService.getWithExternal.bind(this.projectService), projectRequestItem);
|
2018-02-14 11:38:19 +01:00
|
|
|
this.projectAutoCompleteConfigurationTest = new AutoCompleteChipConfiguration(this.projectService.getWithExternal.bind(this.projectService), projectRequestItem);
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-18 11:01:22 +01:00
|
|
|
if (itemId != null) {
|
|
|
|
this.isNew = false;
|
|
|
|
this.dataManagementPlanService.getSingle(itemId).map(data => data as DataManagementPlanModel)
|
|
|
|
.subscribe(data => {
|
2018-01-03 17:36:31 +01:00
|
|
|
this.dataManagementPlan = JsonSerializer.fromJSONObject(data, DataManagementPlanModel);
|
2017-12-18 11:01:22 +01:00
|
|
|
this.formGroup = this.dataManagementPlan.buildForm();
|
2018-01-23 14:46:38 +01:00
|
|
|
this.associatedUsers = data.associatedUsers;
|
2017-12-18 11:01:22 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.dataManagementPlan = new DataManagementPlanModel();
|
|
|
|
setTimeout(() => {
|
|
|
|
this.formGroup = this.dataManagementPlan.buildForm();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-01-24 15:54:43 +01:00
|
|
|
// let clone = this.route.snapshot.data.clone; ginetai kai esti ikalyvas
|
2018-01-23 12:56:43 +01:00
|
|
|
this.route
|
2018-02-07 10:56:30 +01:00
|
|
|
.queryParams
|
|
|
|
.subscribe(params => {
|
|
|
|
this.createNewVersion = params["clone"];
|
|
|
|
});
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|
|
|
|
|
2017-12-18 11:01:22 +01:00
|
|
|
formSubmit(): void {
|
|
|
|
//this.touchAllFormFields(this.formGroup);
|
|
|
|
if (!this.isFormValid()) { return; }
|
|
|
|
this.onSubmit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public isFormValid() {
|
|
|
|
return this.formGroup.valid;
|
|
|
|
}
|
|
|
|
|
2018-02-08 16:32:23 +01:00
|
|
|
onSubmit(): void {
|
2018-02-07 10:56:30 +01:00
|
|
|
this.dataManagementPlanService.createDataManagementPlan(this.formGroup.value).subscribe(
|
|
|
|
complete => this.onCallbackSuccess(),
|
|
|
|
error => this.onCallbackError(error)
|
|
|
|
)
|
2017-12-18 11:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackSuccess(): void {
|
|
|
|
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
|
|
|
|
data: { message: this.isNew ? 'GENERAL.SNACK-BAR.SUCCESSFUL-CREATION' : 'GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE', language: this.language },
|
|
|
|
duration: 3000,
|
|
|
|
extraClasses: ['snackbar-success']
|
|
|
|
})
|
2017-12-20 15:52:09 +01:00
|
|
|
this.router.navigate(['/dmps']);
|
2017-12-18 11:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackError(error: any) {
|
|
|
|
this.setErrorModel(error.error);
|
|
|
|
//this.validateAllFormFields(this.formGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
public setErrorModel(errorModel: BaseErrorModel) {
|
|
|
|
Object.keys(errorModel).forEach(item => {
|
|
|
|
(<any>this.dataManagementPlan.errorModel)[item] = (<any>errorModel)[item];
|
|
|
|
})
|
|
|
|
}
|
2017-12-14 18:13:28 +01:00
|
|
|
|
2017-12-18 11:01:22 +01:00
|
|
|
public cancel(): void {
|
2017-12-20 15:52:09 +01:00
|
|
|
this.router.navigate(['/dmps']);
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|
2017-12-18 12:24:12 +01:00
|
|
|
|
2018-01-05 16:40:19 +01:00
|
|
|
public invite(): void {
|
2018-02-07 10:56:30 +01:00
|
|
|
this.router.navigate(['/invite/' + this.dataManagementPlan.id]);
|
2018-01-05 16:40:19 +01:00
|
|
|
}
|
|
|
|
|
2017-12-18 12:24:12 +01:00
|
|
|
filterOrganisations(value: string): void {
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-18 12:24:12 +01:00
|
|
|
this.filteredOrganisations = undefined;
|
|
|
|
if (value) {
|
|
|
|
this.filteringOrganisationsAsync = true;
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-18 12:24:12 +01:00
|
|
|
this.externalSourcesService.searchDMPOrganizations(value).subscribe(items => {
|
|
|
|
this.filteredOrganisations = items;
|
|
|
|
this.filteringOrganisationsAsync = false;
|
|
|
|
|
|
|
|
// this.filteredOrganisations = items.filter((filteredObj: any) => {
|
|
|
|
// return this.objectsModel ? this.objectsModel.indexOf(filteredObj) < 0 : true;
|
|
|
|
// });
|
|
|
|
|
|
|
|
});
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-18 12:24:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filterResearchers(value: string): void {
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-18 12:24:12 +01:00
|
|
|
this.filteredResearchers = undefined;
|
|
|
|
if (value) {
|
|
|
|
this.filteringResearchersAsync = true;
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-18 12:24:12 +01:00
|
|
|
this.externalSourcesService.searchDMPResearchers(value).subscribe(items => {
|
|
|
|
this.filteredResearchers = items;
|
|
|
|
this.filteringResearchersAsync = false;
|
|
|
|
|
|
|
|
// this.filteredOrganisations = items.filter((filteredObj: any) => {
|
|
|
|
// return this.objectsModel ? this.objectsModel.indexOf(filteredObj) < 0 : true;
|
|
|
|
// });
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-12-20 17:50:16 +01:00
|
|
|
|
|
|
|
filterProfiles(value: string): void {
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-20 17:50:16 +01:00
|
|
|
this.filteredProfiles = undefined;
|
|
|
|
if (value) {
|
|
|
|
this.filteredProfilesAsync = true;
|
2017-12-21 10:39:17 +01:00
|
|
|
|
2017-12-21 10:16:46 +01:00
|
|
|
// this.externalSourcesService.searchDMPProfiles(value).subscribe(items => {
|
|
|
|
// this.filteredProfiles = items;
|
|
|
|
// this.filteredProfilesAsync = false;
|
2017-12-20 17:50:16 +01:00
|
|
|
|
2017-12-21 10:16:46 +01:00
|
|
|
// // this.filteredOrganisations = items.filter((filteredObj: any) => {
|
|
|
|
// // return this.objectsModel ? this.objectsModel.indexOf(filteredObj) < 0 : true;
|
|
|
|
// // });
|
|
|
|
|
|
|
|
// });
|
2017-12-20 17:50:16 +01:00
|
|
|
|
2017-12-21 10:16:46 +01:00
|
|
|
const request = new RequestItem<DatasetProfileCriteria>();
|
|
|
|
let criteria = new DatasetProfileCriteria();
|
|
|
|
criteria.like = value;
|
|
|
|
request.criteria = criteria;
|
|
|
|
this._service.searchDMPProfiles(request).subscribe(items => {
|
|
|
|
this.filteredProfiles = items;
|
|
|
|
this.filteredProfilesAsync = false;
|
2017-12-20 17:50:16 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-05 10:44:40 +01:00
|
|
|
addResearcher(rowId: any, rowName: any) {
|
|
|
|
let dialogRef = this.dialog.open(AddResearchersComponent, {
|
|
|
|
height: '255px',
|
|
|
|
width: '700px',
|
|
|
|
data: {
|
|
|
|
dmpId: rowId,
|
|
|
|
dmpName: rowName
|
|
|
|
}
|
|
|
|
});
|
2018-02-08 09:50:39 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
availableProfiles() {
|
|
|
|
let dialogRef = this.dialog.open(AvailableProfilesComponent, {
|
|
|
|
height: '355px',
|
|
|
|
width: '700px',
|
|
|
|
data: {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2018-02-08 16:32:23 +01:00
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
|
|
this.formGroup.get("profiles").setValue(result);
|
2018-02-08 09:50:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
2018-02-05 10:44:40 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 12:26:23 +01:00
|
|
|
openConfirm(dmpLabel, id): void {
|
2018-02-05 11:34:25 +01:00
|
|
|
this._dialogService.openConfirm({
|
|
|
|
message: 'Are you sure you want to delete the "' + dmpLabel +'"',
|
|
|
|
disableClose: true || false, // defaults to false
|
|
|
|
viewContainerRef: this._viewContainerRef, //OPTIONAL
|
|
|
|
title: 'Confirm', //OPTIONAL, hides if not provided
|
|
|
|
cancelButton: 'No', //OPTIONAL, defaults to 'CANCEL'
|
|
|
|
acceptButton: 'Yes' //OPTIONAL, defaults to 'ACCEPT'
|
|
|
|
// width: '500px', //OPTIONAL, defaults to 400px
|
|
|
|
}).afterClosed().subscribe((accept: boolean) => {
|
|
|
|
if (accept) {
|
2018-02-05 12:26:23 +01:00
|
|
|
this.dataManagementPlanService.delete(id).subscribe(()=>{
|
|
|
|
this.router.navigate(['/dmps'])
|
|
|
|
});
|
2018-02-05 11:34:25 +01:00
|
|
|
} else {
|
|
|
|
// DO SOMETHING ELSE
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-14 18:13:28 +01:00
|
|
|
}
|