From 6a5a9c468f879be8acc6880d8f71299ecd45d577 Mon Sep 17 00:00:00 2001 From: Renaud Michotte Date: Tue, 17 Sep 2019 21:43:17 +0200 Subject: [PATCH] circ_policies ui: increase API size limit * Closes #405 Co-Authored-by: Renaud Michotte --- ui/src/app/core/core.module.ts | 2 - ui/src/app/core/index.ts | 1 - .../app/core/library/library.service.spec.ts | 31 ------------ ui/src/app/core/library/library.service.ts | 50 ------------------- .../circulation-policy.service.ts | 30 +++-------- .../circulation-policy.component.ts | 42 ++++++++-------- .../records/editor/submit/submit.component.ts | 1 - ui/src/app/records/records.service.ts | 6 ++- 8 files changed, 31 insertions(+), 132 deletions(-) delete mode 100644 ui/src/app/core/library/library.service.spec.ts delete mode 100644 ui/src/app/core/library/library.service.ts diff --git a/ui/src/app/core/core.module.ts b/ui/src/app/core/core.module.ts index a9b4f5f248..3febb855ac 100644 --- a/ui/src/app/core/core.module.ts +++ b/ui/src/app/core/core.module.ts @@ -25,7 +25,6 @@ import { TranslateModule } from '@ngx-translate/core'; import { ItemTypeService } from './item-type/item-type.service'; import { ItemTypeTool } from './item-type/item-type-tool'; -import { LibraryService } from './library/library.service'; import { PatronTypeService } from './patron-type/patron-type.service'; import { PatronTypeTool } from './patron-type/patron-type-tool'; import { OrganisationService } from './organisation/organisation.service'; @@ -63,7 +62,6 @@ import { TranslateLanguageService } from './translate/translate-language.service providers: [ ApiService, ItemTypeService, - LibraryService, OrganisationService, OrganisationViewService, PatronTypeService, diff --git a/ui/src/app/core/index.ts b/ui/src/app/core/index.ts index 9b13a56559..b8c92f304b 100644 --- a/ui/src/app/core/index.ts +++ b/ui/src/app/core/index.ts @@ -24,7 +24,6 @@ export * from './dialog/dialog.service'; export * from './filter/nl2br'; export * from './item-type/item-type.service'; export * from './item-type/item-type-tool'; -export * from './library/library.service'; export * from './organisation/organisation.service'; export * from './organisation/organisation-view.service'; export * from './patron-type/patron-type.service'; diff --git a/ui/src/app/core/library/library.service.spec.ts b/ui/src/app/core/library/library.service.spec.ts deleted file mode 100644 index ca0798aeed..0000000000 --- a/ui/src/app/core/library/library.service.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - -RERO ILS -Copyright (C) 2019 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 { TestBed } from '@angular/core/testing'; - -import { LibraryService } from './library.service'; - -describe('LibraryService', () => { - beforeEach(() => TestBed.configureTestingModule({})); - - it('should be created', () => { - const service: LibraryService = TestBed.get(LibraryService); - expect(service).toBeTruthy(); - }); -}); diff --git a/ui/src/app/core/library/library.service.ts b/ui/src/app/core/library/library.service.ts deleted file mode 100644 index 3398914007..0000000000 --- a/ui/src/app/core/library/library.service.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* - -RERO ILS -Copyright (C) 2019 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 { Injectable } from '@angular/core'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { ApiService } from '../api/api.service'; - -const httpOptions = { - headers: new HttpHeaders({ - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }) -}; - -@Injectable() -export class LibraryService { - - constructor( - private apiService: ApiService, - private http: HttpClient - ) { } - - getApiEntryPointRecord(pid: string) { - return this.apiService - .getApiEntryPointByType('libraries', true) + pid; - } - - libraries() { - return this.http.get( - this.apiService.getApiEntryPointByType('libraries'), - httpOptions - ); - } -} diff --git a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy.service.ts b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy.service.ts index 3f0fc34813..b2483166a1 100644 --- a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy.service.ts +++ b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy.service.ts @@ -22,18 +22,11 @@ import { Injectable } from '@angular/core'; import { forkJoin, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { CirculationPolicy } from './circulation-policy'; -import { ItemTypeService, PatronTypeService, ApiService, cleanDictKeys, _ } from '@app/core'; +import { ApiService, cleanDictKeys, _ } from '@app/core'; import { RecordsService } from '@app/records/records.service'; import { Router } from '@angular/router'; import { ToastrService } from 'ngx-toastr'; -const httpOptions = { - headers: new HttpHeaders({ - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }) -}; - @Injectable() export class CirculationPolicyService { @@ -41,18 +34,14 @@ export class CirculationPolicyService { private router: Router, private apiService: ApiService, private client: HttpClient, - private itemTypeService: ItemTypeService, - private patronTypeService: PatronTypeService, private recordsService: RecordsService, private toastService: ToastrService ) { } loadOrCreateCirculationPolicy(pid: number = null) { if (pid) { - return this.client.get( - this.apiService.getApiEntryPointByType('circ_policies') + pid, - httpOptions - ).pipe( + return this.recordsService.getRecord('circ_policies', '' + pid) + .pipe( map(data => new CirculationPolicy(data.metadata)) ); } else { @@ -60,18 +49,11 @@ export class CirculationPolicyService { } } - loadAllCirculationPolicy() { - return this.client.get( - this.apiService.getApiEntryPointByType('circ_policies'), - httpOptions - ); - } - loadAllItemTypesPatronTypesCirculationPolicies() { return forkJoin( - this.itemTypeService.itemTypes(), - this.patronTypeService.patronTypes(), - this.loadAllCirculationPolicy() + this.recordsService.getRecords('global', 'item_types', 1, RecordsService.MAX_REST_RESULTS_SIZE), + this.recordsService.getRecords('global', 'patron_types', 1, RecordsService.MAX_REST_RESULTS_SIZE), + this.recordsService.getRecords('global', 'circ_policies', 1, RecordsService.MAX_REST_RESULTS_SIZE) ); } diff --git a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.ts b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.ts index 7f61f414d5..a56263a5b5 100644 --- a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.ts +++ b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.ts @@ -20,7 +20,7 @@ along with this program. If not, see . import { Component, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; -import { LibraryService, UniqueValidator } from '@app/core'; +import { UniqueValidator } from '@app/core'; import { UserService } from '@app/user.service'; import { CirculationPolicyService } from '../circulation-policy.service'; import { CirculationPolicyFormService } from '../circulation-policy-form.service'; @@ -51,7 +51,6 @@ export class CirculationPolicyComponent implements OnInit { private circulationPolicyService: CirculationPolicyService, private circulationPolicyForm: CirculationPolicyFormService, private userService: UserService, - private libraryService: LibraryService, private circulationMapping: CirculationMappingService, private organisationService: OrganisationService, private recordsService: RecordsService @@ -87,28 +86,27 @@ export class CirculationPolicyComponent implements OnInit { this.circulationMapping.setPolicyLevel( circulation.policy_library_level ); - this.libraryService - .libraries() + this.recordsService.getRecords('global', 'libraries', 1, RecordsService.MAX_REST_RESULTS_SIZE) .subscribe((libraries: any) => { - libraries.hits.hits.forEach(library => { - this.librariesOrg.push({ - id: library.metadata.pid, - name: library.metadata.name + libraries.hits.hits.forEach(library => { + this.librariesOrg.push({ + id: library.metadata.pid, + name: library.metadata.name + }); + this.circulationPolicyForm.populate(this.circulationPolicy); + this.circulationForm = this.circulationPolicyForm.getForm(); + this.circulationForm.controls['name'].setAsyncValidators([ + UniqueValidator.createValidator( + this.recordsService, + 'circ_policies', + 'circ_policy_name', + circulation.pid + ) + ]); }); - }); - this.circulationPolicyForm.populate(this.circulationPolicy); - this.circulationForm = this.circulationPolicyForm.getForm(); - this.circulationForm.controls['name'].setAsyncValidators([ - UniqueValidator.createValidator( - this.recordsService, - 'circ_policies', - 'circ_policy_name', - circulation.pid - ) - ]); - }); - } - ); + } + ); + }); }); }); } diff --git a/ui/src/app/records/editor/submit/submit.component.ts b/ui/src/app/records/editor/submit/submit.component.ts index 362375fe72..72a1ef33fd 100644 --- a/ui/src/app/records/editor/submit/submit.component.ts +++ b/ui/src/app/records/editor/submit/submit.component.ts @@ -21,7 +21,6 @@ import { AbstractControl } from '@angular/forms'; import { Component, Input, OnInit } from '@angular/core'; import { JsonSchemaFormService, hasOwn } from 'angular6-json-schema-form'; import { combineLatest } from 'rxjs'; -import { map } from 'rxjs/operators'; @Component({ // tslint:disable-next-line:component-selector diff --git a/ui/src/app/records/records.service.ts b/ui/src/app/records/records.service.ts index 2d5a5fc94a..9cda494bbc 100644 --- a/ui/src/app/records/records.service.ts +++ b/ui/src/app/records/records.service.ts @@ -30,6 +30,10 @@ import { DialogService, _, extractIdOnRef } from '@app/core'; providedIn: 'root' }) export class RecordsService { + + public static readonly DEFAULT_REST_RESULTS_SIZE = 10; + public static readonly MAX_REST_RESULTS_SIZE = 9999; + private translatePlural; constructor( private http: HttpClient, @@ -56,7 +60,7 @@ export class RecordsService { view: string, record_type: string, page: number = 1, - size: number = 10, + size: number = RecordsService.DEFAULT_REST_RESULTS_SIZE, query: string = '', mime_type: string = 'application/json', filters = [],