Skip to content

Commit

Permalink
document: filter results by org in admin view
Browse files Browse the repository at this point in the history
* Fixes display of organisation facet in document brief view.
* Modifies links to documents brief view to include current organisation as a default parameter.
* Closes #140.
* Removes useless code.
* Implements result filtering for search in main bar.

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
  • Loading branch information
Alicia Zangger and jma committed Apr 20, 2020
1 parent 1150b4e commit c4d58fe
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
<ul class="list-group list-group-flush" *ngIf="item.entries">
<li class="list-group-item p-0" *ngFor="let entry of item.entries">
<a class="list-group-item btn btn-light text-left text-wrap" [routerLink]="entry.routerLink"><i *ngIf="entry.iconCssClass"
<a class="list-group-item btn btn-light text-left text-wrap" [routerLink]="entry.routerLink" [queryParams]="entry.queryParams"><i *ngIf="entry.iconCssClass"
[ngClass]="entry.iconCssClass" aria-hidden="true"></i> {{ entry.name | translate }}</a>
</li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions projects/admin/src/app/menu/menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ng-core-autocomplete
[recordTypes]="recordTypes"
[action]="'/records/documents'"
[extraQueryParams]="autocompleteQueryParams"
[internalRouting]="true"
class="flex-grow-1">
</ng-core-autocomplete>
Expand Down
3 changes: 3 additions & 0 deletions projects/admin/src/app/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class MenuComponent implements OnInit {

linksMenu: any;

autocompleteQueryParams: any = {page: '1', size: '10'};

librariesSwitchMenu = {
navCssClass: 'navbar-nav',
entries: [{
Expand Down Expand Up @@ -85,6 +87,7 @@ export class MenuComponent implements OnInit {
ngOnInit() {
this.initLinksMenu();
const currentUser = this._userService.getCurrentUser();
this.autocompleteQueryParams.organisation = currentUser.library.organisation.pid;
this.languages = this._configService.languages;
for (const lang of this.languages) {
const data: any = { name: lang };
Expand Down
1 change: 0 additions & 1 deletion projects/admin/src/app/routes/documents-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface {
'author__en',
'author__de',
'author__it',
'library',
'organisation',
'language',
'subject',
Expand Down
21 changes: 14 additions & 7 deletions projects/admin/src/app/routes/route-tool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class RouteToolService {

/**
* Constructor
*
* @param _translateService - TranslateService
* @param _recordPermissionService - RecordPermissionMessageService
* @param _userService - UserService
Expand All @@ -85,6 +86,7 @@ export class RouteToolService {

/**
* Enabled action
*
* @param message - string
* @return Observable
*/
Expand All @@ -94,6 +96,7 @@ export class RouteToolService {

/**
* Disabled action
*
* @param message - string
* @return Observable
*/
Expand All @@ -103,6 +106,7 @@ export class RouteToolService {

/**
* Access only for system librarian
*
* @param message - string
* @return Observable
*/
Expand All @@ -114,6 +118,7 @@ export class RouteToolService {

/**
* Can Add
*
* @param record - Object
* @return Observable
*/
Expand All @@ -140,6 +145,7 @@ export class RouteToolService {

/**
* Can Delete
*
* @param record - Object
* @return Observable
*/
Expand Down Expand Up @@ -193,6 +199,7 @@ export class RouteToolService {

/**
* Aggregation filter
*
* @param aggregations - Object
*/
aggregationFilter(aggregations: object): Observable<any> {
Expand All @@ -207,28 +214,28 @@ export class RouteToolService {

/**
* Aggregation filter
*
* @param aggregations - Object
* @return array
*/
private aggFilter(aggregations: object) {
const aggs = {};
Object.keys(aggregations).map(aggregation => {
if ('organisation' !== aggregation) {
if (aggregation.indexOf('__') > -1) {
const splitted = aggregation.split('__');
if (this._translateService.currentLang === splitted[1]) {
aggs[aggregation] = aggregations[aggregation];
}
} else {
if (aggregation.indexOf('__') > -1) {
const splitted = aggregation.split('__');
if (this._translateService.currentLang === splitted[1]) {
aggs[aggregation] = aggregations[aggregation];
}
} else {
aggs[aggregation] = aggregations[aggregation];
}
});
return aggs;
}

/**
* Get route param by name
*
* @param name - string
* @return mixed - string | null
*/
Expand Down
35 changes: 34 additions & 1 deletion projects/admin/src/app/service/menu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { UserService } from './user.service';
})
export class MenuService {

/**
* Menu content
*/
linksMenu = {
navCssClass: 'navbar-nav',
entries: [
Expand All @@ -32,6 +35,7 @@ export class MenuService {
entries: [{
name: this._translateService.instant('Documents'),
routerLink: '/records/documents',
queryParams: this._myDocumentsQueryParams(),
iconCssClass: 'fa fa-file-o'
}, {
name: this._translateService.instant('Create a bibliographic record'),
Expand Down Expand Up @@ -75,7 +79,7 @@ export class MenuService {
iconCssClass: 'fa fa-users'
}, {
name: this._translateService.instant('My organisation'),
routerLink: `/records/organisations/detail/${this._userService.getCurrentUser().library.organisation.pid}`,
routerLink: this._myOrganisationRouterLink(),
iconCssClass: 'fa fa-university'
}, {
name: this._translateService.instant('My library'),
Expand All @@ -90,12 +94,41 @@ export class MenuService {
]
};

/**
* Constructor
*
* @param _translateService : TranslateService
* @param _userService : UserService
*/
constructor(
private _translateService: TranslateService,
private _userService: UserService,
) {}

/**
* Router link to my library
*
* @return logged user library url for router link
*/
private _myLibraryRouterLink() {
return `/records/libraries/detail/${this._userService.getCurrentUser().currentLibrary}`;
}

/**
* Router link to my organisation
*
* @return logged user organisation url for router link
*/
private _myOrganisationRouterLink() {
return `/records/organisations/detail/${this._userService.getCurrentUser().library.organisation.pid}`;
}

/**
* Query params to filter documents by organisation
*
* @return organisation pid as a dictionary
*/
private _myDocumentsQueryParams() {
return {organisation: this._userService.getCurrentUser().library.organisation.pid};
}
}
12 changes: 11 additions & 1 deletion projects/public-search/src/app/service/routing-init.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class RoutingInitService {

/**
* Constructor
*
* @param _translateService - TranslateService
*/
constructor(
Expand All @@ -45,6 +46,7 @@ export class RoutingInitService {

/**
* Route Config
*
* @param viewcode - string
*/
routeConfig(viewcode: string) {
Expand Down Expand Up @@ -95,6 +97,11 @@ export class RoutingInitService {
};
}

/**
* List of aggregations
*
* @param viewcode - viewcode
*/
private aggregations(viewcode: string) {
if (this._appConfigService.globalViewName === viewcode) {
return [
Expand Down Expand Up @@ -124,7 +131,8 @@ export class RoutingInitService {
}

/**
* filter aggregations
* Filter aggregations
*
* @return Observable
*/
private filter(aggregations: object): Observable<any> {
Expand All @@ -139,9 +147,11 @@ export class RoutingInitService {

/**
* Aggregation filter
*
* @return array of value
*/
private aggregationFilter(aggregations: object) {
// TODO replace organisation facet by library facet when the viewcode is not global (needs backend adaptation)
const aggs = {};
Object.keys(aggregations).forEach(aggregation => {
if (aggregation.indexOf('__') > -1) {
Expand Down

0 comments on commit c4d58fe

Please sign in to comment.