From: Bill Erickson Date: Tue, 30 Mar 2021 16:31:08 +0000 (-0400) Subject: LP1904036 dupe barcode/username checking; various bugs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=45b31c117fa31c377c0d5325f81d21a3f168395f;p=evergreen%2Ftadl.git LP1904036 dupe barcode/username checking; various bugs Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- 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 e3d95c047c..73ffee8541 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 @@ -169,18 +169,32 @@ {cls: 'ac', path: 'card', field: 'barcode', disabled: !patron.card().isnew()}}">
- - + + + + + + Barcode is already in use + +
+ + +
+ + + + +
+ + Username is already in use +
- -
@@ -368,6 +382,7 @@ fieldName="au-home_ou-input" [initialOrgId]="patron.home_ou()" [disableOrgs]="cannotHaveUsersOrgs()" + [required]="true" (onChange)=" fieldValueChange(null, null, 'home_ou', $event ? $event.id() : null); afterFieldChange(null, null, 'home_ou')"> @@ -383,6 +398,7 @@ @@ -599,7 +615,7 @@ - +
Statistical Categories
@@ -623,7 +639,7 @@
- +
Surveys
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 c7fb7499fc..55728cd4b8 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 @@ -141,6 +141,9 @@ export class EditComponent implements OnInit, AfterViewInit { secondaryGroups: IdlObject[]; expireDate: Date; changesPending = false; + dupeBarcode = false; + dupeUsername = false; + origUsername: string; fieldPatterns: {[cls: string]: {[field: string]: RegExp}} = { au: {}, @@ -436,6 +439,7 @@ export class EditComponent implements OnInit, AfterViewInit { return this.patronService.getFleshedById(this.patronId) .then(patron => { this.patron = patron; + this.origUsername = patron.usrname(); this.absorbPatronData(); }); } else { @@ -543,11 +547,25 @@ export class EditComponent implements OnInit, AfterViewInit { // Avoid responding to any value changes while we are loading if (this.loading) { return; } - // TODO other checks + // Timeout gives the form a chance to mark fields as (in)valid + setTimeout(() => { - this.changesPending = true; - const canSave = document.querySelector('.ng-invalid') === null; - this.toolbar.disableSaveStateChanged.emit(!canSave); + this.changesPending = true; + + const invalidInput = document.querySelector('.ng-invalid'); + + if (invalidInput) { + console.debug('Field is invalid', invalidInput.id); + } + + const canSave = ( + invalidInput === null && + !this.dupeBarcode && + !this.dupeUsername + ); + + this.toolbar.disableSaveStateChanged.emit(!canSave); + }); } userStatCatChange(cat: IdlObject, entry: ComboboxEntry) { @@ -662,22 +680,56 @@ export class EditComponent implements OnInit, AfterViewInit { break; case 'barcode': - // TODO check for dupes open-ils.actor.barcode.exists - if (!this.patron.usrname()) { - // This will apply the value and fire the dupe checker - this.fieldValueChange(null, null, 'usrname', value); - this.afterFieldChange(null, null, 'usrname'); - } + this.handleBarcodeChange(value); break; case 'usrname': - // TODO check for dupes open-ils.actor.username.exists + this.handleUsernameChange(value); break; } this.adjustSaveSate(); } + handleUsernameChange(value: any) { + this.dupeUsername = false; + + if (!value || value === this.origUsername) { + // In case the usrname changes then changes back. + return; + } + + this.net.request( + 'open-ils.actor', + 'open-ils.actor.username.exists', + this.auth.token(), value + ).subscribe(resp => this.dupeUsername = Boolean(resp)); + } + + handleBarcodeChange(value: any) { + this.dupeBarcode = false; + + if (!value) { return; } + + this.net.request( + 'open-ils.actor', + 'open-ils.actor.barcode.exists', + this.auth.token(), value + ).subscribe(resp => { + if (Number(resp) === 1) { + this.dupeBarcode = true; + } else { + + if (this.patron.usrname()) { return; } + + // Propagate username with barcode value by default. + // This will apply the value and fire the dupe checker + this.fieldValueChange(null, null, 'usrname', value); + this.afterFieldChange(null, null, 'usrname'); + } + }); + } + dupeValueChange(name: string, value: any) { if (name.match(/phone/)) { name = 'phone'; } @@ -814,8 +866,8 @@ export class EditComponent implements OnInit, AfterViewInit { const nowEpoch = new Date().getTime(); const newDate = new Date(nowEpoch + (seconds * 1000 /* millis */)); this.expireDate = newDate; - this.fieldValueChange(null, null, 'profile', newDate.toISOString()); - this.afterFieldChange(null, null, 'profile'); + this.fieldValueChange(null, null, 'expire_date', newDate.toISOString()); + this.afterFieldChange(null, null, 'expire_date'); } handleBoolResponse(success: boolean, @@ -1051,7 +1103,8 @@ export class EditComponent implements OnInit, AfterViewInit { } else { // Create settings for all non-null setting values for new patrons. - this.userSettings.forEach( (val, key) => { + Object.keys(this.userSettings).forEach(key => { + const val = this.userSettings[key]; if (val !== null) { settings[key] = val; } }); } @@ -1145,7 +1198,6 @@ export class EditComponent implements OnInit, AfterViewInit { this.fieldPatterns.au.usrname = new RegExp('.*'); } } - } diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/register.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/register.component.html index 94284b62f7..f78b25a595 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/register.component.html +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/register.component.html @@ -1,10 +1,11 @@ -
- -
+ + + + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.angular-patron.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.angular-patron.sql index 18c63ffba1..85a9389200 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.angular-patron.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.angular-patron.sql @@ -19,8 +19,8 @@ eg.circ.patron.holds.prefetch eg.grid.circ.patron.holds holds_for_patron print template +*/ -items out print template -- insert then update for easier iterative development tweaks INSERT INTO config.print_template @@ -127,7 +127,6 @@ $TEMPLATE$ WHERE name = 'bills_current'; INSERT INTO config.print_template (name, label, owner, active, locale, content_type, template) VALUES ('bills_payment', 'Bills, Payment', 1, TRUE, 'en-US', 'text/html', ''); -*/ UPDATE config.print_template SET template = $TEMPLATE$ [%