diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 7d1788b063..e0ec15a055 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -155,6 +155,7 @@ import { SearchSelectOntologyComponent } from './workspace/search/advanced-searc
import { ExpertSearchComponent } from './workspace/search/expert-search/expert-search.component';
import { FulltextSearchComponent } from './workspace/search/fulltext-search/fulltext-search.component';
import { SearchPanelComponent } from './workspace/search/search-panel/search-panel.component';
+import { CreateLinkResourceComponent } from './workspace/resource/operations/create-link-resource/create-link-resource.component';
// translate: AoT requires an exported function for factories
export function httpLoaderFactory(httpClient: HttpClient) {
@@ -298,6 +299,7 @@ export function httpLoaderFactory(httpClient: HttpClient) {
UsersComponent,
UsersListComponent,
YetAnotherDateValueComponent,
+ CreateLinkResourceComponent,
],
imports: [
AngularSplitModule.forRoot(),
diff --git a/src/app/main/dialog/dialog.component.html b/src/app/main/dialog/dialog.component.html
index 4b9400a6e5..2c7fbecd97 100644
--- a/src/app/main/dialog/dialog.component.html
+++ b/src/app/main/dialog/dialog.component.html
@@ -399,6 +399,13 @@
+
diff --git a/src/app/main/dialog/dialog.component.ts b/src/app/main/dialog/dialog.component.ts
index f1b770cbce..bfb51d3e0a 100644
--- a/src/app/main/dialog/dialog.component.ts
+++ b/src/app/main/dialog/dialog.component.ts
@@ -1,5 +1,6 @@
import { Component, Inject, OnInit, ViewChild } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
+import { ReadResource } from '@dasch-swiss/dsp-js';
import { PropertyInfoObject } from 'src/app/project/ontology/default-data/default-properties';
import { FilteredResources } from 'src/app/workspace/results/list-view/list-view.component';
@@ -16,8 +17,10 @@ export interface DialogData {
canBeUpdated?: boolean;
position?: number;
parentIri?: string;
+ parentResource?: ReadResource;
projectCode?: string;
selectedResources?: FilteredResources;
+ resourceClassDefinition?: string;
}
export interface ConfirmationWithComment {
diff --git a/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.html b/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.html
new file mode 100644
index 0000000000..b2265cb915
--- /dev/null
+++ b/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.html
@@ -0,0 +1,29 @@
+
diff --git a/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.scss b/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.scss
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.spec.ts b/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.spec.ts
new file mode 100644
index 0000000000..969ceedd20
--- /dev/null
+++ b/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.spec.ts
@@ -0,0 +1,310 @@
+import { Component, DebugElement, Inject, Input, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
+import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
+import { MatButtonModule } from '@angular/material/button';
+import { MatDialogModule } from '@angular/material/dialog';
+import { MatFormFieldModule } from '@angular/material/form-field';
+import { MatSnackBarModule } from '@angular/material/snack-bar';
+import { By } from '@angular/platform-browser';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import {
+ CreateIntValue,
+ CreateResource,
+ CreateTextValueAsString,
+ CreateValue,
+ MockOntology,
+ MockResource,
+ ReadResource,
+ ResourceClassAndPropertyDefinitions,
+ ResourceClassDefinition,
+ ResourcePropertyDefinition,
+ ResourcesEndpointV2
+} from '@dasch-swiss/dsp-js';
+import { OntologyCache } from '@dasch-swiss/dsp-js/src/cache/ontology-cache/OntologyCache';
+import { TranslateModule } from '@ngx-translate/core';
+import { of } from 'rxjs';
+import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
+import { BaseValueDirective } from 'src/app/main/directive/base-value.directive';
+import { SwitchPropertiesComponent } from '../../resource-instance-form/select-properties/switch-properties/switch-properties.component';
+import { ValueService } from '../../services/value.service';
+import { IntValueComponent } from '../../values/int-value/int-value.component';
+import { TextValueAsStringComponent } from '../../values/text-value/text-value-as-string/text-value-as-string.component';
+
+import { CreateLinkResourceComponent } from './create-link-resource.component';
+
+/**
+ * test host component to simulate parent component.
+ */
+@Component({
+ template: `
+
`
+})
+class TestHostComponent implements OnInit {
+
+ @ViewChild('createLinkResourceComp') createLinkResourceComponent: CreateLinkResourceComponent;
+
+ parentResource: ReadResource;
+ propDef: string;
+ resourceClassDef: string;
+
+ ngOnInit() {
+ MockResource.getTestThing().subscribe(res => {
+ this.parentResource = res;
+ this.propDef = 'http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherThingValue';
+ this.resourceClassDef = 'http://0.0.0.0:3333/ontology/0001/anything/v2#Thing';
+ });
+ }
+
+}
+
+/**
+ * mock select-properties component to use in tests.
+ */
+@Component({
+ selector: 'app-select-properties',
+ template: `
+
+
+ `
+})
+class MockSelectPropertiesComponent {
+ @ViewChildren('switchProp') switchPropertiesComponent: QueryList
;
+
+ // input for resource's label
+ @ViewChild('createVal') createValueComponent: BaseValueDirective;
+
+ @Input() properties: ResourcePropertyDefinition[];
+
+ @Input() ontologyInfo: ResourceClassAndPropertyDefinitions;
+
+ @Input() resourceClass: ResourceClassDefinition;
+
+ @Input() parentForm: FormGroup;
+
+ parentResource = new ReadResource();
+
+ constructor(private _valueService: ValueService) { }
+}
+
+/**
+ * mock switch-properties component to use in tests.
+ */
+@Component({
+ selector: 'app-switch-properties'
+})
+class MockSwitchPropertiesComponent {
+ @ViewChild('createVal') createValueComponent: BaseValueDirective;
+
+ @Input() property: ResourcePropertyDefinition;
+
+ @Input() parentResource: ReadResource;
+
+ @Input() parentForm: FormGroup;
+
+ @Input() formName: string;
+}
+
+/**
+ * mock value component to use in tests.
+ */
+@Component({
+ selector: 'dsp-int-value'
+})
+class MockCreateIntValueComponent implements OnInit {
+
+ @ViewChild('createVal') createValueComponent: IntValueComponent;
+
+ @Input() parentForm: FormGroup;
+
+ @Input() formName: string;
+
+ @Input() mode;
+
+ @Input() displayValue;
+
+ form: FormGroup;
+
+ valueFormControl: FormControl;
+
+ constructor(@Inject(FormBuilder) private _fb: FormBuilder) { }
+
+ ngOnInit(): void {
+ this.valueFormControl = new FormControl(null, [Validators.required]);
+
+ this.form = this._fb.group({
+ test: this.valueFormControl
+ });
+ }
+
+ getNewValue(): CreateValue {
+ const createIntVal = new CreateIntValue();
+
+ createIntVal.int = 123;
+
+ return createIntVal;
+ }
+
+ updateCommentVisibility(): void { }
+}
+
+/**
+ * mock value component to use in tests.
+ */
+@Component({
+ selector: 'app-text-value-as-string'
+})
+class MockCreateTextValueComponent implements OnInit {
+
+ @ViewChild('createVal') createValueComponent: TextValueAsStringComponent;
+
+ @Input() parentForm: FormGroup;
+
+ @Input() formName: string;
+
+ @Input() mode;
+
+ @Input() displayValue;
+
+ @Input() commentDisabled?: boolean;
+
+ @Input() valueRequiredValidator: boolean;
+
+ form: FormGroup;
+
+ valueFormControl: FormControl;
+ constructor(@Inject(FormBuilder) private _fb: FormBuilder) { }
+ ngOnInit(): void {
+ this.valueFormControl = new FormControl(null, [Validators.required]);
+ this.form = this._fb.group({
+ label: this.valueFormControl
+ });
+ }
+ getNewValue(): CreateValue {
+ const createTextVal = new CreateTextValueAsString();
+ createTextVal.text = 'My Label';
+ return createTextVal;
+ }
+ updateCommentVisibility(): void { }
+}
+
+describe('CreateLinkResourceComponent', () => {
+ let testHostComponent: TestHostComponent;
+ let testHostFixture: ComponentFixture;
+ let createLinkResourceComponentDe: DebugElement;
+
+ beforeEach(waitForAsync(() => {
+
+ const dspConnSpy = {
+ v2: {
+ ontologyCache: jasmine.createSpyObj('ontologyCache', ['getOntology', 'getResourceClassDefinition']),
+ res: jasmine.createSpyObj('res', ['createResource'])
+ }
+ };
+
+ TestBed.configureTestingModule({
+ declarations: [
+ CreateLinkResourceComponent,
+ TestHostComponent,
+ MockSelectPropertiesComponent,
+ MockCreateTextValueComponent,
+ MockSwitchPropertiesComponent,
+ MockCreateIntValueComponent
+ ],
+ imports: [
+ BrowserAnimationsModule,
+ MatButtonModule,
+ MatDialogModule,
+ MatFormFieldModule,
+ MatSnackBarModule,
+ ReactiveFormsModule,
+ TranslateModule.forRoot()
+ ],
+ providers: [
+ {
+ provide: DspApiConnectionToken,
+ useValue: dspConnSpy
+ },
+ ValueService
+ ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ const dspConnSpy = TestBed.inject(DspApiConnectionToken);
+
+ (dspConnSpy.v2.ontologyCache as jasmine.SpyObj).getResourceClassDefinition.and.callFake(
+ (resClassIri: string) => of(MockOntology.mockIResourceClassAndPropertyDefinitions('http://0.0.0.0:3333/ontology/0001/anything/v2#Thing'))
+ );
+
+ testHostFixture = TestBed.createComponent(TestHostComponent);
+ testHostComponent = testHostFixture.componentInstance;
+ testHostFixture.detectChanges();
+ expect(testHostComponent).toBeTruthy();
+
+ const hostCompDe = testHostFixture.debugElement;
+
+ createLinkResourceComponentDe = hostCompDe.query(By.directive(CreateLinkResourceComponent));
+
+ });
+
+ it('should initialize the properties array', async () => {
+ expect(testHostComponent.createLinkResourceComponent.properties.length).toEqual(18);
+ });
+
+ it('should submit the form', () => {
+ const dspConnSpy = TestBed.inject(DspApiConnectionToken);
+
+ (dspConnSpy.v2.res as jasmine.SpyObj).createResource.and.callFake(
+ () => {
+ let resource = new ReadResource();
+
+ MockResource.getTestThing().subscribe((res) => {
+ resource = res;
+ });
+
+ return of(resource);
+ }
+ );
+
+ const anythingOnto = MockOntology.mockReadOntology('http://0.0.0.0:3333/ontology/0001/anything/v2');
+
+ // get resource class definitions
+ const resourceClasses = anythingOnto.getClassDefinitionsByType(ResourceClassDefinition);
+
+ testHostComponent.createLinkResourceComponent.properties = new Array();
+
+ MockResource.getTestThing().subscribe(res => {
+ const resourcePropDef = (res.entityInfo as ResourceClassAndPropertyDefinitions).getAllPropertyDefinitions()[9];
+ testHostComponent.createLinkResourceComponent.properties.push(resourcePropDef as ResourcePropertyDefinition);
+ });
+
+ testHostFixture.detectChanges();
+
+ const selectPropertiesComp = createLinkResourceComponentDe.query(By.directive(MockSelectPropertiesComponent));
+
+ expect(selectPropertiesComp).toBeTruthy();
+
+ const label = new CreateTextValueAsString();
+ label.text = 'My Label';
+
+ const props = {};
+ const createVal = new CreateIntValue();
+ createVal.int = 123;
+ props['http://0.0.0.0:3333/ontology/0001/anything/v2#hasInteger'] = [createVal];
+
+ const expectedCreateResource = new CreateResource();
+ expectedCreateResource.label = 'My Label';
+ expectedCreateResource.type = 'http://0.0.0.0:3333/ontology/0001/anything/v2#Thing';
+ expectedCreateResource.properties = props;
+
+ testHostComponent.createLinkResourceComponent.onSubmit();
+
+ expect(dspConnSpy.v2.res.createResource).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.ts b/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.ts
new file mode 100644
index 0000000000..6831b23af3
--- /dev/null
+++ b/src/app/workspace/resource/operations/create-link-resource/create-link-resource.component.ts
@@ -0,0 +1,146 @@
+import { Component, EventEmitter, Inject, Input, OnInit, Output, ViewChild } from '@angular/core';
+import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
+import {
+ ApiResponseError,
+ Constants,
+ CreateFileValue,
+ CreateResource,
+ CreateTextValueAsString,
+ CreateValue,
+ KnoraApiConnection,
+ ReadResource,
+ ResourceClassAndPropertyDefinitions,
+ ResourceClassDefinition,
+ ResourcePropertyDefinition
+} from '@dasch-swiss/dsp-js';
+import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
+import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
+import { SelectPropertiesComponent } from '../../resource-instance-form/select-properties/select-properties.component';
+
+@Component({
+ selector: 'app-create-link-resource',
+ templateUrl: './create-link-resource.component.html',
+ styleUrls: ['./create-link-resource.component.scss']
+})
+export class CreateLinkResourceComponent implements OnInit {
+
+ @Input() parentResource: ReadResource;
+ @Input() propDef: string;
+ @Input() resourceClassDef: string;
+
+ @Output() closeDialog: EventEmitter = new EventEmitter();
+
+ @ViewChild('selectProps') selectPropertiesComponent: SelectPropertiesComponent;
+
+ properties: ResourcePropertyDefinition[];
+ propertiesForm: FormGroup;
+ resourceClass: ResourceClassDefinition;
+ ontologyInfo: ResourceClassAndPropertyDefinitions;
+ fileValue: CreateFileValue;
+
+ hasFileValue: 'stillImage' | 'movingImage' | 'audio' | 'document' | 'text' | 'archive';
+
+ propertiesObj = {};
+
+ constructor(
+ @Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
+ private _fb: FormBuilder,
+ private _errorHandler: ErrorHandlerService,
+ ) { }
+
+ ngOnInit(): void {
+ this.propertiesForm = this._fb.group({});
+
+ this._dspApiConnection.v2.ontologyCache.getResourceClassDefinition(this.resourceClassDef).subscribe(
+ (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 &&
+ prop.isEditable &&
+ prop.id !== Constants.HasStillImageFileValue &&
+ prop.id !== Constants.HasDocumentFileValue &&
+ prop.id !== Constants.HasAudioFileValue &&
+ prop.id !== Constants.HasArchiveFileValue
+ );
+
+ if (onto.properties[Constants.HasStillImageFileValue]) {
+ this.hasFileValue = 'stillImage';
+ } else if (onto.properties[Constants.HasDocumentFileValue]) {
+ this.hasFileValue = 'document';
+ } else if (onto.properties[Constants.HasAudioFileValue]) {
+ this.hasFileValue = 'audio';
+ } else if (onto.properties[Constants.HasArchiveFileValue]) {
+ this.hasFileValue = 'archive';
+ } else {
+ this.hasFileValue = undefined;
+ }
+ }
+ );
+ }
+
+ onSubmit() {
+ if (this.propertiesForm.valid) {
+ const createResource = new CreateResource();
+
+ const resLabelVal = this.selectPropertiesComponent.createValueComponent.getNewValue();
+
+ createResource.label = resLabelVal.text;
+
+ createResource.type = this.resourceClassDef;
+
+ // todo: find a better way to do this
+ createResource.attachedToProject = 'http://rdfh.ch/projects/' + this.resourceClassDef.split('/')[4];
+
+ this.selectPropertiesComponent.switchPropertiesComponent.forEach((child) => {
+ const createVal = child.createValueComponent.getNewValue();
+ const iri = child.property.id;
+ if (createVal instanceof CreateValue) {
+ if (this.propertiesObj[iri]) {
+ // if a key already exists, add the createVal to the array
+ this.propertiesObj[iri].push(createVal);
+ } else {
+ // if no key exists, add one and add the createVal as the first value of the array
+ this.propertiesObj[iri] = [createVal];
+ }
+ }
+
+ });
+
+ if (this.fileValue) {
+ switch (this.hasFileValue) {
+ case 'stillImage':
+ this.propertiesObj[Constants.HasStillImageFileValue] = [this.fileValue];
+ break;
+ case 'document':
+ this.propertiesObj[Constants.HasDocumentFileValue] = [this.fileValue];
+ break;
+ case 'audio':
+ this.propertiesObj[Constants.HasAudioFileValue] = [this.fileValue];
+ break;
+ case 'archive':
+ this.propertiesObj[Constants.HasArchiveFileValue] = [this.fileValue];
+ }
+ }
+
+ createResource.properties = this.propertiesObj;
+
+ this._dspApiConnection.v2.res.createResource(createResource).subscribe(
+ (res: ReadResource) => {
+ this.closeDialog.emit();
+ },
+ (error: ApiResponseError) => {
+ this._errorHandler.showMessage(error);
+ }
+ );
+ } else {
+ this.propertiesForm.markAllAsTouched();
+ }
+ }
+
+ setFileValue(file: CreateFileValue) {
+ this.fileValue = file;
+ }
+}
diff --git a/src/app/workspace/resource/values/link-value/link-value.component.html b/src/app/workspace/resource/values/link-value/link-value.component.html
index 2511ef23ce..04d2e1f9e0 100644
--- a/src/app/workspace/resource/values/link-value/link-value.component.html
+++ b/src/app/workspace/resource/values/link-value/link-value.component.html
@@ -7,8 +7,11 @@
-
+
+
+ Create New {{resourceClassLabel}}
+
{{res?.label}}
diff --git a/src/app/workspace/resource/values/link-value/link-value.component.spec.ts b/src/app/workspace/resource/values/link-value/link-value.component.spec.ts
index 6e4a103f68..3e727b13be 100644
--- a/src/app/workspace/resource/values/link-value/link-value.component.spec.ts
+++ b/src/app/workspace/resource/values/link-value/link-value.component.spec.ts
@@ -2,11 +2,13 @@ import { Component, DebugElement, OnInit, ViewChild } from '@angular/core';
import { waitForAsync, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
+import { MatDialogModule } from '@angular/material/dialog';
import { MatInputModule } from '@angular/material/input';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {
CreateLinkValue,
+ MockOntology,
MockResource,
ReadLinkValue,
ReadResource,
@@ -14,6 +16,7 @@ import {
SearchEndpointV2,
UpdateLinkValue
} from '@dasch-swiss/dsp-js';
+import { OntologyCache } from '@dasch-swiss/dsp-js/src/cache/ontology-cache/OntologyCache';
import { of } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { LinkValueComponent } from './link-value.component';
@@ -112,6 +115,7 @@ describe('LinkValueComponent', () => {
beforeEach(waitForAsync(() => {
const valuesSpyObj = {
v2: {
+ ontologyCache: jasmine.createSpyObj('ontologyCache', ['getOntology', 'getResourceClassDefinition']),
search: jasmine.createSpyObj('search', ['doSearchByLabel']),
}
};
@@ -126,6 +130,7 @@ describe('LinkValueComponent', () => {
ReactiveFormsModule,
MatInputModule,
MatAutocompleteModule,
+ MatDialogModule,
BrowserAnimationsModule
],
providers: [
@@ -150,6 +155,13 @@ describe('LinkValueComponent', () => {
let commentInputNativeElement;
beforeEach(() => {
+
+ const dspConnSpy = TestBed.inject(DspApiConnectionToken);
+
+ (dspConnSpy.v2.ontologyCache as jasmine.SpyObj).getResourceClassDefinition.and.callFake(
+ (resClassIri: string) => of(MockOntology.mockIResourceClassAndPropertyDefinitions('http://0.0.0.0:3333/ontology/0001/anything/v2#Thing'))
+ );
+
testHostFixture = TestBed.createComponent(TestHostDisplayValueComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();
@@ -483,6 +495,12 @@ describe('LinkValueComponent', () => {
beforeEach(() => {
+ const dspConnSpy = TestBed.inject(DspApiConnectionToken);
+
+ (dspConnSpy.v2.ontologyCache as jasmine.SpyObj).getResourceClassDefinition.and.callFake(
+ (resClassIri: string) => of(MockOntology.mockIResourceClassAndPropertyDefinitions('http://0.0.0.0:3333/ontology/0001/anything/v2#Thing'))
+ );
+
testHostFixture = TestBed.createComponent(TestHostCreateValueComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();
@@ -613,6 +631,12 @@ describe('LinkValueComponent', () => {
beforeEach(() => {
+ const dspConnSpy = TestBed.inject(DspApiConnectionToken);
+
+ (dspConnSpy.v2.ontologyCache as jasmine.SpyObj).getResourceClassDefinition.and.callFake(
+ (resClassIri: string) => of(MockOntology.mockIResourceClassAndPropertyDefinitions('http://0.0.0.0:3333/ontology/0001/anything/v2#Thing'))
+ );
+
testHostFixture = TestBed.createComponent(TestHostCreateValueNoValueRequiredComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();
diff --git a/src/app/workspace/resource/values/link-value/link-value.component.ts b/src/app/workspace/resource/values/link-value/link-value.component.ts
index f9b6ae7963..92a00cf497 100644
--- a/src/app/workspace/resource/values/link-value/link-value.component.ts
+++ b/src/app/workspace/resource/values/link-value/link-value.component.ts
@@ -10,16 +10,19 @@ import {
SimpleChanges
} from '@angular/core';
import { AbstractControl, FormBuilder, FormControl, FormGroup } from '@angular/forms';
+import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import {
CreateLinkValue,
KnoraApiConnection,
ReadLinkValue,
ReadResource,
ReadResourceSequence,
+ ResourceClassAndPropertyDefinitions,
UpdateLinkValue
} from '@dasch-swiss/dsp-js';
import { Subscription } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
+import { DialogComponent } from 'src/app/main/dialog/dialog.component';
import { BaseValueDirective } from 'src/app/main/directive/base-value.directive';
export function resourceValidator(control: AbstractControl) {
@@ -50,6 +53,7 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
valueFormControl: FormControl;
commentFormControl: FormControl;
form: FormGroup;
+ resourceClassLabel: string;
valueChangesSubscription: Subscription;
labelChangesSubscription: Subscription;
@@ -57,6 +61,7 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
customValidators = [resourceValidator];
constructor(
+ private _dialog: MatDialog,
@Inject(FormBuilder) private _fb: FormBuilder,
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection) {
super();
@@ -110,6 +115,11 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
const linkType = this.parentResource.getLinkPropertyIriFromLinkValuePropertyIri(this.propIri);
this.restrictToResourceClass = this.parentResource.entityInfo.properties[linkType].objectType;
+ // get label of resource class
+ this._dspApiConnection.v2.ontologyCache.getResourceClassDefinition(this.restrictToResourceClass).subscribe(
+ (onto: ResourceClassAndPropertyDefinitions) => this.resourceClassLabel = onto.classes[this.restrictToResourceClass].label
+ );
+
// initialize form control elements
this.valueFormControl = new FormControl(null);
@@ -203,4 +213,19 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
refResHovered() {
this.referredResourceHovered.emit(this.displayValue);
}
+
+ openDialog(mode: string, ev: Event, iri?: string): void {
+ ev.preventDefault();
+ const dialogConfig: MatDialogConfig = {
+ width: '840px',
+ maxHeight: '80vh',
+ position: {
+ top: '112px'
+ },
+ data: { mode: mode, title: this.resourceClassLabel, id: iri, parentResource: this.parentResource, resourceClassDefinition: this.restrictToResourceClass },
+ disableClose: true
+ };
+
+ this._dialog.open(DialogComponent, dialogConfig);
+ }
}