From 024a4196101f4a62f14a9cccbb4d222bc70a7d6f Mon Sep 17 00:00:00 2001 From: Vijeinath Tissaveerasingham Date: Wed, 11 Aug 2021 17:59:30 +0200 Subject: [PATCH 1/6] adding incoming links --- .../properties/properties.component.html | 18 ++++++++++++++++++ .../properties/properties.component.ts | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/app/workspace/resource/properties/properties.component.html b/src/app/workspace/resource/properties/properties.component.html index 0fbc9c4f44..2ad6afafa3 100644 --- a/src/app/workspace/resource/properties/properties.component.html +++ b/src/app/workspace/resource/properties/properties.component.html @@ -146,6 +146,24 @@

+ +
+
+
+ +

+ has incoming link +

+
+
+ + +
+
+
+ The resource {{resource?.res.resourceClassLabel}} has no defined properties. diff --git a/src/app/workspace/resource/properties/properties.component.ts b/src/app/workspace/resource/properties/properties.component.ts index 9162bce168..d0a16b19ca 100644 --- a/src/app/workspace/resource/properties/properties.component.ts +++ b/src/app/workspace/resource/properties/properties.component.ts @@ -41,6 +41,7 @@ import { ConfirmationWithComment, DialogComponent } from 'src/app/main/dialog/di import { ErrorHandlerService } from 'src/app/main/error/error-handler.service'; import { DspResource } from '../dsp-resource'; import { RepresentationConstants } from '../representation/file-representation'; +import { IncomingService } from '../incoming.service'; @Component({ selector: 'app-properties', @@ -110,6 +111,8 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { project: ReadProject; user: ReadUser; + incomingLinkResources = []; + showAllProps = false; // show or hide empty properties constructor( @@ -119,10 +122,21 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { private _notification: NotificationService, private _userService: UserService, private _valueOperationEventService: ValueOperationEventService, - private _valueService: ValueService + private _valueService: ValueService, + private _incomingService: IncomingService ) { } ngOnInit(): void { + this._incomingService.getIncomingLinks(this.resource.res.id, 0).subscribe( + (response: ReadResourceSequence) => { + + if (response.resources.length > 0) { + this.incomingLinkResources = response.resources; + } + + } + ); + if (this.resource.res) { // get user permissions const allPermissions = PermissionUtil.allUserPermissions( From f3f19a816b56c9c79208e002987c827652852982 Mon Sep 17 00:00:00 2001 From: Vijeinath Tissaveerasingham Date: Thu, 12 Aug 2021 11:20:44 +0200 Subject: [PATCH 2/6] fix: adding type --- src/app/workspace/resource/properties/properties.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/workspace/resource/properties/properties.component.ts b/src/app/workspace/resource/properties/properties.component.ts index d0a16b19ca..42dba7460d 100644 --- a/src/app/workspace/resource/properties/properties.component.ts +++ b/src/app/workspace/resource/properties/properties.component.ts @@ -111,7 +111,7 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { project: ReadProject; user: ReadUser; - incomingLinkResources = []; + incomingLinkResources: ReadResource[] = []; showAllProps = false; // show or hide empty properties From 60837888a8e76ebb4beef2754a354554ad149b83 Mon Sep 17 00:00:00 2001 From: Vijeinath Tissaveerasingham Date: Thu, 12 Aug 2021 11:23:49 +0200 Subject: [PATCH 3/6] test: incoming links --- .../properties/properties.component.spec.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/workspace/resource/properties/properties.component.spec.ts b/src/app/workspace/resource/properties/properties.component.spec.ts index 5b2c8c12ba..7e0d3265e7 100644 --- a/src/app/workspace/resource/properties/properties.component.spec.ts +++ b/src/app/workspace/resource/properties/properties.component.spec.ts @@ -8,6 +8,7 @@ import { MatTooltipModule } from '@angular/material/tooltip'; import { By } from '@angular/platform-browser'; import { RouterTestingModule } from '@angular/router/testing'; import { + ApiResponseData, ApiResponseError, Constants, IHasPropertyWithPropertyDefinition, @@ -17,7 +18,7 @@ import { MockUsers, ProjectsEndpointAdmin, ReadLinkValue, - ReadResource, + ReadResource, ReadResourceSequence, ReadValue, ResourcePropertyDefinition, SystemPropertyDefinition @@ -37,6 +38,7 @@ import { of, Subscription } from 'rxjs'; import { TestConfig } from 'test.config'; import { DspResource } from '../dsp-resource'; import { PropertiesComponent } from './properties.component'; +import { IncomingService } from '../incoming.service'; /** * test host component to simulate parent component. @@ -147,6 +149,8 @@ describe('PropertiesComponent', () => { const userServiceSpy = jasmine.createSpyObj('UserService', ['getUser']); + const incomingServiceSpy = jasmine.createSpyObj('IncomingService', ['getIncomingLinks']); + TestBed.configureTestingModule({ imports: [ ClipboardModule, @@ -174,6 +178,10 @@ describe('PropertiesComponent', () => { provide: UserService, useValue: userServiceSpy }, + { + provide: IncomingService, + useValue: incomingServiceSpy + }, ] }) .compileComponents(); @@ -224,6 +232,16 @@ describe('PropertiesComponent', () => { } ); + const incomingLinksSpy = TestBed.inject(IncomingService); + + (incomingLinksSpy as jasmine.SpyObj).getIncomingLinks.and.callFake( + () => { + const resources = new ReadResource(); + const incomingLinks = new ReadResourceSequence([resources], true); + return of(incomingLinks); + } + ); + testHostFixture = TestBed.createComponent(TestPropertyParentComponent); testHostComponent = testHostFixture.componentInstance; testHostFixture.detectChanges(); From 30c448cb958a62ec86b51989796e105707123d1f Mon Sep 17 00:00:00 2001 From: Vijeinath Tissaveerasingham Date: Thu, 12 Aug 2021 14:55:27 +0200 Subject: [PATCH 4/6] test: checking amount of incoming link --- .../resource/properties/properties.component.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app/workspace/resource/properties/properties.component.spec.ts b/src/app/workspace/resource/properties/properties.component.spec.ts index 7e0d3265e7..360c12be83 100644 --- a/src/app/workspace/resource/properties/properties.component.spec.ts +++ b/src/app/workspace/resource/properties/properties.component.spec.ts @@ -249,6 +249,11 @@ describe('PropertiesComponent', () => { expect(testHostComponent).toBeTruthy(); }); + it('should get one incoming link', () => { + + expect(testHostComponent.propertiesComponent.incomingLinkResources.length).toEqual(1); + }); + it('should get the resource testding', () => { expect(testHostComponent.parentResource).toBeTruthy(); From b17be13ad6473f84afde2d2a6fdb95d952393f4b Mon Sep 17 00:00:00 2001 From: Vijeinath Tissaveerasingham Date: Fri, 13 Aug 2021 14:22:50 +0200 Subject: [PATCH 5/6] feat: pagination in incoming links --- .../workspace/resource/incoming.service.ts | 5 +- .../properties/properties.component.html | 18 +++++- .../properties/properties.component.scss | 9 +++ .../properties/properties.component.ts | 55 +++++++++++++++---- 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/src/app/workspace/resource/incoming.service.ts b/src/app/workspace/resource/incoming.service.ts index 759cc45d57..70afcae560 100644 --- a/src/app/workspace/resource/incoming.service.ts +++ b/src/app/workspace/resource/incoming.service.ts @@ -176,9 +176,10 @@ FILTER NOT EXISTS { * * @param {string} resourceIri the Iri of the resource whose incoming links should be returned. * @param {number} offset the offset to be used for paging. 0 is the default and is used to get the first page of results. + * @param {boolean} countQuery if set to true, the request returns only the CountQueryResponse; default value is `false` * @returns {Observable} */ - getIncomingLinks(resourceIri: string, offset: number): Observable { + getIncomingLinks(resourceIri: string, offset: number, countQuery: boolean = false): Observable { const sparqlQueryStr = ` PREFIX knora-api: @@ -211,7 +212,7 @@ FILTER NOT EXISTS { } OFFSET ${offset} `; - return this._dspApiConnection.v2.search.doExtendedSearch(sparqlQueryStr); + return countQuery ? this._dspApiConnection.v2.search.doExtendedSearchCountQuery(sparqlQueryStr) : this._dspApiConnection.v2.search.doExtendedSearch(sparqlQueryStr); } } diff --git a/src/app/workspace/resource/properties/properties.component.html b/src/app/workspace/resource/properties/properties.component.html index 2ad6afafa3..f9a4830052 100644 --- a/src/app/workspace/resource/properties/properties.component.html +++ b/src/app/workspace/resource/properties/properties.component.html @@ -156,9 +156,21 @@

