From 3c3d0678b67425f3f9dcdca760cdbb6b33752203 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 20 Mar 2019 12:06:20 -0400 Subject: [PATCH] LP1821382 Angular boolean yes/no display component Simple component that accepts a boolean value and displays a yes/no badge. Added as the default handler for boolean columsn in the grid. Signed-off-by: Bill Erickson Signed-off-by: Dan Wells --- Open-ILS/src/eg2/src/app/common.module.ts | 3 ++ .../src/eg2/src/app/core/format.service.ts | 3 +- .../share/grid/grid-body-cell.component.html | 9 ++++- .../app/share/grid/grid-column.component.ts | 4 ++ Open-ILS/src/eg2/src/app/share/grid/grid.ts | 7 ++++ .../eg2/src/app/share/util/bool.component.ts | 39 +++++++++++++++++++ 6 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/share/util/bool.component.ts diff --git a/Open-ILS/src/eg2/src/app/common.module.ts b/Open-ILS/src/eg2/src/app/common.module.ts index f1d4467830..a4e402680d 100644 --- a/Open-ILS/src/eg2/src/app/common.module.ts +++ b/Open-ILS/src/eg2/src/app/common.module.ts @@ -25,6 +25,7 @@ import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; import {PromptDialogComponent} from '@eg/share/dialog/prompt.component'; import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component'; import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; +import {BoolDisplayComponent} from '@eg/share/util/bool.component'; @NgModule({ declarations: [ @@ -35,6 +36,7 @@ import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; PromptDialogComponent, ProgressInlineComponent, ProgressDialogComponent, + BoolDisplayComponent, FormatValuePipe ], imports: [ @@ -55,6 +57,7 @@ import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; PromptDialogComponent, ProgressInlineComponent, ProgressDialogComponent, + BoolDisplayComponent, FormatValuePipe ] }) 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 8108eec91b..d2b2ce51e2 100644 --- a/Open-ILS/src/eg2/src/app/core/format.service.ts +++ b/Open-ILS/src/eg2/src/app/core/format.service.ts @@ -119,7 +119,8 @@ export class FormatService { case 'bool': // Slightly better than a bare 't' or 'f'. - // Should probably add a global true/false string. + // Note the caller is better off using an for + // boolean display. return Boolean( value === 't' || value === 1 || value === '1' || value === true diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-body-cell.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-body-cell.component.html index 6dc4a99b56..921fafc459 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-body-cell.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-body-cell.component.html @@ -4,7 +4,14 @@ placement="top-left" class="{{context.cellClassCallback(row, column)}}" triggers="mouseenter:mouseleave"> - {{context.getRowColumnValue(row, column)}} + + + + + + {{context.getRowColumnValue(row, column)}} + ; cellContext: any; isIndex: boolean; @@ -658,6 +659,12 @@ export class GridContext { val = this.getObjectFieldValue(row, col.name); } + if (col.datatype === 'bool') { + // Avoid string-ifying bools so we can use an + // in the grid template. + return val; + } + return this.format.transform({ value: val, idlClass: col.idlClass, diff --git a/Open-ILS/src/eg2/src/app/share/util/bool.component.ts b/Open-ILS/src/eg2/src/app/share/util/bool.component.ts new file mode 100644 index 0000000000..37d2e8d7d7 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/util/bool.component.ts @@ -0,0 +1,39 @@ +import {Component, Input} from '@angular/core'; + +/* Simple component to render a boolean value as human-friendly text */ + +@Component({ + selector: 'eg-bool', + template: ` + + Yes + No + + Unset + + ` +}) +export class BoolDisplayComponent { + + _value: boolean; + @Input() set value(v: boolean) { + this._value = v; + } + get value(): boolean { + return this._value; + } + + // If true, a null value displays as unset. + // If false, a null value displays as an empty string. + _ternary: boolean; + @Input() set ternary(t: boolean) { + this._ternary = t; + } + get ternary(): boolean { + return this._ternary; + } + + constructor() { + this.value = null; + } +} \ No newline at end of file -- 2.43.2