diff --git a/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.css b/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.css new file mode 100644 index 000000000..31e8a8de3 --- /dev/null +++ b/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.css @@ -0,0 +1,35 @@ +.full-width { + width: 100%; +} + +.input-table { + table-layout: fixed; +} + +.table-card .mat-grid-tile { + background: rgba(0, 0, 0, 0.32); +} + +.project-editor { + mat-form-field { + width: 100%; + padding: 3px; + } + + .mat-card { + margin: 16px 0; + } + + p { + margin: 16px; + } + + .left-button { + float: left; + } + + .description-area { + height: 100px; + } + +} diff --git a/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.html b/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.html new file mode 100644 index 000000000..177130ba3 --- /dev/null +++ b/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.html @@ -0,0 +1,97 @@ +
+
+ + {{'DMP-EDITOR.TITLE.NEW' | translate}} + {{'DMP-EDITOR.TITLE.EDIT' | translate}} {{project.label}} + + + + + {{baseErrorModel.label}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + + + + + + + + + {{errorModel.description}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + + + + +
{{chip.name.substring(0, 1).toUpperCase()}}
+ {{chip.name}} +
+ +
+ {{option.name}} +
+
+ +
+ + + +
{{chip.name.substring(0, 1).toUpperCase()}}
+ {{chip.name}} +
+ +
+ {{option.name}} +
+
+ +
+ +
+ + + +
+ +
+
+
+
{{ formGroup.value | json }}
+
\ No newline at end of file diff --git a/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.ts b/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.ts new file mode 100644 index 000000000..a1a974d42 --- /dev/null +++ b/dmp-frontend/src/app/datasets_new/editor/dataset-editor.component.ts @@ -0,0 +1,144 @@ +import { Component, ViewChild, OnInit, AfterViewInit, ViewEncapsulation } from "@angular/core"; +import { MatPaginator, MatSort, MatSnackBar } from "@angular/material"; +import { Router, ActivatedRoute, Params } from "@angular/router"; +import { TranslateService } from "@ngx-translate/core"; +import { DataSource } from "@angular/cdk/table"; +import { Observable } from "rxjs/Observable"; +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"; +import { DatasetService } from "../../services/dataset/dataset.service"; +import { DatasetModel } from "../../models/datasets/DatasetModel"; +import { ServerService } from "../../services/server.service"; +import { ExternalSourcesService } from "../../services/external-sources/external-sources.service"; +import { ExternalSourcesItemModel } from "../../models/external-sources/ExternalSourcesItemModel"; + + + +@Component({ + selector: 'app-dataset-editor-component', + templateUrl: 'dataset-editor.component.html', + styleUrls: ['./dataset-editor.component.scss'], + providers: [DatasetService, ExternalSourcesService], + encapsulation: ViewEncapsulation.None +}) +export class DatasetEditorComponent implements AfterViewInit { + + isNew = true; + dataManagementPlan: DatasetModel; + formGroup: FormGroup = null; + + filteringOrganisationsAsync: boolean = false; + filteringResearchersAsync: boolean = false; + filteredOrganisations: ExternalSourcesItemModel[]; + filteredResearchers: ExternalSourcesItemModel[]; + + constructor( + private datasetService: DatasetService, + private externalSourcesService: ExternalSourcesService, + private route: ActivatedRoute, + public snackBar: MatSnackBar, + public router: Router, + public language: TranslateService, + ) { + + } + + ngAfterViewInit() { + this.route.params.subscribe((params: Params) => { + const itemId = params['id']; + + if (itemId != null) { + this.isNew = false; + this.datasetService.getSingle(itemId).map(data => data as DatasetModel) + .subscribe(data => { + this.dataManagementPlan = new JsonSerializer().fromJSONObject(data, DatasetModel); + this.formGroup = this.dataManagementPlan.buildForm(); + }); + } else { + this.dataManagementPlan = new DatasetModel(); + setTimeout(() => { + this.formGroup = this.dataManagementPlan.buildForm(); + }); + } + }); + } + + formSubmit(): void { + //this.touchAllFormFields(this.formGroup); + if (!this.isFormValid()) { return; } + //this.onSubmit(); + } + + public isFormValid() { + return this.formGroup.valid; + } + + // onSubmit(): void { + // this.dataManagementPlanService.createDataManagementPlan(this.formGroup.value).subscribe( + // complete => this.onCallbackSuccess(), + // error => this.onCallbackError(error) + // ); + // } + + 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'] + }) + this.router.navigate(['/dataManagementPlans']); + } + + onCallbackError(error: any) { + this.setErrorModel(error.error); + //this.validateAllFormFields(this.formGroup); + } + + public setErrorModel(errorModel: BaseErrorModel) { + Object.keys(errorModel).forEach(item => { + (this.dataManagementPlan.errorModel)[item] = (errorModel)[item]; + }) + } + + public cancel(): void { + this.router.navigate(['/dataManagementPlans']); + } + + filterOrganisations(value: string): void { + + this.filteredOrganisations = undefined; + if (value) { + this.filteringOrganisationsAsync = true; + + 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; + // }); + + }); + } + } + + filterResearchers(value: string): void { + + this.filteredResearchers = undefined; + if (value) { + this.filteringResearchersAsync = true; + + 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; + // }); + + }); + } + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/datasets/DatasetModel.ts b/dmp-frontend/src/app/models/datasets/DatasetModel.ts new file mode 100644 index 000000000..bd563addc --- /dev/null +++ b/dmp-frontend/src/app/models/datasets/DatasetModel.ts @@ -0,0 +1,63 @@ +import { Serializable } from "../Serializable"; +import { ValidationContext } from "../../utilities/validators/ValidationContext"; +import { FormGroup, FormBuilder, FormControl, Validators } from "@angular/forms"; +import { BackendErrorValidator } from "../../utilities/validators/BackendErrorValidator"; +import { BaseErrorModel } from "../error/BaseErrorModel"; +import { AutoCompleteItem } from "../../shared/components/autocomplete/AutoCompleteItem"; +import { ExternalSourcesItemModel } from "../external-sources/ExternalSourcesItemModel"; + +export class DatasetModel implements Serializable { + public id: String; + public label: String; + public profile: String; + public uri: String; + public status: String; + public description: String; + public services: ExternalSourcesItemModel[] = []; + public registries: ExternalSourcesItemModel[] = []; + public dataRepositories: ExternalSourcesItemModel[] = []; + + public errorModel: BaseErrorModel = new BaseErrorModel(); + + fromJSONObject(item: any): DatasetModel { + this.id = item.id; + this.label = item.label; + this.profile = item.profile; + this.uri = item.uri; + this.status = item.status; + this.description = item.description; + + return this; + } + + buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup { + if (context == null) { context = this.createValidationContext(); } + + const formGroup = new FormBuilder().group({ + label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators], + profile: [{ value: this.profile, disabled: disabled }, context.getValidation('profile').validators], + uri: [{ value: this.uri, disabled: disabled }, context.getValidation('uri').validators], + status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators], + description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators], + services: [{ value: this.services, disabled: disabled }, context.getValidation('services').validators], + registries: [{ value: this.registries, disabled: disabled }, context.getValidation('registries').validators], + dataRepositories: [{ value: this.dataRepositories, disabled: disabled }, context.getValidation('dataRepositories').validators] + }); + + return formGroup; + } + + createValidationContext(): ValidationContext { + const baseContext: ValidationContext = new ValidationContext(); + baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'label')] }); + baseContext.validation.push({ key: 'profile', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'profile')] }); + baseContext.validation.push({ key: 'uri', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'uri')] }); + baseContext.validation.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'status')] }); + baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'description')] }); + baseContext.validation.push({ key: 'services', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'services')] }); + baseContext.validation.push({ key: 'registries', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'registries')] }); + baseContext.validation.push({ key: 'dataRepositories', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'dataRepositories')] }); + + return baseContext; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/services/dataset/dataset.service.ts b/dmp-frontend/src/app/services/dataset/dataset.service.ts index 56c38ba64..594b64e6b 100644 --- a/dmp-frontend/src/app/services/dataset/dataset.service.ts +++ b/dmp-frontend/src/app/services/dataset/dataset.service.ts @@ -7,6 +7,7 @@ import { Observable } from 'rxjs/Observable'; import { DataTableRequest } from '../../models/data-table/DataTableRequest'; import { DataTableData } from '../../models/data-table/DataTableData'; import { DatasetListingModel } from '../../models/datasets/DatasetListingModel'; +import { DatasetModel } from '../../models/datasets/DatasetModel'; @Injectable() @@ -28,7 +29,7 @@ export class DatasetService { return this.http.post>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers }); } - // getSingle(id: string): Observable { - // return this.http.get(this.actionUrl + id, { headers: this.headers }); - // } + getSingle(id: string): Observable { + return this.http.get(this.actionUrl + id, { headers: this.headers }); + } }