Skip to content

Commit

Permalink
fix(viewer): fix several issues in list-view (DSP-1575) (#324)
Browse files Browse the repository at this point in the history
* fix(viewer): fix several issues in list-view (DSP-1575)

* refactor(viewer): fix stupid thing
  • Loading branch information
kilchenmann committed Jul 30, 2021
1 parent 4e8be74 commit 9a76b0a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
Expand Up @@ -11,7 +11,7 @@
<!-- TODO: add button to show as table, if possible (filter by same resource class) -->
</span>
<span class="fill-remaining-space"></span>
<span class="page-navigation">
<span class="page-navigation" *ngIf="!loading && (numberOfAllResults > 0 && resources?.resources.length)">
<mat-paginator [length]="numberOfAllResults" [pageSize]="25" [hidePageSize]="true"
[pageIndex]="pageEvent.pageIndex" [disabled]="loading" (page)="goToPage($event)">
</mat-paginator>
Expand All @@ -23,7 +23,7 @@
<dsp-progress-indicator *ngIf="loading"></dsp-progress-indicator>

<!-- When multiple resources are selected for comparision -->
<div class="list-view" *ngIf="!loading && numberOfAllResults > 0 && resources">
<div class="list-view" *ngIf="!loading && (numberOfAllResults > 0 && resources)">
<div [ngSwitch]="view">
<dsp-resource-list
*ngSwitchCase="'list'"
Expand All @@ -45,10 +45,11 @@
</div>

<!-- In case of 0 result -->
<div class="list-view no-results" *ngIf="!loading && numberOfAllResults === 0">
<div class="list-view no-results" *ngIf="!loading && (numberOfAllResults >= 0 && !resources?.resources.length)">
<p>Your search <span *ngIf="search.mode === 'fulltext'">- <strong> {{search.query}}</strong> -</span> did not match any documents.</p>
<p>Suggestions:</p>
<ul>
<li *ngIf="numberOfAllResults > 0">Make sure that you are logged in and you have all the needed permissions.</li>
<li>Make sure that all words are spelled correctly.</li>
<li>Try different keywords.</li>
<li>Try more general keywords.</li>
Expand Down
@@ -1,6 +1,6 @@
import { Component, EventEmitter, Inject, Input, OnChanges, Output } from '@angular/core';
import { PageEvent } from '@angular/material/paginator';
import { ApiResponseError, CountQueryResponse, IFulltextSearchParams, KnoraApiConnection, ReadResourceSequence } from '@dasch-swiss/dsp-js';
import { ApiResponseError, CountQueryResponse, IFulltextSearchParams, KnoraApiConnection, ReadResource, ReadResourceSequence } from '@dasch-swiss/dsp-js';
import { NotificationService } from '../../../action/services/notification.service';
import { DspApiConnectionToken } from '../../../core/core.module';
import { AdvancedSearchParamsService } from '../../../search/services/advanced-search-params.service';
Expand Down Expand Up @@ -31,7 +31,7 @@ export interface FilteredResouces {
count: number,
resListIndex: number[],
resIds: string[],
selectionType: "multiple" | "single"
selectionType: 'multiple' | 'single'
}

/* return the checkbox value
Expand Down Expand Up @@ -84,7 +84,6 @@ export class ListViewComponent implements OnChanges {
*/
@Output() resourceSelected: EventEmitter<string> = new EventEmitter<string>();


resources: ReadResourceSequence;

selectedResourceIdx: number[] = [];
Expand Down Expand Up @@ -128,7 +127,7 @@ export class ListViewComponent implements OnChanges {
emitSelectedResources(resInfo: FilteredResouces) {
this.selectedResourceIdx = resInfo.resListIndex;

if (resInfo.selectionType === "multiple") {
if (resInfo.selectionType === 'multiple') {
this.multipleResourcesSelected.emit(resInfo);
} else {
this.singleResourceSelected.emit(resInfo.resIds[0]);
Expand All @@ -150,11 +149,18 @@ export class ListViewComponent implements OnChanges {
if (this.pageEvent.pageIndex === 0) {
// perform count query
this._dspApiConnection.v2.search.doFulltextSearchCountQuery(this.search.query, this.pageEvent.pageIndex, this.search.filter).subscribe(
(response: CountQueryResponse) => {
this.numberOfAllResults = response.numberOfResults;
(count: CountQueryResponse) => {
this.numberOfAllResults = count.numberOfResults;

if (this.numberOfAllResults === 0) {
this.resources = undefined;
this._emitSelectedResource(undefined);
this.loading = false;
}
},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
(countError: ApiResponseError) => {
this._notification.openSnackBar(countError);
this._emitSelectedResource(undefined);
}
);
}
Expand All @@ -164,26 +170,33 @@ export class ListViewComponent implements OnChanges {
(response: ReadResourceSequence) => {
this.resources = response;
this.loading = false;
this.emitSelectedResources({ count: 1, resListIndex: [0], resIds: [this.resources.resources[0].id], selectionType: "single" });
this._emitSelectedResource(this.resources.resources);
},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this.resources = undefined;
this.loading = false;
}
);

} else if (this.search.mode === 'gravsearch') {


// search mode: gravsearch
if (this.pageEvent.pageIndex === 0) {
// perform count query
this._dspApiConnection.v2.search.doExtendedSearchCountQuery(this.search.query).subscribe(
(response: CountQueryResponse) => {
this.numberOfAllResults = response.numberOfResults;
(count: CountQueryResponse) => {
this.numberOfAllResults = count.numberOfResults;

if (this.numberOfAllResults === 0) {
this.resources = undefined;
this._emitSelectedResource(undefined);
this.loading = false;
}
},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
(countError: ApiResponseError) => {
this._notification.openSnackBar(countError);
this._emitSelectedResource(undefined);
}
);
}
Expand All @@ -196,19 +209,30 @@ export class ListViewComponent implements OnChanges {
(response: ReadResourceSequence) => {
this.resources = response;
this.loading = false;
this.emitSelectedResources({ count: 1, resListIndex: [0], resIds: [this.resources.resources[0].id], selectionType: "single" });
this._emitSelectedResource(this.resources.resources);
},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this.resources = undefined;
this.loading = false;
}
);
} else {
console.error('The gravsearch query is not set correctly');
this.resources = undefined;
this.loading = false;
}

}

}

private _emitSelectedResource(resources: ReadResource[]) {
if (resources && resources.length > 0) {
this.emitSelectedResources({ count: 1, resListIndex: [0], resIds: [resources[0].id], selectionType: 'single' });
} else {
this.emitSelectedResources({ count: 0, resListIndex: [], resIds: [], selectionType: 'single'});
}
}

}

0 comments on commit 9a76b0a

Please sign in to comment.