From d6de5f2123974e3accc2d2889193256c36eb5d10 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 29 Jun 2021 13:50:56 -0400 Subject: [PATCH] LP1904036 Grid gets dateOnlyIntervalField support E.g. show the time component of a due date if the circulation has a non-day-granular duration. Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/app/core/format.service.ts | 13 +++++++++++++ .../eg2/src/app/share/grid/grid-column.component.ts | 3 +++ Open-ILS/src/eg2/src/app/share/grid/grid.ts | 20 +++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/eg2/src/app/core/format.service.ts b/Open-ILS/src/eg2/src/app/core/format.service.ts index fa1fe7924a..3c5e884d07 100644 --- a/Open-ILS/src/eg2/src/app/core/format.service.ts +++ b/Open-ILS/src/eg2/src/app/core/format.service.ts @@ -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': diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts index aa09c82ee2..bf2abeb63e 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts @@ -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; @@ -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; diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index 26bb0dcf4b..257e1c4719 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -31,6 +31,7 @@ export class GridColumn { ternaryBool: boolean; timezoneContextOrg: number; cellTemplate: TemplateRef; + 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 }); } -- 2.11.0