From 23512199577db294153ee261bb595619b1e10e5d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 17 Mar 2021 17:07:14 -0400 Subject: [PATCH] LP1904036 Patron editor continued Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../src/app/staff/circ/patron/edit.component.html | 363 +++++++++++---------- .../src/app/staff/circ/patron/edit.component.ts | 83 ++++- .../src/app/staff/share/patron/patron.service.ts | 11 + .../share/patron/profile-select.component.html | 2 +- .../staff/share/patron/profile-select.component.ts | 9 +- 5 files changed, 285 insertions(+), 183 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.html index b04a12c462..6481774ff0 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.html +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.html @@ -5,119 +5,117 @@ - + +
-
- - - - - +
- - - - - +
- - - - - +
- + fieldValueChange(args.path, args.field, $event ? $event.id : null); + postFieldChange(args.path, args.field)" + [required]="fieldRequired(getClass(args.cls), args.field)" + [disabled]="args.disabled">
-
+ +
- - +
+ +
+
+ +
-
- + + + + +
+ + +
+
+ + + + +
+ + + +
+ + + *ngTemplateOutlet="fieldInput; context: {args: {field: 'passwd'}}">
+ + + +
{{nameTab}}
-
+ +
+ *ngTemplateOutlet="fieldLabel; context: {args: {field: 'name_keywords'}}">
-
- - - - -
-
+ + + + + + +
+ *ngTemplateOutlet="fieldLabel; context: {args: {field: 'dob'}}">
-
- - -
-
- - -
-
- - -
-
- + + + + + + + + + + + + + + + + -
-
+ + + + + + + +
+ *ngTemplateOutlet="fieldLabel; context: {args: {field: 'home_ou'}}"> +
+ + +
-
+
+ *ngTemplateOutlet="fieldLabel; context: {args: {field: 'profile'}}"> +
+ + +
-
+
+ *ngTemplateOutlet="fieldLabel; context: {args: {field: 'expire_date'}}"> +
+ + +
+
+ +
diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts index c6c3a55b1d..884ed01019 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit, Input} from '@angular/core'; +import {Component, OnInit, Input, ViewChild} from '@angular/core'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap'; import {OrgService} from '@eg/core/org.service'; @@ -9,6 +9,8 @@ import {PcrudService} from '@eg/core/pcrud.service'; import {PatronService} from '@eg/staff/share/patron/patron.service'; import {PatronContextService} from './patron.service'; import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component'; +import {DateUtil} from '@eg/share/util/date'; +import {ProfileSelectComponent} from '@eg/staff/share/patron/profile-select.component'; const COMMON_USER_SETTING_TYPES = [ 'circ.holds_behind_desk', @@ -23,7 +25,7 @@ const COMMON_USER_SETTING_TYPES = [ const FLESH_PATRON_FIELDS = { flesh: 1, flesh_fields: { - au: ['card', 'mailing_address', 'billing_address', 'addresses'] + au: ['card', 'mailing_address', 'billing_address', 'addresses', 'settings'] } }; @@ -38,14 +40,19 @@ export class EditComponent implements OnInit { @Input() cloneId: number; @Input() stageUsername: string; + @ViewChild('profileSelect') private profileSelect: ProfileSelectComponent; + patron: IdlObject; changeHandlerNeeded = false; nameTab = 'primary'; loading = false; identTypes: ComboboxEntry[]; + profileGroups: ComboboxEntry[]; + userSettings: {[name: string]: any} = {}; userSettingTypes: {[name: string]: IdlObject} = {}; optInSettingTypes: {[name: string]: IdlObject} = {}; + expireDate: Date; constructor( private org: OrgService, @@ -105,18 +112,31 @@ export class EditComponent implements OnInit { } }); }); - }; - + } loadPatron(): Promise { if (this.patronId) { return this.patronService.getById(this.patronId, FLESH_PATRON_FIELDS) - .then(patron => this.patron = patron); + .then(patron => { + this.patron = patron; + this.absorbPatronData(); + }); } else { return Promise.resolve(this.createNewPatron()); } } + absorbPatronData() { + this.patron.settings().forEach(setting => { + const value = setting.value(); + if (value !== '' && value !== null) { + this.userSettings[setting.name()] = JSON.parse(value); + } + }); + + this.expireDate = new Date(this.patron.expire_date()); + } + createNewPatron() { const patron = this.idl.create('au'); patron.isnew(true); @@ -148,26 +168,45 @@ export class EditComponent implements OnInit { return this.objectFromPath(path)[field](); } + userSettingChange(name: string, value: any) { + // TODO: set dirty + this.userSettings[name] = value; + } + + // Called as the model changes. + // This may be called many times before the final value is applied, + // so avoid any heavy lifting here. See postFieldChange(); fieldValueChange(path: string, field: string, value: any) { if (typeof value === 'boolean') { value = value ? 't' : 'f'; } - this.changeHandlerNeeded = true; this.objectFromPath(path)[field](value); } - fieldMaybeModified(path: string, field: string) { + // Called after a change operation has completed (e.g. on blur) + postFieldChange(path: string, field: string) { if (!this.changeHandlerNeeded) { return; } // no changes applied - - // TODO: set dirty = true - this.changeHandlerNeeded = false; - // check stuff here.. + // TODO: set dirty + const obj = path ? this.patron[path]() : this.patron; const value = obj[field](); console.debug(`Modifying field path=${path} field=${field} value=${value}`); + + switch (field) { + // TODO: do many more + + case 'profile': + this.setExpireDate(); + break; + } + } + + showField(idlClass: string, field: string): boolean { + // TODO + return true; } fieldRequired(idlClass: string, field: string): boolean { @@ -175,6 +214,7 @@ export class EditComponent implements OnInit { return false; } + fieldPattern(idlClass: string, field: string): string { // TODO return null; @@ -186,7 +226,26 @@ export class EditComponent implements OnInit { // Normally this is called on (blur), but the input is not // focused when using the generate button. - this.fieldMaybeModified(null, 'passwd'); + this.postFieldChange(null, 'passwd'); + } + + + cannotHaveUsersOrgs(): number[] { + return this.org.list() + .filter(org => org.ou_type().can_have_users() === 'f') + .map(org => org.id()); + } + + setExpireDate() { + const profile = this.profileSelect.profiles[this.patron.profile()]; + if (!profile) { return; } + + const seconds = DateUtil.intervalToSeconds(profile.perm_interval()); + const nowEpoch = new Date().getTime(); + const newDate = new Date(nowEpoch + (seconds * 1000 /* millis */)); + this.expireDate = newDate; + this.fieldValueChange(null, 'profile', newDate.toISOString()); + this.postFieldChange(null, 'profile'); } } diff --git a/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts b/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts index ee9cf7df37..6d8f57a0da 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts @@ -13,6 +13,7 @@ import {BarcodeSelectComponent} from '@eg/staff/share/barcodes/barcode-select.co export class PatronService { identTypes: IdlObject[]; + profileGroups: IdlObject[]; constructor( private net: NetService, @@ -99,5 +100,15 @@ export class PatronService { {order_by: {cit: ['name']}}, {atomic: true}) .toPromise().then(types => this.identTypes = types); } + + getProfileGroups(): Promise { + if (this.profileGroups) { + return Promise.resolve(this.profileGroups); + } + + return this.pcrud.retrieveAll('pgt', + {order_by: {cit: ['name']}}, {atomic: true}) + .toPromise().then(types => this.profileGroups = types); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/share/patron/profile-select.component.html b/Open-ILS/src/eg2/src/app/staff/share/patron/profile-select.component.html index d5a36663a9..7784aa4ac9 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/patron/profile-select.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/patron/profile-select.component.html @@ -1,6 +1,6 @@ diff --git a/Open-ILS/src/eg2/src/app/staff/share/patron/profile-select.component.ts b/Open-ILS/src/eg2/src/app/staff/share/patron/profile-select.component.ts index 25ef1cbb80..82fc8901ed 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/patron/profile-select.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/patron/profile-select.component.ts @@ -43,7 +43,9 @@ export class ProfileSelectComponent implements ControlValueAccessor, OnInit { @ViewChild('combobox', {static: false}) cbox: ComboboxComponent; - initialValue: number; + // Set the initial value by ID + @Input() initialGroupId: number; + cboxEntries: ComboboxEntry[] = []; profiles: {[id: number]: IdlObject} = {}; @@ -59,7 +61,8 @@ export class ProfileSelectComponent implements ControlValueAccessor, OnInit { } ngOnInit() { - this.collectGroups().then(grps => this.sortGroups(grps)); + this.collectGroups().then(grps => this.sortGroups(grps)) + .then(_ => this.cbox.selectedId = this.initialGroupId); } collectGroups(): Promise { @@ -152,7 +155,7 @@ export class ProfileSelectComponent implements ControlValueAccessor, OnInit { this.cbox.selectedId = id; } else { // Will propagate to cbox after its instantiated. - this.initialValue = id; + this.initialGroupId = id; } } -- 2.11.0