diff --git a/resources/assets/js/components/ColumnEditor.vue b/resources/assets/js/components/ColumnEditor.vue index 99bbe93..14335f2 100644 --- a/resources/assets/js/components/ColumnEditor.vue +++ b/resources/assets/js/components/ColumnEditor.vue @@ -170,10 +170,12 @@ export default { } }, methods: { + /** Send a query to the server */ query (data, sucfn, erfn) { query(this.route, data, sucfn, erfn) }, + /** Add a column at the end */ addCol () { if (this.newTable) { this.columns.push({ @@ -191,17 +193,25 @@ export default { } }, - move (i, dir) { - let cur = this.columns[i] - let next = this.columns[i + dir] - this.$set(this.columns, i, next) - this.$set(this.columns, i + dir, cur) + /** Swap column in either direction (+1 or -1) */ + move (pos1, dir) { + let pos2 = pos1 + dir + if (pos2 < 0 || pos2 >= this.columns.length) { + console.warn(`Attempted to move out of bounds (${pos1} -> ${pos2})`) + return; + } + let col1 = this.columns[pos1] + let col2 = this.columns[pos2] + this.$set(this.columns, pos1, col2) + this.$set(this.columns, pos2, col1) }, + /** Indicate a column is dirty and needs saving */ markColNeedSave(i) { this.$set(this.columns[i], '_dirty', true) }, + /** User started dragging a column */ beginDrag (i, evt) { const column = this.columns[i] column._dragging = true @@ -241,6 +251,7 @@ export default { $(window).on('mouseup', dragEndListener) }, + /** Compute classes for the column's delete button */ delBtnClass(col) { return [ 'btn', @@ -251,6 +262,7 @@ export default { ] }, + /** Save a column */ saveCol(n) { let col = this.columns[n] if (_.isUndefined(col)) return @@ -267,6 +279,7 @@ export default { }) }, + /** Delete / undelete a column; New columns vanish. */ toggleColDelete(n) { let col = this.columns[n] if (_.isUndefined(col)) return diff --git a/resources/assets/js/components/RowsEditor.vue b/resources/assets/js/components/RowsEditor.vue index 4da3783..247f75a 100644 --- a/resources/assets/js/components/RowsEditor.vue +++ b/resources/assets/js/components/RowsEditor.vue @@ -79,10 +79,12 @@ Rows are identified by row._id, columns by col.id } }, methods: { + /** Send a query to the server */ query (data, sucfn, erfn) { query(this.route, data, sucfn, erfn) }, + /** Toggle row delete status, remove new rows (when using the editor widget for added rows) */ toggleRowDelete (_id) { if (!_.isDefined(this.rows[_id])) return @@ -103,6 +105,7 @@ Rows are identified by row._id, columns by col.id }) }, + /** Save a change */ submitRowChange (row) { this.query({ action: 'row.update', @@ -116,6 +119,7 @@ Rows are identified by row._id, columns by col.id }) }, + /** Toggle editing state - edit or save */ toggleRowEditing (_id) { if (this.rows[_id]._remove) return false // can't edit row marked for removal let editing = !this.rows[_id]._editing @@ -127,6 +131,7 @@ Rows are identified by row._id, columns by col.id } }, + /** Compute classes for a value cell */ colClasses (col) { return [ 'border-top-0', @@ -138,6 +143,7 @@ Rows are identified by row._id, columns by col.id ] }, + /** Compute style for a row */ rowStyle (row) { return { opacity: row._remove ? .8 : 1, @@ -147,10 +153,12 @@ Rows are identified by row._id, columns by col.id } }, + /** Test if a value cell is changed */ isChanged (row, colId) { return row._changed && row._changed.indexOf(colId) > -1 }, + /** Revert a value cell */ revertCell (row, colId) { this.submitRowChange(_.merge({}, row, {[colId]: row._orig[colId]})) }