-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: paging of incoming links works again (#2108)
Co-authored-by: domsteinbach <[email protected]> Co-authored-by: domsteinbach <[email protected]>
- Loading branch information
1 parent
5670459
commit 3e26477
Showing
26 changed files
with
296 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
libs/vre/resource-editor/resource-properties/src/lib/incoming-links-property.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Component, Input, OnChanges } from '@angular/core'; | ||
import { ReadResource, ReadResourceSequence } from '@dasch-swiss/dsp-js'; | ||
import { AppError } from '@dasch-swiss/vre/core/error-handler'; | ||
import { DspResource } from '@dasch-swiss/vre/shared/app-common'; | ||
import { IncomingService } from '@dasch-swiss/vre/shared/app-common-to-move'; | ||
import { Observable, of } from 'rxjs'; | ||
import { expand, map, reduce, take, takeWhile } from 'rxjs/operators'; | ||
import { IncomingOrStandoffLink } from './incoming-link.interface'; | ||
import { sortByKeys } from './sortByKeys'; | ||
|
||
@Component({ | ||
selector: 'app-incoming-links-property', | ||
template: ` | ||
<app-property-row | ||
[tooltip]="'resource.incomingLink.tooltip' | translate" | ||
[label]="'resource.incomingLink.label' | translate" | ||
[borderBottom]="true" | ||
[isEmptyRow]="!loading && allIncomingLinks.length === 0"> | ||
<ng-container *ngIf="allIncomingLinks.length > 0"> | ||
<app-incoming-standoff-link-value [links]="slidedLinks" /> | ||
<app-incoming-resource-pager | ||
*ngIf="allIncomingLinks.length > pageSize" | ||
[pageIndex]="pageIndex" | ||
[pageSize]="pageSize" | ||
[itemsNumber]="allIncomingLinks.length" | ||
(pageChanged)="pageChanged($event)" /> | ||
</ng-container> | ||
</app-property-row> | ||
<app-progress-indicator *ngIf="loading" /> | ||
`, | ||
}) | ||
export class IncomingLinksPropertyComponent implements OnChanges { | ||
@Input({ required: true }) resource!: DspResource; | ||
|
||
loading = true; | ||
|
||
get slidedLinks() { | ||
return this.allIncomingLinks.slice(this.pageIndex * this.pageSize, (this.pageIndex + 1) * this.pageSize); | ||
} | ||
|
||
pageSize = 25; | ||
allIncomingLinks: IncomingOrStandoffLink[] = []; | ||
pageIndex = 0; | ||
|
||
constructor(private _incomingService: IncomingService) {} | ||
|
||
ngOnChanges() { | ||
this._getIncomingLinksRecursively$(this.resource.res.id) | ||
.pipe(take(1)) | ||
.subscribe(incomingLinks => { | ||
this.loading = false; | ||
this.allIncomingLinks = incomingLinks; | ||
}); | ||
} | ||
|
||
pageChanged(page: number) { | ||
this.pageIndex = page; | ||
} | ||
|
||
private _getIncomingLinksRecursively$(resourceId: string) { | ||
let offset = 0; | ||
|
||
return this._incomingService.getIncomingLinksForResource(resourceId, offset).pipe( | ||
expand(sequence => { | ||
if (!(sequence as ReadResourceSequence).mayHaveMoreResults) { | ||
return of(sequence as ReadResourceSequence); | ||
} | ||
|
||
offset += 1; | ||
|
||
return this._incomingService.getIncomingLinksForResource( | ||
resourceId, | ||
offset | ||
) as Observable<ReadResourceSequence>; | ||
}), | ||
takeWhile(response => response.resources.length > 0 && response.mayHaveMoreResults, true), | ||
reduce((all: ReadResource[], data) => all.concat(data.resources), []), | ||
map(incomingResources => { | ||
const incomingLinks = incomingResources.map(resource => | ||
IncomingLinksPropertyComponent.createIncomingOrStandoffLink(resource) | ||
); | ||
return sortByKeys(incomingLinks, ['project', 'label']); | ||
}) | ||
); | ||
} | ||
|
||
static createIncomingOrStandoffLink(resource: ReadResource): IncomingOrStandoffLink { | ||
const resourceIdPathOnly = resource.id.match(/[^\/]*\/[^\/]*$/); | ||
if (!resourceIdPathOnly) { | ||
throw new AppError('Resource id is not in the expected format'); | ||
} | ||
|
||
return { | ||
label: resource.label, | ||
uri: `/resource/${resourceIdPathOnly[0]}`, | ||
project: resource.resourceClassLabel ? resource.resourceClassLabel : '', | ||
}; | ||
} | ||
} |
File renamed without changes.
49 changes: 49 additions & 0 deletions
49
.../resource-properties/src/lib/incoming-resource-pager/incoming-resource-pager.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; | ||
|
||
@Component({ | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
selector: 'app-incoming-resource-pager', | ||
template: ` | ||
<div class="paging-container"> | ||
<div class="navigation"> | ||
<button mat-button class="pagination-button previous" [disabled]="pageIndex === 0" (click)="changePage(-1)"> | ||
<mat-icon>west</mat-icon> | ||
<span>{{ 'uiControls.pager.previous' | translate }}</span> | ||
</button> | ||
<span class="fill-remaining-space"></span> | ||
<div class="range"> | ||
<span>{{ itemRangeStart }} - {{ itemRangeEnd }} of {{ itemsNumber }}</span> | ||
</div> | ||
<span class="fill-remaining-space"></span> | ||
<button | ||
mat-button | ||
class="pagination-button next" | ||
[disabled]="itemRangeEnd === itemsNumber" | ||
(click)="changePage(1)"> | ||
<span>{{ 'uiControls.pager.next' | translate }}</span> | ||
<mat-icon>east</mat-icon> | ||
</button> | ||
</div> | ||
</div> | ||
`, | ||
styleUrls: ['./incoming-resource-pager.component.scss'], | ||
}) | ||
export class IncomingResourcePagerComponent { | ||
@Input({ required: true }) pageIndex!: number; | ||
@Input({ required: true }) pageSize!: number; | ||
@Input({ required: true }) itemsNumber!: number; | ||
@Output() pageChanged = new EventEmitter<number>(); | ||
|
||
get itemRangeStart(): number { | ||
return this.pageSize * this.pageIndex + 1; | ||
} | ||
|
||
get itemRangeEnd(): number { | ||
return Math.min(this.pageSize * (this.pageIndex + 1), this.itemsNumber); | ||
} | ||
|
||
changePage(dir: 1 | -1) { | ||
this.pageIndex += dir; | ||
this.pageChanged.emit(this.pageIndex); | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
...e/resource-editor/resource-properties/src/lib/properties-display-incoming-link.service.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.