diff --git a/src/app/project/ontology/ontology.component.html b/src/app/project/ontology/ontology.component.html index 99bec80683..ef864efadd 100644 --- a/src/app/project/ontology/ontology.component.html +++ b/src/app/project/ontology/ontology.component.html @@ -133,7 +133,7 @@

{{ontology?.label}}

cdkDragBoundary=".drag-drop-stop"> -

+

{{resClass.label | dspTruncate: 24}}

- + - diff --git a/src/app/project/ontology/resource-class-form/resource-class-form.component.scss b/src/app/project/ontology/resource-class-form/resource-class-form.component.scss index 248d734804..be5be95e6e 100644 --- a/src/app/project/ontology/resource-class-form/resource-class-form.component.scss +++ b/src/app/project/ontology/resource-class-form/resource-class-form.component.scss @@ -36,6 +36,12 @@ margin-bottom: 2px; } +.properties-language { + position: absolute; + margin-left: 600px; + margin-top: -$header-height; +} + // properties .property-line { display: flex; diff --git a/src/app/project/ontology/resource-class-form/resource-class-form.component.ts b/src/app/project/ontology/resource-class-form/resource-class-form.component.ts index 4dfa56e0f9..445939423d 100644 --- a/src/app/project/ontology/resource-class-form/resource-class-form.component.ts +++ b/src/app/project/ontology/resource-class-form/resource-class-form.component.ts @@ -23,6 +23,7 @@ import { StringLiteralV2 } from '@dasch-swiss/dsp-js/src/models/v2/string-litera import { DspApiConnectionToken } from '@dasch-swiss/dsp-ui'; import { from, of, Subscription } from 'rxjs'; import { concatMap } from 'rxjs/operators'; +import { AppGlobal } from 'src/app/app-global'; import { CacheService } from 'src/app/main/cache/cache.service'; import { ErrorHandlerService } from 'src/app/main/error/error-handler.service'; import { Property, ResourceClassFormService } from './resource-class-form.service'; @@ -140,6 +141,11 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC lastModificationDate: string; + // for the language selector + selectedLanguage = 'en'; + languages: StringLiteral[] = AppGlobal.languagesList; + + constructor( @Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection, private _cache: CacheService, @@ -223,7 +229,6 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC .subscribe(resourceClass => { this.resourceClassForm = resourceClass; }); - this.resourceClassForm.valueChanges.subscribe(data => this.onValueChanged(data)); } else { // edit mode: res class cardinality @@ -242,6 +247,9 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC this.resourceClassForm = resourceClass; this.properties = this.resourceClassForm.get('properties') as FormArray; }); + + // set default property language from resource class / first element + this.resourceClassForm.controls.language.setValue(ontoClasses[key].labels[0].language); } }); } @@ -254,6 +262,7 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC this.properties = this.resourceClassForm.get('properties') as FormArray; }); } + this.resourceClassForm.valueChanges.subscribe(data => this.onValueChanged(data)); } @@ -343,6 +352,9 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC // use response to go further with properties this.updateParent.emit({ title: this.resourceClassLabels[0].value, subtitle: 'Define the metadata fields for the resource class' }); + // set default property language from res class label + this.resourceClassForm.controls.language.setValue(this.resourceClassLabels[0].language); + // load one first property line if (!this.resourceClassForm.value.properties.length) { this.addProperty(); @@ -523,7 +535,12 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC const newResProp = new CreateResourceProperty(); newResProp.name = uniquePropName; // TODO: update prop.label and use StringLiteralInput in property-form - newResProp.label = [{ "value": prop.label }]; + newResProp.label = [ + { + 'value': prop.label, + 'language': this.resourceClassForm.value['language'] + } + ]; if (prop.guiAttr) { switch (prop.type.gui_ele) { diff --git a/src/app/project/ontology/resource-class-form/resource-class-form.service.ts b/src/app/project/ontology/resource-class-form/resource-class-form.service.ts index 645c0e10c3..57f0f2b23f 100644 --- a/src/app/project/ontology/resource-class-form/resource-class-form.service.ts +++ b/src/app/project/ontology/resource-class-form/resource-class-form.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; -import { Cardinality, Constants, IHasProperty, PropertyDefinition, ResourceClassDefinition, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js'; +import { Cardinality, Constants, IHasProperty, PropertyDefinition, ResourceClassDefinition, ResourcePropertyDefinition, StringLiteral } from '@dasch-swiss/dsp-js'; import { BehaviorSubject, Observable } from 'rxjs'; import { DefaultProperties, PropertyType } from '../default-data/default-properties'; @@ -69,9 +69,11 @@ export class PropertyForm { // resource class data structure export class ResourceClass { + language: string; properties: Property[]; - constructor(properties?: Property[]) { + constructor(language = 'en', properties?: Property[]) { + this.language = language; this.properties = properties; } } @@ -79,12 +81,14 @@ export class ResourceClass { // resource class form controls export class ResourceClassForm { + language = new FormControl(); properties = new FormArray([]); constructor(resourceClass: ResourceClass) { + this.language.setValue('en'); if (resourceClass.properties) { let i = 0; - this.properties.setControl + this.properties.setControl; resourceClass.properties.forEach(prop => { this.properties[i] = new FormControl(prop); i++;