179 lines
6.8 KiB
TypeScript
179 lines
6.8 KiB
TypeScript
import { Component, Input, OnInit } from '@angular/core';
|
|
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';
|
|
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';
|
|
import { ProjectCriteria } from '../../../../core/query/project/project-criteria';
|
|
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';
|
|
import { ProjectService } from '../../../../core/services/project/project.service';
|
|
import { MultipleAutoCompleteConfiguration } from '../../../../library/auto-complete/multiple/multiple-auto-complete-configuration';
|
|
import { SingleAutoCompleteConfiguration } from '../../../../library/auto-complete/single/single-auto-complete-configuration';
|
|
import { LanguageResolverService } from '../../../../services/language-resolver/language-resolver.service';
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '../../../../core/services/notification/ui-notification-service';
|
|
|
|
@Component({
|
|
selector: 'app-dmp-wizard-editor-component',
|
|
templateUrl: 'dmp-wizard-editor.component.html',
|
|
styleUrls: ['./dmp-wizard-editor.component.scss']
|
|
})
|
|
export class DmpWizardEditorComponent extends BaseComponent implements OnInit {
|
|
|
|
isNew = true;
|
|
@Input() formGroup: FormGroup = null;
|
|
|
|
filteringOrganisationsAsync = false;
|
|
filteringResearchersAsync = false;
|
|
filteredProfilesAsync = false;
|
|
filteredOrganisations: ExternalSourceItemModel[];
|
|
filteredResearchers: ExternalSourceItemModel[];
|
|
filteredProfiles: DatasetProfileModel[];
|
|
|
|
projectAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
organisationsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
researchersAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
createNewVersion;
|
|
associatedUsers: Array<UserModel>;
|
|
labelDisabled = false;
|
|
|
|
constructor(
|
|
private dataManagementPlanService: DmpService,
|
|
private projectService: ProjectService,
|
|
private externalSourcesService: ExternalSourcesService,
|
|
private route: ActivatedRoute,
|
|
public snackBar: MatSnackBar,
|
|
public router: Router,
|
|
public language: TranslateService,
|
|
private _service: DmpService,
|
|
private languageResolverService: LanguageResolverService,
|
|
private uiNotificationService:UiNotificationService
|
|
) {
|
|
super();
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
const projectRequestItem: RequestItem<ProjectCriteria> = new RequestItem();
|
|
projectRequestItem.criteria = new ProjectCriteria();
|
|
this.projectAutoCompleteConfiguration = {
|
|
filterFn: this.searchProject.bind(this.projectService),
|
|
initialItems: () => this.searchProject(''),
|
|
displayFn: (item) => item['label'],
|
|
titleFn: (item) => item['label']
|
|
};
|
|
|
|
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'],
|
|
titleFn: (item) => item['label']
|
|
};
|
|
|
|
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'],
|
|
titleFn: (item) => item['name']
|
|
};
|
|
|
|
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'],
|
|
titleFn: (item) => item['name']
|
|
};
|
|
|
|
const organisationRequestItem: RequestItem<BaseCriteria> = new RequestItem();
|
|
organisationRequestItem.criteria = new BaseCriteria();
|
|
|
|
this.route.data
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(value => {
|
|
if (value.clone === false && this.formGroup.get('label').value) {
|
|
this.labelDisabled = true;
|
|
}
|
|
this.formGroup.controls['version'].disable();
|
|
});
|
|
}
|
|
|
|
searchProject(query: string) {
|
|
const projectRequestItem: RequestItem<ProjectCriteria> = new RequestItem();
|
|
projectRequestItem.criteria = new ProjectCriteria();
|
|
projectRequestItem.criteria.like = query;
|
|
return this.projectService.getWithExternal(projectRequestItem);
|
|
}
|
|
|
|
formSubmit(): void {
|
|
//this.touchAllFormFields(this.formGroup);
|
|
if (!this.isFormValid()) { return; }
|
|
this.onSubmit();
|
|
}
|
|
|
|
public isFormValid() {
|
|
return this.formGroup.valid;
|
|
}
|
|
|
|
onSubmit(): void {
|
|
this.dataManagementPlanService.createDmp(this.formGroup.getRawValue())
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(
|
|
complete => this.onCallbackSuccess(),
|
|
error => this.onCallbackError(error)
|
|
);
|
|
}
|
|
|
|
onCallbackSuccess(): void {
|
|
this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
this.router.navigate(['/plans']);
|
|
}
|
|
|
|
onCallbackError(error: any) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public cancel(): void {
|
|
this.router.navigate(['/plans']);
|
|
}
|
|
|
|
filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
this.filteredOrganisations = undefined;
|
|
this.filteringOrganisationsAsync = true;
|
|
|
|
return this.externalSourcesService.searchDMPOrganizations(value);
|
|
}
|
|
|
|
filterResearchers(value: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
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);
|
|
}
|
|
|
|
}
|