-
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.
- Loading branch information
Showing
6 changed files
with
47 additions
and
47 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
56 changes: 33 additions & 23 deletions
56
libs/vre/resource-editor/resource-editor/src/lib/resource-fetcher.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 |
---|---|---|
@@ -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(); | ||
} | ||
} |
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