Skip to content

Commit

Permalink
Merge branch 'main' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
derschnee68 authored Feb 26, 2025
2 parents 5eb12c9 + 097b620 commit 8900ec5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken, RouteConstants } from '@dasch-swiss/vre/core/config';
import { OntologiesSelectors } from '@dasch-swiss/vre/core/state';
import { ResourceService } from '@dasch-swiss/vre/shared/app-common';
import { FilteredResources, SearchParams } from '@dasch-swiss/vre/shared/app-common-to-move';
import { ComponentCommunicationEventService, EmitEvent, Events } from '@dasch-swiss/vre/shared/app-helper-services';
import { NotificationService } from '@dasch-swiss/vre/ui/notification';
Expand Down Expand Up @@ -91,7 +90,6 @@ export class ListViewComponent implements OnChanges, OnInit, OnDestroy {
private _dspApiConnection: KnoraApiConnection,
private _componentCommsService: ComponentCommunicationEventService,
private _notification: NotificationService,
private _resourceService: ResourceService,
private _route: ActivatedRoute,
private _router: Router,
private _cd: ChangeDetectorRef,
Expand All @@ -114,12 +112,6 @@ export class ListViewComponent implements OnChanges, OnInit, OnDestroy {
}
})
);

this._resourceService.resourceDeleted$.pipe(takeUntil(this.ngUnsubscribe)).subscribe((resourceIri: string) => {
if (resourceIri) {
this.doSearch();
}
});
}

ngOnChanges(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DspResource, GenerateProperty } from '@dasch-swiss/vre/shared/app-commo
import { ComponentCommunicationEventService, EmitEvent, Events } from '@dasch-swiss/vre/shared/app-helper-services';
import { TranslateService } from '@ngx-translate/core';
import { Store } from '@ngxs/store';
import { BehaviorSubject, Subscription } from 'rxjs';
import { BehaviorSubject, Subject, Subscription } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';

