mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
434 lines
12 KiB
434 lines
12 KiB
3 years ago
|
import { isVirtualCol, filterOutSystemColumns } from 'nocodb-sdk'
|
||
3 years ago
|
import { getUIDTIcon } from '~/components/project/spreadsheet/helpers/uiTypes'
|
||
3 years ago
|
|
||
4 years ago
|
export default {
|
||
|
data: () => ({
|
||
3 years ago
|
showSystemFieldsLoc: false,
|
||
4 years ago
|
viewStatus: {},
|
||
|
fieldFilter: '',
|
||
|
filtersKey: 0,
|
||
|
filters: [],
|
||
|
sortList: [],
|
||
|
showFields: {},
|
||
|
// fieldList: [],
|
||
3 years ago
|
// meta: {},
|
||
3 years ago
|
data: [],
|
||
|
syncDataDebounce() {
|
||
|
// not implemented
|
||
|
}
|
||
4 years ago
|
}),
|
||
|
methods: {
|
||
3 years ago
|
mapFieldsAndShowFields() {
|
||
3 years ago
|
// this.fieldList = this.availableColumns.map(c => c.title);
|
||
4 years ago
|
this.showFields = this.fieldList.reduce((obj, k) => {
|
||
3 years ago
|
obj[k] = k in this.showFields ? this.showFields[k] : true
|
||
|
return obj
|
||
|
}, {})
|
||
4 years ago
|
},
|
||
3 years ago
|
onKeyDown(e) {
|
||
3 years ago
|
if (this.selected.col === null || this.selected.row === null) {
|
||
|
return
|
||
|
}
|
||
4 years ago
|
switch (e.keyCode) {
|
||
|
// left
|
||
|
case 37:
|
||
3 years ago
|
if (this.selected.col > 0) {
|
||
|
this.selected.col--
|
||
|
}
|
||
3 years ago
|
break
|
||
4 years ago
|
// right
|
||
|
case 39:
|
||
3 years ago
|
if (this.selected.col < this.colLength - 1) {
|
||
|
this.selected.col++
|
||
|
}
|
||
3 years ago
|
break
|
||
4 years ago
|
// up
|
||
|
case 38:
|
||
3 years ago
|
if (this.selected.row > 0) {
|
||
|
this.selected.row--
|
||
|
}
|
||
3 years ago
|
break
|
||
4 years ago
|
// down
|
||
|
case 40:
|
||
3 years ago
|
if (this.selected.row < this.rowLength - 1) {
|
||
|
this.selected.row++
|
||
|
}
|
||
3 years ago
|
break
|
||
4 years ago
|
// enter
|
||
|
case 13:
|
||
|
this.makeEditable(this.selected.col, this.selected.row)
|
||
3 years ago
|
break
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
3 years ago
|
showSystemFields: {
|
||
|
get() {
|
||
|
return this.showSystemFieldsLoc
|
||
|
},
|
||
|
set(v) {
|
||
|
this.showSystemFieldsLoc = v
|
||
|
}
|
||
|
},
|
||
3 years ago
|
isLocked() {
|
||
4 years ago
|
return this.viewStatus && this.viewStatus.type === 'locked'
|
||
|
},
|
||
3 years ago
|
fieldList() {
|
||
3 years ago
|
return this.availableColumns.map((c) => {
|
||
3 years ago
|
return c.alias
|
||
4 years ago
|
})
|
||
|
},
|
||
3 years ago
|
realFieldList() {
|
||
3 years ago
|
return this.availableRealColumns.map((c) => {
|
||
3 years ago
|
return c.title
|
||
3 years ago
|
})
|
||
|
},
|
||
3 years ago
|
formulaFieldList() {
|
||
|
return this.availableColumns.reduce((arr, c) => {
|
||
|
if (c.formula) {
|
||
3 years ago
|
arr.push(c.title)
|
||
3 years ago
|
}
|
||
|
return arr
|
||
|
}, [])
|
||
|
},
|
||
3 years ago
|
availableRealColumns() {
|
||
3 years ago
|
return this.availableColumns && this.availableColumns.filter(c => !isVirtualCol(c)).map(c => ({
|
||
|
...c,
|
||
|
icon: getUIDTIcon(c.uidt)
|
||
|
}))
|
||
3 years ago
|
},
|
||
4 years ago
|
|
||
3 years ago
|
allColumns() {
|
||
3 years ago
|
if (!this.meta) {
|
||
|
return []
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
let columns = this.meta.columns
|
||
4 years ago
|
if (this.meta && this.meta.v) {
|
||
3 years ago
|
columns = [...columns, ...this.meta.v.map(v => ({
|
||
|
...v,
|
||
|
virtual: 1
|
||
|
}))]
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
{
|
||
|
columns.forEach((c) => {
|
||
3 years ago
|
c.alias = c.title
|
||
3 years ago
|
})
|
||
|
}
|
||
3 years ago
|
return columns
|
||
|
},
|
||
|
availableColumns() {
|
||
|
let columns = []
|
||
|
|
||
3 years ago
|
if (!this.meta) {
|
||
|
return []
|
||
|
}
|
||
3 years ago
|
// todo: generate hideCols based on default values
|
||
|
if (this.showSystemFields) {
|
||
|
columns = this.meta.columns || []
|
||
3 years ago
|
} else {
|
||
3 years ago
|
columns = filterOutSystemColumns(this.meta.columns)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
{
|
||
|
columns.forEach((c) => {
|
||
3 years ago
|
c.alias = c.title
|
||
3 years ago
|
})
|
||
|
}
|
||
4 years ago
|
if (this.fieldsOrder.length) {
|
||
|
return [...columns].sort((c1, c2) => {
|
||
3 years ago
|
const i1 = this.fieldsOrder.indexOf(c1.title)
|
||
|
const i2 = this.fieldsOrder.indexOf(c2.title)
|
||
4 years ago
|
return (i1 === -1 ? Infinity : i1) - (i2 === -1 ? Infinity : i2)
|
||
|
})
|
||
|
}
|
||
|
|
||
3 years ago
|
return columns
|
||
4 years ago
|
},
|
||
3 years ago
|
concatenatedXWhere() {
|
||
3 years ago
|
let where = ''
|
||
4 years ago
|
if (this.searchField && this.searchQuery.trim()) {
|
||
3 years ago
|
const col = this.availableColumns.find(({ alias }) => alias === this.searchField) || this.availableColumns[0]
|
||
3 years ago
|
// bigint values are displayed in string format in UI
|
||
|
// when searching bigint values, the operator should be 'eq' instead of 'like'
|
||
|
if (['text', 'string'].includes(this.sqlUi.getAbstractType(col)) && col.dt !== 'bigint') {
|
||
4 years ago
|
where = `(${this.searchField},like,%${this.searchQuery.trim()}%)`
|
||
|
} else {
|
||
|
where = `(${this.searchField},eq,${this.searchQuery.trim()})`
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!where) {
|
||
3 years ago
|
return this.xWhere
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
return this.xWhere ? where + `~and(${this.xWhere})` : where
|
||
4 years ago
|
},
|
||
3 years ago
|
nestedAndRollupColumnParams() {
|
||
|
// generate params for nested columns
|
||
|
const nestedFields = ((this.meta && this.meta.v && this.meta.v) || []).reduce((obj, vc) => {
|
||
|
if (vc.hm) {
|
||
3 years ago
|
obj.hm.push(vc.hm.table_name)
|
||
3 years ago
|
} else if (vc.bt) {
|
||
|
obj.bt.push(vc.bt.rtn)
|
||
|
} else if (vc.mm) {
|
||
|
obj.mm.push(vc.mm.rtn)
|
||
|
}
|
||
|
return obj
|
||
3 years ago
|
}, {
|
||
|
hm: [],
|
||
|
bt: [],
|
||
|
mm: []
|
||
|
})
|
||
3 years ago
|
|
||
|
// todo: handle if virtual column missing
|
||
|
// construct fields args based on lookup columns
|
||
|
const fieldsObj = ((this.meta && this.meta.v && this.meta.v) || []).reduce((obj, vc) => {
|
||
3 years ago
|
if (!vc.lk) {
|
||
3 years ago
|
return obj
|
||
|
}
|
||
|
|
||
|
let key
|
||
|
let index
|
||
|
let column
|
||
|
|
||
3 years ago
|
switch (vc.lk.type) {
|
||
3 years ago
|
case 'mm':
|
||
3 years ago
|
index = nestedFields.mm.indexOf(vc.lk.ltn) + 1
|
||
3 years ago
|
key = `mfields${index}`
|
||
3 years ago
|
column = vc.lk.lcn
|
||
3 years ago
|
break
|
||
|
case 'hm':
|
||
3 years ago
|
index = nestedFields.hm.indexOf(vc.lk.ltn) + 1
|
||
3 years ago
|
key = `hfields${index}`
|
||
3 years ago
|
column = vc.lk.lcn
|
||
3 years ago
|
break
|
||
|
case 'bt':
|
||
3 years ago
|
index = nestedFields.bt.indexOf(vc.lk.ltn) + 1
|
||
3 years ago
|
key = `bfields${index}`
|
||
3 years ago
|
column = vc.lk.lcn
|
||
3 years ago
|
break
|
||
|
}
|
||
|
|
||
|
if (index && column) {
|
||
|
obj[key] = `${obj[key] ? `${obj[key]},` : ''}${column}`
|
||
|
}
|
||
|
|
||
|
return obj
|
||
|
}, {})
|
||
|
return {
|
||
3 years ago
|
...Object.entries(nestedFields).reduce((ro, [k, a]) => ({
|
||
|
...ro,
|
||
|
[k]: a.join(',')
|
||
|
}), {}),
|
||
3 years ago
|
...fieldsObj
|
||
|
}
|
||
|
},
|
||
3 years ago
|
queryParams() {
|
||
4 years ago
|
return {
|
||
|
limit: this.size,
|
||
|
offset: this.size * (this.page - 1),
|
||
4 years ago
|
// condition: this.condition,
|
||
3 years ago
|
where: this.concatenatedXWhere
|
||
|
// sort: this.sort,
|
||
|
// ...this.nestedAndRollupColumnParams
|
||
3 years ago
|
// ...Object.entries(nestedFields).reduce((ro, [k, a]) => ({ ...ro, [k]: a.join(',') })),
|
||
|
// ...fieldsObj
|
||
4 years ago
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
colLength() {
|
||
4 years ago
|
return (this.availableColumns && this.availableColumns.length) || 0
|
||
|
},
|
||
3 years ago
|
visibleColLength() {
|
||
4 years ago
|
return (this.availableColumns && this.availableColumns.length) || 0
|
||
|
},
|
||
3 years ago
|
rowLength() {
|
||
4 years ago
|
return (this.data && this.data.length) || 0
|
||
3 years ago
|
},
|
||
3 years ago
|
edited() {
|
||
4 years ago
|
return this.data && this.data.some(r => r.rowMeta && (r.rowMeta.new || r.rowMeta.changed))
|
||
|
},
|
||
3 years ago
|
hasMany() {
|
||
4 years ago
|
// todo: use cn alias
|
||
3 years ago
|
return this.meta && this.meta.hasMany
|
||
|
? this.meta.hasMany.reduce((hm, o) => {
|
||
3 years ago
|
const _rcn = this.meta.columns.find(c => c.column_name === o.rcn).title
|
||
3 years ago
|
hm[_rcn] = hm[_rcn] || []
|
||
|
hm[_rcn].push(o)
|
||
|
return hm
|
||
|
}, {})
|
||
|
: {}
|
||
4 years ago
|
},
|
||
3 years ago
|
haveHasManyrelation() {
|
||
3 years ago
|
return !!Object.keys(this.hasMany).length
|
||
4 years ago
|
},
|
||
3 years ago
|
belongsTo() {
|
||
3 years ago
|
return this.meta && this.meta.belongsTo
|
||
|
? this.meta.belongsTo.reduce((bt, o) => {
|
||
3 years ago
|
const _cn = (this.meta.columns.find(c => c.column_name === o.column_name) || {}).title
|
||
3 years ago
|
bt[_cn] = o
|
||
|
return bt
|
||
|
}, {})
|
||
|
: {}
|
||
4 years ago
|
},
|
||
3 years ago
|
table() {
|
||
4 years ago
|
if (this.relationType === 'hm') {
|
||
3 years ago
|
return this.relation.table_name
|
||
4 years ago
|
} else if (this.relationType === 'bt') {
|
||
3 years ago
|
return this.relation.rtn
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
return this.nodes.table_name || this.nodes.view_name
|
||
4 years ago
|
},
|
||
3 years ago
|
primaryValueColumn() {
|
||
3 years ago
|
if (!this.meta || !this.availableColumns || !this.availableColumns.length) {
|
||
|
return ''
|
||
|
}
|
||
3 years ago
|
return (this.availableColumns.find(col => col.pv) || { _cn: '' }).title
|
||
3 years ago
|
}
|
||
4 years ago
|
},
|
||
|
watch: {
|
||
3 years ago
|
meta() {
|
||
|
this.mapFieldsAndShowFields()
|
||
|
},
|
||
3 years ago
|
'viewStatus.type'() {
|
||
3 years ago
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
4 years ago
|
},
|
||
|
showFields: {
|
||
3 years ago
|
handler(v) {
|
||
3 years ago
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
4 years ago
|
},
|
||
|
deep: true
|
||
|
},
|
||
3 years ago
|
extraViewParams: {
|
||
|
handler(v) {
|
||
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
|
},
|
||
|
deep: true
|
||
3 years ago
|
},
|
||
3 years ago
|
coverImageField(v) {
|
||
3 years ago
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
|
},
|
||
3 years ago
|
groupingField(v) {
|
||
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
|
},
|
||
4 years ago
|
fieldsOrder: {
|
||
3 years ago
|
handler(v) {
|
||
3 years ago
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
4 years ago
|
},
|
||
|
deep: true
|
||
3 years ago
|
},
|
||
3 years ago
|
showSystemFields(v) {
|
||
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
|
},
|
||
3 years ago
|
filters: {
|
||
3 years ago
|
async handler(filter) {
|
||
3 years ago
|
let defaultQuery = ''
|
||
|
let j = 0
|
||
4 years ago
|
const xWhere = filter.reduce((condition, filt, k) => {
|
||
|
if (filt.readOnly) {
|
||
|
defaultQuery += `(${filt.field},eq,${filt.value})`
|
||
3 years ago
|
j++
|
||
|
return condition
|
||
4 years ago
|
}
|
||
3 years ago
|
const i = k - j
|
||
4 years ago
|
|
||
|
if (i && !filt.logicOp) {
|
||
3 years ago
|
return condition
|
||
4 years ago
|
}
|
||
|
if (!(filt.field && filt.op)) {
|
||
3 years ago
|
return condition
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
condition += (i ? `~${filt.logicOp}` : '')
|
||
3 years ago
|
// if (this.allColumnsNames.includes(filt.field)) {
|
||
4 years ago
|
switch (filt.op) {
|
||
|
case 'is equal':
|
||
3 years ago
|
return condition + `(${filt.field},eq,${filt.value})`
|
||
4 years ago
|
case 'is not equal':
|
||
3 years ago
|
return condition + `~not(${filt.field},eq,${filt.value})`
|
||
4 years ago
|
case 'is like':
|
||
3 years ago
|
return condition + `(${filt.field},like,%${filt.value}%)`
|
||
4 years ago
|
case 'is not like':
|
||
3 years ago
|
return condition + `~not(${filt.field},like,%${filt.value}%)`
|
||
4 years ago
|
case 'is empty':
|
||
3 years ago
|
return condition + `(${filt.field},in,)`
|
||
4 years ago
|
case 'is not empty':
|
||
3 years ago
|
return condition + `~not(${filt.field},in,)`
|
||
4 years ago
|
case 'is null':
|
||
3 years ago
|
return condition + `(${filt.field},is,null)`
|
||
4 years ago
|
case 'is not null':
|
||
3 years ago
|
return condition + `~not(${filt.field},is,null)`
|
||
4 years ago
|
case '<':
|
||
3 years ago
|
return condition + `(${filt.field},lt,${filt.value})`
|
||
4 years ago
|
case '<=':
|
||
3 years ago
|
return condition + `(${filt.field},le,${filt.value})`
|
||
4 years ago
|
case '>':
|
||
3 years ago
|
return condition + `(${filt.field},gt,${filt.value})`
|
||
4 years ago
|
case '>=':
|
||
3 years ago
|
return condition + `(${filt.field},ge,${filt.value})`
|
||
4 years ago
|
}
|
||
3 years ago
|
// }
|
||
3 years ago
|
return condition
|
||
|
}, '')
|
||
4 years ago
|
|
||
3 years ago
|
this.xWhere = defaultQuery ? defaultQuery + (xWhere ? `~and(${xWhere})` : xWhere) : xWhere
|
||
4 years ago
|
|
||
|
// if (!this.progress) {
|
||
|
// await this.loadTableData();
|
||
|
// }
|
||
3 years ago
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
4 years ago
|
},
|
||
|
deep: true
|
||
|
},
|
||
|
sortList: {
|
||
3 years ago
|
async handler(sortList) {
|
||
3 years ago
|
// const sort = sortList.map((sort) => {
|
||
|
// // && this.allColumnsNames.includes(sort.field)
|
||
|
// 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)
|
||
4 years ago
|
// }
|
||
|
},
|
||
|
deep: true
|
||
|
},
|
||
3 years ago
|
columnsWidth() {
|
||
3 years ago
|
if (!this.loadingMeta || !this.loadingData) {
|
||
|
this.syncDataDebounce(this)
|
||
|
}
|
||
4 years ago
|
},
|
||
3 years ago
|
sort(n, o) {
|
||
4 years ago
|
if (o !== n) {
|
||
3 years ago
|
this.loadTableData()
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
concatenatedXWhere(n, o) {
|
||
4 years ago
|
if (o !== n) {
|
||
3 years ago
|
this.loadTableData()
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|