Column order saving to Changeset
This commit is contained in:
@@ -188,6 +188,11 @@ class TableEditController extends Controller
|
|||||||
$resp = $changeset->addBlankCol();
|
$resp = $changeset->addBlankCol();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'col.sort':
|
||||||
|
$changeset->setColOrder($input->order);
|
||||||
|
$resp = null;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$resp = "Bad Action";
|
$resp = "Bad Action";
|
||||||
$code = 400;
|
$code = 400;
|
||||||
|
|||||||
@@ -265,7 +265,9 @@ class Changeset
|
|||||||
$colsById = collect($columns)->keyBy('id')->all();
|
$colsById = collect($columns)->keyBy('id')->all();
|
||||||
$newOrder = [];
|
$newOrder = [];
|
||||||
foreach ($this->columnOrder as $id) {
|
foreach ($this->columnOrder as $id) {
|
||||||
$newOrder[] = $colsById[$id];
|
if (isset($colsById[$id])) {
|
||||||
|
$newOrder[] = $colsById[$id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$leftover_keys = array_diff(array_keys($colsById), $this->columnOrder);
|
$leftover_keys = array_diff(array_keys($colsById), $this->columnOrder);
|
||||||
@@ -455,6 +457,8 @@ class Changeset
|
|||||||
{
|
{
|
||||||
if ($this->isNewColumn($id)) {
|
if ($this->isNewColumn($id)) {
|
||||||
unset($this->newColumns[$id]);
|
unset($this->newColumns[$id]);
|
||||||
|
// remove it from order
|
||||||
|
$this->columnOrder = array_diff($this->columnOrder, [$id]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$this->removedColumns[] = $id;
|
$this->removedColumns[] = $id;
|
||||||
@@ -573,4 +577,14 @@ class Changeset
|
|||||||
$this->newColumns[$cid] = $col;
|
$this->newColumns[$cid] = $col;
|
||||||
return $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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ export default {
|
|||||||
newColNum: 0,
|
newColNum: 0,
|
||||||
columns: this.xColumns,
|
columns: this.xColumns,
|
||||||
colTypes: ['string', 'int', 'float', 'bool'],
|
colTypes: ['string', 'int', 'float', 'bool'],
|
||||||
|
debouncedSortUpdate: _.debounce(() => this.submitColOrder(), 350)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -200,6 +201,14 @@ export default {
|
|||||||
query(this.route, data, sucfn, erfn)
|
query(this.route, data, sucfn, erfn)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
submitColOrder() {
|
||||||
|
let ids = this.columns.map((c) => c.id)
|
||||||
|
this.query ({
|
||||||
|
action: 'col.sort',
|
||||||
|
order: ids,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
colPos(col) {
|
colPos(col) {
|
||||||
for (let n = 0; n < this.columns.length; n++) {
|
for (let n = 0; n < this.columns.length; n++) {
|
||||||
if (this.columns[n].id == col.id) return n;
|
if (this.columns[n].id == col.id) return n;
|
||||||
@@ -261,6 +270,8 @@ export default {
|
|||||||
// Put focus on the new field
|
// Put focus on the new field
|
||||||
// For some reason, it loses it when moving down
|
// For some reason, it loses it when moving down
|
||||||
setTimeout(() => this.$refs[`col${pos2}-sort`][0].focus(), 0)
|
setTimeout(() => this.$refs[`col${pos2}-sort`][0].focus(), 0)
|
||||||
|
|
||||||
|
this.debouncedSortUpdate();
|
||||||
},
|
},
|
||||||
|
|
||||||
/** User started dragging a column */
|
/** User started dragging a column */
|
||||||
@@ -368,6 +379,7 @@ export default {
|
|||||||
this.submitColChange(_.merge({}, col, {[cell]: col._orig[cell]}))
|
this.submitColChange(_.merge({}, col, {[cell]: col._orig[cell]}))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** compute styles for a field cell */
|
||||||
tdWidthStyle(cell) {
|
tdWidthStyle(cell) {
|
||||||
let w = 10;
|
let w = 10;
|
||||||
if (cell == 'name') w = '14'
|
if (cell == 'name') w = '14'
|
||||||
|
|||||||
Vendored
+1
@@ -5,6 +5,7 @@ export { default as isUndefined } from 'lodash/isUndefined'
|
|||||||
export { default as merge } from 'lodash/merge'
|
export { default as merge } from 'lodash/merge'
|
||||||
export { default as unset } from 'lodash/unset'
|
export { default as unset } from 'lodash/unset'
|
||||||
export { default as isEmpty } from 'lodash/isEmpty'
|
export { default as isEmpty } from 'lodash/isEmpty'
|
||||||
|
export { default as debounce } from 'lodash/debounce'
|
||||||
|
|
||||||
function isDefined (x) {
|
function isDefined (x) {
|
||||||
return typeof x !== 'undefined'
|
return typeof x !== 'undefined'
|
||||||
|
|||||||
Reference in New Issue
Block a user