From 85730bac50c936ac698f43c22db09e1e1b0dd160 Mon Sep 17 00:00:00 2001 From: Lauren-D Date: Wed, 11 Sep 2019 17:06:20 +0200 Subject: [PATCH] UI: Fix circulation policies editor #363 * structure editor with section. * add overdue amount and currency in circ policies editor. * add an allow renewals button calculated dynamically. Co-Authored-by: Laurent Dubois Co-Authored-by: Renaud Michotte --- .../core/organisation/organisation.service.ts | 14 +- .../circulation-policy-form.service.ts | 28 +- .../circulation-policy.ts | 4 +- .../circulation-policy.component.html | 503 ++++++++++-------- .../circulation-policy.component.ts | 29 +- 5 files changed, 348 insertions(+), 230 deletions(-) diff --git a/ui/src/app/core/organisation/organisation.service.ts b/ui/src/app/core/organisation/organisation.service.ts index aeb5db076f..1f1c3ac7c2 100644 --- a/ui/src/app/core/organisation/organisation.service.ts +++ b/ui/src/app/core/organisation/organisation.service.ts @@ -19,12 +19,22 @@ along with this program. If not, see . import { Injectable } from '@angular/core'; import { ApiService } from '../api/api.service'; +import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {map} from 'rxjs/operators'; + +const httpOptions = { + headers: new HttpHeaders({ + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }) +}; @Injectable() export class OrganisationService { constructor( - private apiService: ApiService + private apiService: ApiService, + private http: HttpClient ) { } getApiEntryPointRecord(pid: string) { @@ -32,3 +42,5 @@ export class OrganisationService { .getApiEntryPointByType('organisations', true) + pid; } } + + diff --git a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy-form.service.ts b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy-form.service.ts index d653242b68..13a6017a74 100644 --- a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy-form.service.ts +++ b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy-form.service.ts @@ -49,6 +49,7 @@ export class CirculationPolicyFormService { allow_requests: circulation.allow_requests, number_renewals: circulation.number_renewals, renewal_duration: circulation.renewal_duration, + overdue_amount: circulation.overdue_amount, policy_library_level: circulation.policy_library_level, is_default: circulation.is_default, settings: this.unserializeSettings(circulation.settings) @@ -76,8 +77,10 @@ export class CirculationPolicyFormService { checkout_duration: [7], number_of_days_after_due_date: [5], number_of_days_before_due_date: [5], + allow_renewals: [true], number_renewals: [0], renewal_duration: [null], + overdue_amount: [0], policy_library_level: [false], is_default: [], libraries: [], @@ -90,16 +93,15 @@ export class CirculationPolicyFormService { const numberRenewalsControl = this.getControlByFieldName('number_renewals'); const daysAfterControl = this.getControlByFieldName('number_of_days_after_due_date'); const daysBeforeControl = this.getControlByFieldName('number_of_days_before_due_date'); + const overdueAmountControl = this.getControlByFieldName('overdue_amount'); this.form.get('allow_checkout').valueChanges.subscribe(checkout => { if (checkout) { + checkoutDurationControl.setValidators([ Validators.required, Validators.min(1) ]); - numberRenewalsControl.setValidators([ - Validators.required, - Validators.min(0) - ]); + daysAfterControl.setValidators([ Validators.required, Validators.min(1) @@ -108,10 +110,26 @@ export class CirculationPolicyFormService { Validators.required, Validators.min(1) ]); + overdueAmountControl.setValidators([ + Validators.required, + Validators.min(0) + ]); } else { checkoutDurationControl.clearValidators(); numberRenewalsControl.clearValidators(); daysAfterControl.clearValidators(); + daysBeforeControl.clearValidators(); + overdueAmountControl.clearValidators(); + } + }); + this.form.get('allow_renewals').valueChanges.subscribe(renewals => { + if (renewals) { + numberRenewalsControl.setValidators([ + Validators.required, + Validators.min(0) + ]); + } else { + numberRenewalsControl.clearValidators(); } }); const renewalDuration = this.getControlByFieldName('renewal_duration'); @@ -133,6 +151,8 @@ export class CirculationPolicyFormService { getValues() { const formValues = this.form.value; + // delete calculate field before returns values of form + formValues.allow_renewals = null; formValues.libraries = this.serializeLibraries(formValues.libraries); formValues.settings = this.serializeSettings(formValues.settings); return formValues; diff --git a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy.ts b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy.ts index 274a808686..9ce70cadaf 100644 --- a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy.ts +++ b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy.ts @@ -35,6 +35,7 @@ export class CirculationPolicy { number_of_days_before_due_date: number = null; number_renewals: number = null; renewal_duration: number = null; + overdue_amount: number = null; policy_library_level: boolean = null; is_default: boolean = null; libraries: Array = []; @@ -54,10 +55,11 @@ export class CirculationPolicy { this.number_of_days_after_due_date = 5; this.number_of_days_before_due_date = 5; this.number_renewals = 0; + this.overdue_amount = 0; this.policy_library_level = false; this.is_default = false; this.organisation = { - $ref: null + $ref: null, }; this.libraries = []; this.settings = []; diff --git a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.html b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.html index 7d4b586a79..4b7f025447 100644 --- a/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.html +++ b/ui/src/app/records/custom-editor/circulation-settings/circulation-policy/circulation-policy.component.html @@ -21,246 +21,303 @@
-

