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 results and suggestions filtering for search in main bar.
* Updates @rero/ng-core version for the latest one.

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 24, 2020
1 parent c9e7cc4 commit e6ffd7a
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 45 deletions.
47 changes: 14 additions & 33 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@ngx-formly/bootstrap": "^5.5.10",
"@ngx-formly/core": "^5.5.10",
"@ngx-translate/core": "^12.1.1",
"@rero/ng-core": "0.1.0",
"@rero/ng-core": "0.2.1",
"bootstrap": "^4.3.1",
"crypto-js": "^3.1.9-1",
"document-register-element": "^1.7.2",
Expand Down
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
4 changes: 4 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 Expand Up @@ -113,6 +116,7 @@ export class MenuComponent implements OnInit {
this.recordTypes = [{
type: 'documents',
field: 'autocomplete_title',
preFilters: {organisation: currentUser.library.organisation.pid},
getSuggestions: (query, documents) => this.getDocumentsSuggestions(query, documents)
}, {
type: 'persons',
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};
}
}
Loading

0 comments on commit e6ffd7a

Please sign in to comment.