From 8c402b6b7c0dbae34b85e9e9c3ad7a02f2332d69 Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Tue, 16 Feb 2021 07:32:18 +0100 Subject: [PATCH] document: improvement of the display get tab * Fixes missing translations. * Removes custom display of book. * Adds cancel button on request dialog. * Closes rero/rero-ils#1660. Co-Authored-by: Bertrand Zuchuat --- .../operation-logs.component.ts | 7 +- .../src/app/app.module.ts | 12 +-- projects/public-holdings-items/src/index.html | 7 +- .../src/app/api/holdings-api.service.spec.ts | 6 -- .../src/app/api/holdings-api.service.ts | 10 --- .../src/app/api/item-api.service.spec.ts | 6 -- .../src/app/api/item-api.service.ts | 36 +------- .../document-detail/book/book.component.html | 22 ----- .../book/book.component.spec.ts | 86 ------------------- .../document-detail/book/book.component.ts | 86 ------------------- .../holdings-items.component.html | 20 ----- .../holdings-items.component.spec.ts | 45 ---------- .../holdings/holdings.component.ts | 5 +- .../holdings/items/items.component.ts | 5 +- .../pickup-location.component.html | 6 ++ .../pickup-location.component.ts | 10 ++- .../request/request.component.html | 7 +- .../request/request.component.ts | 7 +- ...ems.component.ts => manual_translation.ts} | 23 ++--- 19 files changed, 51 insertions(+), 355 deletions(-) delete mode 100644 projects/public-search/src/app/document-detail/book/book.component.html delete mode 100644 projects/public-search/src/app/document-detail/book/book.component.spec.ts delete mode 100644 projects/public-search/src/app/document-detail/book/book.component.ts delete mode 100644 projects/public-search/src/app/document-detail/holdings-items/holdings-items.component.html delete mode 100644 projects/public-search/src/app/document-detail/holdings-items/holdings-items.component.spec.ts rename projects/public-search/src/{app/document-detail/holdings-items/holdings-items.component.ts => manual_translation.ts} (65%) diff --git a/projects/admin/src/app/record/operation-logs/operation-logs.component.ts b/projects/admin/src/app/record/operation-logs/operation-logs.component.ts index de7e3f30f..295c2406e 100644 --- a/projects/admin/src/app/record/operation-logs/operation-logs.component.ts +++ b/projects/admin/src/app/record/operation-logs/operation-logs.component.ts @@ -15,10 +15,11 @@ * along with this program. If not, see . */ import { Component, Input, OnInit } from '@angular/core'; +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { TranslateService } from '@ngx-translate/core'; import { Record } from '@rero/ng-core'; import { BehaviorSubject, forkJoin, Observable } from 'rxjs'; -import { first, map } from 'rxjs/operators'; +import { map } from 'rxjs/operators'; import { OperationLogsApiService } from '../../api/operation-logs-api.service'; import { OperationLogsService } from '../../service/operation-logs.service'; @@ -117,8 +118,8 @@ export class OperationLogsComponent implements OnInit { let count = this.recordTotals - (this.page * this.itemsPerPage); if (count < 0) { count = 0; } const linkText = (count > 1) - ? '{{ counter }} hidden operation logs' - : '{{ counter }} hidden operation log'; + ? _('{{ counter }} hidden operation logs') + : _('{{ counter }} hidden operation log'); return this._translateService.instant(linkText, { counter: count }); } diff --git a/projects/public-holdings-items/src/app/app.module.ts b/projects/public-holdings-items/src/app/app.module.ts index c8b6dafd8..c913cb05b 100644 --- a/projects/public-holdings-items/src/app/app.module.ts +++ b/projects/public-holdings-items/src/app/app.module.ts @@ -28,8 +28,6 @@ import { TranslateLoader as BaseTranslateLoader, TranslateModule } from '@ngx-tr import { CoreConfigService, CoreModule, RecordModule, TranslateLoader } from '@rero/ng-core'; import { SharedModule } from '@rero/shared'; import { TypeaheadModule } from 'ngx-bootstrap/typeahead'; -import { BookComponent } from 'projects/public-search/src/app/document-detail/book/book.component'; -import { HoldingsItemsComponent } from 'projects/public-search/src/app/document-detail/holdings-items/holdings-items.component'; import { HoldingComponent } from 'projects/public-search/src/app/document-detail/holdings/holding/holding.component'; import { HoldingsComponent } from 'projects/public-search/src/app/document-detail/holdings/holdings.component'; import { ItemsComponent } from 'projects/public-search/src/app/document-detail/holdings/items/items.component'; @@ -48,8 +46,6 @@ export function appInitFactory(appInitializerService: AppInitializerService) { @NgModule({ declarations: [ - BookComponent, - HoldingsItemsComponent, HoldingsComponent, ItemComponent, ItemsComponent, @@ -88,8 +84,6 @@ export function appInitFactory(appInitializerService: AppInitializerService) { } ], entryComponents: [ - BookComponent, - HoldingsItemsComponent, HoldingsComponent, ItemComponent, ItemsComponent @@ -104,9 +98,9 @@ export class AppModule { } ngDoBootstrap() { - if (!customElements.get('public-holdings-items')) { - const searchBar = createCustomElement(HoldingsItemsComponent, { injector: this.injector }); - customElements.define('public-holdings-items', searchBar); + if (!customElements.get('public-search-holdings')) { + const searchBar = createCustomElement(HoldingsComponent, { injector: this.injector }); + customElements.define('public-search-holdings', searchBar); } } } diff --git a/projects/public-holdings-items/src/index.html b/projects/public-holdings-items/src/index.html index 583272278..c79d5613a 100644 --- a/projects/public-holdings-items/src/index.html +++ b/projects/public-holdings-items/src/index.html @@ -43,11 +43,10 @@

