mirror of
https://github.com/nocodb/nocodb.git
synced 2026-04-29 14:06:45 +00:00
refactor(gui): linting
Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
This commit is contained in:
@@ -9,98 +9,96 @@ export default {
|
||||
showFields: {},
|
||||
// fieldList: [],
|
||||
// meta: {},
|
||||
data: [],
|
||||
data: []
|
||||
}),
|
||||
methods: {
|
||||
mapFieldsAndShowFields() {
|
||||
mapFieldsAndShowFields () {
|
||||
// this.fieldList = this.availableColumns.map(c => c._cn);
|
||||
this.showFields = this.fieldList.reduce((obj, k) => {
|
||||
obj[k] = k in this.showFields ? this.showFields[k] : true;
|
||||
return obj;
|
||||
}, {});
|
||||
obj[k] = k in this.showFields ? this.showFields[k] : true
|
||||
return obj
|
||||
}, {})
|
||||
},
|
||||
syncDataDebounce() {
|
||||
syncDataDebounce () {
|
||||
// not implemented
|
||||
},
|
||||
onKeyDown(e) {
|
||||
if (this.selected.col === null || this.selected.row === null) return;
|
||||
onKeyDown (e) {
|
||||
if (this.selected.col === null || this.selected.row === null) { return }
|
||||
switch (e.keyCode) {
|
||||
// left
|
||||
case 37:
|
||||
if (this.selected.col > 0) this.selected.col--;
|
||||
break;
|
||||
if (this.selected.col > 0) { this.selected.col-- }
|
||||
break
|
||||
// right
|
||||
case 39:
|
||||
if (this.selected.col < this.colLength - 1) this.selected.col++;
|
||||
break;
|
||||
if (this.selected.col < this.colLength - 1) { this.selected.col++ }
|
||||
break
|
||||
// up
|
||||
case 38:
|
||||
if (this.selected.row > 0) this.selected.row--;
|
||||
break;
|
||||
if (this.selected.row > 0) { this.selected.row-- }
|
||||
break
|
||||
// down
|
||||
case 40:
|
||||
if (this.selected.row < this.rowLength - 1) this.selected.row++;
|
||||
break;
|
||||
if (this.selected.row < this.rowLength - 1) { this.selected.row++ }
|
||||
break
|
||||
// enter
|
||||
case 13:
|
||||
this.makeEditable(this.selected.col, this.selected.row)
|
||||
break;
|
||||
break
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isLocked() {
|
||||
isLocked () {
|
||||
return this.viewStatus && this.viewStatus.type === 'locked'
|
||||
},
|
||||
fieldList() {
|
||||
return this.availableColumns.map(c => {
|
||||
return c._cn;
|
||||
fieldList () {
|
||||
return this.availableColumns.map((c) => {
|
||||
return c._cn
|
||||
})
|
||||
},
|
||||
realFieldList() {
|
||||
return this.availableRealColumns.map(c => {
|
||||
return c._cn;
|
||||
realFieldList () {
|
||||
return this.availableRealColumns.map((c) => {
|
||||
return c._cn
|
||||
})
|
||||
},
|
||||
availableRealColumns() {
|
||||
availableRealColumns () {
|
||||
return this.availableColumns && this.availableColumns.filter(c => !c.virtual)
|
||||
},
|
||||
availableColumns() {
|
||||
let columns = [];
|
||||
availableColumns () {
|
||||
let columns = []
|
||||
|
||||
// todo: generate hideCols based on default values
|
||||
const hideCols = ['created_at', 'updated_at'];
|
||||
const hideCols = ['created_at', 'updated_at']
|
||||
|
||||
if (this.showSystemFields) {
|
||||
columns = this.meta.columns || [];
|
||||
columns = this.meta.columns || []
|
||||
} else if (this.data && this.data.length) {
|
||||
columns = (this.meta.columns.filter(c => !(c.pk && c.ai)
|
||||
&& !((this.meta.v || []).some(v => v.bt && v.bt.cn === c.cn))
|
||||
&& !hideCols.includes(c.cn))) || [];
|
||||
columns = (this.meta.columns.filter(c => !(c.pk && c.ai) &&
|
||||
!((this.meta.v || []).some(v => v.bt && v.bt.cn === c.cn)) &&
|
||||
!hideCols.includes(c.cn))) || []
|
||||
} else {
|
||||
columns = (this.meta && this.meta.columns && this.meta.columns.filter(c => !(c.pk && c.ai) && !hideCols.includes(c.cn))) || [];
|
||||
columns = (this.meta && this.meta.columns && this.meta.columns.filter(c => !(c.pk && c.ai) && !hideCols.includes(c.cn))) || []
|
||||
}
|
||||
|
||||
|
||||
if (this.meta && this.meta.v) {
|
||||
columns = [...columns, ...this.meta.v.map(v => ({...v, virtual: 1}))];
|
||||
columns = [...columns, ...this.meta.v.map(v => ({ ...v, virtual: 1 }))]
|
||||
}
|
||||
|
||||
|
||||
if (this.fieldsOrder.length) {
|
||||
return [...columns].sort((c1, c2) => {
|
||||
const i1 = this.fieldsOrder.indexOf(c1._cn);
|
||||
const i2 = this.fieldsOrder.indexOf(c2._cn);
|
||||
const i1 = this.fieldsOrder.indexOf(c1._cn)
|
||||
const i2 = this.fieldsOrder.indexOf(c2._cn)
|
||||
return (i1 === -1 ? Infinity : i1) - (i2 === -1 ? Infinity : i2)
|
||||
})
|
||||
}
|
||||
|
||||
return columns;
|
||||
return columns
|
||||
},
|
||||
concatenatedXWhere() {
|
||||
let where = '';
|
||||
concatenatedXWhere () {
|
||||
let where = ''
|
||||
if (this.searchField && this.searchQuery.trim()) {
|
||||
if (['text', 'string'].includes(this.sqlUi.getAbstractType(this.availableColumns.find(({_cn}) => _cn === this.searchField) || this.availableColumns[0]))) {
|
||||
if (['text', 'string'].includes(this.sqlUi.getAbstractType(this.availableColumns.find(({ _cn }) => _cn === this.searchField) || this.availableColumns[0]))) {
|
||||
where = `(${this.searchField},like,%${this.searchQuery.trim()}%)`
|
||||
} else {
|
||||
where = `(${this.searchField},eq,${this.searchQuery.trim()})`
|
||||
@@ -108,12 +106,12 @@ export default {
|
||||
}
|
||||
|
||||
if (!where) {
|
||||
return this.xWhere;
|
||||
return this.xWhere
|
||||
}
|
||||
|
||||
return this.xWhere ? where + `~and(${this.xWhere})` : where;
|
||||
return this.xWhere ? where + `~and(${this.xWhere})` : where
|
||||
},
|
||||
queryParams() {
|
||||
queryParams () {
|
||||
return {
|
||||
limit: this.size,
|
||||
offset: this.size * (this.page - 1),
|
||||
@@ -121,160 +119,158 @@ export default {
|
||||
where: this.concatenatedXWhere,
|
||||
sort: this.sort,
|
||||
// todo: use reduce
|
||||
hm: (this.meta && this.meta.v && this.meta.v.filter(v => v.hm).map(({hm}) => hm.tn).join()) || '',
|
||||
bt: (this.meta && this.meta.v && this.meta.v.filter(v => v.bt).map(({bt}) => bt.rtn).join()) || '',
|
||||
mm: (this.meta && this.meta.v && this.meta.v.filter(v => v.mm).map(({mm}) => mm.rtn).join()) || ''
|
||||
hm: (this.meta && this.meta.v && this.meta.v.filter(v => v.hm).map(({ hm }) => hm.tn).join()) || '',
|
||||
bt: (this.meta && this.meta.v && this.meta.v.filter(v => v.bt).map(({ bt }) => bt.rtn).join()) || '',
|
||||
mm: (this.meta && this.meta.v && this.meta.v.filter(v => v.mm).map(({ mm }) => mm.rtn).join()) || ''
|
||||
}
|
||||
}, colLength() {
|
||||
},
|
||||
colLength () {
|
||||
return (this.availableColumns && this.availableColumns.length) || 0
|
||||
},
|
||||
visibleColLength() {
|
||||
visibleColLength () {
|
||||
return (this.availableColumns && this.availableColumns.length) || 0
|
||||
},
|
||||
rowLength() {
|
||||
rowLength () {
|
||||
return (this.data && this.data.length) || 0
|
||||
}, edited() {
|
||||
},
|
||||
edited () {
|
||||
return this.data && this.data.some(r => r.rowMeta && (r.rowMeta.new || r.rowMeta.changed))
|
||||
},
|
||||
hasMany() {
|
||||
hasMany () {
|
||||
// todo: use cn alias
|
||||
return this.meta && this.meta.hasMany ? this.meta.hasMany.reduce((hm, o) => {
|
||||
const _rcn = this.meta.columns.find(c => c.cn === o.rcn)._cn
|
||||
hm[_rcn] = hm[_rcn] || [];
|
||||
hm[_rcn].push(o);
|
||||
return hm;
|
||||
}, {}) : {};
|
||||
return this.meta && this.meta.hasMany
|
||||
? this.meta.hasMany.reduce((hm, o) => {
|
||||
const _rcn = this.meta.columns.find(c => c.cn === o.rcn)._cn
|
||||
hm[_rcn] = hm[_rcn] || []
|
||||
hm[_rcn].push(o)
|
||||
return hm
|
||||
}, {})
|
||||
: {}
|
||||
},
|
||||
haveHasManyrelation() {
|
||||
return !!Object.keys(this.hasMany).length;
|
||||
haveHasManyrelation () {
|
||||
return !!Object.keys(this.hasMany).length
|
||||
},
|
||||
belongsTo() {
|
||||
return this.meta && this.meta.belongsTo ? this.meta.belongsTo.reduce((bt, o) => {
|
||||
const _cn = (this.meta.columns.find(c => c.cn === o.cn) || {})._cn
|
||||
bt[_cn] = o;
|
||||
return bt;
|
||||
}, {}) : {};
|
||||
belongsTo () {
|
||||
return this.meta && this.meta.belongsTo
|
||||
? this.meta.belongsTo.reduce((bt, o) => {
|
||||
const _cn = (this.meta.columns.find(c => c.cn === o.cn) || {})._cn
|
||||
bt[_cn] = o
|
||||
return bt
|
||||
}, {})
|
||||
: {}
|
||||
},
|
||||
table() {
|
||||
|
||||
table () {
|
||||
if (this.relationType === 'hm') {
|
||||
return this.relation.tn;
|
||||
return this.relation.tn
|
||||
} else if (this.relationType === 'bt') {
|
||||
return this.relation.rtn;
|
||||
return this.relation.rtn
|
||||
}
|
||||
|
||||
return this.nodes.tn || this.nodes.view_name
|
||||
},
|
||||
primaryValueColumn() {
|
||||
if (!this.meta || !this.availableColumns || !this.availableColumns.length) return '';
|
||||
return (this.availableColumns.find(col => col.pv) || {_cn: ''})._cn;
|
||||
},
|
||||
primaryValueColumn () {
|
||||
if (!this.meta || !this.availableColumns || !this.availableColumns.length) { return '' }
|
||||
return (this.availableColumns.find(col => col.pv) || { _cn: '' })._cn
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'viewStatus.type': function () {
|
||||
if (!this.loadingMeta || !this.loadingData)
|
||||
this.syncDataDebounce(this);
|
||||
'viewStatus.type' () {
|
||||
if (!this.loadingMeta || !this.loadingData) { this.syncDataDebounce(this) }
|
||||
},
|
||||
showFields: {
|
||||
handler(v) {
|
||||
if (!this.loadingMeta || !this.loadingData)
|
||||
this.syncDataDebounce(this);
|
||||
handler (v) {
|
||||
if (!this.loadingMeta || !this.loadingData) { this.syncDataDebounce(this) }
|
||||
},
|
||||
deep: true
|
||||
},
|
||||
fieldsOrder: {
|
||||
handler(v) {
|
||||
if (!this.loadingMeta || !this.loadingData)
|
||||
this.syncDataDebounce(this);
|
||||
handler (v) {
|
||||
if (!this.loadingMeta || !this.loadingData) { this.syncDataDebounce(this) }
|
||||
},
|
||||
deep: true
|
||||
}, filters: {
|
||||
async handler(filter) {
|
||||
let defaultQuery = '';
|
||||
let j = 0;
|
||||
},
|
||||
filters: {
|
||||
async handler (filter) {
|
||||
let defaultQuery = ''
|
||||
let j = 0
|
||||
const xWhere = filter.reduce((condition, filt, k) => {
|
||||
|
||||
if (filt.readOnly) {
|
||||
defaultQuery += `(${filt.field},eq,${filt.value})`
|
||||
j++;
|
||||
return condition;
|
||||
j++
|
||||
return condition
|
||||
}
|
||||
let i = k - j;
|
||||
const i = k - j
|
||||
|
||||
if (i && !filt.logicOp) {
|
||||
return condition;
|
||||
return condition
|
||||
}
|
||||
if (!(filt.field && filt.op)) {
|
||||
return condition;
|
||||
return condition
|
||||
}
|
||||
|
||||
condition += (i ? `~${filt.logicOp}` : '');
|
||||
condition += (i ? `~${filt.logicOp}` : '')
|
||||
switch (filt.op) {
|
||||
case 'is equal':
|
||||
return condition + `(${filt.field},eq,${filt.value})`;
|
||||
return condition + `(${filt.field},eq,${filt.value})`
|
||||
case 'is not equal':
|
||||
return condition + `~not(${filt.field},eq,${filt.value})`;
|
||||
return condition + `~not(${filt.field},eq,${filt.value})`
|
||||
case 'is like':
|
||||
return condition + `(${filt.field},like,%${filt.value}%)`;
|
||||
return condition + `(${filt.field},like,%${filt.value}%)`
|
||||
case 'is not like':
|
||||
return condition + `~not(${filt.field},like,%${filt.value}%)`;
|
||||
return condition + `~not(${filt.field},like,%${filt.value}%)`
|
||||
case 'is empty':
|
||||
return condition + `(${filt.field},in,)`;
|
||||
return condition + `(${filt.field},in,)`
|
||||
case 'is not empty':
|
||||
return condition + `~not(${filt.field},in,)`;
|
||||
return condition + `~not(${filt.field},in,)`
|
||||
case 'is null':
|
||||
return condition + `(${filt.field},is,null)`;
|
||||
return condition + `(${filt.field},is,null)`
|
||||
case 'is not null':
|
||||
return condition + `~not(${filt.field},is,null)`;
|
||||
return condition + `~not(${filt.field},is,null)`
|
||||
case '<':
|
||||
return condition + `(${filt.field},lt,${filt.value})`;
|
||||
return condition + `(${filt.field},lt,${filt.value})`
|
||||
case '<=':
|
||||
return condition + `(${filt.field},le,${filt.value})`;
|
||||
return condition + `(${filt.field},le,${filt.value})`
|
||||
case '>':
|
||||
return condition + `(${filt.field},gt,${filt.value})`;
|
||||
return condition + `(${filt.field},gt,${filt.value})`
|
||||
case '>=':
|
||||
return condition + `(${filt.field},ge,${filt.value})`;
|
||||
return condition + `(${filt.field},ge,${filt.value})`
|
||||
}
|
||||
return condition;
|
||||
return condition
|
||||
}, '')
|
||||
|
||||
}, '');
|
||||
|
||||
this.xWhere = defaultQuery ? defaultQuery + (xWhere ? `~and(${xWhere})` : xWhere) : xWhere;
|
||||
this.xWhere = defaultQuery ? defaultQuery + (xWhere ? `~and(${xWhere})` : xWhere) : xWhere
|
||||
|
||||
// if (!this.progress) {
|
||||
// await this.loadTableData();
|
||||
// }
|
||||
if (!this.loadingMeta || !this.loadingData)
|
||||
this.syncDataDebounce(this);
|
||||
if (!this.loadingMeta || !this.loadingData) { this.syncDataDebounce(this) }
|
||||
},
|
||||
deep: true
|
||||
},
|
||||
sortList: {
|
||||
async handler(sortList) {
|
||||
async handler (sortList) {
|
||||
const sort = sortList.map((sort) => {
|
||||
return sort.field ? `${sort.order}${sort.field}` : '';
|
||||
}).filter(Boolean).join(',');
|
||||
this.sort = sort;
|
||||
return sort.field ? `${sort.order}${sort.field}` : ''
|
||||
}).filter(Boolean).join(',')
|
||||
this.sort = sort
|
||||
// if (!this.progress) {
|
||||
// await this.loadTableData();
|
||||
// }
|
||||
if (!this.loadingMeta || !this.loadingData)
|
||||
this.syncDataDebounce(this);
|
||||
if (!this.loadingMeta || !this.loadingData) { this.syncDataDebounce(this) }
|
||||
},
|
||||
deep: true
|
||||
},
|
||||
columnsWidth() {
|
||||
if (!this.loadingMeta || !this.loadingData)
|
||||
this.syncDataDebounce(this);
|
||||
columnsWidth () {
|
||||
if (!this.loadingMeta || !this.loadingData) { this.syncDataDebounce(this) }
|
||||
},
|
||||
sort(n, o) {
|
||||
sort (n, o) {
|
||||
if (o !== n) {
|
||||
this.loadTableData();
|
||||
this.loadTableData()
|
||||
}
|
||||
},
|
||||
concatenatedXWhere(n, o) {
|
||||
concatenatedXWhere (n, o) {
|
||||
if (o !== n) {
|
||||
this.loadTableData();
|
||||
this.loadTableData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user