Skip to content

Commit

Permalink
feat(resource-instance): add subclass creation support (DEV-553) (#686)
Browse files Browse the repository at this point in the history
* feat(new-resource-instance-form): add support for creating subclasses during the creation of a resource

* refactor: rename ontoIri to currentOntoIri to fix tests

* test(link-value): fix link value tests

* chore(config): add ls-test-server config

* chore(cleanup): remove console logs

* chore(link-value): add colon to clarify label
  • Loading branch information
mdelez committed Mar 22, 2022
1 parent b0d72a6 commit d0a260d
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 25 deletions.
22 changes: 22 additions & 0 deletions angular.json
Expand Up @@ -106,6 +106,22 @@
"vendorChunk": false,
"buildOptimizer": false,
"budgets": []
},
"ls-test-server": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.ls-test-server.ts"
}
],
"optimization": false,
"sourceMap": true,
"namedChunks": true,
"aot": true,
"extractLicenses": false,
"vendorChunk": false,
"buildOptimizer": false,
"budgets": []
}
}
},
Expand All @@ -123,6 +139,9 @@
},
"test-server": {
"browserTarget": "dsp-app:build:test-server"
},
"ls-test-server": {
"browserTarget": "dsp-app:build:ls-test-server"
}
}
},
Expand Down Expand Up @@ -176,6 +195,9 @@
},
"test-server": {
"devServerTarget": "dsp-app:serve:test-server"
},
"ls-test-server": {
"devServerTarget": "dsp-app:serve:ls-test-server"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -9,6 +9,7 @@
"ng": "ng",
"start": "ng serve",
"start-with-test-server": "ng serve --configuration test-server",
"start-with-ls-test-server": "ng serve --configuration ls-test-server",
"lint-ci": "eslint --color -c .eslintrc.js --ext .ts ./src/app",
"lint-local": "eslint --color --fix -c .eslintrc.js --ext .ts ./src/app",
"e2e": "ng e2e",
Expand Down
2 changes: 1 addition & 1 deletion src/app/main/dialog/dialog.component.html
Expand Up @@ -402,7 +402,7 @@
<div *ngSwitchCase="'createLinkResource'">
<app-dialog-header [title]="data.title" [subtitle]="'Create a new linked resource'"></app-dialog-header>
<mat-dialog-content>
<app-create-link-resource [parentResource]="data.parentResource" [propDef]="data.id" [resourceClassDef]="data.resourceClassDefinition" (closeDialog)="dialogRef.close($event)"></app-create-link-resource>
<app-create-link-resource [parentResource]="data.parentResource" [propDef]="data.id" [resourceClassDef]="data.resourceClassDefinition" [currentOntoIri]="data.ontoIri" (closeDialog)="dialogRef.close($event)"></app-create-link-resource>
</mat-dialog-content>
</div>

Expand Down
1 change: 1 addition & 0 deletions src/app/main/dialog/dialog.component.ts
Expand Up @@ -22,6 +22,7 @@ export interface DialogData {
selectedResources?: FilteredResources;
resourceClassDefinition?: string;
fullSize?: boolean;
ontoIri?: string;
}

export interface ConfirmationWithComment {
Expand Down
Expand Up @@ -424,7 +424,6 @@ export class PropertyFormComponent implements OnInit {

this._dspApiConnection.v2.onto.updateResourceProperty(onto4Comment).subscribe(
(classCommentResponse: ResourcePropertyDefinitionWithAllLanguages) => {
console.log(classCommentResponse);
this.lastModificationDate = classCommentResponse.lastModificationDate;

if (!this.unsupportedPropertyType) {
Expand Down
Expand Up @@ -8,9 +8,10 @@

<app-select-properties #selectProps
[ontologyInfo]="ontologyInfo"
[resourceClass]="resourceClass"
[selectedResourceClass]="resourceClass"
[properties]="properties"
[parentForm]="propertiesForm"
[currentOntoIri]="currentOntoIri"
class="select-properties">
</app-select-properties>
<div class="form-panel form-action">
Expand Down
Expand Up @@ -27,6 +27,7 @@ export class CreateLinkResourceComponent implements OnInit {
@Input() parentResource: ReadResource;
@Input() propDef: string;
@Input() resourceClassDef: string;
@Input() currentOntoIri: string;

@Output() closeDialog: EventEmitter<any> = new EventEmitter<any>();

Expand Down Expand Up @@ -55,7 +56,6 @@ export class CreateLinkResourceComponent implements OnInit {
(onto: ResourceClassAndPropertyDefinitions) => {
this.ontologyInfo = onto;
this.resourceClass = onto.classes[this.resourceClassDef];
// this.properties = onto.getPropertyDefinitionsByType(ResourcePropertyDefinition);
this.properties = onto.getPropertyDefinitionsByType(ResourcePropertyDefinition).filter(
prop =>
!prop.isLinkProperty &&
Expand Down
Expand Up @@ -19,7 +19,7 @@
<app-time-value class="parent-value-component" #displayVal *ngSwitchCase="constants.TimeValue" [mode]="mode" [displayValue]="$any(displayValue)"></app-time-value>
<app-geoname-value class="parent-value-component" #displayVal *ngSwitchCase="constants.GeonameValue" [mode]="mode" [displayValue]="$any(displayValue)"></app-geoname-value>
<app-link-value class="parent-value-component" #displayVal *ngSwitchCase="constants.LinkValue" [mode]="mode" [displayValue]="$any(displayValue)"
[parentResource]="parentResource" [propIri]="displayValue.property" (referredResourceClicked)="referredResourceClicked.emit($event)" (referredResourceHovered)="referredResourceHovered.emit($event)"></app-link-value>
[parentResource]="parentResource" [propIri]="displayValue.property" [currentOntoIri]="ontoIri" (referredResourceClicked)="referredResourceClicked.emit($event)" (referredResourceHovered)="referredResourceHovered.emit($event)"></app-link-value>
<!-- <app-date-value class="parent-value-component" #displayVal *ngSwitchCase="constants.DateValue" [mode]="mode" [displayValue]="$any(displayValue)" [displayOptions]="dateDisplayOptions" [labels]="showDateLabels" [ontologyDateFormat]="dateFormat"></app-date-value> -->
<app-date-value class="parent-value-component" #displayVal *ngSwitchCase="constants.DateValue" [mode]="mode" [displayValue]="$any(displayValue)" [ontologyDateFormat]="dateFormat"></app-date-value>
<app-list-value class="parent-value-component" #displayVal *ngSwitchCase="constants.ListValue" [mode]="mode" [displayValue]="$any(displayValue)"
Expand Down
Expand Up @@ -119,6 +119,8 @@ export class DisplayEditComponent implements OnInit {

user: ReadUser;

ontoIri: string;

constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _valueOperationEventService: ValueOperationEventService,
Expand All @@ -128,7 +130,7 @@ export class DisplayEditComponent implements OnInit {
}

ngOnInit() {

this.ontoIri = this.parentResource.type.split('#')[0];
this.mode = 'read';
this.dateDisplayOptions = 'all';
this.showDateLabels = true;
Expand Down
Expand Up @@ -69,9 +69,10 @@
<!-- create property values -->
<app-select-properties #selectProps
[ontologyInfo]="ontologyInfo"
[resourceClass]="selectedResourceClass"
[selectedResourceClass]="selectedResourceClass"
[properties]="properties"
[parentForm]="propertiesParentForm"
[currentOntoIri]="selectedOntology"
class="select-properties">
</app-select-properties>

Expand Down
Expand Up @@ -44,7 +44,8 @@
[parentResource]="parentResource"
[parentForm]="parentForm"
[formName]="prop.label + '_' + i"
[isRequiredProp]="propertyValuesKeyValuePair[prop.id + '-cardinality']">
[isRequiredProp]="propertyValuesKeyValuePair[prop.id + '-cardinality']"
[currentOntoIri]="currentOntoIri">
</app-switch-properties>
</div>
<div class="buttons">
Expand Down
Expand Up @@ -21,9 +21,10 @@ import { SwitchPropertiesComponent } from './switch-properties/switch-properties
<app-select-properties
#selectProps
[ontologyInfo]="ontoInfo"
[resourceClass]="selectedResourceClass"
[selectedResourceClass]="selectedResourceClass"
[properties]="properties"
[parentForm]="propertiesParentForm">
[parentForm]="propertiesParentForm"
[currentOntoIri]="currentOntoIri">
</app-select-properties>`
})
class TestSelectPropertiesParentComponent implements OnInit {
Expand All @@ -38,6 +39,8 @@ class TestSelectPropertiesParentComponent implements OnInit {

propertiesParentForm: FormGroup;

currentOntoIri: string;

constructor(private _fb: FormBuilder) { }

ngOnInit() {
Expand All @@ -48,6 +51,8 @@ class TestSelectPropertiesParentComponent implements OnInit {
this.selectedResourceClass = this.ontoInfo.classes['http://0.0.0.0:3333/ontology/0001/anything/v2#Thing'];

this.properties = this.ontoInfo.getPropertyDefinitionsByType(ResourcePropertyDefinition).filter(prop => prop.isEditable && !prop.isLinkProperty);

this.currentOntoIri = 'http://0.0.0.0:3333/ontology/0001/anything/v2';
}

}
Expand Down
Expand Up @@ -28,10 +28,12 @@ export class SelectPropertiesComponent implements OnInit {

@Input() ontologyInfo: ResourceClassAndPropertyDefinitions;

@Input() resourceClass: ResourceClassDefinition;
@Input() selectedResourceClass: ResourceClassDefinition;

@Input() parentForm: FormGroup;

@Input() currentOntoIri: string;

parentResource = new ReadResource();

index = 0;
Expand Down Expand Up @@ -79,7 +81,7 @@ export class SelectPropertiesComponent implements OnInit {
return CardinalityUtil.createValueForPropertyAllowed(
prop.id,
this.propertyValuesKeyValuePair[prop.id].length,
this.ontologyInfo.classes[this.resourceClass.id]
this.ontologyInfo.classes[this.selectedResourceClass.id]
);
}

Expand All @@ -91,8 +93,8 @@ export class SelectPropertiesComponent implements OnInit {
* @param propId property id
*/
isPropRequired(propId: string): boolean {
if (this.resourceClass !== undefined && propId) {
this.resourceClass.propertiesList.filter(
if (this.selectedResourceClass !== undefined && propId) {
this.selectedResourceClass.propertiesList.filter(
(card: IHasProperty) => {
if (card.propertyIndex === propId) {
// cardinality 1 or 1-N
Expand Down
Expand Up @@ -10,7 +10,7 @@
<app-time-value #createVal *ngSwitchCase="constants.TimeValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-time-value>
<app-geoname-value #createVal *ngSwitchCase="constants.GeonameValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-geoname-value>
<app-link-value #createVal *ngSwitchCase="constants.LinkValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"
[parentResource]="parentResource" [propIri]="property.id"></app-link-value>
[parentResource]="parentResource" [propIri]="property.id" [currentOntoIri]="currentOntoIri"></app-link-value>
<app-date-value #createVal *ngSwitchCase="constants.DateValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-date-value>
<app-list-value #createVal *ngSwitchCase="constants.ListValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"
[propertyDef]="property"></app-list-value>
Expand Down
@@ -1,6 +1,6 @@
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Constants, ReadResource, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
import { Constants, ReadResource, ResourceClassDefinition, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
import { BaseValueDirective } from 'src/app/main/directive/base-value.directive';
import { ValueService } from '../../../services/value.service';

Expand All @@ -23,6 +23,8 @@ export class SwitchPropertiesComponent implements OnInit {

@Input() isRequiredProp: boolean;

@Input() currentOntoIri?: string;

mode = 'create';

// gui element in case of textValue
Expand All @@ -35,7 +37,6 @@ export class SwitchPropertiesComponent implements OnInit {
) { }

ngOnInit(): void {

// 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;
Expand Down
Expand Up @@ -9,8 +9,8 @@
<mat-form-field class="child-value-component" floatLabel="never">
<input matInput [formControlName]="'value'" class="value" type="text" placeholder="{{resourceClassLabel}}" aria-label="resource" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayResource">
<mat-option (click)="openDialog('createLinkResource', $event, propIri)">
Create New {{resourceClassLabel}}
<mat-option *ngFor="let rc of resourceClasses" (click)="openDialog('createLinkResource', $event, propIri, rc)">
Create New: {{rc?.label}}
</mat-option>
<mat-option *ngFor="let res of resources" [value]="res">
{{res?.label}}
Expand Down

0 comments on commit d0a260d

Please sign in to comment.