@Injectable()
Expand All @@ -17,6 +17,9 @@ export class ResourceFetcherService {
private _resourceSubject = new BehaviorSubject<DspResource | null>(null);
resource$ = this._resourceSubject.asObservable();

private _resourceIsDeletedSubject = new Subject<void>();
resourceIsDeleted$ = this._resourceIsDeletedSubject.asObservable();

private _subscription: Subscription | undefined;

constructor(
Expand Down Expand Up @@ -57,6 +60,10 @@ export class ResourceFetcherService {
this._loadResourceSubject.next(null);
}

resourceIsDeleted() {
this._resourceIsDeletedSubject.next();
}

private _getResource() {
return this._dspApiConnection.v2.res.getResource(this._resourceIri).pipe(
map(response => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
import { ChangeDetectorRef, Component, Input, OnChanges, OnDestroy } from '@angular/core';
import { Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
import { ResourceFetcherService } from '@dasch-swiss/vre/resource-editor/representations';
import { DspResource } from '@dasch-swiss/vre/shared/app-common';
import { Subscription } from 'rxjs';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

@Component({
selector: 'app-resource-fetcher',
template: ' <app-resource *ngIf="resource" [resource]="resource" />',
template: `
<ng-container *ngIf="!loading">
<app-resource *ngIf="resource; else noResourceTpl" [resource]="resource" />
</ng-container>
<ng-template #noResourceTpl
><h3 style="text-align: center; margin-top: 50px">This resource does not exist.</h3>
</ng-template>
`,
providers: [ResourceFetcherService],
})
export class ResourceFetcherComponent implements OnChanges, OnDestroy {
export class ResourceFetcherComponent implements OnInit, OnChanges, OnDestroy {
@Input({ required: true }) resourceIri!: string;

resource?: DspResource;
loading!: boolean;
private _ngUnsubscribe = new Subject<void>();

private _subscription?: Subscription;
constructor(private _resourceFetcherService: ResourceFetcherService) {}

constructor(
private _cdr: ChangeDetectorRef,
private _resourceFetcherService: ResourceFetcherService
) {}

ngOnChanges() {
this._resourceFetcherService.onDestroy();
this._resourceFetcherService.onInit(this.resourceIri);

if (this._subscription) {
this._subscription.unsubscribe();
}

this._subscription = this._resourceFetcherService.resource$.subscribe(resource => {
ngOnInit() {
this._resourceFetcherService.resource$.pipe(takeUntil(this._ngUnsubscribe)).subscribe(resource => {
if (resource === null) {
return;
}

this.loading = false;

if (resource.res.isDeleted) {
this.resource = undefined;
return;
}

this._reloadEditor(resource);
this.resource = resource;
});

this._resourceFetcherService.resourceIsDeleted$.pipe(takeUntil(this._ngUnsubscribe)).subscribe(() => {
this.resource = undefined;
});
}

private _reloadEditor(resource: DspResource) {
this.resource = resource;
this._cdr.detectChanges();
ngOnChanges() {
this.loading = true;
this._resourceFetcherService.onDestroy();
this._resourceFetcherService.onInit(this.resourceIri);
}

ngOnDestroy() {
this._resourceFetcherService.onDestroy();

this._ngUnsubscribe.next();
this._ngUnsubscribe.complete();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { AppConfigService, RouteConstants } from '@dasch-swiss/vre/core/config';
import { ProjectsSelectors } from '@dasch-swiss/vre/core/state';
import { Store } from '@ngxs/store';
import { filter, map } from 'rxjs/operators';

@Component({
selector: 'app-resource-page',
template:
'<app-resource-fetcher *ngIf="resourceIri$ | async as resourceIri" [resourceIri]="resourceIri" (resourceIsDeleted)="goToHome()" />',
template: '<app-resource-fetcher *ngIf="resourceIri$ | async as resourceIri" [resourceIri]="resourceIri" />',
})
export class ResourcePageComponent {
constructor(
private _route: ActivatedRoute,
private _router: Router,
private _acs: AppConfigService,
private _store: Store
) {}
Expand All @@ -25,8 +23,4 @@ export class ResourcePageComponent {
filter(v => v !== undefined),
map(project => `${this._acs.dspAppConfig.iriBase}/${project.shortcode}/${this.instanceId}`)
);

goToHome() {
this._router.navigate(['/']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, Input } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ReadResource } from '@dasch-swiss/dsp-js';
import { ProjectsSelectors } from '@dasch-swiss/vre/core/state';
import { ResourceUtil } from '@dasch-swiss/vre/resource-editor/representations';
import { ResourceFetcherService, ResourceUtil } from '@dasch-swiss/vre/resource-editor/representations';
import {
DeleteResourceDialogComponent,
EraseResourceDialogComponent,
Expand Down Expand Up @@ -126,6 +126,7 @@ export class ResourceToolbarComponent {
constructor(
protected notification: NotificationService,
private _resourceService: ResourceService,
private _resourceFetcherService: ResourceFetcherService,
private _dialog: MatDialog,
private _store: Store
) {}
Expand All @@ -140,7 +141,7 @@ export class ResourceToolbarComponent {
.afterClosed()
.pipe(filter(response => !!response))
.subscribe(() => {
this._resourceService.resourceDeleted.next(this.resource.res.id);
this._resourceFetcherService.resourceIsDeleted();
});
}

Expand All @@ -150,7 +151,7 @@ export class ResourceToolbarComponent {
.afterClosed()
.pipe(filter(response => !!response))
.subscribe(() => {
this._resourceService.resourceDeleted.next(this.resource.res.id);
this._resourceFetcherService.resourceIsDeleted();
});
}
}
4 changes: 0 additions & 4 deletions libs/vre/shared/app-common/src/lib/resource.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { Injectable } from '@angular/core';
import { AppConfigService } from '@dasch-swiss/vre/core/config';
import { Subject } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class ResourceService {
iriBase: string;

resourceDeleted = new Subject<string>();
resourceDeleted$ = this.resourceDeleted.asObservable();

constructor(private _acs: AppConfigService) {
this.iriBase = this._getIriBaseWithoutTrailingSlash(this._acs.dspAppConfig.iriBase);
}
Expand Down

0 comments on commit 8900ec5

Please sign in to comment.