Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(list-view): refresh list view after a resource is deleted or erased (DEV-1353) #828

Merged
merged 4 commits into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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[]= [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between bracket and equal character


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