diff --git a/src/app/main/services/component-communication-event.service.ts b/src/app/main/services/component-communication-event.service.ts index 75bdddc05a..d9c2a2f38e 100644 --- a/src/app/main/services/component-communication-event.service.ts +++ b/src/app/main/services/component-communication-event.service.ts @@ -38,5 +38,6 @@ export class EmitEvent { export enum Events { loginSuccess, gravSearchExecuted, - projectCreated + projectCreated, + resourceDeleted } diff --git a/src/app/project/beta/ontology-classes/ontology-class-item/ontology-class-item.component.ts b/src/app/project/beta/ontology-classes/ontology-class-item/ontology-class-item.component.ts index 829de38035..bfcde67b44 100644 --- a/src/app/project/beta/ontology-classes/ontology-class-item/ontology-class-item.component.ts +++ b/src/app/project/beta/ontology-classes/ontology-class-item/ontology-class-item.component.ts @@ -1,7 +1,9 @@ import { Component, Inject, Input, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { ClassDefinition, KnoraApiConnection, CountQueryResponse, ApiResponseError, Constants } from '@dasch-swiss/dsp-js'; +import { Subscription } from 'rxjs'; import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens'; +import { ComponentCommunicationEventService, Events } from 'src/app/main/services/component-communication-event.service'; import { ErrorHandlerService } from 'src/app/main/services/error-handler.service'; import { OntologyService } from 'src/app/project/ontology/ontology.service'; @@ -24,6 +26,8 @@ export class OntologyClassItemComponent implements OnInit { icon: string; + componentCommsSubscriptions: Subscription[]= []; + // i18n setup itemPluralMapping = { entry: { @@ -37,13 +41,13 @@ export class OntologyClassItemComponent implements OnInit { private _errorHandler: ErrorHandlerService, private _ontologyService: OntologyService, private _route: ActivatedRoute, - private _router: Router + private _router: Router, + private _componentCommsService: ComponentCommunicationEventService, ) { } ngOnInit(): void { - const projectCode = this._route.snapshot.params.shortcode; const splitIri = this.resClass.id.split('#'); const ontologyName = this._ontologyService.getOntologyName(splitIri[0]); @@ -52,16 +56,15 @@ export class OntologyClassItemComponent implements OnInit { this.gravsearch = this._setGravsearch(this.resClass.id); // get number of resource instances - this._dspApiConnection.v2.search.doExtendedSearchCountQuery(this.gravsearch).subscribe( - (res: CountQueryResponse) => { - this.results = res.numberOfResults; - }, - (error: ApiResponseError) => { - this._errorHandler.showMessage(error); - } - ); + this._getSearchCount(); this.icon = this._getIcon(); + + this.componentCommsSubscriptions.push(this._componentCommsService.on( + Events.resourceDeleted, () => { + this._getSearchCount(); + } + )); } open(route: string) { @@ -121,4 +124,15 @@ export class OntologyClassItemComponent implements OnInit { } } + private _getSearchCount() { + this._dspApiConnection.v2.search.doExtendedSearchCountQuery(this.gravsearch).subscribe( + (res: CountQueryResponse) => { + this.results = res.numberOfResults; + }, + (error: ApiResponseError) => { + this._errorHandler.showMessage(error); + } + ); + } + } diff --git a/src/app/workspace/resource/properties/properties.component.ts b/src/app/workspace/resource/properties/properties.component.ts index bb09ec4863..1fd7bac445 100644 --- a/src/app/workspace/resource/properties/properties.component.ts +++ b/src/app/workspace/resource/properties/properties.component.ts @@ -30,6 +30,7 @@ import { import { Subscription } from 'rxjs'; import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens'; import { ConfirmationWithComment, DialogComponent } from 'src/app/main/dialog/dialog.component'; +import { ComponentCommunicationEventService, EmitEvent, Events as CommsEvents } from 'src/app/main/services/component-communication-event.service'; import { ErrorHandlerService } from 'src/app/main/services/error-handler.service'; import { NotificationService } from 'src/app/main/services/notification.service'; import { DspResource } from '../dsp-resource'; @@ -155,6 +156,7 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { private _userService: UserService, private _valueOperationEventService: ValueOperationEventService, private _valueService: ValueService, + private _componentCommsService: ComponentCommunicationEventService ) { } ngOnInit(): void { @@ -318,6 +320,7 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { // display notification and mark resource as 'deleted' this._notification.openSnackBar(`${response.result}: ${this.resource.res.label}`); this.deletedResource = true; + this._componentCommsService.emit(new EmitEvent(CommsEvents.resourceDeleted)); }, (error: ApiResponseError) => { this._errorHandler.showMessage(error); @@ -332,6 +335,7 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { // display notification and mark resource as 'erased' this._notification.openSnackBar(`${response.result}: ${this.resource.res.label}`); this.deletedResource = true; + this._componentCommsService.emit(new EmitEvent(CommsEvents.resourceDeleted)); }, (error: ApiResponseError) => { this._errorHandler.showMessage(error); diff --git a/src/app/workspace/results/list-view/list-view.component.ts b/src/app/workspace/results/list-view/list-view.component.ts index dd3a3eb41c..9b9cce8be1 100644 --- a/src/app/workspace/results/list-view/list-view.component.ts +++ b/src/app/workspace/results/list-view/list-view.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Inject, Input, OnChanges, Output } from '@angular/core'; +import { Component, EventEmitter, Inject, Input, OnChanges, OnInit, Output } from '@angular/core'; import { PageEvent } from '@angular/material/paginator'; import { ApiResponseError, CountQueryResponse, IFulltextSearchParams, KnoraApiConnection, ReadResourceSequence } from '@dasch-swiss/dsp-js'; import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens'; @@ -6,6 +6,7 @@ import { ErrorHandlerService } from 'src/app/main/services/error-handler.service import { ComponentCommunicationEventService, EmitEvent, Events } from 'src/app/main/services/component-communication-event.service'; import { NotificationService } from 'src/app/main/services/notification.service'; import { ActivatedRoute } from '@angular/router'; +import { Subscription } from 'rxjs'; /** * query: search query. It can be gravserch query or fulltext string query. @@ -59,7 +60,7 @@ export interface CheckboxUpdate { templateUrl: './list-view.component.html', styleUrls: ['./list-view.component.scss'] }) -export class ListViewComponent implements OnChanges { +export class ListViewComponent implements OnChanges, OnInit { @Input() search: SearchParams; @@ -81,6 +82,8 @@ export class ListViewComponent implements OnChanges { selectedResourceIdx: number[] = []; + componentCommsSubscriptions: Subscription[] = []; + resetCheckBoxes = false; // matPaginator Output @@ -110,6 +113,14 @@ export class ListViewComponent implements OnChanges { } } + ngOnInit(): void { + this.componentCommsSubscriptions.push(this._componentCommsService.on( + Events.resourceDeleted, () => { + this._doSearch(); + } + )); + } + ngOnChanges(): void { // reset this.pageEvent = new PageEvent();