Database column filters
continuous-integration/drone/push Build is passing Details

master
Garrett Mills 3 years ago
parent f1a34b7d1f
commit 3b14c2dc1c
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -37,6 +37,7 @@ import {WysiwygComponent} from './wysiwyg/wysiwyg.component';
import {WysiwygEditorComponent} from './editor/database/editors/wysiwyg/wysiwyg-editor.component'; import {WysiwygEditorComponent} from './editor/database/editors/wysiwyg/wysiwyg-editor.component';
import {WysiwygModalComponent} from './editor/database/editors/wysiwyg/wysiwyg-modal.component'; import {WysiwygModalComponent} from './editor/database/editors/wysiwyg/wysiwyg-modal.component';
import {AngularResizedEventModule} from 'angular-resize-event'; import {AngularResizedEventModule} from 'angular-resize-event';
import {DateTimeFilterComponent} from './editor/database/filters/date-time.filter';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -68,6 +69,7 @@ import {AngularResizedEventModule} from 'angular-resize-event';
WysiwygComponent, WysiwygComponent,
WysiwygEditorComponent, WysiwygEditorComponent,
WysiwygModalComponent, WysiwygModalComponent,
DateTimeFilterComponent,
], ],
imports: [ imports: [
CommonModule, CommonModule,
@ -111,6 +113,7 @@ import {AngularResizedEventModule} from 'angular-resize-event';
WysiwygComponent, WysiwygComponent,
WysiwygEditorComponent, WysiwygEditorComponent,
WysiwygModalComponent, WysiwygModalComponent,
DateTimeFilterComponent,
], ],
exports: [ exports: [
NodePickerComponent, NodePickerComponent,
@ -141,6 +144,7 @@ import {AngularResizedEventModule} from 'angular-resize-event';
WysiwygComponent, WysiwygComponent,
WysiwygEditorComponent, WysiwygEditorComponent,
WysiwygModalComponent, WysiwygModalComponent,
DateTimeFilterComponent,
] ]
}) })
export class ComponentsModule {} export class ComponentsModule {}

@ -25,6 +25,7 @@
(cellValueChanged)="onCellValueChanged()" (cellValueChanged)="onCellValueChanged()"
(gridReady)="onGridReady($event)" (gridReady)="onGridReady($event)"
(columnResized)="onColumnResize($event)" (columnResized)="onColumnResize($event)"
[frameworkComponents]="frameworkComponents"
#agGridElement #agGridElement
></ag-grid-angular> ></ag-grid-angular>
</div> </div>

