Skip to content

Commit

Permalink
search filter: implement advanced search on brief view
Browse files Browse the repository at this point in the history
* Updates routes to add advanced search filter.
* Fixes number of parameters for component implement RecordSearchPage.
* Closes rero/rero-ils#1824.
* Uses ng-core version 1.8.x.
* Fixes tests.
* Adds a new karma package to display the test name in the console:
  `karma-spec-reporter`.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr authored and jma committed May 17, 2021
1 parent f7e6f9e commit 3a4666f
Show file tree
Hide file tree
Showing 34 changed files with 192 additions and 89 deletions.
7 changes: 6 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "admin:build"
"browserTarget": "admin:build",
"sourceMap": {
"scripts": true,
"styles": false,
"vendor": true
}
},
"configurations": {
"production": {
Expand Down
15 changes: 12 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@ngx-loading-bar/http-client": "^5.1.1",
"@ngx-loading-bar/router": "^5.1.1",
"@ngx-translate/core": "^13.0.0",
"@rero/ng-core": "~1.7.0",
"@rero/ng-core": "^1.8.0",
"bootstrap": "^4.6.0",
"crypto-js": "^3.3.0",
"document-register-element": "^1.14.10",
Expand Down Expand Up @@ -118,6 +118,7 @@
"karma-chrome-launcher": "~3.1.0",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.4",
"karma-spec-reporter": "0.0.32",
"ng-packagr": "^10.1.2",
"protractor": "~7.0.0",
"ts-node": "~9.0.0",
Expand Down
5 changes: 3 additions & 2 deletions projects/admin/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = function (config) {
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-spec-reporter')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
Expand All @@ -19,7 +20,7 @@ module.exports = function (config) {
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
reporters: ['progress', 'kjhtml', 'spec'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { IdAttributePipe, SharedModule, testUserPatronWithSettings, UserApiService, UserService } from '@rero/shared';
import { cloneDeep } from 'lodash-es';
Expand All @@ -37,6 +38,7 @@ describe('MenuDashboardComponent', () => {
imports: [
SharedModule,
HttpClientTestingModule,
RouterTestingModule,
TranslateModule.forRoot()
],
providers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { BsLocaleService } from 'ngx-bootstrap/datepicker';
import { MenuLanguageComponent } from './menu-language.component';
Expand All @@ -31,7 +32,8 @@ describe('MenuLanguageComponent', () => {
await TestBed.configureTestingModule({
declarations: [ MenuLanguageComponent ],
imports: [
TranslateModule.forRoot()
TranslateModule.forRoot(),
RouterTestingModule
],
providers: [
BsLocaleService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { MenuUserServicesService } from '../service/menu-user-services.service';
import { MenuUserServicesComponent } from './menu-user-services.component';
Expand All @@ -35,6 +36,7 @@ describe('MenuUserServicesComponent', () => {
declarations: [ MenuUserServicesComponent ],
imports: [
HttpClientTestingModule,
RouterTestingModule,
TranslateModule.forRoot()
],
providers: [
Expand Down
3 changes: 2 additions & 1 deletion projects/admin/src/app/menu/menu.component.html

Large diffs are not rendered by default.

35 changes: 32 additions & 3 deletions projects/admin/src/app/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/

import { Component, OnInit } from '@angular/core';
import { NavigationEnd, Router, UrlSegment } from '@angular/router';
import { SearchBarConfigService, UserService } from '@rero/shared';
import { filter } from 'rxjs/operators';

@Component({
selector: 'admin-menu',
Expand All @@ -37,31 +39,58 @@ export class MenuComponent implements OnInit {
/** Autocomplte query params */
autocompleteQueryParams: any = { page: '1', size: '10' };

/** Is document url */
private hideSearchElement = false;

/** Resources involved in hiding the search area */
private hideSearchResources = ['documents'];

/**
* Get Typehead option limit
* @return number
*/
get typeaheadOptionsLimit() {
get typeaheadOptionsLimit(): number {
return this._searchBarConfigService.typeaheadOptionsLimit;
}

/**
* Get hide search
* @return boolean
*/
get hideSearch(): boolean {
return this.hideSearchElement;
}

/**
* Constructor
* @param _userService - UserService
* @param _searchBarConfigService - SearchBarConfigService
* @param _router - Router
*/
constructor(
private _userService: UserService,
private _searchBarConfigService: SearchBarConfigService
) {}
private _searchBarConfigService: SearchBarConfigService,
private _router: Router
) { }

/** Init */
ngOnInit() {
this._hideSearch();
this._router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() => this._hideSearch());
const currentUser = this._userService.user;
this.autocompleteQueryParams.organisation = currentUser.currentOrganisation;

this.recordTypes = this._searchBarConfigService.getConfig(
true, this, undefined, this.maxLengthSuggestion
);
}

/** Search the resource to determine whether to hide the search */
private _hideSearch(): void {
this.hideSearchElement =
this._router.parseUrl(this._router.url).root.children.primary?.segments
.some((segment: UrlSegment) => this.hideSearchResources.includes(segment.path));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { SearchResult, RecordSearchPageComponent, RecordSearchService, RecordService } from '@rero/ng-core';
import { SearchResult, RecordSearchPageComponent, RecordSearchService, RecordService, RecordUiService } from '@rero/ng-core';

@Component({
selector: 'admin-document-record-search',
Expand Down Expand Up @@ -58,18 +58,20 @@ export class DocumentRecordSearchComponent extends RecordSearchPageComponent imp

/**
* Constructor
* @param _route - ActivatedRoute
* @param _activatedRoute - ActivatedRoute
* @param _router - Router
* @param _recordSearchService - RecordSearchService
* @param _recordUiService - RecordUiService
* @param _recordService - RecordService
*/
constructor(
protected _route: ActivatedRoute,
protected _activatedRoute: ActivatedRoute,
protected _router: Router,
protected _recordSearchService: RecordSearchService,
private _recordService: RecordService
protected _recordUiService: RecordUiService,
private _recordService: RecordService,
) {
super(_route, _router, _recordSearchService);
super(_activatedRoute, _router, _recordSearchService, _recordUiService);
}

/** Init */
Expand All @@ -94,7 +96,7 @@ export class DocumentRecordSearchComponent extends RecordSearchPageComponent imp
*/
linkToGlobalDocuments(event: any) {
event.preventDefault();
const queryParams = this._route.snapshot.queryParams;
const queryParams = this._activatedRoute.snapshot.queryParams;
this._router.navigate(
[this._baseUrl],
{ relativeTo: this._route, queryParams: {
Expand Down
7 changes: 3 additions & 4 deletions projects/admin/src/app/routes/acquisition-orders-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ export class AcquisitionOrdersRoute extends BaseRoute implements RouteInterface
label: _('Orders'),
component: AcquisitionOrderBriefViewComponent,
detailComponent: AcquisitionOrderDetailViewComponent,
searchFilters: [
this.expertSearchFilter()
],
permissions: (record: any) => this._routeToolService.permissions(record, this.recordType),
// use simple query for UI search
preFilters: {
simple: 1
},
preCreateRecord: (data: any) => {
const user = this._routeToolService.userService.user;
data.order_date = formatDate(
Expand Down
40 changes: 39 additions & 1 deletion projects/admin/src/app/routes/base-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { UrlSegment } from '@angular/router';
import { RouteToolService } from './route-tool.service';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { extractIdOnRef } from '@rero/ng-core';
import { of } from 'rxjs';
import { RouteToolService } from './route-tool.service';

export class BaseRoute {

Expand Down Expand Up @@ -93,4 +94,41 @@ export class BaseRoute {
: recordMetadata.pid;
return of(`${baseUrl}/${pid}`);
}

/**
* Expert search filter configuration
* @return Object - Search filter configuration
*/
protected expertSearchFilter() {
return {
label: _('Expert search'),
filter: 'simple',
value: '0',
disabledValue: '1',
persistent: true,
// TODO: activate this part when the help is online
// and correct the links of the help
// url: {
// external: true,
// link: this._expertSearchLink(),
// title: this._routeToolService.translateService.instant('Link to expert search help')
// }
};
}

/**
* Expert search link
* @return string, link of help page
*/
private _expertSearchLink() {
const defaultPath = 'help/recherche';
const searchPaths = {
fr: 'help/recherche'
// TODO: Add other paths
};
const availableLanguages = Object.keys(searchPaths);
return (this._routeToolService.translateService.currentLang in availableLanguages)
? searchPaths[this._routeToolService.translateService.currentLang]
: defaultPath;
}
}
7 changes: 3 additions & 4 deletions projects/admin/src/app/routes/budgets-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ export class BudgetsRoute extends BaseRoute implements RouteInterface {
label: _('Budgets'),
component: BudgetsBriefViewComponent,
detailComponent: BudgetDetailViewComponent,
searchFilters: [
this.expertSearchFilter()
],
canAdd: () => this._routeToolService.canSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: () => this._routeToolService.canNot(),
// use simple query for UI search
preFilters: {
simple: 1
},
preCreateRecord: (data: any) => {
const user = this._routeToolService.userService.user;
data.organisation = {
Expand Down
7 changes: 3 additions & 4 deletions projects/admin/src/app/routes/circulation-policies-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ export class CirculationPoliciesRoute extends BaseRoute implements RouteInterfac
},
component: CircPoliciesBriefViewComponent,
detailComponent: CircPolicyDetailViewComponent,
searchFilters: [
this.expertSearchFilter()
],
canAdd: () => this._routeToolService.canSystemLibrarian(),
permissions: (record: any) => this._routeToolService.permissions(record, this.recordType),
// use simple query for UI search
preFilters: {
simple: 1
},
preCreateRecord: (data: any) => {
const user: User = this._routeToolService.userService.user;
if (data.parent == null) {
Expand Down
7 changes: 3 additions & 4 deletions projects/admin/src/app/routes/collections-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ export class CollectionsRoute extends BaseRoute implements RouteInterface {
label: 'Exhibition/course',
component: CollectionBriefViewComponent,
detailComponent: CollectionDetailViewComponent,
searchFilters: [
this.expertSearchFilter()
],
canAdd: () => this._routeToolService.can(),
permissions: (record: any) => this._routeToolService.permissions(record, this.recordType),
// use simple query for UI search
preFilters: {
simple: 1
},
aggregationsOrder: ['type', 'library', 'teacher', 'subject'],
aggregationsExpand: ['type'],
preprocessRecordEditor: (record: any) => {
Expand Down
10 changes: 4 additions & 6 deletions projects/admin/src/app/routes/corporate-bodies-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ export class CorporateBodiesRoute extends BaseRoute implements RouteInterface {
label: 'corporate-bodies',
component: ContributionBriefComponent,
detailComponent: ContributionDetailViewComponent,
searchFilters: [
this.expertSearchFilter()
],
aggregationsOrder: ['sources'],
aggregationsExpand: ['sources'],
// use simple query for UI search
preFilters: {
type: 'bf:Organisation',
simple: 1
}
aggregationsExpand: ['sources']
}
]
}
Expand Down
Loading

0 comments on commit 3a4666f

Please sign in to comment.