Database - in place updates to preserve editing flow
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

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

@ -38,6 +38,7 @@
[style]="fullPage ? 'width: 100%; height: 100%;' : 'width: 100%; height: 500px;'" [style]="fullPage ? 'width: 100%; height: 100%;' : 'width: 100%; height: 500px;'"
[ngClass]="isDark() ? 'ag-theme-balham-dark' : 'ag-theme-balham'" [ngClass]="isDark() ? 'ag-theme-balham-dark' : 'ag-theme-balham'"
[rowData]="rowData" [rowData]="rowData"
[getRowNodeId]="getRowNodeId"
[columnDefs]="columnDefs" [columnDefs]="columnDefs"
[singleClickEdit]="true" [singleClickEdit]="true"
[enterMovesDownAfterEdit]="true" [enterMovesDownAfterEdit]="true"

@ -15,7 +15,7 @@ import {BooleanRendererComponent} from './renderers/boolean-renderer.component';
import {EditorNodeContract} from '../../nodes/EditorNode.contract'; 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, uuid_v4} from '../../../utility';
import {DateTimeFilterComponent} from './filters/date-time.filter'; import {DateTimeFilterComponent} from './filters/date-time.filter';
import {DatabasePageComponent} from './database-page.component'; import {DatabasePageComponent} from './database-page.component';
import {PageLinkRendererComponent} from './renderers/page-link-renderer.component'; import {PageLinkRendererComponent} from './renderers/page-link-renderer.component';
@ -416,17 +416,40 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
}); });
} }
public getRowNodeId(data: any) {
if ( !data.UUID ) {
data.UUID = uuid_v4();
}
return data.UUID;
}
protected getAllRows() {
const rowData: any[] = [];
this.agGridElement.api.forEachNode(node => {
if ( !node.data.UUID ) {
node.data.UUID = uuid_v4();
}
rowData.push(node.data);
});
return rowData;
}
public async performSave(): Promise<void> { public async performSave(): Promise<void> {
// Save the columns first // Save the columns first
await this.api.saveDatabaseColumns(this.page.UUID, this.node.UUID, this.node.Value.Value, this.getSaveColumns()); await this.api.saveDatabaseColumns(this.page.UUID, this.node.UUID, this.node.Value.Value, this.getSaveColumns());
// Save the data // Save the data
const rows = await this.api.saveDatabaseEntries(this.page.UUID, this.node.UUID, this.node.Value.Value, this.rowData); const allRows = this.getAllRows();
this.rowData = rows.map(x => x.RowData); const rows = await this.api.saveDatabaseEntries(this.page.UUID, this.node.UUID, this.node.Value.Value, allRows);
// this.rowData = rows.map(x => x.RowData);
// Dynamically update the row data to avoid breaking open editors // Dynamically update the row data to avoid breaking open editors
const rowUUIDs = this.rowData.map(x => x.UUID); const returnedUUIDs = rows.map(x => x.UUID);
const gridUUIDs = []; const existingUUIDs = [];
const rowDataTransaction = { const rowDataTransaction = {
add: [], add: [],
@ -436,11 +459,11 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
this.agGridElement.api.forEachNode((rowNode, index) => { this.agGridElement.api.forEachNode((rowNode, index) => {
const data = rowNode.data; const data = rowNode.data;
if ( !data.UUID || !rowUUIDs.includes(data.UUID) ) { if ( !returnedUUIDs.includes(data.UUID) ) {
rowDataTransaction.remove.push(rowNode.id); rowDataTransaction.remove.push(rowNode.id);
} else { } else {
gridUUIDs.push(data.UUID); existingUUIDs.push(data.UUID);
const updatedRow = this.rowData.find(x => x.UUID === data.UUID); const updatedRow = rows.find(x => x.UUID === data.UUID);
if ( updatedRow ) { if ( updatedRow ) {
for ( const prop in updatedRow ) { for ( const prop in updatedRow ) {
@ -456,11 +479,11 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
} }
}); });
for ( const row of this.rowData ) { // for ( const row of rows ) {
if ( !gridUUIDs.includes(row.UUID) ) { // if ( !gridUUIDs.includes(row.UUID) ) {
rowDataTransaction.add.push(row); // rowDataTransaction.add.push(row);
} // }
} // }
// @ts-ignore // @ts-ignore
this.agGridElement.api.applyTransaction(rowDataTransaction); this.agGridElement.api.applyTransaction(rowDataTransaction);

@ -1046,7 +1046,7 @@ export class ApiService {
for ( const row of rowData ) { for ( const row of rowData ) {
const newDatabaseEntry = new DatabaseEntry( const newDatabaseEntry = new DatabaseEntry(
DatabaseId, DatabaseId,
DatabaseEntry.getUUID(), row.UUID || DatabaseEntry.getUUID(),
JSON.stringify(row), JSON.stringify(row),
true true
); );

Loading…
Cancel
Save