setItem(key: string, val: any, isJson?: Boolean): Promise<void> {
// TODO: route keys appropriately
- this.setLocalItem(key, val, false);
+ this.setLocalItem(key, val, isJson);
return Promise.resolve();
}
setLocalItem(key: string, val: any, isJson?: Boolean): void {
if (!isJson) val = JSON.stringify(val);
+ console.log(`${key} ${val}`);
window.localStorage.setItem(key, val);
}
<span class="material-icons">compare_arrows</span>
<span class="ml-2" i18n>Manage Column Widths</span>
</a>
+ <a class="dropdown-item label-with-material-icon"
+ (click)="saveColumns()">
+ <span class="material-icons">save</span>
+ <span class="ml-2" i18n>Save Columns</span>
+ </a>
+
<div class="dropdown-divider"></div>
<a class="dropdown-item label-with-material-icon"
@Input() toolbarButtons: EgGridToolbarButton[];
@Input() columnSet: EgGridColumnSet;
@Input() colWidthConfig: EgGridColumnWidthComponent;
+ @Input() persistKey: string;
+
+ constructor(private gridSvc: EgGridService) {}
ngOnInit() {
this.pager.onChange$.subscribe(
val => this.dataSource.requestPage(this.pager));
}
+
+ saveColumns() {
+ // TODO: when server-side settings are supported, this operation
+ // may offer to save to user/workstation OR org unit settings
+ // depending on perms.
+
+ this.gridSvc.saveColumns(this.columnSet, this.persistKey)
+ .then(
+ // hide the with config after saving
+ ok => this.colWidthConfig.isVisible = false,
+ err => console.error(`Error saving columns: ${err}`)
+ );
+ }
}
<eg-grid-toolbar
[dataSource]="dataSource" [pager]="pager"
[toolbarButtons]="toolbarButtons" [columnSet]="columnSet"
- [colWidthConfig]="colWidthConfig">
+ [colWidthConfig]="colWidthConfig" persistKey="{{persistKey}}">
</eg-grid-toolbar>
<eg-grid-header [columnSet]="columnSet" [dataSource]="dataSource"></eg-grid-header>
<eg-grid-column-width #colWidthConfig [columnSet]="columnSet"></eg-grid-column-width>
import {EgIdlService, EgIdlObject} from '@eg/core/idl.service';
import {EgOrgService} from '@eg/core/org.service';
import {EgPcrudService} from '@eg/core/pcrud.service';
+import {EgStoreService} from '@eg/core/store.service';
@Injectable()
constructor(
private idl: EgIdlService,
private org: EgOrgService,
+ private store: EgStoreService,
private pcrud: EgPcrudService
) {
}
return columnSet;
}
+
+
+ saveColumns(columnSet: EgGridColumnSet, persistKey: string): Promise<any> {
+ if (!persistKey)
+ throw new Error('Grid persistKey required to save columns');
+ let compiled = columnSet.compileSaveObject();
+ return this.store.setItem('eg.grid.' + persistKey, compiled);
+ }
+
+ // TODO: saveColumnsAsOrgSetting(...)
}
path: string;
label: string;
flex: number;
+ align: string;
hidden: boolean;
visible: boolean;
sort: number;
if (col.isPkey) this.pkeyColumn = col;
if (!col.flex) col.flex = 2;
if (!col.label) col.label = col.name;
+ if (!col.align) col.align = 'left';
col.visible = !col.hidden;
this.columns.splice(targetIdx, 0, col);
}
+ compileSaveObject() {
+ // only store information about visible columns.
+ let conf = this.displayColumns();
+
+ // scrunch the data down to just the needed info
+ return conf.map(col => {
+ let c: any = {name : col.name}
+ if (col.align != 'left') c.align = col.align;
+ if (col.flex != 2) c.flex = col.flex;
+ if (Number(col.sort)) c.sort = Number(c.sort);
+ return c;
+ });
+ }
+
}
export class EgGridToolbarButton {
<eg-staff-banner bannerText="Billing Type Configuration" i18n-bannerText>
</eg-staff-banner>
-<eg-grid #btGrid idlClass="cbt" [dataSource]="dataSource" [isSortable]="true">
+<eg-grid #btGrid idlClass="cbt" [dataSource]="dataSource"
+ [isSortable]="true" persistKey="admin.server.config.billing_type">
<eg-grid-toolbar-button label="New Billing Type" i18n-label [action]="createBillingType">
</eg-grid-toolbar-button>
</eg-grid>