UX improvements in table editor

This commit is contained in:
2018-08-10 18:11:34 +02:00
parent c642774316
commit 1e183f5059
24 changed files with 654 additions and 405 deletions
+25 -2
View File
@@ -191,6 +191,13 @@ class Changeset
if ($this->isNewRow($row->_id)) {
if ($decorate) {
$row->_new = true;
$row->_orig = array_diff((array)$row, []);
// remove junk
unset($row->_orig['_id']);
unset($row->_orig['_new']);
unset($row->_orig['_remove']);
unset($row->_orig['_changed']);
unset($row->_orig['_orig']);
}
return $row;
}
@@ -359,7 +366,9 @@ class Changeset
public function fetchRow(int $id)
{
if ($this->isNewRow($id)) {
return (object)$this->newRows[$id];
$nr = (object)$this->newRows[$id];
$nr->_new = true;
return $nr;
}
$r = $this->revision->rowsData($this->fetchColumns(), true, false)
@@ -557,7 +566,8 @@ class Changeset
$rows = self::csvToRowsArray($columns, $csvArray, false)
->keyBy('_id');
$this->newRows = array_merge($this->newRows, $rows->all());
// using '+' to avoid renumbering
$this->newRows = $this->newRows + $rows->toArray();
}
public function addBlankCol()
@@ -587,4 +597,17 @@ class Changeset
$this->columnOrder = array_merge($order, $missing);
}
public function removeEmptyNewRows()
{
$cols = $this->fetchColumns();
$emptyTpl = collect($cols)->keyBy('id')->map(function(Column $c) {
return $c->cast(null);
})->all();
$this->newRows = array_filter($this->newRows, function ($r) use ($emptyTpl) {
$emptyTpl['_id'] = $r['_id'];
return $emptyTpl != $r;
});
}
}