Circulation Policy

-
-
- -
- -
-
- Name is required. -
-
- Name must be at least 2 characters long. -
-
- Name is already taken. -
-
-
-
-
- -
- -
-
-
-
Allow
-
-
- - -
- -
- - -
-
-
-
- -
- -
-
- Checkout duration is required. -
-
- Checkout duration must be greater than 1. -
-
-
-
- -
- -
- -
-
- First reminder days is required. -
-
- First reminder days must be greater than 0. +

Circulation Policy

+ +
+ +
+ +
+
+ Name is required. +
+
+ Name must be at least 2 characters long. +
+
+ Name is already taken. +
-
- - -
- -
- -
-
- Days before due date is required. -
-
- Days before due date must be greater or equal to 0. -
+
+ +
+
-
-
- -
- -
-
- Checkout duration is required. -
-
- Checkout duration must be greater than 0. -
-
-
-
-
- -
- -
-
- Renewal duration is required. -
-
- Checkout duration must be great than 1. + +
+
+ Circulation settings +
+
+
+
+
+ + {{ 'checkout' | translate | titlecase }} +
+
+
+
+ +
+ +
+
+ Checkout duration is required. +
+
+ Checkout duration must be greater than 1. +
+
+
+
+
+
+
+
+
+ + {{ 'renewals' | translate | titlecase }} +
+
+
+
+ +
+ +
+
+ Checkout duration is required. +
+
+ Checkout duration must be greater than 0. +
+
+
+
+
+ +
+ +
+
+ Renewal duration is required. +
+
+ Checkout duration must be great than 1. +
+
+
+
+
+
+
+
+
+ + {{ 'requests' | translate | titlecase }} +
+
+
+
-
-
+ + -
- -
- -
-
-
- + + - -
- -
-
- {{ patronType.name }} -
- Circulation categories: -
    -
  • - {{ itemType.name }} -
  • -
+ +
+
+ Application +
+
+ +
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ + {{ library.name }} +
+
+
+ + + +
+ +
+
+ {{ patronType.name }} +
+ Circulation categories: +
    +
  • + {{ itemType.name }} +
  • +
+
+
+
+
+
-
- -
+ + -
-
- - +
+
+ + +
-
- +
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 7f4ffd9d64..acefe08a56 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 @@ -43,6 +43,8 @@ export class CirculationPolicyComponent implements OnInit { public librariesOrg = []; + public organisation; + constructor( private router: Router, private route: ActivatedRoute, @@ -66,7 +68,11 @@ export class CirculationPolicyComponent implements OnInit { circulation['organisation']['$ref'] = this.organisationService .getApiEntryPointRecord(user.library.organisation.pid); this.circulationPolicy = circulation; - + // Load organisation + this.recordsService.getRecord('organisations', user.library.organisation.pid) + .subscribe( + data => this.organisation = data.metadata + ); // Load all required elements this.circulationPolicyService .loadAllItemTypesPatronTypesCirculationPolicies() @@ -112,10 +118,19 @@ export class CirculationPolicyComponent implements OnInit { allowCheckoutCheckbox(checkbox: boolean) { if (!this.allow_checkout.value) { this.checkout_duration.setValue(null); + this.allow_renewals.setValue(false); this.number_renewals.setValue(null); this.renewal_duration.setValue(null); this.number_of_days_after_due_date.setValue(null); this.number_of_days_before_due_date.setValue(null); + this.overdue_amount.setValue(null); + } + } + + allowRenewalsCheckbox(checkbox: boolean) { + if (!this.allow_renewals.value) { + this.number_renewals.setValue(null); + this.renewal_duration.setValue(null); } } @@ -233,6 +248,12 @@ export class CirculationPolicyComponent implements OnInit { get allow_checkout() { return this.getField('allow_checkout'); } + get allow_requests() { + return this.getField('allow_requests'); + } + get allow_renewals() { + return this.getField('allow_renewals'); + } get number_of_days_after_due_date() { return this.getField('number_of_days_after_due_date'); } @@ -248,6 +269,12 @@ export class CirculationPolicyComponent implements OnInit { get renewal_duration() { return this.getField('renewal_duration'); } + get overdue_amount() { + return this.getField('overdue_amount'); + } + get currency() { + return this.organisation.default_currency; + } get policy_library_level() { return this.getField('policy_library_level'); }