Skip to content

Commit

Permalink
search: open aggregation with filters
Browse files Browse the repository at this point in the history
* 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 Mariéthoz <Johnny.Mariethoz@rero.ch>
  • Loading branch information
jma authored and vgranata committed Jul 25, 2022
1 parent 8723e4c commit 4f6ea4a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
22 changes: 21 additions & 1 deletion projects/admin/src/app/routes/documents-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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';
Expand All @@ -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 {

Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions projects/admin/src/app/routes/route.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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';
Expand Down Expand Up @@ -61,6 +61,7 @@ export class RouteService {
constructor(
private _routeCollectionService: RouteCollectionService,
private _router: Router,
private _route: ActivatedRoute,
private _routeToolService: RouteToolService,
private _translateService: TranslateService
) { }
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -25,7 +26,8 @@ describe('DocumentRouteService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot()
TranslateModule.forRoot(),
RouterTestingModule
]
});
service = TestBed.inject(DocumentsRouteService);
Expand Down
13 changes: 11 additions & 2 deletions projects/public-search/src/app/routes/documents-route.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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}`,
Expand Down

0 comments on commit 4f6ea4a

Please sign in to comment.