|
|
@ -6,6 +6,7 @@ namespace App\Tables; |
|
|
|
use App\Models\Revision; |
|
|
|
use App\Models\Revision; |
|
|
|
use App\Models\Row; |
|
|
|
use App\Models\Row; |
|
|
|
use App\Models\Table; |
|
|
|
use App\Models\Table; |
|
|
|
|
|
|
|
use Illuminate\Pagination\Paginator; |
|
|
|
use Illuminate\Queue\SerializesModels; |
|
|
|
use Illuminate\Queue\SerializesModels; |
|
|
|
use Illuminate\Support\Collection; |
|
|
|
use Illuminate\Support\Collection; |
|
|
|
use MightyPork\Exceptions\NotExistException; |
|
|
|
use MightyPork\Exceptions\NotExistException; |
|
|
@ -186,7 +187,7 @@ class Changeset |
|
|
|
$row->_orig = []; |
|
|
|
$row->_orig = []; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Removed rows |
|
|
|
// Removed rows - return as null |
|
|
|
if (in_array($row->_id, $this->removedRows)) { |
|
|
|
if (in_array($row->_id, $this->removedRows)) { |
|
|
|
if ($decorate) { |
|
|
|
if ($decorate) { |
|
|
|
$row->_remove = true; |
|
|
|
$row->_remove = true; |
|
|
@ -195,16 +196,19 @@ class Changeset |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Changed values |
|
|
|
// if marked for removal, hide changes |
|
|
|
if (isset($this->rowUpdates[$row->_id])) { |
|
|
|
if (!$row->_remove) { |
|
|
|
$newVals = $this->rowUpdates[$row->_id]; |
|
|
|
// Changed values |
|
|
|
|
|
|
|
if (isset($this->rowUpdates[$row->_id])) { |
|
|
|
|
|
|
|
$newVals = $this->rowUpdates[$row->_id]; |
|
|
|
|
|
|
|
|
|
|
|
if ($decorate) { |
|
|
|
if ($decorate) { |
|
|
|
$row->_changed = array_keys($newVals); |
|
|
|
$row->_changed = array_keys($newVals); |
|
|
|
$row->_orig = array_only((array)$row, $row->_changed); |
|
|
|
$row->_orig = array_only((array)$row, $row->_changed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$row = (object)array_merge((array)$row, $newVals); |
|
|
|
$row = (object)array_merge((array)$row, $newVals); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Drop deleted columns |
|
|
|
// Drop deleted columns |
|
|
@ -300,8 +304,16 @@ class Changeset |
|
|
|
return (object)$r->getAttributes(); |
|
|
|
return (object)$r->getAttributes(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Apply a row update, adding the row to the list of changes, or removing it |
|
|
|
|
|
|
|
* if all differences were undone. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param array|object $newVals |
|
|
|
|
|
|
|
*/ |
|
|
|
public function rowUpdate($newVals) |
|
|
|
public function rowUpdate($newVals) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
$newVals = (object)$newVals; |
|
|
|
|
|
|
|
|
|
|
|
$_id = $newVals->_id; |
|
|
|
$_id = $newVals->_id; |
|
|
|
$origRow = $this->fetchRow($_id); |
|
|
|
$origRow = $this->fetchRow($_id); |
|
|
|
|
|
|
|
|
|
|
@ -309,8 +321,6 @@ class Changeset |
|
|
|
$cols = collect($this->fetchAndTransformColumns())->keyBy('id'); |
|
|
|
$cols = collect($this->fetchAndTransformColumns())->keyBy('id'); |
|
|
|
|
|
|
|
|
|
|
|
$updateObj = []; |
|
|
|
$updateObj = []; |
|
|
|
\Debugbar::addMessage(json_encode($cols)); |
|
|
|
|
|
|
|
\Debugbar::addMessage(var_export($newVals, true)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($newVals as $colId => $value) { |
|
|
|
foreach ($newVals as $colId => $value) { |
|
|
|
if (starts_with($colId, '_')) continue; // internals |
|
|
|
if (starts_with($colId, '_')) continue; // internals |
|
|
@ -320,10 +330,6 @@ class Changeset |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
\Debugbar::addMessage("New: ".json_encode($newVals)); |
|
|
|
|
|
|
|
\Debugbar::addMessage("Orig: ".json_encode($origRow)); |
|
|
|
|
|
|
|
\Debugbar::addMessage("UpdateObj: ".json_encode($updateObj)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($updateObj)) { |
|
|
|
if (!empty($updateObj)) { |
|
|
|
$this->rowUpdates[$_id] = $updateObj; |
|
|
|
$this->rowUpdates[$_id] = $updateObj; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -331,4 +337,15 @@ class Changeset |
|
|
|
unset($this->rowUpdates[$_id]); |
|
|
|
unset($this->rowUpdates[$_id]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get a page of added rows for display in the editor |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param int $perPage |
|
|
|
|
|
|
|
* @return \Illuminate\Pagination\LengthAwarePaginator|Collection|array |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getAddedRows(int $perPage = 25) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return collection_paginate($this->newRows, $perPage); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|