LP1904036 Grid gets dateOnlyIntervalField support
authorBill Erickson <berickxx@gmail.com>
Tue, 29 Jun 2021 17:50:56 +0000 (13:50 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 29 Jun 2021 17:50:59 +0000 (13:50 -0400)
E.g. show the time component of a due date if the circulation has a
non-day-granular duration.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/core/format.service.ts
Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.ts

index fa1fe79..3c5e884 100644 (file)
@@ -4,6 +4,7 @@ import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
 import {LocaleService} from '@eg/core/locale.service';
 import * as moment from 'moment-timezone';
+import {DateUtil} from '@eg/share/util/date';
 
 /**
  * Format IDL vield values for display.
@@ -19,6 +20,7 @@ export interface FormatParams {
     orgField?: string; // 'shortname' || 'name'
     datePlusTime?: boolean;
     timezoneContextOrg?: number;
+    dateOnlyInterval?: string;
 }
 
 @Injectable({providedIn: 'root'})
@@ -135,10 +137,21 @@ export class FormatService {
                     console.error('Invalid date in format service', value);
                     return '';
                 }
+
                 let fmt = this.dateFormat || 'shortDate';
+
                 if (params.datePlusTime) {
+                    // Time component directly requested
                     fmt = this.dateTimeFormat || 'short';
+
+                } else if (params.dateOnlyInterval) {
+                    // Time component displays for non-day-granular intervals.
+                    const secs = DateUtil.intervalToSeconds(params.dateOnlyInterval);
+                    if (secs !== null && secs % 86400 !== 0) {
+                        fmt = this.dateTimeFormat || 'short';
+                    }
                 }
+
                 return this.datePipe.transform(date.toISOString(true), fmt, date.format('ZZ'));
 
             case 'money':
index aa09c82..bf2abeb 100644 (file)
@@ -36,6 +36,8 @@ export class GridColumnComponent implements OnInit {
     // Display using a specific OU's timestamp when datatype = timestamp
     @Input() timezoneContextOrg: number;
 
+    @Input() dateOnlyIntervalField: string;
+
     // Used in conjunction with cellTemplate
     @Input() cellContext: any;
     @Input() cellTemplate: TemplateRef<any>;
@@ -79,6 +81,7 @@ export class GridColumnComponent implements OnInit {
         col.datePlusTime = this.datePlusTime;
         col.ternaryBool = this.ternaryBool;
         col.timezoneContextOrg = this.timezoneContextOrg;
+        col.dateOnlyIntervalField = this.dateOnlyIntervalField;
         col.idlClass = this.idlClass;
         col.isAuto = false;
 
index 26bb0dc..257e1c4 100644 (file)
@@ -31,6 +31,7 @@ export class GridColumn {
     ternaryBool: boolean;
     timezoneContextOrg: number;
     cellTemplate: TemplateRef<any>;
+    dateOnlyIntervalField: string;
 
     cellContext: any;
     isIndex: boolean;
@@ -98,6 +99,7 @@ export class GridColumn {
         col.datePlusTime = this.datePlusTime;
         col.ternaryBool = this.ternaryBool;
         col.timezoneContextOrg = this.timezoneContextOrg;
+        col.dateOnlyIntervalField = this.dateOnlyIntervalField;
         col.idlClass = this.idlClass;
         col.isAuto = this.isAuto;
 
@@ -909,13 +911,29 @@ export class GridContext {
             return val;
         }
 
+        // Get the value of
+        let interval;
+        const intField = col.dateOnlyIntervalField;
+        if (intField) {
+            if (intField in row) {
+                interval = this.getObjectFieldValue(row, intField);
+            } else  {
+                // find the referenced column
+                const intCol = this.columnSet.columns.filter(c => c.path === intField)[0];
+                if (intCol) {
+                    interval = this.nestedItemFieldValue(row, intCol);
+                }
+            }
+        }
+
         return this.format.transform({
             value: val,
             idlClass: col.idlClass,
             idlField: col.idlFieldDef ? col.idlFieldDef.name : col.name,
             datatype: col.datatype,
             datePlusTime: Boolean(col.datePlusTime),
-            timezoneContextOrg: Number(col.timezoneContextOrg)
+            timezoneContextOrg: Number(col.timezoneContextOrg),
+            dateOnlyInterval: interval
         });
     }