@ -16,6 +16,7 @@ import {EditorNodeContract} from '../../nodes/EditorNode.contract';
import {EditorService} from '../../../service/editor.service'; import {EditorService} from '../../../service/editor.service';
import {WysiwygEditorComponent} from './editors/wysiwyg/wysiwyg-editor.component'; import {WysiwygEditorComponent} from './editors/wysiwyg/wysiwyg-editor.component';
import {debounce, debug} from '../../../utility'; import {debounce, debug} from '../../../utility';
import {DateTimeFilterComponent} from './filters/date-time.filter';
@Component({ @Component({
selector: 'editor-database', selector: 'editor-database',
@ -27,6 +28,10 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
@Input() editorUUID?: string; @Input() editorUUID?: string;
@ViewChild('agGridElement') agGridElement: AgGridAngular; @ViewChild('agGridElement') agGridElement: AgGridAngular;
frameworkComponents = {
agDateInput: DateTimeFilterComponent
};
public dbRecord: any; public dbRecord: any;
public pendingSetup = true; public pendingSetup = true;
public dirty = false; public dirty = false;
@ -189,33 +194,73 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
// Set editors and renderers for different types // Set editors and renderers for different types
if ( x.Type === 'text' ) { if ( x.Type === 'text' ) {
x.editor = 'agTextCellEditor'; x.editor = 'agTextCellEditor';
x.filter = 'agTextColumnFilter';
} else if ( x.Type === 'number' ) { } else if ( x.Type === 'number' ) {
x.cellEditorFramework = NumericEditorComponent; x.cellEditorFramework = NumericEditorComponent;
x.filter = 'agNumberColumnFilter';
} else if ( x.Type === 'paragraph' ) { } else if ( x.Type === 'paragraph' ) {
x.cellEditorFramework = ParagraphEditorComponent; x.cellEditorFramework = ParagraphEditorComponent;
x.filter = 'agTextColumnFilter';
} else if ( x.Type === 'boolean' ) { } else if ( x.Type === 'boolean' ) {
x.cellRendererFramework = BooleanRendererComponent; x.cellRendererFramework = BooleanRendererComponent;
x.cellEditorFramework = BooleanEditorComponent; x.cellEditorFramework = BooleanEditorComponent;
x.suppressSizeToFit = true; x.suppressSizeToFit = true;
} else if ( x.Type === 'select' ) { } else if ( x.Type === 'select' ) {
x.cellEditorFramework = SelectEditorComponent; x.cellEditorFramework = SelectEditorComponent;
x.filter = 'agTextColumnFilter';
} else if ( x.Type === 'multiselect' ) { } else if ( x.Type === 'multiselect' ) {
x.cellEditorFramework = MultiSelectEditorComponent; x.cellEditorFramework = MultiSelectEditorComponent;
x.filter = 'agTextColumnFilter';
} else if ( x.Type === 'datetime' ) { } else if ( x.Type === 'datetime' ) {
x.cellEditorFramework = DatetimeEditorComponent; x.cellEditorFramework = DatetimeEditorComponent;
x.cellRendererFramework = DatetimeRendererComponent; x.cellRendererFramework = DatetimeRendererComponent;
x.filter = 'agDateColumnFilter';
x.filterParams = {
buttons: ['apply', 'clear'],
displayFormat: x.additionalData.format,
comparator: (filterDate: Date, cellValue) => {
if ( !cellValue ) {
return 0;
}
const cellDate = new Date(cellValue);
if ( x.additionalData.format === 'YYYY-MM-DD' ) {
cellDate.setHours(0);
cellDate.setMinutes(0);
cellDate.setSeconds(0);
cellDate.setMilliseconds(0);
} else if ( x.additionalData.format === 'h:mm a' ) {
cellDate.setFullYear(filterDate.getFullYear());
cellDate.setMonth(filterDate.getMonth());
cellDate.setDate(filterDate.getDate());
}
// Now that both parameters are Date objects, we can compare
if (cellDate < filterDate) {
return -1;
} else if (cellDate > filterDate) {
return 1;
} else {
return 0;
}
},
};
} else if ( x.Type === 'currency' ) { } else if ( x.Type === 'currency' ) {
x.cellEditorFramework = NumericEditorComponent; x.cellEditorFramework = NumericEditorComponent;
x.cellRendererFramework = CurrencyRendererComponent; x.cellRendererFramework = CurrencyRendererComponent;
x.filter = 'agNumberColumnFilter';
} else if ( x.Type === 'index' ) { } else if ( x.Type === 'index' ) {
x.editable = false; x.editable = false;
x.suppressSizeToFit = true; x.suppressSizeToFit = true;
x.filter = 'agNumberColumnFilter';
if ( !x.width ) { if ( !x.width ) {
x.width = 80; x.width = 80;
} }
x.minWidth = 80; x.minWidth = 80;
} else if ( x.Type === 'wysiwyg' ) { } else if ( x.Type === 'wysiwyg' ) {
x.cellEditorFramework = WysiwygEditorComponent; x.cellEditorFramework = WysiwygEditorComponent;
x.filter = 'agTextColumnFilter';
} }
return x; return x;

@ -0,0 +1,57 @@
import { Component } from '@angular/core';
@Component({
selector: 'noded-date-time-filter',
template: `
<ion-datetime
[displayFormat]="displayFormat"
class="ag-custom-component-popup"
[(ngModel)]="stringValue"
(ionChange)="onDateChanged()"
></ion-datetime>
`,
styles: [
`
ion-datetime {
border: 2px solid darkgrey;
border-radius: 3px;
margin: 3px;
}
`
],
})
export class DateTimeFilterComponent {
private params: any;
public displayFormat = 'YYYY-MM-DD h:mm a';
public stringValue = '';
public get dateValue() {
return new Date(this.stringValue);
}
public set dateValue(date: Date) {
this.stringValue = date.toISOString();
}
agInit(params: any): void {
this.params = params;
this.displayFormat = params?.filterParams?.displayFormat || 'YYYY-MM-DD h:mm a';
}
onDateChanged() {
this.params.onDateChanged();
}
getDate(): Date {
return this.dateValue;
}
setDate(date?: Date): void {
if ( date ) {
this.dateValue = date;
} else {
this.stringValue = '';
}
}
}

@ -71,7 +71,7 @@
contenteditable contenteditable
appDomChange appDomChange
*ngIf="isFocused" *ngIf="isFocused"
[innerHTML]="initialValue" [innerHTML]="contents"
#editable #editable
(domChange)="onContentsChanged($event)" (domChange)="onContentsChanged($event)"
></div> ></div>

@ -8,12 +8,22 @@ import {Component, EventEmitter, HostListener, Input, OnInit, Output, ViewChild}
export class WysiwygComponent implements OnInit { export class WysiwygComponent implements OnInit {
@ViewChild('editable') editable; @ViewChild('editable') editable;
@Input() readonly = false; @Input() readonly = false;
@Input() contents = ''; @Input() set contents(val: string) {
if ( this.currentContents !== val ) {
this.currentContents = val;
}
}
get contents(): string {
return this.currentContents;
}
@Output() contentsChanged: EventEmitter<string> = new EventEmitter<string>(); @Output() contentsChanged: EventEmitter<string> = new EventEmitter<string>();
public currentContents = '';
public isFocused = false; public isFocused = false;
protected hadOneFocusOut = false; protected hadOneFocusOut = false;
public initialValue = '';
protected isEditOnly = false; protected isEditOnly = false;
public get editonly() { public get editonly() {
@ -37,9 +47,7 @@ export class WysiwygComponent implements OnInit {
return document.body.classList.contains('dark'); return document.body.classList.contains('dark');
} }
ngOnInit() { ngOnInit() { }
this.initialValue = this.contents;
}
onFocusIn(event: MouseEvent) { onFocusIn(event: MouseEvent) {
console.log('on focus in', event); console.log('on focus in', event);

Loading…
Cancel
Save