diff --git a/packages/nc-gui/components/project/spreadsheet/components/editable.vue b/packages/nc-gui/components/project/spreadsheet/components/editable.vue new file mode 100644 index 0000000000..b8340e2145 --- /dev/null +++ b/packages/nc-gui/components/project/spreadsheet/components/editable.vue @@ -0,0 +1,31 @@ + + + + + diff --git a/packages/nc-gui/components/project/spreadsheet/components/editableCell.vue b/packages/nc-gui/components/project/spreadsheet/components/editableCell.vue index 7e5d7d0867..131a6d626d 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/editableCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/editableCell.vue @@ -151,7 +151,8 @@ export default { meta: Object, ignoreFocus: Boolean, isForm: Boolean, - active: Boolean + active: Boolean, + dummy: Boolean }, data: () => ({ changed: false, diff --git a/packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue b/packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue index 1f7575c79d..919ef94130 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue @@ -247,9 +247,13 @@ - + !c.virtual) }, - availableColumns() { - let columns = [] - - if (!this.meta) { return [] } - // todo: generate hideCols based on default values - const hideCols = ['created_at', 'updated_at'] - - if (this.showSystemFields) { - 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))) || [] - } else { - columns = (this.meta && this.meta.columns && this.meta.columns.filter(c => !(c.pk && c.ai) && !hideCols.includes(c.cn))) || [] - } + allColumns() { + let columns = this.meta.columns if (this.meta && this.meta.v) { columns = [...columns, ...this.meta.v.map(v => ({ ...v, virtual: 1 }))] } @@ -119,6 +105,25 @@ export default { } }) } + return columns + }, + availableColumns() { + let columns = [] + + if (!this.meta) { return [] } + // todo: generate hideCols based on default values + const hideCols = ['created_at', 'updated_at'] + + if (this.showSystemFields) { + 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))) || [] + } else { + columns = (this.meta && this.meta.columns && this.meta.columns.filter(c => !(c.pk && c.ai) && !hideCols.includes(c.cn))) || [] + } + if (this.fieldsOrder.length) { return [...columns].sort((c1, c2) => { const i1 = this.fieldsOrder.indexOf(c1.alias) @@ -283,6 +288,11 @@ export default { this.syncDataDebounce(this) } }, + extraViewParams(v) { + if (!this.loadingMeta || !this.loadingData) { + this.syncDataDebounce(this) + } + }, fieldsOrder: { handler(v) { if (!this.loadingMeta || !this.loadingData) { diff --git a/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue b/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue index 58b6bea729..1d5a968885 100644 --- a/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue +++ b/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue @@ -1,7 +1,7 @@ - + @@ -72,62 +72,65 @@ - - - mdi-reload - - - - - mdi-plus - - - - - save - - Save - - + + + + mdi-reload + + + + + mdi-plus + + + + + save + + Save + + + - - + + + expandRow(rowIndex,rowMeta)" /> - + expandRow(rowIndex,rowMeta)" /> - + - + - - + + + + Fields + + add all + remove all + - {{ col.alias }} - - - - - - - - - - - + + - - + + mdi-drag + + + + + Drag and drop field here to hide + + + + + mdi-plus + + Add new field to this table + + + + + + + + + + + + + + + + + + i !== j)"> + mdi-eye-off-outline + + + + + + + + + + + + + + + + - - + + + + Submit + + + @@ -105,18 +176,184 @@ import VirtualHeaderCell from '../components/virtualHeaderCell' import HeaderCell from '../components/headerCell' import VirtualCell from '../components/virtualCell' import EditableCell from '../components/editableCell' +import Editable from '../components/editable' export default { name: 'FormView', - components: { EditableCell, VirtualCell, HeaderCell, VirtualHeaderCell, draggable }, - props: ['meta', 'availableColumns', 'nodes', 'sqlUi', 'formParams'], - data: () => ({ localState: {}, columns: [], hiddenColumns: [] }), - computed: {}, + components: { Editable, EditableCell, VirtualCell, HeaderCell, VirtualHeaderCell, draggable }, + props: ['meta', 'availableColumns', 'nodes', 'sqlUi', 'formParams', 'showFields', 'fieldsOrder', 'allColumns'], + data: () => ({ + localState: {}, + moved: false + // hiddenColumns: [] + }), + computed: { + localParams: { + get() { + return this.formParams || {} + }, + set(params) { + this.$emit('update:formParams', params) + } + }, + hiddenColumns: { + get() { + return this.allColumns.filter(c => !this.showFields[c.alias]) + } + }, + columns: { + get() { + return this.allColumns.filter(c => this.showFields[c.alias]) + }, + set(val) { + const showFields = val.reduce((o, v) => { + o[v.alias] = true + return o + }, {}) + console.log(showFields, this.showFields) + const fieldsOrder = val.map(v => v.alias) + // debugger + this.$emit('update:showFields', showFields) + this.$emit('update:fieldsOrder', fieldsOrder) + } + } + }, + watch: { + // visibleColumns: { + // handler(val) { + // + // }, + // deep: true + // } + }, mounted() { - this.columns = [...this.availableColumns] + this.localParams = Object.assign({ name: this.meta._tn, description: 'Form view description' }, this.localParams) + // this.columns = [...this.availableColumns] + // this.hiddenColumns = this.meta.columns.filter(c => this.availableColumns.find(c1 => c.cn === c1.cn && c._cn === c1._cn)) + }, + methods: { + handleMouseUp(col) { + if (!this.moved) { + this.columns = [...this.columns, col] + } + } } } diff --git a/packages/nc-gui/mixins/device.js b/packages/nc-gui/mixins/device.js index dee099f14a..3a782e0168 100644 --- a/packages/nc-gui/mixins/device.js +++ b/packages/nc-gui/mixins/device.js @@ -44,7 +44,9 @@ export default { return process.env.EE }, _isZh() { - return ['zh', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-sg', 'zh-tw'].includes((navigator.language || navigator.userLanguage || 'en').toLowerCase()) + const zhLan = ['zh', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-sg', 'zh-tw'] + const browserLan = (navigator.languages || [navigator.language || navigator.userLanguage || 'en']).map(v => v.toLowerCase()) + return zhLan.some(l => browserLan.includes(l)) }, ...mapGetters({ _isUIAllowed: 'users/GtrIsUIAllowed'