LP#1823393: various usability improvements
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 23 May 2019 16:47:56 +0000 (12:47 -0400)
committerJane Sandberg <sandbej@linnbenton.edu>
Fri, 24 May 2019 17:57:11 +0000 (10:57 -0700)
- display the number of org units associated with the selected type
- disable the Delete button if a type either has children types
  or org units linked to it
- ensure that the type name and label fields are required
- ensure that the tree is fully refreshed after an update

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-type.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-type.component.ts

index d812d12..3c0af3b 100644 (file)
@@ -16,7 +16,9 @@
   dialogBody="Delete Org Unit Type {{selected ? selected.label : ''}}?">
 </eg-confirm-dialog>
 
-<eg-fm-record-editor #editDialog idlClass="aout" readonlyFields="depth,parent">
+<eg-fm-record-editor #editDialog idlClass="aout" readonlyFields="depth,parent"
+  [fieldOptions]="{name:{isRequired:true},opac_label:{isRequired:true}}"
+>
 </eg-fm-record-editor>
 
 <div class="row">
@@ -39,7 +41,8 @@
         <div class="col-lg-9">
           <button class="btn btn-info mr-2" (click)="edit()" i18n>Edit</button>
           <button class="btn btn-info mr-2" (click)="addChild()" i18n>Add Child</button>
-          <button class="btn btn-warning mr-2" (click)="remove()" i18n>Delete</button>
+          <button class="btn btn-warning mr-2" (click)="remove()"
+            [disabled]="selected.callerData.aout.children().length > 0 || selected.callerData.orgCount > 0" i18n>Delete</button>
         </div>
       </div>
       <div class="row">
@@ -48,7 +51,7 @@
           <label i18n>Name: </label>
         </div>
         <div class="col-lg-8 font-weight-bold">
-          {{selected.callerData.name()}}
+          {{selected.callerData.aout.name()}}
         </div>
       </div>
       <div class="row">
@@ -56,7 +59,7 @@
           <label i18n>Label: </label>
         </div>
         <div class="col-lg-8 font-weight-bold">
-          {{selected.callerData.opac_label()}}
+          {{selected.callerData.aout.opac_label()}}
         </div>
       </div>
       <div class="row">
@@ -65,7 +68,7 @@
         </div>
         <div class="col-lg-8 font-weight-bold">
           <!-- TODO: use <eg-bool/> once merged-->
-          {{selected.callerData.can_have_users() == 't'}}
+          {{selected.callerData.aout.can_have_users() == 't'}}
         </div>
       </div>
       <div class="row">
@@ -74,7 +77,7 @@
           </div>
           <div class="col-lg-8 font-weight-bold">
             <!-- TODO: use <eg-bool/> once merged-->
-            {{selected.callerData.can_have_vols() == 't'}}
+            {{selected.callerData.aout.can_have_vols() == 't'}}
           </div>
         </div>
       <div class="row">
           <label i18n>Depth: </label>
         </div>
         <div class="col-lg-8 font-weight-bold">
-          {{selected.callerData.depth()}}
+          {{selected.callerData.aout.depth()}}
+        </div>
+      </div>
+      <div class="row">
+        <div class="col-lg-4">
+          <label i18n>Number of Org Units Of This Type: </label>
+        </div>
+        <div class="col-lg-8 font-weight-bold">
+          {{selected.callerData.orgCount}}
         </div>
       </div>
     </div>
index 1820cc8..978b46f 100644 (file)
@@ -38,7 +38,7 @@ export class OrgUnitTypeComponent implements OnInit {
 
     loadAoutTree() {
         this.pcrud.search('aout', {depth: 0},
-            {flesh: -1, flesh_fields: {aout: ['children']}},
+            {flesh: -1, flesh_fields: {aout: ['children','org_units']}},
             {anonymous: true}
         ).subscribe(aoutTree => this.ingestAoutTree(aoutTree));
     }
@@ -49,10 +49,16 @@ export class OrgUnitTypeComponent implements OnInit {
         const handleNode = (aoutNode: IdlObject): TreeNode => {
             if (!aoutNode) { return; }
 
+            // grab number of associated org units, then
+            // clear it so that FmRecordEditor doesn't try
+            // to render the list
+            const orgCount = aoutNode.org_units().length;
+            aoutNode.org_units(null);
+
             const treeNode = new TreeNode({
                 id: aoutNode.id(),
                 label: aoutNode.name(),
-                callerData: aoutNode
+                callerData: { aout: aoutNode, orgCount: orgCount },
             });
 
             aoutNode.children().forEach(childNode =>
@@ -83,11 +89,14 @@ export class OrgUnitTypeComponent implements OnInit {
 
     edit() {
         this.editDialog.mode = 'update';
-        this.editDialog.setRecord(this.selected.callerData);
+        this.editDialog.setRecord(this.selected.callerData.aout);
 
         this.editDialog.open().then(
             success => {
                 this.postUpdate(this.editString);
+                this.loadAoutTree(); // since the tree is never going to
+                                     // be large, just reload the whole
+                                     // thing
             },
             rejected => {
                 if (rejected && rejected.dismissed) {
@@ -102,7 +111,7 @@ export class OrgUnitTypeComponent implements OnInit {
     remove() {
         this.delConfirm.open().then(
             ok => {
-                this.pcrud.remove(this.selected.callerData)
+                this.pcrud.remove(this.selected.callerData.aout)
                 .subscribe(
                     ok2 => {},
                     err => {
@@ -112,7 +121,9 @@ export class OrgUnitTypeComponent implements OnInit {
                     ()  => {
                         // Avoid updating until we know the entire
                         // pcrud action/transaction completed.
-                        this.tree.removeNode(this.selected);
+                        this.loadAoutTree(); // since the tree is never going to
+                                             // be large, just reload the whole
+                                             // thing
                         this.selected = null;
                         this.postUpdate(this.editString);
                     }
@@ -124,7 +135,7 @@ export class OrgUnitTypeComponent implements OnInit {
 
     addChild() {
         const parentTreeNode = this.selected;
-        const parentType = parentTreeNode.callerData;
+        const parentType = parentTreeNode.callerData.aout;
 
         const newType = this.idl.create('aout');
         newType.parent(parentType.id());
@@ -140,9 +151,11 @@ export class OrgUnitTypeComponent implements OnInit {
                 const newNode = new TreeNode({
                     id: result.id(),
                     label: result.name(),
-                    callerData: result
+                    callerData: { aout: result, orgCount: 0 }
                 });
-                parentTreeNode.children.push(newNode);
+                this.loadAoutTree(); // since the tree is never going to
+                                     // be large, just reload the whole
+                                     // thing
                 this.postUpdate(this.createString);
             },