Document holdings items

- + >
diff --git a/projects/public-search/src/app/api/holdings-api.service.spec.ts b/projects/public-search/src/app/api/holdings-api.service.spec.ts index 7a28c68e2..8a32e44cc 100644 --- a/projects/public-search/src/app/api/holdings-api.service.spec.ts +++ b/projects/public-search/src/app/api/holdings-api.service.spec.ts @@ -79,10 +79,4 @@ describe('HoldingsService', () => { expect(result.hits[0]).toEqual(record); }); }); - - it('should return a set of Holdings Pids', () => { - service.getHoldingsPidsByDocumentPidAndViewcode('1', 'global').subscribe((result: string[]) => { - expect(result).toEqual(holdingsPids); - }); - }); }); diff --git a/projects/public-search/src/app/api/holdings-api.service.ts b/projects/public-search/src/app/api/holdings-api.service.ts index a592ae6f8..9a70e1952 100644 --- a/projects/public-search/src/app/api/holdings-api.service.ts +++ b/projects/public-search/src/app/api/holdings-api.service.ts @@ -53,14 +53,4 @@ export class HoldingsApiService { .getRecords('holdings', `document.pid:${documentPid}`, page, itemsPerPage, undefined, { view: viewcode }, this._headers) .pipe(map((response: Record) => response.hits)); } - - /** - * Get Holdings pids by document pid and viewcode - * @param documentPid - string - * @param viewcode - string - * @return Observable - */ - getHoldingsPidsByDocumentPidAndViewcode(documentPid: string, viewcode: string): Observable { - return this._httpClient.get(`/api/holding/pids/${documentPid}?view=${viewcode}`); - } } diff --git a/projects/public-search/src/app/api/item-api.service.spec.ts b/projects/public-search/src/app/api/item-api.service.spec.ts index 173ba245c..5ecba828a 100644 --- a/projects/public-search/src/app/api/item-api.service.spec.ts +++ b/projects/public-search/src/app/api/item-api.service.spec.ts @@ -94,12 +94,6 @@ describe('ItemService', () => { }); }); - it('should return a set of Items by document pid', () => { - service.getItemsByDocumentPidAndViewcode('1', 'global', 1).subscribe((result: QueryResponse) => { - expect(result.hits[0]).toEqual(record); - }); - }); - it('should return item can request', () => { service.canRequest('1', 'xxxxxxxx').subscribe((result: any) => { expect(result).toEqual(canRequest); diff --git a/projects/public-search/src/app/api/item-api.service.ts b/projects/public-search/src/app/api/item-api.service.ts index 151ee8d88..c9ae1c9e5 100644 --- a/projects/public-search/src/app/api/item-api.service.ts +++ b/projects/public-search/src/app/api/item-api.service.ts @@ -18,7 +18,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Record, RecordService } from '@rero/ng-core'; import { Observable } from 'rxjs'; -import { map, switchMap } from 'rxjs/operators'; +import { map } from 'rxjs/operators'; import { QueryResponse } from '../record'; import { HoldingsApiService } from './holdings-api.service'; @@ -61,40 +61,6 @@ export class ItemApiService { ).pipe(map((response: Record) => response.hits)); } - /** - * Get items by holdings pids and viewcode - * @param documentPid - string - * @param viewcode - string - * @param page - number - * @param itemsPerPage - number - * @return Observable - */ - getItemsByDocumentPidAndViewcode( - documentPid: string, viewcode: string, page: number, itemsPerPage: number = 5): Observable { - return this._holdingsApiService.getHoldingsPidsByDocumentPidAndViewcode(documentPid, viewcode) - .pipe( - switchMap((holdingPids: string[]) => { - return this.getItemsByHoldingsPids(holdingPids, viewcode, page, itemsPerPage); - }) - ); - } - - /** - * Get Items by holdings pids - * @param holdingsPids - array of string - * @param viewcode - string - * @param page - number - * @param itemsPerPage -number - * @return Observable - */ - getItemsByHoldingsPids( - holdingsPids: string[], viewcode: string, page: number, itemsPerPage: number = 5): Observable { - const query = 'holding.pid:' + holdingsPids.join(' OR holding.pid:'); - return this._recordService - .getRecords('items', query, page, itemsPerPage, undefined, { view: viewcode }, this._headers, 'library') - .pipe(map((response: Record) => response.hits)); - } - /** * Item Can request * @param itemPid - string diff --git a/projects/public-search/src/app/document-detail/book/book.component.html b/projects/public-search/src/app/document-detail/book/book.component.html deleted file mode 100644 index 9b4424dce..000000000 --- a/projects/public-search/src/app/document-detail/book/book.component.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - diff --git a/projects/public-search/src/app/document-detail/book/book.component.spec.ts b/projects/public-search/src/app/document-detail/book/book.component.spec.ts deleted file mode 100644 index 097db1ddf..000000000 --- a/projects/public-search/src/app/document-detail/book/book.component.spec.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - * RERO ILS UI - * Copyright (C) 2021 RERO - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -import { HttpClientTestingModule } from '@angular/common/http/testing'; -import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateModule } from '@ngx-translate/core'; -import { of } from 'rxjs'; -import { ItemApiService } from '../../api/item-api.service'; -import { QueryResponse } from '../../record'; -import { BookComponent } from './book.component'; - - -describe('BookComponent', () => { - let component: BookComponent; - let fixture: ComponentFixture; - - const records: QueryResponse = { - total: { - value: 10, - relation: 'eq' - }, - hits: [] - }; - - const recordServiceSpy = jasmine.createSpyObj('ItemService', [ - 'getItemsByDocumentPidAndViewcode' - ]); - recordServiceSpy.getItemsByDocumentPidAndViewcode.and.returnValue(of(records)); - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [ - HttpClientTestingModule, - TranslateModule.forRoot() - ], - declarations: [ BookComponent ], - providers: [ - { provide: ItemApiService, useValue: recordServiceSpy } - ], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA - ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(BookComponent); - component = fixture.componentInstance; - component.documentpid = '1'; - component.viewcode = 'global'; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); - - it('should display the link more items', () => { - component.itemsTotal = 10; - fixture.detectChanges(); - const showMore = fixture.nativeElement.querySelector('#show-more-1'); - expect(showMore.textContent.trim()).toEqual('Show more'); - }); - - it('should don\'t display the link more items', () => { - component.itemsTotal = 4; - fixture.detectChanges(); - const showMore = fixture.nativeElement.querySelector('#show-more-1'); - expect(showMore).toBeNull(); - }); -}); diff --git a/projects/public-search/src/app/document-detail/book/book.component.ts b/projects/public-search/src/app/document-detail/book/book.component.ts deleted file mode 100644 index 7e4445d11..000000000 --- a/projects/public-search/src/app/document-detail/book/book.component.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - * RERO ILS UI - * Copyright (C) 2021 RERO - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -import { Component, Input, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; -import { ItemApiService } from '../../api/item-api.service'; -import { QueryResponse } from '../../record'; - -@Component({ - selector: 'public-search-book', - templateUrl: './book.component.html' -}) -export class BookComponent implements OnInit { - - /** Document pid */ - @Input() documentpid: string; - - /** View code */ - @Input() viewcode: string; - - /** Holdings per page */ - private itemsPerPage = 4; - - /** Page */ - page = 1; - - /** Array of items */ - items: any[]; - - /** Items count */ - itemsTotal = 0; - - /** - * Constructor - * @param _itemApiService - ItemApiService - */ - constructor(private _itemApiService: ItemApiService) {} - - /** OnInit hook */ - ngOnInit(): void { - this._itemsQuery(1).subscribe((response: QueryResponse) => { - this.itemsTotal = response.total.value; - this.items = response.hits; - }); - } - - /** - * Is link show more - * @return boolean - */ - get isLinkShowMore() { - return this.itemsTotal > 0 - && ((this.page * this.itemsPerPage) < this.itemsTotal); - } - - /** Show more */ - showMore() { - this.page++; - this._itemsQuery(this.page).subscribe((response: QueryResponse) => { - this.items = this.items.concat(response.hits); - }); - } - - /** - * Items query - * @param page - number - * @return Observable - */ - private _itemsQuery(page: number): Observable { - return this._itemApiService - .getItemsByDocumentPidAndViewcode(this.documentpid, this.viewcode, page, this.itemsPerPage); - } -} diff --git a/projects/public-search/src/app/document-detail/holdings-items/holdings-items.component.html b/projects/public-search/src/app/document-detail/holdings-items/holdings-items.component.html deleted file mode 100644 index 89c9538f4..000000000 --- a/projects/public-search/src/app/document-detail/holdings-items/holdings-items.component.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - diff --git a/projects/public-search/src/app/document-detail/holdings-items/holdings-items.component.spec.ts b/projects/public-search/src/app/document-detail/holdings-items/holdings-items.component.spec.ts deleted file mode 100644 index 77cb04585..000000000 --- a/projects/public-search/src/app/document-detail/holdings-items/holdings-items.component.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * RERO ILS UI - * Copyright (C) 2021 RERO - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { HoldingsItemsComponent } from './holdings-items.component'; - - -describe('HoldingsItemsComponent', () => { - let component: HoldingsItemsComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ HoldingsItemsComponent ], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA - ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(HoldingsItemsComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/public-search/src/app/document-detail/holdings/holdings.component.ts b/projects/public-search/src/app/document-detail/holdings/holdings.component.ts index 01c350479..0f731d62e 100644 --- a/projects/public-search/src/app/document-detail/holdings/holdings.component.ts +++ b/projects/public-search/src/app/document-detail/holdings/holdings.component.ts @@ -15,6 +15,7 @@ * along with this program. If not, see . */ import { Component, Input, OnInit } from '@angular/core'; +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { TranslateService } from '@ngx-translate/core'; import { Observable } from 'rxjs'; import { HoldingsApiService } from '../../api/holdings-api.service'; @@ -63,8 +64,8 @@ export class HoldingsComponent implements OnInit { count = 0; } const linkText = (count > 1) - ? '{{ counter }} hidden holdings' - : '{{ counter }} hidden holding'; + ? _('{{ counter }} hidden holdings') + : _('{{ counter }} hidden holding'); return this._translateService.instant(linkText, { counter: count}); } diff --git a/projects/public-search/src/app/document-detail/holdings/items/items.component.ts b/projects/public-search/src/app/document-detail/holdings/items/items.component.ts index 0097986cd..c0d3c8e75 100644 --- a/projects/public-search/src/app/document-detail/holdings/items/items.component.ts +++ b/projects/public-search/src/app/document-detail/holdings/items/items.component.ts @@ -15,6 +15,7 @@ * along with this program. If not, see . */ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { TranslateService } from '@ngx-translate/core'; import { ItemApiService } from '../../../api/item-api.service'; import { QueryResponse } from '../../../record'; @@ -65,8 +66,8 @@ export class ItemsComponent implements OnInit { count = 0; } const linkText = (count > 1) - ? '{{ counter }} hidden items' - : '{{ counter }} hidden item'; + ? _('{{ counter }} hidden items') + : _('{{ counter }} hidden item'); return this._translateService.instant(linkText, { counter: count}); } diff --git a/projects/public-search/src/app/document-detail/request/pickup-location/pickup-location.component.html b/projects/public-search/src/app/document-detail/request/pickup-location/pickup-location.component.html index 3807d05f3..db842f486 100644 --- a/projects/public-search/src/app/document-detail/request/pickup-location/pickup-location.component.html +++ b/projects/public-search/src/app/document-detail/request/pickup-location/pickup-location.component.html @@ -20,6 +20,12 @@
+