From 8058b3d9cb7c8cb892abf8fee88b58ac3ef4ba00 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 16 Aug 2019 12:48:55 -0400 Subject: [PATCH] LP1840050 org unit admin UI WIP Signed-off-by: Bill Erickson --- .../app/staff/admin/server/admin-server.module.ts | 7 +- .../app/staff/admin/server/org-addr.component.html | 34 +++++++ .../app/staff/admin/server/org-addr.component.ts | 113 +++++++++++++++++++++ .../staff/admin/server/org-unit-routing.module.ts | 19 ++++ .../app/staff/admin/server/org-unit.component.html | 56 +--------- .../app/staff/admin/server/org-unit.component.ts | 31 ++---- .../src/app/staff/admin/server/org-unit.module.ts | 27 +++++ .../src/app/staff/admin/server/routing.module.ts | 4 +- 8 files changed, 210 insertions(+), 81 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-routing.module.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.module.ts diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server.module.ts index a7fe8250fd..27a2c99810 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server.module.ts @@ -1,17 +1,14 @@ import {NgModule} from '@angular/core'; import {TreeModule} from '@eg/share/tree/tree.module'; -import {StaffCommonModule} from '@eg/staff/common.module'; -import {AdminServerRoutingModule} from './routing.module'; import {AdminCommonModule} from '@eg/staff/admin/common.module'; +import {AdminServerRoutingModule} from './routing.module'; import {AdminServerSplashComponent} from './admin-server-splash.component'; import {OrgUnitTypeComponent} from './org-unit-type.component'; -import {OrgUnitComponent} from './org-unit.component'; @NgModule({ declarations: [ AdminServerSplashComponent, - OrgUnitTypeComponent, - OrgUnitComponent + OrgUnitTypeComponent ], imports: [ AdminCommonModule, diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.html new file mode 100644 index 0000000000..0545025c6e --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.html @@ -0,0 +1,34 @@ + + + + type = {{type}} + + + + + + + + +
+ This address is used for multiple address types. + +
+
+
+
+
+
+ diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts new file mode 100644 index 0000000000..1bc28634cd --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts @@ -0,0 +1,113 @@ +import {Component, Input, Output, EventEmitter} from '@angular/core'; +import {IdlService, IdlObject} from '@eg/core/idl.service'; +import {OrgService} from '@eg/core/org.service'; +import {PcrudService} from '@eg/core/pcrud.service'; + +const ADDR_TYPES = + ['billing_address', 'holds_address', 'mailing_address', 'ill_address']; + +@Component({ + selector: 'eg-admin-org-address', + templateUrl: './org-addr.component.html' +}) +export class OrgAddressComponent { + + private orgUnit: IdlObject = null; + + private _orgId: number; + + get orgId(): number { return this._orgId; } + + @Input() set orgId(newId: number) { + if (newId) { + if (!this._orgId || this._orgId !== newId) { + this._orgId = newId; + this.init(); + } + } else { + this._orgId = null; + } + } + + @Output() addrChange: EventEmitter; + + constructor( + private idl: IdlService, + private org: OrgService, + private pcrud: PcrudService + ) { + this.addrChange = new EventEmitter(); + } + + init() { + if (!this.orgId) { return; } + + return this.pcrud.retrieve('aou', this.orgId, + {flesh : 1, flesh_fields : {aou : ADDR_TYPES}}, + {authoritative: true} + ).subscribe(org => { + this.orgUnit = org; + ADDR_TYPES.forEach(aType => { + if (!this.addr(aType)) { + this.createAddress(aType); + } + }); + }); + } + + addrTypes(): string[] { // for UI + return ADDR_TYPES; + } + + // Template shorthand -- get a specific address by type. + addr(addrType: string) { + return this.orgUnit ? this.orgUnit[addrType]() : null; + } + + createAddress(addrType: string) { + const addr = this.idl.create('aoa'); + addr.isnew(true); + addr.valid('t'); + addr.org_unit(this.orgUnit); + this.orgUnit[addrType](addr); + } + + cloneAddress(addrType: string) { + + // Find the address + let fromAddr: IdlObject; + ADDR_TYPES.forEach(aType => { + if (aType !== addrType && + this.addr(aType).id() === this.addr(addrType).id()) { + fromAddr = this.addr(aType); + } + }); + + const addr = this.idl.clone(fromAddr); + addr.id(null); + addr.isnew(true); + addr.valid('t'); + this.orgUnit[addrType](addr); + } + + // True if the provided address is used for more than one addr type. + sharedAddress(addrId: number): boolean { + return ADDR_TYPES.filter(aType => { + return ( + !this.addr(aType).isnew() && this.addr(aType).id() === addrId + ); + }).length > 1; + } + + addrSaved(addr: number | IdlObject) { + const id = typeof addr === 'object' ? addr.id() : addr; + + // TODO: update org if needed... + } + + addrDeleted(addr: number | IdlObject) { + const id = typeof addr === 'object' ? addr.id() : addr; + // TODO: update org + } +} + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-routing.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-routing.module.ts new file mode 100644 index 0000000000..cbd36804f8 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-routing.module.ts @@ -0,0 +1,19 @@ +import {NgModule} from '@angular/core'; +import {RouterModule, Routes} from '@angular/router'; +import {OrgUnitComponent} from './org-unit.component'; + +// Since org-unit admin has its own module with page-level components, +// it needs its own routing module as well to define which component +// to display at page load time. + +const routes: Routes = [{ + path: '', + component: OrgUnitComponent +}]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) + +export class OrgUnitRoutingModule {} 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 8b600a92b7..ef8d360ab1 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 @@ -105,60 +105,8 @@ [disabled]="currentOrg().isnew()">
- - - - - - - - - - - - - - - - - - - - - - - - - - + +
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 6c86587921..6df6379291 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 @@ -59,14 +59,16 @@ export class OrgUnitComponent implements OnInit { } loadAouTree(selectNodeId?: number): Promise { + + const flesh = ['children', 'ou_type', 'hours_of_operation']; + return this.pcrud.search('aou', {parent_ou : null}, - {flesh : -1, flesh_fields : {aou : [ - 'children', 'ou_type', 'hours_of_operation', 'ill_address', - 'holds_address', 'mailing_address', 'billing_address' - ]}}, {authoritative: true} + {flesh : -1, flesh_fields : {aou : flesh}}, {authoritative: true} + ).toPromise().then(tree => { this.ingestAouTree(tree); if (!selectNodeId) { selectNodeId = this.org.root().id(); } + const node = this.tree.findNode(selectNodeId); this.selected = node; this.tree.selectNode(node); @@ -83,8 +85,6 @@ export class OrgUnitComponent implements OnInit { this.generateHours(orgNode); } - this.addAddresses(orgNode); - const treeNode = new TreeNode({ id: orgNode.id(), label: orgNode.name(), @@ -111,20 +111,6 @@ 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.id(org.id()); @@ -271,5 +257,10 @@ export class OrgUnitComponent implements OnInit { callerData: {orgUnit: org} }); } + + addressChanged(thing: any) { + // Reload to pick up org unit address changes. + this.orgSaved(this.currentOrg().id()); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.module.ts new file mode 100644 index 0000000000..09150a803a --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.module.ts @@ -0,0 +1,27 @@ +import {NgModule} from '@angular/core'; +import {TreeModule} from '@eg/share/tree/tree.module'; +import {AdminCommonModule} from '@eg/staff/admin/common.module'; +import {OrgUnitComponent} from './org-unit.component'; +import {OrgAddressComponent} from './org-addr.component'; +import {OrgUnitRoutingModule} from './org-unit-routing.module'; + +@NgModule({ + declarations: [ + OrgUnitComponent, + OrgAddressComponent + ], + imports: [ + AdminCommonModule, + OrgUnitRoutingModule, + TreeModule + ], + exports: [ + ], + providers: [ + ] +}) + +export class OrgUnitModule { +} + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/routing.module.ts index aa4ec3184b..60bf2c9436 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/routing.module.ts @@ -11,9 +11,9 @@ const routes: Routes = [{ }, { path: 'actor/org_unit_type', component: OrgUnitTypeComponent -}, { +}, { path: 'actor/org_unit', - component: OrgUnitComponent + loadChildren: '@eg/staff/admin/server/org-unit.module#OrgUnitModule' }, { path: ':schema/:table', component: BasicAdminPageComponent -- 2.11.0