2019-01-18 18:03:45 +01:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { FormGroup } from '@angular/forms';
|
|
|
|
import { MatSnackBar } from '@angular/material';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { BaseComponent } from '../../../../core/common/base/base.component';
|
|
|
|
import { DatasetProfileModel } from '../../../../core/model/dataset/dataset-profile';
|
|
|
|
import { ExternalSourceItemModel } from '../../../../core/model/external-sources/external-source-item';
|
|
|
|
import { UserModel } from '../../../../core/model/user/user';
|
|
|
|
import { BaseCriteria } from '../../../../core/query/base-criteria';
|
|
|
|
import { DatasetProfileCriteria } from '../../../../core/query/dataset-profile/dataset-profile-criteria';
|
2019-08-01 09:54:40 +02:00
|
|
|
import { GrantCriteria } from '../../../../core/query/grant/grant-criteria';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { RequestItem } from '../../../../core/query/request-item';
|
|
|
|
import { DmpService } from '../../../../core/services/dmp/dmp.service';
|
|
|
|
import { ExternalSourcesService } from '../../../../core/services/external-sources/external-sources.service';
|
2019-08-01 09:54:40 +02:00
|
|
|
import { GrantService } from '../../../../core/services/grant/grant.service';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { MultipleAutoCompleteConfiguration } from '../../../../library/auto-complete/multiple/multiple-auto-complete-configuration';
|
|
|
|
import { SingleAutoCompleteConfiguration } from '../../../../library/auto-complete/single/single-auto-complete-configuration';
|
2019-01-24 11:46:29 +01:00
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '../../../../core/services/notification/ui-notification-service';
|
2018-02-07 10:56:30 +01:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-dmp-wizard-editor-component',
|
|
|
|
templateUrl: 'dmp-wizard-editor.component.html',
|
2019-01-18 18:03:45 +01:00
|
|
|
styleUrls: ['./dmp-wizard-editor.component.scss']
|
2018-02-07 10:56:30 +01:00
|
|
|
})
|
2019-01-18 18:03:45 +01:00
|
|
|
export class DmpWizardEditorComponent extends BaseComponent implements OnInit {
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
isNew = true;
|
|
|
|
@Input() formGroup: FormGroup = null;
|
|
|
|
|
|
|
|
filteringOrganisationsAsync = false;
|
|
|
|
filteringResearchersAsync = false;
|
|
|
|
filteredProfilesAsync = false;
|
2019-01-18 18:03:45 +01:00
|
|
|
filteredOrganisations: ExternalSourceItemModel[];
|
|
|
|
filteredResearchers: ExternalSourceItemModel[];
|
2018-10-05 17:00:54 +02:00
|
|
|
filteredProfiles: DatasetProfileModel[];
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
grantAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
2018-10-05 17:00:54 +02:00
|
|
|
profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
|
|
organisationsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
|
|
researchersAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
|
|
createNewVersion;
|
2019-01-18 18:03:45 +01:00
|
|
|
associatedUsers: Array<UserModel>;
|
2018-10-05 17:00:54 +02:00
|
|
|
labelDisabled = false;
|
|
|
|
|
|
|
|
constructor(
|
2019-01-18 18:03:45 +01:00
|
|
|
private dataManagementPlanService: DmpService,
|
2019-08-01 09:54:40 +02:00
|
|
|
private grantService: GrantService,
|
2018-10-05 17:00:54 +02:00
|
|
|
private externalSourcesService: ExternalSourcesService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
public snackBar: MatSnackBar,
|
|
|
|
public router: Router,
|
|
|
|
public language: TranslateService,
|
2019-01-18 18:03:45 +01:00
|
|
|
private _service: DmpService,
|
2019-02-12 13:19:03 +01:00
|
|
|
private uiNotificationService: UiNotificationService
|
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() {
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
const grantRequestItem: RequestItem<GrantCriteria> = new RequestItem();
|
|
|
|
grantRequestItem.criteria = new GrantCriteria();
|
|
|
|
this.grantAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchGrant.bind(this.grantService),
|
|
|
|
initialItems: () => this.searchGrant(''),
|
2018-10-05 17:00:54 +02:00
|
|
|
displayFn: (item) => item['label'],
|
2019-01-21 12:14:20 +01:00
|
|
|
titleFn: (item) => item['label']
|
2018-10-05 17:00:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this.profilesAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterProfiles.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterProfiles('').map(result => result.filter(resultItem => excludedItems.map(x => x.id).indexOf(resultItem.id) === -1)),
|
|
|
|
displayFn: (item) => item['label'],
|
2019-01-21 12:14:20 +01:00
|
|
|
titleFn: (item) => item['label']
|
2018-10-05 17:00:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this.organisationsAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterOrganisations.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterOrganisations('').map(result => result.filter(resultItem => excludedItems.map(x => x.id).indexOf(resultItem.id) === -1)),
|
|
|
|
displayFn: (item) => item['name'],
|
2019-01-21 12:14:20 +01:00
|
|
|
titleFn: (item) => item['name']
|
2018-10-05 17:00:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this.researchersAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterResearchers.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterResearchers('').map(result => result.filter(resultItem => excludedItems.map(x => x.id).indexOf(resultItem.id) === -1)),
|
|
|
|
displayFn: (item) => item['name'],
|
2019-01-21 12:14:20 +01:00
|
|
|
titleFn: (item) => item['name']
|
2018-10-05 17:00:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const organisationRequestItem: RequestItem<BaseCriteria> = new RequestItem();
|
|
|
|
organisationRequestItem.criteria = new BaseCriteria();
|
|
|
|
|
2018-11-27 18:33:17 +01:00
|
|
|
this.route.data
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(value => {
|
|
|
|
this.formGroup.controls['version'].disable();
|
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
searchGrant(query: string) {
|
|
|
|
const grantRequestItem: RequestItem<GrantCriteria> = new RequestItem();
|
|
|
|
grantRequestItem.criteria = new GrantCriteria();
|
|
|
|
grantRequestItem.criteria.like = query;
|
|
|
|
return this.grantService.getWithExternal(grantRequestItem);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
formSubmit(): void {
|
|
|
|
//this.touchAllFormFields(this.formGroup);
|
|
|
|
if (!this.isFormValid()) { return; }
|
|
|
|
this.onSubmit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public isFormValid() {
|
|
|
|
return this.formGroup.valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit(): void {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dataManagementPlanService.createDmp(this.formGroup.getRawValue())
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
complete => this.onCallbackSuccess(),
|
|
|
|
error => this.onCallbackError(error)
|
|
|
|
);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackSuccess(): void {
|
2019-01-24 11:46:29 +01:00
|
|
|
this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans']);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackError(error: any) {
|
2019-02-12 13:19:03 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-06-14 17:11:57 +02:00
|
|
|
availableProfiles() {}
|
2019-01-21 12:14:20 +01:00
|
|
|
|
2019-06-14 17:11:57 +02:00
|
|
|
addResearcher() {}
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
public cancel(): void {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans']);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> {
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
this.filteredOrganisations = undefined;
|
|
|
|
this.filteringOrganisationsAsync = true;
|
|
|
|
|
|
|
|
return this.externalSourcesService.searchDMPOrganizations(value);
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
filterResearchers(value: string): Observable<ExternalSourceItemModel[]> {
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
this.filteredResearchers = undefined;
|
|
|
|
this.filteringResearchersAsync = true;
|
|
|
|
|
|
|
|
return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } });
|
|
|
|
}
|
|
|
|
|
|
|
|
filterProfiles(value: string): Observable<DatasetProfileModel[]> {
|
|
|
|
|
|
|
|
this.filteredProfiles = undefined;
|
|
|
|
this.filteredProfilesAsync = true;
|
|
|
|
|
|
|
|
const request = new RequestItem<DatasetProfileCriteria>();
|
|
|
|
const criteria = new DatasetProfileCriteria();
|
|
|
|
criteria.like = value;
|
|
|
|
request.criteria = criteria;
|
|
|
|
return this._service.searchDMPProfiles(request);
|
|
|
|
}
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|