From 9ec5a151cc31343aebc89de25d8fe22b7a50e156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 11 Aug 2018 19:30:55 +0200 Subject: [PATCH] Fixes in value revert logic --- app/Tables/Changeset.php | 15 +++++++++++---- resources/assets/js/components/RowsEditor.vue | 14 +++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/Tables/Changeset.php b/app/Tables/Changeset.php index ed0b6a5..ad2aabd 100644 --- a/app/Tables/Changeset.php +++ b/app/Tables/Changeset.php @@ -178,7 +178,7 @@ class Changeset */ public function transformRow($row, $decorate) { - if ($row instanceof Row) $row = (object)$row->getAttributes(); + if ($row instanceof Row) $row = (object)$row->getAttributes(); // row must be in the rowData() format if ($decorate) { $row->_remove = false; @@ -220,7 +220,12 @@ class Changeset if ($decorate) { $row->_changed = array_keys($newVals); - $row->_orig = array_only((array)$row, $row->_changed); + $row->_orig = array_diff((array)$row, []); + unset($row->_orig['_id']); + unset($row->_orig['_new']); + unset($row->_orig['_remove']); + unset($row->_orig['_changed']); + unset($row->_orig['_orig']); } $row = (object)array_merge((array)$row, $newVals); @@ -231,6 +236,7 @@ class Changeset if (!$decorate) { foreach ($this->removedColumns as $colId) { unset($row->$colId); + unset($row->_orig[$colId]); } } @@ -456,9 +462,10 @@ class Changeset $col = $cols[$colId]; $value = $col->cast($value); - $origValue = $col->cast(isset($origRow->$colId) ? $origRow->$colId : null); + $origValue = isset($origRow->$colId) ? $origRow->$colId : null; + $origValueCast = $col->cast($origValue); - if ($value !== $origValue) { + if ($value !== $origValueCast && !($origValue===null&&$value==="")) { // fix for null in numeric cols being forcibly populated and sticking as change $updateObj[$colId] = $value; } } diff --git a/resources/assets/js/components/RowsEditor.vue b/resources/assets/js/components/RowsEditor.vue index 4b88110..7ceb3ad 100644 --- a/resources/assets/js/components/RowsEditor.vue +++ b/resources/assets/js/components/RowsEditor.vue @@ -290,9 +290,17 @@ Rows are identified by row._id, columns by col.id let wasDirty = this.isRowChanged(row, true) let changes = [] - _.each(row._orig, (v, k) => { - if (row[k] != v) { - changes.push(k) + _.each(this.columns, (col) => { + let val = row[col.id]; + let orig = row._orig[col.id]; + if (_.isUndefined(orig)) { + // null in DB + if (val !== '' && val !== 0) { + changes.push(col.id) + console.log('is dirty', JSON.stringify(val)) + } + } else if (val != orig) { + changes.push(col.id) } })