From ff271b89558250635ae1c85b700a2d9cb95575c9 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 12 Aug 2019 16:16:01 -0400 Subject: [PATCH] LPXXX org unit admin UI WIP Signed-off-by: Bill Erickson --- Open-ILS/examples/fm_IDL.xml | 6 +- .../app/share/org-select/org-select.component.html | 2 +- .../server/admin-server-splash.component.html | 2 +- .../app/staff/admin/server/admin-server.module.ts | 4 +- .../app/staff/admin/server/org-unit.component.html | 37 +++++ .../app/staff/admin/server/org-unit.component.ts | 150 +++++++++++++++++++++ .../src/app/staff/admin/server/routing.module.ts | 4 + 7 files changed, 199 insertions(+), 6 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.ts diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index d28d7084d7..7b9bf776ba 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -6742,14 +6742,14 @@ SELECT usr, - - + + - + diff --git a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html index d49217c6fb..32bc94e2b9 100644 --- a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html +++ b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html @@ -4,7 +4,7 @@ {{r.label}} - + {{selected.label}} diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html index 99cb4781b7..7c62f20cfe 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html @@ -76,7 +76,7 @@ + routerLink="/staff/admin/server/actor/org_unit"> + + +Org Unit Update Succeeded + + +Org Unit Succeessfully Created + + +Org Unit Update Failed + + + + + +
+
+

Org Units

+ +
+
+

Selected Org Unit

+ +
+ Select an org unit type from the tree on the left. +
+
+ + +
+
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 new file mode 100644 index 0000000000..2dde40c425 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.ts @@ -0,0 +1,150 @@ +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 {OrgService} from '@eg/core/org.service'; +import {AuthService} from '@eg/core/auth.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; +import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; + +@Component({ + templateUrl: './org-unit.component.html' +}) + +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; + + constructor( + private idl: IdlService, + private org: OrgService, + private auth: AuthService, + private pcrud: PcrudService, + private toast: ToastService + ) {} + + + ngOnInit() { + // On initial page load, use the existing org tree data and + // select the root node. + this.ingestAouTree(this.org.tree()); + this.selected = this.tree.rootNode; + this.editDialog.setRecord(this.selected.callerData.orgUnit); + } + + loadAouTree() { + this.org.fetchOrgs().then(() => this.ingestAouTree(this.org.tree())); + } + + // Translate the org unt type tree into a structure EgTree can use. + ingestAouTree(aouTree) { + + const handleNode = (orgNode: IdlObject): TreeNode => { + if (!orgNode) { return; } + + // Clone to avoid modifying the shared org tree + const node = this.idl.clone(orgNode); + node.ou_type(node.ou_type().id()); + + const treeNode = new TreeNode({ + id: node.id(), + label: node.name(), + callerData: {orgUnit: node} + }); + + node.children().forEach(childNode => + treeNode.children.push(handleNode(childNode)) + ); + + return treeNode; + }; + + const rootNode = handleNode(aouTree); + this.tree = new Tree(rootNode); + } + + nodeClicked($event: any) { + this.selected = $event; + this.editDialog.setRecord(this.selected.callerData.orgUnit); + } + + postUpdate(message: StringComponent) { + // Modifying org unit types means refetching the org unit + // data normally fetched on page load, since it includes + // org unit type data. + this.org.fetchOrgs().then(() => + message.current().then(str => this.toast.success(str))); + } + + remove() { + this.delConfirm.open().subscribe(confirmed => { + if (!confirmed) { return; } + + const org = this.selected.callerData.orgUnit; + + this.pcrud.remove(org).subscribe( + ok2 => {}, + err => { + this.errorString.current() + .then(str => this.toast.danger(str)); + }, + () => { + // Avoid updating until we know the entire + // pcrud action/transaction completed. + this.loadAouTree(); + + // After removal, select the parent org if available + // otherwise the root org. + const orgId = org.parent_ou() ? org.parent_ou() : this.org.root().id(); + this.selected = this.tree.findNode(orgId); + this.editDialog.setRecord(this.selected.callerData.orgUnit); + + this.postUpdate(this.editString); + } + ); + }); + } + + addChild() { + const parentTreeNode = this.selected; + const parentOrg = parentTreeNode.callerData.orgUnit; + + const newOrg = this.idl.create('aou'); + newOrg.parent(parentOrg.id()); + + this.editDialog.setRecord(newOrg); + this.editDialog.mode = 'create'; + + // TODO UNSUBSCRIBE + this.editDialog.onSave$.subscribe(result => { // aou object + + // Add our new node to the tree + const newNode = new TreeNode({ + id: result.id(), + label: result.name(), + callerData: {orgUnit: result} + }); + this.loadAouTree(); + this.postUpdate(this.createString); + }); + + // TODO subscribe / unsub error events + + /* + rejected => { + this.errorString.current() + .then(str => this.toast.danger(str)); + } + ); + */ + } +} + 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 c971ed74a7..aa4ec3184b 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 @@ -3,6 +3,7 @@ import {RouterModule, Routes} from '@angular/router'; import {AdminServerSplashComponent} from './admin-server-splash.component'; import {BasicAdminPageComponent} from '@eg/staff/admin/basic-admin-page.component'; import {OrgUnitTypeComponent} from './org-unit-type.component'; +import {OrgUnitComponent} from './org-unit.component'; const routes: Routes = [{ path: 'splash', @@ -11,6 +12,9 @@ const routes: Routes = [{ path: 'actor/org_unit_type', component: OrgUnitTypeComponent }, { + path: 'actor/org_unit', + component: OrgUnitComponent +}, { path: ':schema/:table', component: BasicAdminPageComponent }]; -- 2.11.0