LP1816475: adding default values to end/start times
authorJane Sandberg <sandbej@linnbenton.edu>
Sun, 7 Apr 2019 17:10:19 +0000 (10:10 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 17 Apr 2019 20:41:53 +0000 (13:41 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.html
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts
Open-ILS/src/eg2/src/app/staff/booking/pull-list.component.ts

index 28205a8..33da14e 100644 (file)
@@ -21,6 +21,7 @@ export class DateTimeSelectComponent implements OnInit {
     @Input() validatorError = '';
 
     @Input() initialIso: string;
+    @Input() initialMoment: Moment;
 
     @Output() onChangeAsIso = new EventEmitter<string>();
     @Output() onChangeAsMoment = new EventEmitter<Moment>();
@@ -35,7 +36,8 @@ export class DateTimeSelectComponent implements OnInit {
     }
 
     ngOnInit() {
-        const start = this.initialIso ? Moment.tz(this.initialIso, Moment.ISO_8601, this.timezone) : Moment.tz([], this.timezone);
+        let start = this.initialIso ? Moment.tz(this.initialIso, Moment.ISO_8601, this.timezone) : Moment.tz([], this.timezone);
+        if (this.initialMoment) { start = this.initialMoment; }
         this.stringVersion = this.format.transform({value: start, datatype: 'timestamp', datePlusTime: true});
         this.setDatePicker(start);
         this.setTimePicker(start);
index f1c2aac..3cf0f3f 100644 (file)
 
 <eg-grid *ngIf="resources.length" #scheduleGrid
   [sortable]="false"
-  (onRowActivate)="showNewDialog($event)"
+  (onRowActivate)="openCreateDialog([$event])"
   [dataSource]="scheduleSource"
   [rowFlairIsEnabled]="true"
   [rowFlairCallback]="resourceAvailabilityIcon"
   [disablePager]="true"
   [disableSaveSettings]="true"
   [cellClassCallback]="isBooked">
+  <eg-grid-toolbar-action label="Create Reservation" i18n-label [action]="openCreateDialog"></eg-grid-toolbar-action>
   <eg-grid-column path="time" [index]="true" ></eg-grid-column>
   <eg-grid-column *ngFor="let resource of resources" path="{{resource.barcode()}}" [cellTemplate]="reservationsTemplate"></eg-grid-column>
 </eg-grid>
 <eg-fm-record-editor #newDialog
   idlClass="bresv"
   datetimeFields="start_time,end_time"
-  [fieldOptions]="{usr:{customTemplate:{template:patronTemplate,context:{'patronId':this.patronId}}}}"
+  [fieldOptions]="{usr:{customTemplate:{template:patronTemplate}},start_time:{customTemplate:{template:datetimeWithDefaults}},end_time:{customTemplate:{template:datetimeWithDefaults}}}"
   hiddenFields="id,xact_start,request_time,capture_time,pickup_time,return_time,capture_staff,xact_finish,cancel_time,booking_interval,target_resource,unrecovered,request_lib,fine_interval,fine_amount,max_fine">
 </eg-fm-record-editor>
 
     </ul>
   </ng-container>
 </ng-template>
-<ng-template #patronTemplate let-record="record" let-patronId="patronId">
+<ng-template #patronTemplate let-record="record">
 <input type="hidden" value="{{record.request_lib(auth.user().ws_ou())}}">
   <ng-container *ngIf="patronId">
     <input *ngIf="patronId" type="text" disabled value="{{record.usr(patronId)}}" class="form-control" name="usr">
     </div>
   </div>
 </ng-template>
+<ng-template #datetimeWithDefaults let-record="record" let-field="field">
+  <input type="hidden" value="{{record[field.name](defaultTimes[field.name].toIsoString()}}">
+  <eg-datetime-select
+    [showTZ]="true"
+    [minuteStep]="minuteStep()"
+    timezone="{{format.wsOrgTimezone}}"
+    (onChangeAsIso)="record[field.name]($event)"
+    [initialMoment]="defaultTimes[field.name]">
+  </eg-datetime-select>
+</ng-template>
 
index e96781a..91a3ea6 100644 (file)
@@ -44,8 +44,12 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
     endOfDay: NgbTimeStruct = {hour: 17, minute: 0, second: 0};
     granularity: 15 | 30 | 60 | 1440 = 30; // 1440 minutes = 24 hours
 
+    defaultTimes: {start_time: Moment, end_time: Moment};
+
     scheduleSource: GridDataSource = new GridDataSource();
 
+    minuteStep: () => number;
+
     resources: IdlObject[] = [];
     limitByAttr: (attributeId: number, $event: ComboboxEntry) => void;
     useCurrentResourceBarcode: () => void;
@@ -90,6 +94,10 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
 
 
     ngOnInit() {
+        this.defaultTimes = {
+            'start_time': Moment.tz([], this.format.wsOrgTimezone),
+            'end_time': Moment.tz([], this.format.wsOrgTimezone).add(this.granularity, 'minutes')
+        };
         this.route.paramMap.subscribe((params: ParamMap) => {
             this.patronId = +params.get('patron_id');
             this.resourceBarcode = params.get('resource_barcode');
@@ -107,14 +115,14 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
                     .pipe(single())
                     .subscribe((item) => {
                         this.net.request( 'open-ils.booking',
-                       'open-ils.booking.resources.create_from_copies',
+                        'open-ils.booking.resources.create_from_copies',
                         this.auth.token(), [item.id()])
-                       .subscribe((response) =>  {
+                        .subscribe((response) =>  {
                             this.toast.info('Made this barcode bookable');
                             this.resourceId = response['brsrc'][0][0];
                         }, (error) => {
                             this.toast.danger('Cannot make this barcode bookable');
-                        })
+                        });
                     }, (acperror) => {
                         this.toast.danger('No resource found with this barcode');
                         this.resourceId = -1;
@@ -140,7 +148,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
                 this.granularity = 1440;
             } else {
                 this.store.getItem('eg.booking.create.granularity').then(granularity => {
-                    if (granularity) { 
+                    if (granularity) {
                         this.granularity = granularity;
                     } else {
                         this.granularity = 30;
@@ -198,7 +206,9 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
                 );
             }
         };
-
+        this.minuteStep = () => {
+            return (this.granularity < 60) ? this.granularity : 15;
+        }
 
     }
 
@@ -208,7 +218,16 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
         this.fetchData();
     }
 
-    showNewDialog(idlThing: IdlObject) {
+    openCreateDialog(rows: IdlObject[]) {
+        if (this.multiday) {
+            this.defaultTimes['start_time'] = this.format.momentizeDateString(rows[0]['time'], this.format.wsOrgTimezone);
+            this.defaultTimes['end_time'] = this.format.momentizeDateString(
+                rows[rows.length - 1]['time'], this.format.wsOrgTimezone).clone()
+                .add(this.granularity, 'minutes');
+        } else {
+            this.defaultTimes['start_time'] = Moment.tz(rows[0]['time'], 'LT', this.format.wsOrgTimezone);
+            this.defaultTimes['end_time'] = Moment.tz(rows[rows.length - 1]['time'], 'LT', this.format.wsOrgTimezone).add(this.granularity, 'minutes');
+        }
         return this.newDialog.open({size: 'lg'}).then(
             response => {
                console.log(response);
index e8d63e8..c242a51 100644 (file)
@@ -29,7 +29,7 @@ export class PullListComponent implements OnInit {
 
 
     ngOnInit() {
-        this.disableOrgs = () => {return this.org.filterList({canHaveVolumes : false}, true);}
+        this.disableOrgs = () => { return this.org.filterList( { canHaveVolumes : false }, true); };
 
         this.fill_grid = (orgId = this.auth.user().ws_ou()) => {
             this.net.request(
@@ -55,7 +55,7 @@ export class PullListComponent implements OnInit {
                 });
                 this.dataSource.data = data;
             });
-        }
+        };
         this.dataSource = new GridDataSource();
         this.fill_grid(this.auth.user().ws_ou());
     }