diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index 8f84bcf..2633bd5 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -31,7 +31,7 @@ class TableController extends Controller ->where('name', $table)->first(); if ($tableModel === null) abort(404, "No such table."); - // make it possible to show other revisions + // option to show other revisions if ($input->has('rev')) { $rev = (int)$input->rev; $revision = $tableModel->revisions()->orderBy('created_at')->skip($rev - 1)->first(); @@ -54,6 +54,28 @@ class TableController extends Controller ]); } + public function draftChange(Request $request, User $user, string $table) + { + /** @var Table $tableModel */ + $tableModel = $user->tables()->with('revision')->where('name', $table)->first(); + if ($tableModel === null) abort(404, "No such table."); + + $revision = $tableModel->revision; + + $columns = Column::columnsFromJson($revision->columns); + + $rows = $revision->rowsData($columns)->paginate(25, []); + + // TODO instantiate changeset and store it in session + + return view('table.view', [ + 'table' => $tableModel, + 'revision' => $revision, + 'columns' => $columns, + 'rows' => $rows, + ]); + } + public function delete(Request $request, User $user, string $table) { /** @var Table $tableModel */ diff --git a/app/Tables/Changeset.php b/app/Tables/Changeset.php new file mode 100644 index 0000000..39cfe88 --- /dev/null +++ b/app/Tables/Changeset.php @@ -0,0 +1,69 @@ + values, ...] + */ + public $rowUpdates; + + /** + * New rows in the full Row::data format, including GRIDs. + * Values are identified by GCIDs from previously defined, or new columns. + * + * @var array|null - [[_id:..., ...], [..., ...], ...] + */ + public $newRows; + + /** + * Rows to be removed + * + * @var int[]|null - GRIDs + */ + public $removedRows; + + /** + * Values changed in column specifications, such as name, title, etc. + * This does not affect the table rows in any way. + * + * @var array[] - column specification objects, with GCIDs + */ + public $columnUpdates; + + /** + * New columns in the full format, including GCIDs + * + * @var array|null - [[id:..., ...], [..., ...], ...] + */ + public $newColumns; + + /** + * When reordering columns, here is the column IDs array + * in the new order. Columns meanwhile removed from the table + * or added to it are to be ignored or appended at the end. + * + * This shall not be filled if merely editing or adding columns, + * unless the order is explicitly adjusted by the user. + * + * @var string[]|null - GCIDs + */ + public $columnOrder; + + /** + * Columns to be removed + * + * The data associated to those columns may or may not be removed from the Rows. + * It does not matter, other than in regard to the table size. + * + * @var int[]|null - GCIDs + */ + public $removedColumns; +}