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: [
PromptDialogComponent,
ProgressInlineComponent,
ProgressDialogComponent,
+ BoolDisplayComponent,
FormatValuePipe
],
imports: [
PromptDialogComponent,
ProgressInlineComponent,
ProgressDialogComponent,
+ BoolDisplayComponent,
FormatValuePipe
]
})
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 <eg-bool/> for
+ // boolean display.
return Boolean(
value === 't' || value === 1 ||
value === '1' || value === true
placement="top-left"
class="{{context.cellClassCallback(row, column)}}"
triggers="mouseenter:mouseleave">
- {{context.getRowColumnValue(row, column)}}
+ <ng-container *ngIf="column.datatype == 'bool'">
+ <eg-bool [value]="context.getRowColumnValue(row, column)"
+ [ternary]="column.ternaryBool">
+ </eg-bool>
+ </ng-container>
+ <ng-container *ngIf="column.datatype != 'bool'">
+ {{context.getRowColumnValue(row, column)}}
+ </ng-container>
</span>
<span *ngIf="column.cellTemplate"
class="{{context.cellClassCallback(row, column)}}"
@Input() datatype: string;
@Input() multiSortable: boolean;
+ // If true, boolean fields support 3 values: true, false, null (unset)
+ @Input() ternaryBool: boolean;
+
// Display date and time when datatype = timestamp
@Input() datePlusTime: boolean;
col.isMultiSortable = this.multiSortable;
col.datatype = this.datatype;
col.datePlusTime = this.datePlusTime;
+ col.ternaryBool = this.ternaryBool;
col.isAuto = false;
this.grid.context.columnSet.add(col);
}
idlFieldDef: any;
datatype: string;
datePlusTime: boolean;
+ ternaryBool: boolean;
cellTemplate: TemplateRef<any>;
cellContext: any;
isIndex: boolean;
val = this.getObjectFieldValue(row, col.name);
}
+ if (col.datatype === 'bool') {
+ // Avoid string-ifying bools so we can use an <eg-bool/>
+ // in the grid template.
+ return val;
+ }
+
return this.format.transform({
value: val,
idlClass: col.idlClass,
--- /dev/null
+import {Component, Input} from '@angular/core';
+
+/* Simple component to render a boolean value as human-friendly text */
+
+@Component({
+ selector: 'eg-bool',
+ template: `
+ <ng-container>
+ <span *ngIf="value" class="badge badge-success" i18n>Yes</span>
+ <span *ngIf="value == false" class="badge badge-secondary" i18n>No</span>
+ <ng-container *ngIf="value === null">
+ <span *ngIf="ternary" class="badge badge-light" i18n>Unset</span>
+ <span *ngIf="!ternary"> </span>
+ </ng-container>`
+})
+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