Skip to content

Commit

Permalink
fix(list-view): refresh list view after a resource is deleted or eras…
Browse files Browse the repository at this point in the history
…ed (DEV-1353) (#828)

* fix(list-view): refresh list view after a resource is deleted or erased

* chore: syntax fix
  • Loading branch information
mdelez committed Sep 21, 2022
1 parent 0304943 commit c15d87b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
Expand Up @@ -38,5 +38,6 @@ export class EmitEvent {
export enum Events {
loginSuccess,
gravSearchExecuted,
projectCreated
projectCreated,
resourceDeleted
}
@@ -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';

Expand All @@ -24,6 +26,8 @@ export class OntologyClassItemComponent implements OnInit {

icon: string;

componentCommsSubscriptions: Subscription[]= [];

// i18n setup
itemPluralMapping = {
entry: {
Expand All @@ -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]);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
);
}

}
4 changes: 4 additions & 0 deletions src/app/workspace/resource/properties/properties.component.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions src/app/workspace/results/list-view/list-view.component.ts
@@ -1,11 +1,12 @@
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';
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.
Expand Down Expand Up @@ -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;

Expand All @@ -81,6 +82,8 @@ export class ListViewComponent implements OnChanges {

selectedResourceIdx: number[] = [];

componentCommsSubscriptions: Subscription[] = [];

resetCheckBoxes = false;

// matPaginator Output
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c15d87b

Please sign in to comment.