Skip to content

Commit

Permalink
refactor: resource editor (DEV-4339) (#1890)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Schneider <[email protected]>
  • Loading branch information
domsteinbach and derschnee68 authored Nov 18, 2024
1 parent 3baff81 commit 39d176c
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 167 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UploadedFileResponse } from '@dasch-swiss/vre/shared/app-representations';
import { faker } from '@faker-js/faker';
import { UploadedFileResponse } from '../../../../../libs/vre/shared/app-representations/src';
import { ThingPictureClass } from '../../models/existing-data-models';
import { UserProfiles } from '../../models/user-profiles';
import { Project0001Page, Project0803Page } from '../../support/pages/existing-ontology-class-page';
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('Check project admin existing resource functionality', () => {
project0001Page.visitClass('ThingPicture');
cy.get('[data-cy=resource-list-item] h3.res-class-value').contains(thingPictureData.label).click();

cy.intercept('GET', `**/resources/**`).as('resourceRequest');
cy.intercept('GET', '**/resources/**').as('resourceRequest');
cy.get('[data-cy=resource-header-label]').contains(thingPictureData.label);
cy.get('[data-cy=edit-label-button]').should('be.visible').click();
const newLabel = faker.lorem.word();
Expand Down Expand Up @@ -152,7 +152,6 @@ describe('Check project admin existing resource functionality', () => {
cy.get('[data-cy="confirm-button"]').click();
cy.get('[data-cy="delete-comment"]', { timeout: 2000 }).should('not.exist');
cy.get('[data-cy=property-value]').should('have.length', 1);
cy.get('[data-cy=show-all-comments]').scrollIntoView().click();
cy.get('[data-cy=property-value-comment]').should('have.length', 1);
cy.log('new property value with comment has been removed');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UploadedFileResponse } from '@dasch-swiss/vre/shared/app-representations';
import { faker } from '@faker-js/faker';
import { UploadedFileResponse } from '../../../../../libs/vre/shared/app-representations/src';
import { ThingPictureClass } from '../../models/existing-data-models';
import { UserProfiles } from '../../models/user-profiles';
import { Project0001Page, Project0803Page } from '../../support/pages/existing-ontology-class-page';
Expand Down Expand Up @@ -149,7 +149,6 @@ describe('Check project admin existing resource functionality', () => {
cy.get('[data-cy="confirm-button"]').click();
cy.get('[data-cy="delete-comment"]', { timeout: 2000 }).should('not.exist');
cy.get('[data-cy=property-value]').should('have.length', 1);
cy.get('[data-cy=show-all-comments]').scrollIntoView().click();
cy.get('[data-cy=property-value-comment]').should('have.length', 1);
cy.log('new property value with comment has been removed');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterViewInit, Component, EventEmitter, Inject, Input, OnInit, Output } from '@angular/core';
import { Component, Inject, Input, OnChanges, SimpleChanges } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import {
Constants,
Expand Down Expand Up @@ -26,13 +26,10 @@ import { RepresentationService } from '../representation.service';
templateUrl: './archive.component.html',
styleUrls: ['./archive.component.scss'],
})
export class ArchiveComponent implements OnInit, AfterViewInit {
export class ArchiveComponent implements OnChanges {
@Input() src: FileRepresentation;
@Input() attachedProject: ReadProject | undefined;
@Input() parentResource: ReadResource;

@Output() loaded = new EventEmitter<boolean>();

originalFilename: string;

failedToLoad = false;
Expand All @@ -48,19 +45,17 @@ export class ArchiveComponent implements OnInit, AfterViewInit {
private _rs: RepresentationService
) {}

ngOnInit(): void {
this._rs.getFileInfo(this.src.fileValue.fileUrl).subscribe(
res => {
this.originalFilename = res['originalFilename'];
},
() => {
this.failedToLoad = true;
}
);
}

ngAfterViewInit() {
this.loaded.emit(true);
ngOnChanges(changes: SimpleChanges): void {
if (changes['src']) {
this._rs.getFileInfo(this.src.fileValue.fileUrl).subscribe(
res => {
this.originalFilename = res['originalFilename'];
},
() => {
this.failedToLoad = true;
}
);
}
}

download(url: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnDestroy, Output } from '@angular/core';
import { ChangeDetectorRef, Component, Input, OnChanges, OnDestroy } from '@angular/core';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { ReadResource } from '@dasch-swiss/dsp-js';
import { NotificationService } from '@dasch-swiss/vre/shared/app-notification';
Expand All @@ -20,8 +20,6 @@ export class AudioComponent implements OnChanges, OnDestroy {
@Input({ required: true }) isAdmin!: boolean;
@Input({ required: true }) parentResource!: ReadResource;

@Output() loaded = new EventEmitter<boolean>();

originalFilename?: string;
failedToLoad = false;
audioFileUrl!: SafeUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { DOCUMENT } from '@angular/common';
import {
AfterViewInit,
ChangeDetectorRef,
Component,
EventEmitter,
Inject,
Input,
OnInit,
Output,
ViewChild,
} from '@angular/core';
import { ChangeDetectorRef, Component, Inject, Input, OnChanges, SimpleChanges, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import {
Constants,
Expand All @@ -24,7 +14,6 @@ import {
} from '@dasch-swiss/dsp-js';
import { ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { DspApiConnectionToken } from '@dasch-swiss/vre/shared/app-config';
import { Store } from '@ngxs/store';
import { PdfViewerComponent } from 'ng2-pdf-viewer';
import { mergeMap } from 'rxjs/operators';
import { FileRepresentation } from '../file-representation';
Expand All @@ -39,13 +28,11 @@ import { RepresentationService } from '../representation.service';
templateUrl: './document.component.html',
styleUrls: ['./document.component.scss'],
})
export class DocumentComponent implements OnInit, AfterViewInit {
export class DocumentComponent implements OnChanges {
@Input() src: FileRepresentation;
@Input() parentResource: ReadResource;
@Input() attachedProject: ReadProject | undefined;

@Output() loaded = new EventEmitter<boolean>();

@ViewChild(PdfViewerComponent) private _pdfComponent: PdfViewerComponent;

originalFilename: string;
Expand All @@ -70,29 +57,25 @@ export class DocumentComponent implements OnInit, AfterViewInit {
private _dspApiConnection: KnoraApiConnection,
private _dialog: MatDialog,
private _rs: RepresentationService,
private _cd: ChangeDetectorRef,
private _store: Store
private _cd: ChangeDetectorRef
) {}

ngOnInit(): void {
this.fileType = this._getFileType(this.src.fileValue.filename);

this._rs.getFileInfo(this.src.fileValue.fileUrl).subscribe(
res => {
this.originalFilename = res['originalFilename'];
},
() => {
// error already handled by getFileInfo
this.failedToLoad = true;
ngOnChanges(changes: SimpleChanges): void {
if (changes['src'] && changes['src'].currentValue) {
this._rs.getFileInfo(this.src.fileValue.fileUrl).subscribe(
res => {
this.originalFilename = res['originalFilename'];
},
() => {
// error already handled by getFileInfo
this.failedToLoad = true;
}
);
this.fileType = this._getFileType(this.src.fileValue.filename);
if (this.fileType === 'pdf') {
this.elem = document.getElementsByClassName('pdf-viewer')[0];
}
);
}

ngAfterViewInit() {
if (this.fileType === 'pdf') {
this.elem = document.getElementsByClassName('pdf-viewer')[0];
}
this.loaded.emit(true);
}

searchQueryChanged(newQuery: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class OsdDrawerService implements OnDestroy {
this._subscribeToCreatedRectangle();
}

update(resource: ReadResource): void {
this.resource = resource;
}

private _subscribeToSelectedRegion() {
this._regionService.selectedRegion$.pipe(takeUntil(this._ngUnsubscribe)).subscribe(region => {
this._unhighlightAllRegions();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
Input,
OnChanges,
OnDestroy,
SimpleChanges,
ViewChild,
} from '@angular/core';
import { Constants, ReadResource, ReadStillImageFileValue } from '@dasch-swiss/dsp-js';
Expand Down Expand Up @@ -41,7 +42,7 @@ import { StillImageHelper } from './still-image-helper';
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [OsdDrawerService, OpenSeaDragonService],
})
export class StillImageComponent implements AfterViewInit, OnDestroy {
export class StillImageComponent implements OnChanges, AfterViewInit, OnDestroy {
@Input({ required: true }) compoundMode!: boolean;
@Input({ required: true }) resource!: ReadResource;
@ViewChild('osdViewer') osdViewerElement!: ElementRef;
Expand All @@ -51,28 +52,33 @@ export class StillImageComponent implements AfterViewInit, OnDestroy {

constructor(
protected osdService: OpenSeaDragonService,
private _osdDrawerService: OsdDrawerService,
private _cdr: ChangeDetectorRef
private _osdDrawerService: OsdDrawerService
) {}

ngOnChanges(changes: SimpleChanges): void {
if (this.isViewInitialized && changes['resource']) {
this._osdDrawerService.update(this.resource);
this._loadImage();
}
}

ngAfterViewInit() {
this.osdService.onInit(this.osdViewerElement.nativeElement);
this._osdDrawerService.onInit(this.resource);
this.isViewInitialized = true;
this._cdr.detectChanges();
this._loadImages();
this._loadImage();
}

afterFormatChange(value: boolean) {
this.isPng = value;
this._loadImages();
this._loadImage();
}

ngOnDestroy() {
this.osdService.viewer.destroy();
}

private _loadImages() {
private _loadImage() {
const image = this.resource.properties[Constants.HasStillImageFileValue][0];

switch (image.type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterViewInit, Component, EventEmitter, Inject, Input, OnInit, Output } from '@angular/core';
import { Component, Inject, Input, OnChanges } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import {
Constants,
Expand Down Expand Up @@ -26,13 +26,11 @@ import { RepresentationService } from '../representation.service';
templateUrl: './text.component.html',
styleUrls: ['./text.component.scss'],
})
export class TextComponent implements OnInit, AfterViewInit {
export class TextComponent implements OnChanges {
@Input() src: FileRepresentation;
@Input() attachedProject: ReadProject | undefined;
@Input() parentResource: ReadResource;

@Output() loaded = new EventEmitter<boolean>();

originalFilename: string;

failedToLoad = false;
Expand All @@ -48,7 +46,7 @@ export class TextComponent implements OnInit, AfterViewInit {
private _rs: RepresentationService
) {}

ngOnInit(): void {
ngOnChanges(): void {
this._rs.getFileInfo(this.src.fileValue.fileUrl).subscribe(
res => {
this.originalFilename = res['originalFilename'];
Expand All @@ -59,10 +57,6 @@ export class TextComponent implements OnInit, AfterViewInit {
);
}

ngAfterViewInit() {
this.loaded.emit(true);
}

download(url: string) {
this._rs.downloadFile(url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class AnnotationTabComponent implements OnInit, OnDestroy {

ngOnDestroy() {
this._subscription.unsubscribe();
this.regionService.showRegions(false);
}

private _scrollToRegion(iri: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { DspResource } from '@dasch-swiss/vre/shared/app-common';
import { CompoundService } from './compound.service';

@Component({
selector: 'app-compound-viewer',
template: `
<ng-container *ngIf="compoundService.compoundPosition">
<ng-container *ngIf="compoundService.incomingResource as incomingResource">
<ng-container *ngIf="compoundService.incomingResource$ | async as incomingResource">
<app-still-image class="dsp-representation" [resource]="incomingResource.res" [compoundMode]="true" />
</ng-container>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ import { IncomingService } from '@dasch-swiss/vre/shared/app-common-to-move';
import { DspApiConnectionToken } from '@dasch-swiss/vre/shared/app-config';
import { AppError } from '@dasch-swiss/vre/shared/app-error-handler';
import { RegionService } from '@dasch-swiss/vre/shared/app-representations';
import { BehaviorSubject } from 'rxjs';

/**
* Service to handle compound resources, which are resources that are composed of multiple resources.
*/
@Injectable()
export class CompoundService {
compoundPosition?: DspCompoundPosition;
incomingResource?: DspResource;

private _resource!: DspResource;
private _incomingResource = new BehaviorSubject<DspResource | undefined>(undefined);
incomingResource$ = this._incomingResource.asObservable();

get exists() {
return this.compoundPosition !== undefined;
}
private _resource!: DspResource;

constructor(
@Inject(DspApiConnectionToken)
Expand Down Expand Up @@ -88,9 +87,7 @@ export class CompoundService {
}

private _reloadViewer(resource: DspResource) {
this.incomingResource = undefined;
this._cd.detectChanges();
this.incomingResource = resource;
this._incomingResource.next(resource);
this._cd.detectChanges();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import { Subscription } from 'rxjs';

@Component({
selector: 'app-resource-fetcher',
template: ' <app-resource *ngIf="resource" [resource]="resource" [isDifferentResource]="isDifferentResource" />',
template: ' <app-resource *ngIf="resource" [resource]="resource" />',
providers: [ResourceFetcherService],
})
export class ResourceFetcherComponent implements OnChanges, OnDestroy {
@Input({ required: true }) resourceIri!: string;

resource?: DspResource;
isDifferentResource = true;

private _subscription?: Subscription;

Expand All @@ -38,8 +37,6 @@ export class ResourceFetcherComponent implements OnChanges, OnDestroy {
return;
}

this.isDifferentResource = resource.res.id !== this.resource?.res.id;

this._reloadEditor(resource);
});
}
Expand All @@ -51,8 +48,6 @@ export class ResourceFetcherComponent implements OnChanges, OnDestroy {
* @private
*/
private _reloadEditor(resource: DspResource) {
this.resource = undefined;
this._cdr.detectChanges();
this.resource = resource;
this._cdr.detectChanges();
}
Expand Down
Loading

0 comments on commit 39d176c

Please sign in to comment.