doc comments

pull/35/head
Ondřej Hruška 6 years ago
parent 4570239548
commit 786c18cec9
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 23
      resources/assets/js/components/ColumnEditor.vue
  2. 8
      resources/assets/js/components/RowsEditor.vue

@ -170,10 +170,12 @@ export default {
} }
}, },
methods: { methods: {
/** Send a query to the server */
query (data, sucfn, erfn) { query (data, sucfn, erfn) {
query(this.route, data, sucfn, erfn) query(this.route, data, sucfn, erfn)
}, },
/** Add a column at the end */
addCol () { addCol () {
if (this.newTable) { if (this.newTable) {
this.columns.push({ this.columns.push({
@ -191,17 +193,25 @@ export default {
} }
}, },
move (i, dir) { /** Swap column in either direction (+1 or -1) */
let cur = this.columns[i] move (pos1, dir) {
let next = this.columns[i + dir] let pos2 = pos1 + dir
this.$set(this.columns, i, next) if (pos2 < 0 || pos2 >= this.columns.length) {
this.$set(this.columns, i + dir, cur) 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) { markColNeedSave(i) {
this.$set(this.columns[i], '_dirty', true) this.$set(this.columns[i], '_dirty', true)
}, },
/** User started dragging a column */
beginDrag (i, evt) { beginDrag (i, evt) {
const column = this.columns[i] const column = this.columns[i]
column._dragging = true column._dragging = true
@ -241,6 +251,7 @@ export default {
$(window).on('mouseup', dragEndListener) $(window).on('mouseup', dragEndListener)
}, },
/** Compute classes for the column's delete button */
delBtnClass(col) { delBtnClass(col) {
return [ return [
'btn', 'btn',
@ -251,6 +262,7 @@ export default {
] ]
}, },
/** Save a column */
saveCol(n) { saveCol(n) {
let col = this.columns[n] let col = this.columns[n]
if (_.isUndefined(col)) return if (_.isUndefined(col)) return
@ -267,6 +279,7 @@ export default {
}) })
}, },
/** Delete / undelete a column; New columns vanish. */
toggleColDelete(n) { toggleColDelete(n) {
let col = this.columns[n] let col = this.columns[n]
if (_.isUndefined(col)) return if (_.isUndefined(col)) return

@ -79,10 +79,12 @@ Rows are identified by row._id, columns by col.id
} }
}, },
methods: { methods: {
/** Send a query to the server */
query (data, sucfn, erfn) { query (data, sucfn, erfn) {
query(this.route, 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) { toggleRowDelete (_id) {
if (!_.isDefined(this.rows[_id])) return 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) { submitRowChange (row) {
this.query({ this.query({
action: 'row.update', 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) { toggleRowEditing (_id) {
if (this.rows[_id]._remove) return false // can't edit row marked for removal if (this.rows[_id]._remove) return false // can't edit row marked for removal
let editing = !this.rows[_id]._editing 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) { colClasses (col) {
return [ return [
'border-top-0', 'border-top-0',
@ -138,6 +143,7 @@ Rows are identified by row._id, columns by col.id
] ]
}, },
/** Compute style for a row */
rowStyle (row) { rowStyle (row) {
return { return {
opacity: row._remove ? .8 : 1, 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) { isChanged (row, colId) {
return row._changed && row._changed.indexOf(colId) > -1 return row._changed && row._changed.indexOf(colId) > -1
}, },
/** Revert a value cell */
revertCell (row, colId) { revertCell (row, colId) {
this.submitRowChange(_.merge({}, row, {[colId]: row._orig[colId]})) this.submitRowChange(_.merge({}, row, {[colId]: row._orig[colId]}))
} }

Loading…
Cancel
Save