Column order saving to Changeset

This commit is contained in:
2018-08-10 13:11:50 +02:00
parent 1fbd3384ce
commit aceb0453fc
4 changed files with 33 additions and 1 deletions
+15 -1
View File
@@ -265,7 +265,9 @@ class Changeset
$colsById = collect($columns)->keyBy('id')->all();
$newOrder = [];
foreach ($this->columnOrder as $id) {
$newOrder[] = $colsById[$id];
if (isset($colsById[$id])) {
$newOrder[] = $colsById[$id];
}
}
$leftover_keys = array_diff(array_keys($colsById), $this->columnOrder);
@@ -455,6 +457,8 @@ class Changeset
{
if ($this->isNewColumn($id)) {
unset($this->newColumns[$id]);
// remove it from order
$this->columnOrder = array_diff($this->columnOrder, [$id]);
}
else {
$this->removedColumns[] = $id;
@@ -573,4 +577,14 @@ class Changeset
$this->newColumns[$cid] = $col;
return $col;
}
public function setColOrder(array $order)
{
$allCols = $this->fetchAndTransformColumns();
$ids = collect($allCols)->pluck('id')->all();
$order = array_intersect($order, $ids);
$missing = array_diff($ids, $order);
$this->columnOrder = array_merge($order, $missing);
}
}