LP1840050 org unit admin UI WIP
authorBill Erickson <berickxx@gmail.com>
Tue, 13 Aug 2019 16:23:14 +0000 (12:23 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 13 Aug 2019 16:23:14 +0000 (12:23 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts
Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.ts

index dee3248..dc14deb 100644 (file)
@@ -182,7 +182,7 @@ export class OrgSelectComponent implements OnInit {
     }
 
     // Remove the tree-padding spaces when matching.
-    formatter = (result: OrgDisplay) => result.label.trim();
+    formatter = (result: OrgDisplay) => result ? result.label.trim() : '';
 
     // reset the state of the component
     reset() {
index a1ef44a..22ae883 100644 (file)
@@ -13,7 +13,7 @@
 <eg-confirm-dialog #delConfirm 
   i18n-dialogTitle i18n-dialogBody
   dialogTitle="Confirm Delete"
-  dialogBody="Delete Org Unit {{selected.label}}?">
+  dialogBody="Delete Org Unit {{selected ? selected.label : ''}}?">
 </eg-confirm-dialog>
 
 <div class="row">
     <eg-tree [tree]="tree" (nodeClicked)="nodeClicked($event)"></eg-tree>
   </div>
   <div class="col-lg-8">
-    <ngb-tabset #rootTabs [activeId]="main">
+    <ngb-tabset #rootTabs>
       <ngb-tab title="Main Settings" i18n-title id="main">
         <ng-template ngbTabContent>
-          <eg-fm-record-editor #editDialog idlClass="aou" [displayMode]="inline" 
-            [mode]="selected ? 'update' : 'create'"
-            readonlyFields="parent,ou_type,parent_ou" [recordId]="selected ? selected.id : null" 
-            fieldOrder="parent_ou,ou_type,name,shortname,phone,email,opac_visible,fiscal_calendar"
-            hiddenFields="id,billing_address,mailing_address,holds_address,ill_address">
-          </eg-fm-record-editor>
+          <div class="mt-2">
+            <eg-fm-record-editor #editDialog idlClass="aou" [displayMode]="inline" 
+              [mode]="selected ? 'update' : 'create'"
+              readonlyFields="parent,ou_type,parent_ou" [recordId]="selected ? selected.id : null" 
+              fieldOrder="parent_ou,ou_type,name,shortname,phone,email,opac_visible,fiscal_calendar"
+              hiddenFields="id,billing_address,mailing_address,holds_address,ill_address">
+            </eg-fm-record-editor>
+          </div>
+        </ng-template>
+      </ngb-tab>
+      <ngb-tab title="Hours of Operation" i18n-title id="hours">
+        <ng-template ngbTabContent>
+          <div class="mt-2">
+            <div class="row font-weight-bold mb-2">
+              <div class="col-lg-3 offset-lg-2" i18n>Open Time</div>
+              <div class="col-lg-3" i18n>Close Time</div>
+            </div>
+            <div class="row">
+              <div class="col-lg-2" i18n>Monday</div>
+              <div class="col-lg-3">
+                <input class="form-control" type='time' step="60" 
+                  [ngModel]="hours().dow_0_open()" min="00:00:00" max="23:59:59"
+                  (ngModelChange)="hours().dow_0_open($event)"/>
+              </div>
+              <div class="col-lg-3">
+                <input  class="form-control" type='time' step="60"
+                  [ngModel]="hours().dow_0_close()" min="00:00:00" max="23:59:59"
+                  (ngModelChange)="hours().dow_0_close($event)"/>
+              </div>
+              <div class="col-lg-2">
+                <button class="btn btn-outline-dark" (click)="closedOn(0)" i18n>
+                  Closed
+                </button>
+              </div>
+            </div>
+          </div>
+        </ng-template>
+      </ngb-tab>
+      <ngb-tab title="Addresses" i18n-title id="addresses">
+        <ng-template ngbTabContent>
+          <div class="mt-2">
+            <ngb-tabset #rootTabs>
+              <ngb-tab title="Physical Address" i18n-title id="physical">
+              </ngb-tab>
+              <ngb-tab title="Holds Address" i18n-title id="holds">
+              </ngb-tab>
+              <ngb-tab title="Mailing Address" i18n-title id="mailing">
+              </ngb-tab>
+              <ngb-tab title="ILL Address" i18n-title id="ill">
+              </ngb-tab>
+            </ngb-tabset>
+          </div>
         </ng-template>
       </ngb-tab>
     </ngb-tabset>
index 65b21d0..0446ecf 100644 (file)
@@ -12,7 +12,6 @@ import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
 @Component({
     templateUrl: './org-unit.component.html'
 })
-
 export class OrgUnitComponent implements OnInit {
 
     tree: Tree;
@@ -33,14 +32,21 @@ export class OrgUnitComponent implements OnInit {
 
 
     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.loadAouTree(this.org.root().id());
     }
 
-    loadAouTree() {
-        this.org.fetchOrgs().then(() => this.ingestAouTree(this.org.tree()));
+    loadAouTree(selectNodeId?: number): Promise<any> {
+        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}
+        ).toPromise().then(tree => {
+            this.ingestAouTree(tree);
+            if (selectNodeId) {
+                this.selected = this.tree.findNode(selectNodeId);
+            }
+        });
     }
 
     // Translate the org unt type tree into a structure EgTree can use.
@@ -49,17 +55,26 @@ export class OrgUnitComponent implements OnInit {
         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());
+            if (!orgNode.hours_of_operation()) {
+                const hours = this.idl.create('aouhoo');
+                hours.org_unit(orgNode.id());
+                hours.isnew(true);
+                [0, 1, 2, 3, 4, 5, 6].forEach(dow => {
+                    hours[`dow_${dow}_open`]('09:00:00');
+                    hours[`dow_${dow}_close`]('17:00:00');
+                });
+                orgNode.hours_of_operation(hours);
+            }
+
+            // TODO addresses
 
             const treeNode = new TreeNode({
-                id: node.id(),
-                label: node.name(),
-                callerData: {orgUnit: node}
+                id: orgNode.id(),
+                label: orgNode.name(),
+                callerData: {orgUnit: orgNode}
             });
 
-            node.children().forEach(childNode =>
+            orgNode.children().forEach(childNode =>
                 treeNode.children.push(handleNode(childNode))
             );
 
@@ -74,6 +89,16 @@ export class OrgUnitComponent implements OnInit {
         this.selected = $event;
     }
 
+    hours(): IdlObject {
+        if (this.selected) {
+            console.log('we have org ', this.selected.callerData.orgUnit);
+            console.log('we have hours ', this.selected.callerData.orgUnit.hours_of_operation());
+            return this.selected.callerData.orgUnit.hours_of_operation();
+        }
+        return this.selected ? 
+            this.selected.callerData.orgUnit.hours_of_operation() : null;
+    }
+
     postUpdate(message: StringComponent) {
         // Modifying org unit types means refetching the org unit
         // data normally fetched on page load, since it includes
@@ -97,13 +122,12 @@ export class OrgUnitComponent implements OnInit {
                 ()  => {
                     // 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.postUpdate(this.editString);
+                    const orgId = org.parent_ou() ? 
+                        org.parent_ou() : this.org.root().id();
+                    this.loadAouTree(orgId).then(_ => 
+                        this.postUpdate(this.editString));
                 }
             );
         });
@@ -125,8 +149,8 @@ export class OrgUnitComponent implements OnInit {
                 label: result.name(),
                 callerData: {orgUnit: result}
             });
-            this.loadAouTree();
-            this.postUpdate(this.createString);
+            this.loadAouTree(result.id()).then(_ => 
+                this.postUpdate(this.createString));
         });
 
         // TODO subscribe / unsub error events