Skip to content

Commit 97230d1

Browse files
author
André Kilchenmann
authored
feat(ontology): default language for property label (#382)
* feat(ontology): language selector in res class form * feat(ontology): language selector for property label * chore(ontology): fix res class tooltip: show comment * fix(ontology): select default language in edit mode * chore(ontology): disable language selector in edit mode * chore(ontology): shortened the placeholder
1 parent 34c74a6 commit 97230d1

5 files changed

Lines changed: 44 additions & 8 deletions

File tree

‎src/app/project/ontology/ontology.component.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ <h3 class="mat-title" [matTooltip]="ontology.id">{{ontology?.label}}</h3>
133133
cdkDragBoundary=".drag-drop-stop">
134134
<mat-toolbar class="resource-class-header" cdkDragHandle>
135135
<mat-toolbar-row>
136-
<h4 mat-card-title [matTooltip]="resClass.label" matTooltipPosition="above">
136+
<h4 mat-card-title [matTooltip]="resClass.comment" matTooltipPosition="above">
137137
{{resClass.label | dspTruncate: 24}}</h4>
138138
<span class="fill-remaining-space"></span>
139139
<button mat-icon-button [matMenuTriggerFor]="resClassMenu"

‎src/app/project/ontology/resource-class-form/resource-class-form.component.html‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@
5353

5454
<!-- content: Step 2 = define properties for resource class -->
5555
<div *ngIf="!showResourceClassForm" class="properties-data">
56+
<!-- default language selector -->
57+
<mat-form-field class="properties-language">
58+
<mat-label>Default language for the labels</mat-label>
59+
<mat-select [formControl]="resourceClassForm.controls['language']" [value]="resourceClassForm.value['language']" [disabled]="edit">
60+
<mat-option *ngFor="let option of languages" [value]="option.language">
61+
{{ option.value }}
62+
</mat-option>
63+
</mat-select>
64+
</mat-form-field>
5665

5766
<!-- propertiy: one line, with "add" icon to add additional properties -->
5867
<div cdkDropList class="properties-list" (cdkDropListDropped)="drop($event)">
@@ -75,7 +84,7 @@
7584
aria-label="Delete this property" class="suffix delete-line" (click)="removeProperty(i)">
7685
<mat-icon>delete_outlined</mat-icon>
7786
</button>
78-
<!-- </div> -->
87+
<!-- </div> -->
7988
</div>
8089
<button [disabled]="!properties.valid" mat-button type="button" color="primary"
8190
aria-label="Add new property" class="add-new-line" (click)="addProperty()">
@@ -88,7 +97,7 @@
8897
<button *ngIf="!edit" mat-button type="button" (click)="prevStep($event)">
8998
{{ 'appLabels.form.action.back' | translate }}
9099
</button>
91-
<button *ngIf="edit" mat-button type="button" (click)="closeDialog.emit()">
100+
<button mat-button type="button" (click)="closeDialog.emit()">
92101
{{ 'appLabels.form.action.cancel' | translate }}
93102
</button>
94103
</span>

‎src/app/project/ontology/resource-class-form/resource-class-form.component.scss‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
margin-bottom: 2px;
3737
}
3838

39+
.properties-language {
40+
position: absolute;
41+
margin-left: 600px;
42+
margin-top: -$header-height;
43+
}
44+
3945
// properties
4046
.property-line {
4147
display: flex;

‎src/app/project/ontology/resource-class-form/resource-class-form.component.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { StringLiteralV2 } from '@dasch-swiss/dsp-js/src/models/v2/string-litera
2323
import { DspApiConnectionToken } from '@dasch-swiss/dsp-ui';
2424
import { from, of, Subscription } from 'rxjs';
2525
import { concatMap } from 'rxjs/operators';
26+
import { AppGlobal } from 'src/app/app-global';
2627
import { CacheService } from 'src/app/main/cache/cache.service';
2728
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
2829
import { Property, ResourceClassFormService } from './resource-class-form.service';
@@ -140,6 +141,11 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC
140141

141142
lastModificationDate: string;
142143

144+
// for the language selector
145+
selectedLanguage = 'en';
146+
languages: StringLiteral[] = AppGlobal.languagesList;
147+
148+
143149
constructor(
144150
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
145151
private _cache: CacheService,
@@ -223,7 +229,6 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC
223229
.subscribe(resourceClass => {
224230
this.resourceClassForm = resourceClass;
225231
});
226-
this.resourceClassForm.valueChanges.subscribe(data => this.onValueChanged(data));
227232

228233
} else {
229234
// edit mode: res class cardinality
@@ -242,6 +247,9 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC
242247
this.resourceClassForm = resourceClass;
243248
this.properties = this.resourceClassForm.get('properties') as FormArray;
244249
});
250+
251+
// set default property language from resource class / first element
252+
this.resourceClassForm.controls.language.setValue(ontoClasses[key].labels[0].language);
245253
}
246254
});
247255
}
@@ -254,6 +262,7 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC
254262
this.properties = this.resourceClassForm.get('properties') as FormArray;
255263
});
256264
}
265+
257266
this.resourceClassForm.valueChanges.subscribe(data => this.onValueChanged(data));
258267
}
259268

@@ -343,6 +352,9 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC
343352
// use response to go further with properties
344353
this.updateParent.emit({ title: this.resourceClassLabels[0].value, subtitle: 'Define the metadata fields for the resource class' });
345354

355+
// set default property language from res class label
356+
this.resourceClassForm.controls.language.setValue(this.resourceClassLabels[0].language);
357+
346358
// load one first property line
347359
if (!this.resourceClassForm.value.properties.length) {
348360
this.addProperty();
@@ -523,7 +535,12 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC
523535
const newResProp = new CreateResourceProperty();
524536
newResProp.name = uniquePropName;
525537
// TODO: update prop.label and use StringLiteralInput in property-form
526-
newResProp.label = [{ "value": prop.label }];
538+
newResProp.label = [
539+
{
540+
'value': prop.label,
541+
'language': this.resourceClassForm.value['language']
542+
}
543+
];
527544
if (prop.guiAttr) {
528545
switch (prop.type.gui_ele) {
529546

‎src/app/project/ontology/resource-class-form/resource-class-form.service.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
3-
import { Cardinality, Constants, IHasProperty, PropertyDefinition, ResourceClassDefinition, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
3+
import { Cardinality, Constants, IHasProperty, PropertyDefinition, ResourceClassDefinition, ResourcePropertyDefinition, StringLiteral } from '@dasch-swiss/dsp-js';
44
import { BehaviorSubject, Observable } from 'rxjs';
55
import { DefaultProperties, PropertyType } from '../default-data/default-properties';
66

@@ -69,22 +69,26 @@ export class PropertyForm {
6969

7070
// resource class data structure
7171
export class ResourceClass {
72+
language: string;
7273
properties: Property[];
7374

74-
constructor(properties?: Property[]) {
75+
constructor(language = 'en', properties?: Property[]) {
76+
this.language = language;
7577
this.properties = properties;
7678
}
7779
}
7880

7981

8082
// resource class form controls
8183
export class ResourceClassForm {
84+
language = new FormControl();
8285
properties = new FormArray([]);
8386

8487
constructor(resourceClass: ResourceClass) {
88+
this.language.setValue('en');
8589
if (resourceClass.properties) {
8690
let i = 0;
87-
this.properties.setControl
91+
this.properties.setControl;
8892
resourceClass.properties.forEach(prop => {
8993
this.properties[i] = new FormControl(prop);
9094
i++;

0 commit comments

Comments
 (0)