From: Bill Erickson Date: Wed, 14 Aug 2019 16:42:33 +0000 (-0400) Subject: LP1840050 org unit admin UI WIP X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b822dc739284db06daf7554bec5b5b6a9f9bd22f;p=working%2FEvergreen.git LP1840050 org unit admin UI WIP Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 7b9bf776ba..cb2b8bf157 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -6205,17 +6205,17 @@ SELECT usr, - - - + + + - - + + - + - + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html index 798538ce84..9a0ef8f1a9 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html @@ -1,13 +1,10 @@ -Org Unit Update Succeeded +Update Succeeded -Org Unit Succeessfully Created - - -Org Unit Update Failed +Update Failed
- +
+
+ {{currentOrg().name()}} ({{currentOrg().shortname()}}) +
+
+
- @@ -37,7 +42,7 @@ -
+
Open Time
Close Time
@@ -63,10 +68,17 @@ (ngModelChange)="hours(dow, 'close', $event)"/>
- +
+
+
+
+
+
@@ -74,8 +86,19 @@
- + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.ts index 83abd090f9..2a45303aab 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.ts @@ -1,6 +1,7 @@ import {Component, Input, ViewChild, OnInit} from '@angular/core'; import {Tree, TreeNode} from '@eg/share/tree/tree'; import {IdlService, IdlObject} from '@eg/core/idl.service'; +import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap'; import {OrgService} from '@eg/core/org.service'; import {AuthService} from '@eg/core/auth.service'; import {PcrudService} from '@eg/core/pcrud.service'; @@ -16,8 +17,6 @@ export class OrgUnitComponent implements OnInit { tree: Tree; selected: TreeNode; - @ViewChild('editDialog') editDialog: FmRecordEditorComponent; - @ViewChild('createString') createString: StringComponent; @ViewChild('editString') editString: StringComponent; @ViewChild('errorString') errorString: StringComponent; @ViewChild('delConfirm') delConfirm: ConfirmDialogComponent; @@ -35,16 +34,27 @@ export class OrgUnitComponent implements OnInit { this.loadAouTree(this.org.root().id()); } + tabChanged(evt: NgbTabChangeEvent) { + const tab = evt.nextId; + // stubbing out in case we need it. + } + + orgSaved(orgId: number) { + this.loadAouTree(orgId).then(_ => this.postUpdate(this.editString)); + } + loadAouTree(selectNodeId?: number): Promise { return this.pcrud.search('aou', {parent_ou : null}, {flesh : -1, flesh_fields : {aou : [ - 'children', 'ou_type', 'hours_of_operation', 'ill_address', + 'children', 'ou_type', 'hours_of_operation', 'ill_address', 'holds_address', 'mailing_address', 'billing_address' ]}}, {authoritative: true} ).toPromise().then(tree => { this.ingestAouTree(tree); if (selectNodeId) { - this.selected = this.tree.findNode(selectNodeId); + const node = this.tree.findNode(selectNodeId); + this.selected = node; + this.tree.selectNode(node); } }); } @@ -59,7 +69,7 @@ export class OrgUnitComponent implements OnInit { this.generateHours(orgNode); } - // TODO addresses + this.addAddresses(orgNode); const treeNode = new TreeNode({ id: orgNode.id(), @@ -82,9 +92,23 @@ export class OrgUnitComponent implements OnInit { this.selected = $event; } + // Fills the org unit in with 'new' addresses for any fields + // that are missing. + addAddresses(org: IdlObject) { + ['billing_address', 'mailing_address', 'holds_address', 'ill_address'] + .forEach(addrType => { + if (org[addrType]()) { return ; } + const addr = this.idl.create('aoa'); + addr.isnew(true); + addr.valid('t'); + addr.org_unit(org.id()); + org[addrType](addr); + }); + } + generateHours(org: IdlObject) { const hours = this.idl.create('aouhoo'); - hours.org_unit(org.id()); + hours.id(org.id()); hours.isnew(true); [0, 1, 2, 3, 4, 5, 6].forEach(dow => { @@ -98,17 +122,24 @@ export class OrgUnitComponent implements OnInit { // if a 'value' is passed, it will be applied to the optional // hours-of-operation object, otherwise the hours on the currently // selected org unit. - hours(dow: number, which: 'open' | 'close', value?: string, hoo?: IdlObject): IdlObject { + hours(dow: number, which: 'open' | 'close', value?: string, hoo?: IdlObject): string { if (!hoo && !this.selected) { return null; } const hours = hoo || this.selected.callerData.orgUnit.hours_of_operation(); if (value) { - hours[`dow_${dow}_${which}`](value); + hours[`dow_${dow}_${which}`](value); hours.ischanged(true); } - return hours[`dow_${dow}_${which}`](); + return hours[`dow_${dow}_${which}`](); + } + + isClosed(dow: number): boolean { + return ( + this.hours(dow, 'open') === '00:00:00' && + this.hours(dow, 'close') === '00:00:00' + ); } closedOn(dow: number) { @@ -116,6 +147,27 @@ export class OrgUnitComponent implements OnInit { this.hours(dow, 'close', '00:00:00'); } + saveHours() { + const org = this.currentOrg(); + const hours = org.hours_of_operation(); + this.pcrud.autoApply(hours).subscribe( + result => { + console.debug('Hours saved ', result); + this.editString.current() + .then(msg => this.toast.success(msg)); + }, + error => { + this.errorString.current() + .then(msg => this.toast.danger(msg)); + }, + () => this.loadAouTree(this.selected.id) + ); + } + + currentOrg(): IdlObject { + return this.selected ? this.selected.callerData.orgUnit : null; + } + postUpdate(message: StringComponent) { // Modifying org unit types means refetching the org unit // data normally fetched on page load, since it includes @@ -141,9 +193,9 @@ export class OrgUnitComponent implements OnInit { // pcrud action/transaction completed. // After removal, select the parent org if available // otherwise the root org. - const orgId = org.parent_ou() ? + const orgId = org.parent_ou() ? org.parent_ou() : this.org.root().id(); - this.loadAouTree(orgId).then(_ => + this.loadAouTree(orgId).then(_ => this.postUpdate(this.editString)); } ); @@ -154,31 +206,17 @@ export class OrgUnitComponent implements OnInit { const parentTreeNode = this.selected; const parentOrg = parentTreeNode.callerData.orgUnit; - const newOrg = this.idl.create('aou'); - newOrg.parent(parentOrg.id()); - - // TODO UNSUBSCRIBE - this.editDialog.onSave$.subscribe(result => { // aou object + const org = this.idl.create('aou'); + org.isnew(true); + org.parent(parentOrg.id()); + // TODO: limit org type selector to types at parent depth + 1 - // Add our new node to the tree - const newNode = new TreeNode({ - id: result.id(), - label: result.name(), - callerData: {orgUnit: result} - }); - this.loadAouTree(result.id()).then(_ => - this.postUpdate(this.createString)); + // Create a dummy, detached org node to keep the UI happy. + this.selected = new TreeNode({ + id: org.id(), + label: org.name(), + callerData: {orgUnit: org} }); - - // TODO subscribe / unsub error events - - /* - rejected => { - this.errorString.current() - .then(str => this.toast.danger(str)); - } - ); - */ } }