From 4f6ea4ae421e29e634376e2daada054275598540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Marie=CC=81thoz?= Date: Wed, 1 Jun 2022 13:20:05 +0200 Subject: [PATCH 1/2] search: open aggregation with filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Marks the aggregation as open if the url contains a corresponding filter including children filters. * Adds the ActivatedRoute service for the document route class. Co-Authored-by: Johnny MarieĢthoz --- .../admin/src/app/routes/documents-route.ts | 22 ++++++++++++++++++- .../admin/src/app/routes/route.service.ts | 5 +++-- .../routes/documents-route.service.spec.ts | 4 +++- .../src/app/routes/documents-route.service.ts | 13 +++++++++-- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/projects/admin/src/app/routes/documents-route.ts b/projects/admin/src/app/routes/documents-route.ts index ba2e48afb..df9aa8ed6 100644 --- a/projects/admin/src/app/routes/documents-route.ts +++ b/projects/admin/src/app/routes/documents-route.ts @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +import { ActivatedRoute } from '@angular/router'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { DetailComponent, RouteInterface } from '@rero/ng-core'; import { Observable, of } from 'rxjs'; @@ -24,6 +25,7 @@ import { DocumentEditorComponent } from '../record/custom-editor/document-editor import { DocumentDetailViewComponent } from '../record/detail-view/document-detail-view/document-detail-view.component'; import { DocumentRecordSearchComponent } from '../record/document-record-search/document-record-search.component'; import { BaseRoute } from './base-route'; +import { RouteToolService } from './route-tool.service'; export class DocumentsRoute extends BaseRoute implements RouteInterface { @@ -33,6 +35,17 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface { /** Record type */ readonly recordType = 'documents'; + /** + * Constructor + * @param routeToolService - RouteToolService + */ + constructor( + protected _routeToolService: RouteToolService, + protected _route: ActivatedRoute + ) { + super(_routeToolService); + } + /** * Get Configuration * @return Object @@ -85,7 +98,14 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface { 'subject', 'status' ], - aggregationsExpand: ['document_type'], + aggregationsExpand: () => { + const expand = ['document_type']; + const queryParams = this._route.snapshot.queryParams; + if (queryParams.location || queryParams.library) { + expand.push('organisation'); + } + return expand; + }, aggregationsBucketSize: 10, itemHeaders: { Accept: 'application/rero+json, application/json' diff --git a/projects/admin/src/app/routes/route.service.ts b/projects/admin/src/app/routes/route.service.ts index 45c1ae588..53b109f04 100644 --- a/projects/admin/src/app/routes/route.service.ts +++ b/projects/admin/src/app/routes/route.service.ts @@ -15,7 +15,7 @@ * along with this program. If not, see . */ import { Injectable } from '@angular/core'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { RouteCollectionService } from '@rero/ng-core'; import { ReceiptLinesRoute } from '../acquisition/routes/receipt-lines-route'; @@ -61,6 +61,7 @@ export class RouteService { constructor( private _routeCollectionService: RouteCollectionService, private _router: Router, + private _route: ActivatedRoute, private _routeToolService: RouteToolService, private _translateService: TranslateService ) { } @@ -71,7 +72,7 @@ export class RouteService { initializeRoutes() { this._routeCollectionService .addRoute(new CirculationPoliciesRoute(this._routeToolService)) - .addRoute(new DocumentsRoute(this._routeToolService)) + .addRoute(new DocumentsRoute(this._routeToolService, this._route)) .addRoute(new HoldingsRoute(this._routeToolService)) .addRoute(new ItemsRoute(this._routeToolService)) .addRoute(new IssuesRoute(this._routeToolService)) diff --git a/projects/public-search/src/app/routes/documents-route.service.spec.ts b/projects/public-search/src/app/routes/documents-route.service.spec.ts index 43f1d388c..783e7a3fb 100644 --- a/projects/public-search/src/app/routes/documents-route.service.spec.ts +++ b/projects/public-search/src/app/routes/documents-route.service.spec.ts @@ -16,6 +16,7 @@ */ import { TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; import { TranslateModule } from '@ngx-translate/core'; import { DocumentsRouteService } from './documents-route.service'; @@ -25,7 +26,8 @@ describe('DocumentRouteService', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [ - TranslateModule.forRoot() + TranslateModule.forRoot(), + RouterTestingModule ] }); service = TestBed.inject(DocumentsRouteService); diff --git a/projects/public-search/src/app/routes/documents-route.service.ts b/projects/public-search/src/app/routes/documents-route.service.ts index 93611671c..86f0921fe 100644 --- a/projects/public-search/src/app/routes/documents-route.service.ts +++ b/projects/public-search/src/app/routes/documents-route.service.ts @@ -16,6 +16,7 @@ */ import { Injectable } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { TranslateService } from '@ngx-translate/core'; import { ContributionBriefComponent } from '@rero/shared'; @@ -55,7 +56,8 @@ export class DocumentsRouteService extends BaseRoute implements ResourceRouteInt */ constructor( translateService: TranslateService, - private appConfigService: AppConfigService + private appConfigService: AppConfigService, + private _route: ActivatedRoute ) { super(translateService); } @@ -98,7 +100,14 @@ export class DocumentsRouteService extends BaseRoute implements ResourceRouteInt organisation: _('Library') }, aggregationsOrder: this.aggregations(viewcode), - aggregationsExpand: ['document_type'], + aggregationsExpand: () => { + const expand = ['document_type']; + const queryParams = this._route.snapshot.queryParams; + if (queryParams.location || queryParams.library) { + expand.push('organisation'); + } + return expand; + }, aggregationsBucketSize: 10, preFilters: { view: `${viewcode}`, From 3abddf41ae68f4a46404cea2a995a5426bdb1bd0 Mon Sep 17 00:00:00 2001 From: Valeria Granata Date: Thu, 2 Jun 2022 17:15:59 +0200 Subject: [PATCH 2/2] documents: add more facets for documents Co-Authored-by: Valeria Granata --- .../service/menu-user-services.service.ts | 3 -- .../admin/src/app/routes/documents-route.ts | 44 ++++++++++------- .../admin/src/app/routes/route.service.ts | 5 +- .../src/app/routes/documents-route.service.ts | 49 ++++++++++++++++--- projects/public-search/src/index.html | 2 +- 5 files changed, 71 insertions(+), 32 deletions(-) diff --git a/projects/admin/src/app/menu/service/menu-user-services.service.ts b/projects/admin/src/app/menu/service/menu-user-services.service.ts index 44f316e05..7c92e901c 100644 --- a/projects/admin/src/app/menu/service/menu-user-services.service.ts +++ b/projects/admin/src/app/menu/service/menu-user-services.service.ts @@ -151,7 +151,6 @@ export class MenuUserServicesService extends MenuBase { // ----- DOCUMENTS this._documentsMenu = catalogMenu.addChild('Documents') .setRouterLink(['/', 'records', 'documents']) - .setQueryParam('organisation', this._userService.user.currentOrganisation) .setAttribute('id', 'documents-menu') .setExtra('iconClass', 'fa fa-file-o'); this._translatedName(this._documentsMenu, 'Documents'); @@ -329,8 +328,6 @@ export class MenuUserServicesService extends MenuBase { // USER SERVICES: COLLECTIONS, ILL REQUESTS this._illRequestsMenu.setQueryParam('library', user.currentLibrary); this._collectionsMenu.setQueryParam('library', user.currentLibrary); - // CATALOG: DOCUMENTS - this._documentsMenu.setQueryParam('organisation', user.currentOrganisation); // ACQUISITION: this._ordersMenu.setQueryParam('library', user.currentLibrary); this._lateIssuesMenu.setQueryParam('library', user.currentLibrary); diff --git a/projects/admin/src/app/routes/documents-route.ts b/projects/admin/src/app/routes/documents-route.ts index df9aa8ed6..26836f386 100644 --- a/projects/admin/src/app/routes/documents-route.ts +++ b/projects/admin/src/app/routes/documents-route.ts @@ -15,7 +15,6 @@ * along with this program. If not, see . */ -import { ActivatedRoute } from '@angular/router'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { DetailComponent, RouteInterface } from '@rero/ng-core'; import { Observable, of } from 'rxjs'; @@ -25,7 +24,6 @@ import { DocumentEditorComponent } from '../record/custom-editor/document-editor import { DocumentDetailViewComponent } from '../record/detail-view/document-detail-view/document-detail-view.component'; import { DocumentRecordSearchComponent } from '../record/document-record-search/document-record-search.component'; import { BaseRoute } from './base-route'; -import { RouteToolService } from './route-tool.service'; export class DocumentsRoute extends BaseRoute implements RouteInterface { @@ -35,17 +33,6 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface { /** Record type */ readonly recordType = 'documents'; - /** - * Constructor - * @param routeToolService - RouteToolService - */ - constructor( - protected _routeToolService: RouteToolService, - protected _route: ActivatedRoute - ) { - super(_routeToolService); - } - /** * Get Configuration * @return Object @@ -76,7 +63,17 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface { component: DocumentsBriefViewComponent, detailComponent: DocumentDetailViewComponent, searchFilters: [ - this.expertSearchFilter() + this.expertSearchFilter(), + { + label: _('Online resources'), + filter: 'online', + value: 'true' + }, + { + label: _('Physical resources'), + filter: 'not_online', + value: 'true' + } ], permissions: (record: any) => this._routeToolService.permissions(record, this.recordType), preprocessRecordEditor: (record: any) => { @@ -87,20 +84,31 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface { aggregations: (aggregations: any) => this._routeToolService .aggregationFilter(aggregations), aggregationsName: { - organisation: _('Library') + online: _('Online resources'), + not_online: _('Physical resources'), + organisation: _('Library'), + genreForm: _('Genre, form'), + intendedAudience: _('Intended audience'), + year: _('Publication year'), + subject_fiction: _('Subject (fiction)'), + subject_no_fiction: _('Subject (non-fiction)'), }, allowEmptySearch: false, aggregationsOrder: [ 'document_type', - 'author', 'organisation', 'language', - 'subject', + 'year', + 'author', + 'subject_no_fiction', + 'subject_fiction', + 'genreForm', + 'intendedAudience', 'status' ], aggregationsExpand: () => { const expand = ['document_type']; - const queryParams = this._route.snapshot.queryParams; + const queryParams = this._routeToolService.activatedRoute.snapshot.queryParams; if (queryParams.location || queryParams.library) { expand.push('organisation'); } diff --git a/projects/admin/src/app/routes/route.service.ts b/projects/admin/src/app/routes/route.service.ts index 53b109f04..45c1ae588 100644 --- a/projects/admin/src/app/routes/route.service.ts +++ b/projects/admin/src/app/routes/route.service.ts @@ -15,7 +15,7 @@ * along with this program. If not, see . */ import { Injectable } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; +import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { RouteCollectionService } from '@rero/ng-core'; import { ReceiptLinesRoute } from '../acquisition/routes/receipt-lines-route'; @@ -61,7 +61,6 @@ export class RouteService { constructor( private _routeCollectionService: RouteCollectionService, private _router: Router, - private _route: ActivatedRoute, private _routeToolService: RouteToolService, private _translateService: TranslateService ) { } @@ -72,7 +71,7 @@ export class RouteService { initializeRoutes() { this._routeCollectionService .addRoute(new CirculationPoliciesRoute(this._routeToolService)) - .addRoute(new DocumentsRoute(this._routeToolService, this._route)) + .addRoute(new DocumentsRoute(this._routeToolService)) .addRoute(new HoldingsRoute(this._routeToolService)) .addRoute(new ItemsRoute(this._routeToolService)) .addRoute(new IssuesRoute(this._routeToolService)) diff --git a/projects/public-search/src/app/routes/documents-route.service.ts b/projects/public-search/src/app/routes/documents-route.service.ts index 86f0921fe..c8dacaadd 100644 --- a/projects/public-search/src/app/routes/documents-route.service.ts +++ b/projects/public-search/src/app/routes/documents-route.service.ts @@ -53,6 +53,7 @@ export class DocumentsRouteService extends BaseRoute implements ResourceRouteInt * Constructor * @param translateService - TranslateService * @param appConfigService - AppConfigService + * @param _route - ActivatedRoute */ constructor( translateService: TranslateService, @@ -97,18 +98,44 @@ export class DocumentsRouteService extends BaseRoute implements ResourceRouteInt label: _('Documents'), aggregations: (aggregations: any) => this.aggFilter(aggregations), aggregationsName: { - organisation: _('Library') + online: _('Online resources'), + not_online: _('Physical resources'), + organisation: _('Library'), + genreForm: _('Genre, form'), + intendedAudience: _('Intended audience'), + year: _('Publication year'), + subject_fiction: _('Subject (fiction)'), + subject_no_fiction: _('Subject (non-fiction)'), }, + showFacetsIfNoResults: true, aggregationsOrder: this.aggregations(viewcode), aggregationsExpand: () => { const expand = ['document_type']; const queryParams = this._route.snapshot.queryParams; - if (queryParams.location || queryParams.library) { - expand.push('organisation'); + if (this.appConfigService.globalViewName === viewcode) { + if (queryParams.location || queryParams.library) { + expand.push('organisation'); + } + } else { + if (queryParams.location) { + expand.push('library'); + } } return expand; }, aggregationsBucketSize: 10, + searchFilters: [ + { + label: _('Online resources'), + filter: 'online', + value: 'true' + }, + { + label: _('Physical resources'), + filter: 'not_online', + value: 'true' + } + ], preFilters: { view: `${viewcode}`, simple: 1 @@ -196,19 +223,27 @@ export class DocumentsRouteService extends BaseRoute implements ResourceRouteInt if (this.appConfigService.globalViewName === viewcode) { return [ _('document_type'), - _('author'), _('organisation'), _('language'), - _('subject'), + _('year'), + _('author'), + _('subject_no_fiction'), + _('subject_fiction'), + _('genreForm'), + _('intendedAudience'), _('status') ]; } else { return [ _('document_type'), - _('author'), _('library'), _('language'), - _('subject'), + _('year'), + _('author'), + _('subject_no_fiction'), + _('subject_fiction'), + _('genreForm'), + _('intendedAudience'), _('status') ]; } diff --git a/projects/public-search/src/index.html b/projects/public-search/src/index.html index 173c8868d..e2c979ea6 100644 --- a/projects/public-search/src/index.html +++ b/projects/public-search/src/index.html @@ -24,7 +24,7 @@ - +