@@ -19,7 +24,8 @@
[property]="prop"
[parentResource]="parentResource"
[parentForm]="parentForm"
- [formName]="prop.label + '_' + i">
+ [formName]="prop.label + '_' + i"
+ [isRequiredProp]="propertyValuesKeyValuePair[prop.id + '-cardinality']">
diff --git a/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.scss b/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.scss
index 53a0e43cd7..d236932b33 100644
--- a/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.scss
+++ b/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.scss
@@ -40,11 +40,21 @@
.label {
text-align: right;
+ display: block;
+ float: left;
+ width: 95%;
}
.label-info {
cursor: help;
}
+
+ .propIsRequired {
+ color: red;
+ display: block;
+ float: right;
+ width: 5%;
+ }
}
.property-value {
diff --git a/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.spec.ts b/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.spec.ts
index dd1595560a..793aef53f7 100644
--- a/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.spec.ts
+++ b/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.spec.ts
@@ -97,8 +97,8 @@ describe('SelectPropertiesComponent', () => {
}
}
- // each property has two entries in the keyValuePair object
- expect(propsArray.length).toEqual(18 * 2);
+ // each property has three entries in the keyValuePair object
+ expect(propsArray.length).toEqual(18 * 3);
});
describe('Add/Delete functionality', () => {
diff --git a/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.ts b/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.ts
index d1020ad5ec..cd58e271b2 100644
--- a/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.ts
+++ b/src/app/workspace/resource/resource-instance-form/select-properties/select-properties.component.ts
@@ -1,6 +1,6 @@
-import { Component, Input, OnInit, QueryList, ViewChildren } from '@angular/core';
+import { AfterViewInit, Component, Input, OnInit, QueryList, ViewChildren } from '@angular/core';
import { FormGroup } from '@angular/forms';
-import { CardinalityUtil, ReadResource, ResourceClassAndPropertyDefinitions, ResourceClassDefinition, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
+import { Cardinality, CardinalityUtil, IHasProperty, ReadResource, ResourceClassAndPropertyDefinitions, ResourceClassDefinition, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
import { ValueService } from '@dasch-swiss/dsp-ui';
import { SwitchPropertiesComponent } from './switch-properties/switch-properties.component';
@@ -29,6 +29,8 @@ export class SelectPropertiesComponent implements OnInit {
addButtonIsVisible: boolean;
+ isRequiredProp: boolean;
+
constructor(private _valueService: ValueService) { }
ngOnInit() {
@@ -45,6 +47,11 @@ export class SelectPropertiesComponent implements OnInit {
// each property will also have a filtered array to be used when deleting a value.
// see the deleteValue method below for more info
this.propertyValuesKeyValuePair[prop.id + '-filtered'] = [0];
+
+ // each property will also have a cardinality array to be used when marking a field as required
+ // see the isPropRequired method below for more info
+ this.isPropRequired(prop.id);
+ this.propertyValuesKeyValuePair[prop.id + '-cardinality'] = [this.isRequiredProp ? 1 : 0];
}
}
}
@@ -52,6 +59,7 @@ export class SelectPropertiesComponent implements OnInit {
this.parentResource.entityInfo = this.ontologyInfo;
}
+
/**
* Given a resource property, check if an add button should be displayed under the property values
*
@@ -65,6 +73,31 @@ export class SelectPropertiesComponent implements OnInit {
);
}
+ /**
+ * Check the cardinality of a property
+ * If the cardinality is 1 or 1-N, the property will be marked as required
+ * If the cardinality is 0-1 or 0-N, the property will not be required
+ *
+ * @param propId property id
+ */
+ isPropRequired(propId: string): boolean {
+ if (this.resourceClass !== undefined && propId) {
+ this.resourceClass.propertiesList.filter(
+ (card: IHasProperty) => {
+ if (card.propertyIndex === propId) {
+ // cardinality 1 or 1-N
+ if (card.cardinality === Cardinality._1 || card.cardinality === Cardinality._1_n) {
+ this.isRequiredProp = true;
+ } else { // cardinality 0-1 or 0-N
+ this.isRequiredProp = false;
+ }
+ }
+ }
+ );
+ return this.isRequiredProp;
+ }
+ }
+
/**
* Called from the template when the user clicks on the add button
*/
diff --git a/src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.html b/src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.html
index e915b03a5c..4e841e88b3 100644
--- a/src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.html
+++ b/src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.html
@@ -1,18 +1,18 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
Cannot match any value component for {{property.objectType}}
diff --git a/src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.ts b/src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.ts
index 2fbe9287e3..44ba10e11d 100644
--- a/src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.ts
+++ b/src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.ts
@@ -1,4 +1,4 @@
-import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core';
+import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Constants, ReadResource, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
import { BaseValueComponent } from 'src/app/base-value.component';
@@ -8,7 +8,7 @@ import { BaseValueComponent } from 'src/app/base-value.component';
templateUrl: './switch-properties.component.html',
styleUrls: ['./switch-properties.component.scss']
})
-export class SwitchPropertiesComponent implements OnInit, AfterViewInit {
+export class SwitchPropertiesComponent implements OnInit {
@ViewChild('createVal') createValueComponent: BaseValueComponent;
@@ -20,23 +20,21 @@ export class SwitchPropertiesComponent implements OnInit, AfterViewInit {
@Input() formName: string;
+ @Input() isRequiredProp: boolean;
+
mode = 'create';
constants = Constants;
constructor() { }
ngOnInit(): void {
- // console.log('prop', this.property);
- }
-
- ngAfterViewInit() {
- // console.log('createValueComponent', this.createValueComponent);
- // this.saveNewValue();
+ // the input isRequiredProp provided by KeyValuePair is stored as a number
+ // a conversion from a number to a boolean is required by the input valueRequiredValidator
+ this.isRequiredProp = !!+this.isRequiredProp;
}
saveNewValue() {
const createVal = this.createValueComponent.getNewValue();
- console.log('createVal', createVal);
}
}