- -
- {{inRes.label}} +
+ ...Loading +
+
+ + + +
diff --git a/src/app/workspace/resource/properties/properties.component.scss b/src/app/workspace/resource/properties/properties.component.scss index e9cac7aab1..d11f3c2d4e 100644 --- a/src/app/workspace/resource/properties/properties.component.scss +++ b/src/app/workspace/resource/properties/properties.component.scss @@ -166,6 +166,15 @@ color: rgba(0, 0, 0, 0.54); } +:host::ng-deep .mat-paginator-container { + justify-content: start; + padding: 0; +} + +:host::ng-deep .mat-paginator-range-label { + margin: 0; +} + @media screen and (max-width: 768px) { .properties, .incoming { diff --git a/src/app/workspace/resource/properties/properties.component.ts b/src/app/workspace/resource/properties/properties.component.ts index 42dba7460d..837359c6f4 100644 --- a/src/app/workspace/resource/properties/properties.component.ts +++ b/src/app/workspace/resource/properties/properties.component.ts @@ -1,11 +1,10 @@ import { Component, EventEmitter, Inject, Input, OnChanges, OnDestroy, OnInit, Output } from '@angular/core'; import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; -import { MatSnackBar } from '@angular/material/snack-bar'; import { ApiResponseData, ApiResponseError, CardinalityUtil, - Constants, + Constants, CountQueryResponse, DeleteResource, DeleteResourceResponse, DeleteValue, @@ -42,6 +41,7 @@ import { ErrorHandlerService } from 'src/app/main/error/error-handler.service'; import { DspResource } from '../dsp-resource'; import { RepresentationConstants } from '../representation/file-representation'; import { IncomingService } from '../incoming.service'; +import { PageEvent } from '@angular/material/paginator'; @Component({ selector: 'app-properties', @@ -112,6 +112,9 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { user: ReadUser; incomingLinkResources: ReadResource[] = []; + pageEvent: PageEvent; + numberOffAllIncomingLinkRes: number; + loading = false; showAllProps = false; // show or hide empty properties @@ -127,15 +130,11 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { ) { } ngOnInit(): void { - this._incomingService.getIncomingLinks(this.resource.res.id, 0).subscribe( - (response: ReadResourceSequence) => { + // reset the page event + this.pageEvent = new PageEvent(); + this.pageEvent.pageIndex = 0; - if (response.resources.length > 0) { - this.incomingLinkResources = response.resources; - } - - } - ); + this._getIncomingLinks(); if (this.resource.res) { // get user permissions @@ -229,6 +228,15 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { // --> TODO: pop up project preview on hover } + /** + * goes to the next page of the incoming link pagination + * @param page + */ + goToPage(page: PageEvent) { + this.pageEvent = page; + this._getIncomingLinks(); + } + /** * opens resource * @param linkValue @@ -450,6 +458,33 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { localStorage.setItem('showAllProps', JSON.stringify(this.showAllProps)); } + /** + * gets the number of incoming links and gets the incoming links. + * @private + */ + private _getIncomingLinks() { + this.loading = true; + + if (this.pageEvent.pageIndex === 0) { + this._incomingService.getIncomingLinks(this.resource.res.id, this.pageEvent.pageIndex, true).subscribe( + (response: CountQueryResponse) => { + this.numberOffAllIncomingLinkRes = response.numberOfResults; + } + ); + } + + this._incomingService.getIncomingLinks(this.resource.res.id, this.pageEvent.pageIndex).subscribe( + (response: ReadResourceSequence) => { + if (response.resources.length > 0) { + this.incomingLinkResources = response.resources; + } + this.loading = false; + }, (error: ApiResponseError) => { + this.loading = false; + } + ); + } + /** * updates the standoff link value for the resource being displayed. * From d13259de03344ffb7a1ab42195269b6bedd61de0 Mon Sep 17 00:00:00 2001 From: Vijeinath Tissaveerasingham Date: Tue, 17 Aug 2021 07:33:58 +0200 Subject: [PATCH 6/6] fix(test): code style --- .../workspace/resource/properties/properties.component.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/workspace/resource/properties/properties.component.spec.ts b/src/app/workspace/resource/properties/properties.component.spec.ts index 360c12be83..8a42419fc3 100644 --- a/src/app/workspace/resource/properties/properties.component.spec.ts +++ b/src/app/workspace/resource/properties/properties.component.spec.ts @@ -18,7 +18,8 @@ import { MockUsers, ProjectsEndpointAdmin, ReadLinkValue, - ReadResource, ReadResourceSequence, + ReadResource, + ReadResourceSequence, ReadValue, ResourcePropertyDefinition, SystemPropertyDefinition