LP1840050 org unit admin UI WIP
authorBill Erickson <berickxx@gmail.com>
Tue, 13 Aug 2019 16:56:52 +0000 (12:56 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 13 Aug 2019 16:56:52 +0000 (12:56 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
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 22ae883..798538c 100644 (file)
               <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="row mb-2" *ngFor="let dow of [0,1,2,3,4,5,6]">
+              <div class="col-lg-2" [ngSwitch]="dow">
+                <span *ngSwitchCase="0" i18n>Monday</span>
+                <span *ngSwitchCase="1" i18n>Tuesday</span>
+                <span *ngSwitchCase="2" i18n>Wednesday</span>
+                <span *ngSwitchCase="3" i18n>Thursday</span>
+                <span *ngSwitchCase="4" i18n>Friday</span>
+                <span *ngSwitchCase="5" i18n>Saturday</span>
+                <span *ngSwitchCase="6" i18n>Sunday</span>
+              </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)"/>
+                  [ngModel]="hours(dow, 'open')" min="00:00:00" max="23:59:59"
+                  (ngModelChange)="hours(dow, '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)"/>
+                  [ngModel]="hours(dow, 'close')" min="00:00:00" max="23:59:59"
+                  (ngModelChange)="hours(dow, 'close', $event)"/>
               </div>
               <div class="col-lg-2">
-                <button class="btn btn-outline-dark" (click)="closedOn(0)" i18n>
+                <button class="btn btn-outline-dark" (click)="closedOn(dow)" i18n>
                   Closed
                 </button>
               </div>
index 0446ecf..83abd09 100644 (file)
@@ -56,14 +56,7 @@ export class OrgUnitComponent implements OnInit {
             if (!orgNode) { return; }
 
             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);
+                this.generateHours(orgNode);
             }
 
             // TODO addresses
@@ -89,14 +82,38 @@ 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();
+    generateHours(org: IdlObject) {
+        const hours = this.idl.create('aouhoo');
+        hours.org_unit(org.id());
+        hours.isnew(true);
+
+        [0, 1, 2, 3, 4, 5, 6].forEach(dow => {
+            this.hours(dow, 'open', '09:00:00', hours);
+            this.hours(dow, 'close', '17:00:00', hours);
+        });
+
+        org.hours_of_operation(hours);
+    }
+
+    // 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 {
+        if (!hoo && !this.selected) { return null; }
+
+        const hours = hoo || this.selected.callerData.orgUnit.hours_of_operation();
+
+        if (value) {
+            hours[`dow_${dow}_${which}`](value);    
+            hours.ischanged(true);
         }
-        return this.selected ? 
-            this.selected.callerData.orgUnit.hours_of_operation() : null;
+
+        return hours[`dow_${dow}_${which}`]();    
+    }
+
+    closedOn(dow: number) {
+        this.hours(dow, 'open', '00:00:00');
+        this.hours(dow, 'close', '00:00:00');
     }
 
     postUpdate(message: StringComponent) {