Browse Source

feat(gui): add locked view, form view validation

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/614/head
Pranav C 3 years ago
parent
commit
86f8941c29
  1. 18
      packages/nc-gui/components/project/spreadsheet/components/editableCell.vue
  2. 2
      packages/nc-gui/components/project/spreadsheet/components/expandedForm.vue
  3. 12
      packages/nc-gui/components/project/spreadsheet/components/headerCell.vue
  4. 3
      packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue
  5. 36
      packages/nc-gui/components/project/spreadsheet/components/virtualCell.vue
  6. 4
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue
  7. 10
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue
  8. 10
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue
  9. 8
      packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue
  10. 12
      packages/nc-gui/components/project/spreadsheet/mixins/form.js
  11. 15
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  12. 169
      packages/nc-gui/components/project/spreadsheet/views/formView.vue
  13. 22
      packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue
  14. 5
      packages/nc-gui/package-lock.json
  15. 1
      packages/nc-gui/package.json

18
packages/nc-gui/components/project/spreadsheet/components/editableCell.vue

@ -1,5 +1,6 @@
<template> <template>
<div <div
class="nc-cell"
@keydown.stop.left @keydown.stop.left
@keydown.stop.right @keydown.stop.right
@keydown.stop.up @keydown.stop.up
@ -105,6 +106,8 @@
<text-cell v-else v-model="localState" v-on="$listeners" /> <text-cell v-else v-model="localState" v-on="$listeners" />
<span v-if="hint" class="nc-hint">{{ hint }}</span> <span v-if="hint" class="nc-hint">{{ hint }}</span>
<div v-if="isLocked" class="nc-locked-overlay" />
</div> </div>
</template> </template>
@ -155,7 +158,8 @@ export default {
isForm: Boolean, isForm: Boolean,
active: Boolean, active: Boolean,
dummy: Boolean, dummy: Boolean,
hint: String hint: String,
isLocked: Boolean
}, },
data: () => ({ data: () => ({
changed: false, changed: false,
@ -228,6 +232,18 @@ div {
font-size: .61rem; font-size: .61rem;
color:grey; color:grey;
} }
.nc-cell {
position: relative;
}
.nc-locked-overlay {
position: absolute;
z-index: 2;
height: 100%;
width: 100%;
top:0;
left:0;
}
</style> </style>
<!-- <!--
/** /**

2
packages/nc-gui/components/project/spreadsheet/components/expandedForm.vue

@ -84,7 +84,7 @@
:key="i" :key="i"
:class="{ :class="{
'active-row' : active === col._cn, 'active-row' : active === col._cn,
required: isRequired(col, localState) required: isValid(col, localState)
}" }"
class="row-col my-4" class="row-col my-4"
> >

12
packages/nc-gui/components/project/spreadsheet/components/headerCell.vue

@ -41,20 +41,20 @@
mdi-card-text-outline mdi-card-text-outline
</v-icon> </v-icon>
<span class="name" :title="value">{{ value }}</span> <span class="name" style="white-space: pre-wrap" :title="value">{{ value }}</span>
<span v-if="column.rqd || required" class="error--text text--lighten-1">&nbsp;*</span> <span v-if="(column.rqd && !column.default) || required" class="error--text text--lighten-1">&nbsp;*</span>
<v-spacer /> <v-spacer />
<v-menu <v-menu
v-if="!isPublicView && _isUIAllowed('edit-column') && !isForm" v-if="!isLocked &&!isPublicView && _isUIAllowed('edit-column') && !isForm"
offset-y offset-y
open-on-hover open-on-hover
left left
> >
<template #activator="{on}"> <template #activator="{on}">
<v-icon v-if="!isVirtual" small v-on="on"> <v-icon v-if="!isLocked && !isVirtual" small v-on="on">
mdi-menu-down mdi-menu-down
</v-icon> </v-icon>
</template> </template>
@ -141,7 +141,7 @@ export default {
name: 'HeaderCell', name: 'HeaderCell',
components: { EditColumn }, components: { EditColumn },
mixins: [cell], mixins: [cell],
props: ['value', 'column', 'isForeignKey', 'meta', 'nodes', 'columnIndex', 'isForm', 'isPublicView', 'isVirtual', 'required'], props: ['value', 'column', 'isForeignKey', 'meta', 'nodes', 'columnIndex', 'isForm', 'isPublicView', 'isVirtual', 'required', 'isLocked'],
data: () => ({ data: () => ({
editColumnMenu: false, editColumnMenu: false,
columnDeleteDialog: false columnDeleteDialog: false
@ -201,7 +201,7 @@ export default {
</script> </script>
<style scoped> <style scoped>
.name{ .name {
max-width: calc(100% - 40px); max-width: calc(100% - 40px);
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;

3
packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue

@ -14,7 +14,7 @@
<!-- Views --> <!-- Views -->
<span class="body-2 grey--text">{{ $t('nav_drawer.title') }}</span> <span class="body-2 grey--text">{{ $t('nav_drawer.title') }}</span>
</v-list-item> </v-list-item>
<v-list-item-group v-model="selectedViewIdLocal" color="primary"> <v-list-item-group v-model="selectedViewIdLocal" mandatory color="primary">
<v-list-item <v-list-item
v-for="(view, i) in viewsList" v-for="(view, i) in viewsList"
:key="i" :key="i"
@ -23,6 +23,7 @@
active-class="x-active--text" active-class="x-active--text"
class="body-2 text-capitalize view nc-view-item" class="body-2 text-capitalize view nc-view-item"
:class="`nc-${view.show_as}-view-item`" :class="`nc-${view.show_as}-view-item`"
@click="$emit('generateNewViewKey')"
> >
<v-list-item-icon class="mr-n1"> <v-list-item-icon class="mr-n1">
<v-icon <v-icon

36
packages/nc-gui/components/project/spreadsheet/components/virtualCell.vue

@ -1,5 +1,5 @@
<template> <template>
<div> <div class="nc-virtual-cell">
<v-lazy> <v-lazy>
<has-many-cell <has-many-cell
v-if="hm" v-if="hm"
@ -14,6 +14,8 @@
:is-new="isNew" :is-new="isNew"
:is-form="isForm" :is-form="isForm"
:breadcrumbs="breadcrumbs" :breadcrumbs="breadcrumbs"
:is-locked="isLocked"
:required="required"
v-on="$listeners" v-on="$listeners"
/> />
<many-to-many-cell <many-to-many-cell
@ -30,6 +32,8 @@
:api="api" :api="api"
:is-form="isForm" :is-form="isForm"
:breadcrumbs="breadcrumbs" :breadcrumbs="breadcrumbs"
:is-locked="isLocked"
:required="required"
v-on="$listeners" v-on="$listeners"
/> />
<belongs-to-cell <belongs-to-cell
@ -47,6 +51,7 @@
:is-new="isNew" :is-new="isNew"
:is-form="isForm" :is-form="isForm"
:breadcrumbs="breadcrumbs" :breadcrumbs="breadcrumbs"
:is-locked="isLocked"
v-on="$listeners" v-on="$listeners"
/> />
<lookup-cell <lookup-cell
@ -61,6 +66,7 @@
:is-new="isNew" :is-new="isNew"
:is-form="isForm" :is-form="isForm"
:column="column" :column="column"
:is-locked="isLocked"
v-on="$listeners " v-on="$listeners "
/> />
<formula-cell <formula-cell
@ -75,16 +81,17 @@
/> />
</v-lazy> </v-lazy>
<span v-if="hint" class="nc-hint">{{ hint }}</span> <span v-if="hint" class="nc-hint">{{ hint }}</span>
<div v-if="isLocked" class="nc-locked-overlay" />
</div> </div>
</template> </template>
<script> <script>
import RollupCell from './virtualCell/rollupCell' import RollupCell from './virtualCell/rollupCell'
import FormulaCell from '@/components/project/spreadsheet/components/virtualCell/formulaCell' import FormulaCell from './virtualCell/formulaCell'
import hasManyCell from '@/components/project/spreadsheet/components/virtualCell/hasManyCell' import hasManyCell from './virtualCell/hasManyCell'
import LookupCell from '@/components/project/spreadsheet/components/virtualCell/lookupCell' import LookupCell from './virtualCell/lookupCell'
import manyToManyCell from '@/components/project/spreadsheet/components/virtualCell/manyToManyCell' import manyToManyCell from './virtualCell/manyToManyCell'
import belongsToCell from '@/components/project/spreadsheet/components/virtualCell/belongsToCell' import belongsToCell from './virtualCell/belongsToCell'
// todo: optimize parent/child meta extraction // todo: optimize parent/child meta extraction
@ -121,7 +128,9 @@ export default {
default: false default: false
}, },
disabledColumns: Object, disabledColumns: Object,
hint: String hint: String,
isLocked: Boolean,
required: Boolean
}, },
computed: { computed: {
hm() { hm() {
@ -161,6 +170,19 @@ export default {
font-size: .61rem; font-size: .61rem;
color: grey; color: grey;
} }
.nc-virtual-cell {
position: relative;
}
.nc-locked-overlay {
position: absolute;
z-index: 2;
height: 100%;
width: 100%;
top: 0;
left: 0;
}
</style> </style>
<!-- <!--
/** /**

4
packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue

@ -7,13 +7,14 @@
:active="active" :active="active"
:item="value" :item="value"
:value="cellValue" :value="cellValue"
:readonly="isLocked"
@edit="editParent" @edit="editParent"
@unlink="unlink" @unlink="unlink"
/> />
</template> </template>
</div> </div>
<div <div
v-if="_isUIAllowed('xcDatatableEditable')" v-if="!isLocked && _isUIAllowed('xcDatatableEditable')"
class="action align-center justify-center px-1 flex-shrink-1" class="action align-center justify-center px-1 flex-shrink-1"
:class="{'d-none': !active, 'd-flex':active }" :class="{'d-none': !active, 'd-flex':active }"
> >
@ -105,6 +106,7 @@ export default {
name: 'BelongsToCell', name: 'BelongsToCell',
components: { ListChildItems, ItemChip, ListItems }, components: { ListChildItems, ItemChip, ListItems },
props: { props: {
isLocked: Boolean,
breadcrumbs: { breadcrumbs: {
type: Array, type: Array,
default() { default() {

10
packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue

@ -9,12 +9,13 @@
:active="active" :active="active"
:item="ch" :item="ch"
:value="getCellValue(ch)" :value="getCellValue(ch)"
:readonly="isLocked"
@edit="editChild" @edit="editChild"
@unlink="unlinkChild" @unlink="unlinkChild"
/> />
<span <span
v-if="value && value.length === 10" v-if="!isLocked && value && value.length === 10"
class="caption pointer ml-1 grey--text" class="caption pointer ml-1 grey--text"
@click="showChildListModal" @click="showChildListModal"
>more... >more...
@ -22,6 +23,7 @@
</template> </template>
</div> </div>
<div <div
v-if="!isLocked"
class="actions align-center justify-center px-1 flex-shrink-1" class="actions align-center justify-center px-1 flex-shrink-1"
:class="{'d-none': !active, 'd-flex':active }" :class="{'d-none': !active, 'd-flex':active }"
> >
@ -149,6 +151,7 @@ export default {
listChildItemsModal listChildItemsModal
}, },
props: { props: {
isLocked: Boolean,
breadcrumbs: { breadcrumbs: {
type: Array, type: Array,
default() { default() {
@ -163,7 +166,8 @@ export default {
sqlUi: [Object, Function], sqlUi: [Object, Function],
active: Boolean, active: Boolean,
isNew: Boolean, isNew: Boolean,
isForm: Boolean isForm: Boolean,
required: Boolean
}, },
data: () => ({ data: () => ({
newRecordModal: false, newRecordModal: false,
@ -288,6 +292,7 @@ export default {
async unlinkChild(child) { async unlinkChild(child) {
if (this.isNew) { if (this.isNew) {
this.localState.splice(this.localState.indexOf(child), 1) this.localState.splice(this.localState.indexOf(child), 1)
this.$emit('update:localState', [...this.localState])
return return
} }
@ -332,6 +337,7 @@ export default {
async addChildToParent(child) { async addChildToParent(child) {
if (this.isNew && this.localState.every(it => it[this.childForeignKey] !== child[this.childPrimaryKey])) { if (this.isNew && this.localState.every(it => it[this.childForeignKey] !== child[this.childPrimaryKey])) {
this.localState.push(child) this.localState.push(child)
this.$emit('update:localState', [...this.localState])
this.newRecordModal = false this.newRecordModal = false
return return
} }

10
packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue

@ -9,13 +9,15 @@
:active="active" :active="active"
:item="v" :item="v"
:value="getCellValue(v)" :value="getCellValue(v)"
:readonly="isLocked"
@edit="editChild" @edit="editChild"
@unlink="unlinkChild" @unlink="unlinkChild"
/> />
</template> </template>
<span v-if="value && value.length === 10" class="caption pointer ml-1 grey--text" @click="showChildListModal">more...</span> <span v-if="!isLocked && value && value.length === 10" class="caption pointer ml-1 grey--text" @click="showChildListModal">more...</span>
</div> </div>
<div <div
v-if="!isActive && !isLocked"
class="actions align-center justify-center px-1 flex-shrink-1" class="actions align-center justify-center px-1 flex-shrink-1"
:class="{'d-none': !active, 'd-flex':active }" :class="{'d-none': !active, 'd-flex':active }"
> >
@ -128,6 +130,7 @@ export default {
name: 'ManyToManyCell', name: 'ManyToManyCell',
components: { ListChildItems, ItemChip, ListItems, DlgLabelSubmitCancel, listChildItemsModal }, components: { ListChildItems, ItemChip, ListItems, DlgLabelSubmitCancel, listChildItemsModal },
props: { props: {
isLocked: Boolean,
breadcrumbs: { breadcrumbs: {
type: Array, type: Array,
default() { default() {
@ -143,7 +146,8 @@ export default {
sqlUi: [Object, Function], sqlUi: [Object, Function],
active: Boolean, active: Boolean,
isNew: Boolean, isNew: Boolean,
isForm: Boolean isForm: Boolean,
required: Boolean
}, },
data: () => ({ data: () => ({
isNewChild: false, isNewChild: false,
@ -290,6 +294,7 @@ export default {
async unlinkChild(child) { async unlinkChild(child) {
if (this.isNew) { if (this.isNew) {
this.localState.splice(this.localState.indexOf(child), 1) this.localState.splice(this.localState.indexOf(child), 1)
this.$emit('update:localState', [...this.localState])
return return
} }
await Promise.all([this.loadChildMeta(), this.loadAssociateTableMeta()]) await Promise.all([this.loadChildMeta(), this.loadAssociateTableMeta()])
@ -367,6 +372,7 @@ export default {
async addChildToParent(child) { async addChildToParent(child) {
if (this.isNew && this.localState.every(it => it[this.childForeignKey] !== child[this.childPrimaryKey])) { if (this.isNew && this.localState.every(it => it[this.childForeignKey] !== child[this.childPrimaryKey])) {
this.localState.push(child) this.localState.push(child)
this.$emit('update:localState', [...this.localState])
this.newRecordModal = false this.newRecordModal = false
return return
} }

8
packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue

@ -37,7 +37,7 @@
</v-icon> </v-icon>
</template> </template>
<span v-on="on"> <span v-on="on">
<span class="name flex-grow-1" :title="column._cn" v-html="alias" /> <span class="name flex-grow-1" style="white-space: pre-wrap" :title="column._cn" v-html="alias" />
<span v-if="column.rqd || required" class="error--text text--lighten-1">&nbsp;*</span> <span v-if="column.rqd || required" class="error--text text--lighten-1">&nbsp;*</span>
</span> </span>
</template> </template>
@ -46,13 +46,13 @@
<v-spacer /> <v-spacer />
<v-menu <v-menu
v-if="!isPublicView && _isUIAllowed('edit-column') && !isForm" v-if="!isLocked && !isPublicView && _isUIAllowed('edit-column') && !isForm"
offset-y offset-y
open-on-hover open-on-hover
left left
> >
<template #activator="{on}"> <template #activator="{on}">
<v-icon v-if="!isForm" small v-on="on"> <v-icon v-if="!isLocked && !isForm" small v-on="on">
mdi-menu-down mdi-menu-down
</v-icon> </v-icon>
</template> </template>
@ -133,7 +133,7 @@ import EditVirtualColumn from '@/components/project/spreadsheet/components/editV
export default { export default {
name: 'VirtualHeaderCell', name: 'VirtualHeaderCell',
components: { EditVirtualColumn }, components: { EditVirtualColumn },
props: ['column', 'nodes', 'meta', 'isForm', 'isPublicView', 'sqlUi', 'required'], props: ['column', 'nodes', 'meta', 'isForm', 'isPublicView', 'sqlUi', 'required', 'isLocked'],
data: () => ({ data: () => ({
columnDeleteDialog: false, columnDeleteDialog: false,
editColumnMenu: false, editColumnMenu: false,

12
packages/nc-gui/components/project/spreadsheet/mixins/form.js

@ -12,14 +12,22 @@ export default {
api: [Object] api: [Object]
}, },
methods: { methods: {
isRequired(_columnObj, rowObj) { isValid(_columnObj, rowObj, required = false) {
let columnObj = _columnObj let columnObj = _columnObj
if (columnObj.bt) { if (columnObj.bt) {
columnObj = this.meta.columns.find(c => c.cn === columnObj.bt.cn) columnObj = this.meta.columns.find(c => c.cn === columnObj.bt.cn)
} }
return (columnObj.rqd && return ((required || columnObj.rqd) &&
(rowObj[columnObj._cn] === undefined || rowObj[columnObj._cn] === null) && (rowObj[columnObj._cn] === undefined || rowObj[columnObj._cn] === null) &&
!columnObj.default) !columnObj.default)
},
isRequired(_columnObj, rowObj, required = false) {
let columnObj = _columnObj
if (columnObj.bt) {
columnObj = this.meta.columns.find(c => c.cn === columnObj.bt.cn)
}
return ((required || columnObj.rqd) &&
!columnObj.default)
} }
} }
} }

15
packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue

@ -61,8 +61,9 @@
<v-spacer class="h-100" @dblclick="debug=true" /> <v-spacer class="h-100" @dblclick="debug=true" />
<template v-if="!isForm">
<debug-metas v-if="debug" class="mr-3" /> <debug-metas v-if="debug" class="mr-3" />
<v-tooltip v-if="!isForm" bottom> <v-tooltip bottom>
<template #activator="{on}"> <template #activator="{on}">
<v-icon v-if="!isPkAvail && !isForm" color="warning" small class="mr-3" v-on="on"> <v-icon v-if="!isPkAvail && !isForm" color="warning" small class="mr-3" v-on="on">
mdi-information-outline mdi-information-outline
@ -73,7 +74,6 @@
</v-tooltip> </v-tooltip>
<lock-menu v-if="_isUIAllowed('view-type')" v-model="viewStatus.type" /> <lock-menu v-if="_isUIAllowed('view-type')" v-model="viewStatus.type" />
<template v-if="!isForm">
<x-btn tooltip="Reload view data" outlined small text @click="reload"> <x-btn tooltip="Reload view data" outlined small text @click="reload">
<v-icon small class="mr-1" color="grey darken-3"> <v-icon small class="mr-1" color="grey darken-3">
mdi-reload mdi-reload
@ -130,7 +130,6 @@
:field-list="[...realFieldList, ...formulaFieldList]" :field-list="[...realFieldList, ...formulaFieldList]"
dense dense
/> />
</template>
<v-tooltip <v-tooltip
v-if="_isUIAllowed('table-delete')" v-if="_isUIAllowed('table-delete')"
bottom bottom
@ -153,6 +152,7 @@
</template> </template>
<span class="">Delete table</span> <span class="">Delete table</span>
</v-tooltip> </v-tooltip>
</template>
<!-- Cell height --> <!-- Cell height -->
<!-- <v-menu> <!-- <v-menu>
<template v-slot:activator="{ on, attrs }"> <template v-slot:activator="{ on, attrs }">
@ -282,7 +282,7 @@
</template> </template>
<template v-else-if="isForm"> <template v-else-if="isForm">
<form-view <form-view
:key="selectedViewId" :key="selectedViewId + viewKey"
:nodes="nodes" :nodes="nodes"
:table="table" :table="table"
:available-columns="availableColumns" :available-columns="availableColumns"
@ -336,6 +336,7 @@
:columns-width.sync="columnsWidth" :columns-width.sync="columnsWidth"
:show-system-fields.sync="showSystemFields" :show-system-fields.sync="showSystemFields"
:extra-view-params.sync="extraViewParams" :extra-view-params.sync="extraViewParams"
@generateNewViewKey="generateNewViewKey"
@mapFieldsAndShowFields="mapFieldsAndShowFields" @mapFieldsAndShowFields="mapFieldsAndShowFields"
@loadTableData="loadTableData" @loadTableData="loadTableData"
@showAdditionalFeatOverlay="showAdditionalFeatOverlay($event)" @showAdditionalFeatOverlay="showAdditionalFeatOverlay($event)"
@ -517,13 +518,13 @@
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import debounce from 'debounce' import debounce from 'debounce'
import FormView from './views/formView' import FormView from './views/formView'
import XcGridView from './views/xcGridView'
import DebugMetas from '@/components/project/spreadsheet/components/debugMetas' import DebugMetas from '@/components/project/spreadsheet/components/debugMetas'
import AdditionalFeatures from '@/components/project/spreadsheet/overlay/additinalFeatures' import AdditionalFeatures from '@/components/project/spreadsheet/overlay/additinalFeatures'
import GalleryView from '@/components/project/spreadsheet/views/galleryView' import GalleryView from '@/components/project/spreadsheet/views/galleryView'
import CalendarView from '@/components/project/spreadsheet/views/calendarView' import CalendarView from '@/components/project/spreadsheet/views/calendarView'
import KanbanView from '@/components/project/spreadsheet/views/kanbanView' import KanbanView from '@/components/project/spreadsheet/views/kanbanView'
import XcGridView from '@/components/project/spreadsheet/views/xcGridView'
import SortList from '@/components/project/spreadsheet/components/sortListMenu' import SortList from '@/components/project/spreadsheet/components/sortListMenu'
import Fields from '@/components/project/spreadsheet/components/fieldsMenu' import Fields from '@/components/project/spreadsheet/components/fieldsMenu'
import SpreadsheetNavDrawer from '@/components/project/spreadsheet/components/spreadsheetNavDrawer' import SpreadsheetNavDrawer from '@/components/project/spreadsheet/components/spreadsheetNavDrawer'
@ -566,6 +567,7 @@ export default {
showTabs: [Boolean, Number] showTabs: [Boolean, Number]
}, },
data: () => ({ data: () => ({
viewKey: 0,
extraViewParams: {}, extraViewParams: {},
debug: false, debug: false,
key: 1, key: 1,
@ -677,6 +679,9 @@ export default {
...mapActions({ ...mapActions({
loadTablesFromChildTreeNode: 'project/loadTablesFromChildTreeNode' loadTablesFromChildTreeNode: 'project/loadTablesFromChildTreeNode'
}), }),
generateNewViewKey() {
this.viewKey = Math.random()
},
loadNext() { loadNext() {
this.selectedExpandRowIndex = ++this.selectedExpandRowIndex % this.data.length this.selectedExpandRowIndex = ++this.selectedExpandRowIndex % this.data.length
}, },

169
packages/nc-gui/components/project/spreadsheet/views/formView.vue

@ -20,16 +20,22 @@
</template> </template>
<template v-else> <template v-else>
<v-col v-if="isEditable" class="h-100 col-md-4 col-lg-3"> <v-col v-if="isEditable" class="h-100 col-md-4 col-lg-3">
<v-card class="h-100 overflow-auto pa-2 backgroundColor elevation-0 nc-form-left-nav"> <v-card class="h-100 overflow-auto pa-4 pa-md-6 backgroundColor elevation-0 nc-form-left-nav">
<div class="d-flex grey--text"> <div class="d-flex grey--text">
<span class="">Fields</span> <span class="">Fields</span>
<v-spacer /> <v-spacer />
<span <span
v-if="hiddenColumns.length"
class="pointer caption mr-2" class="pointer caption mr-2"
style="border-bottom: 2px solid rgba(128,128,128,0.67)" style="border-bottom: 2px solid rgb(218,218,218)"
@click="columns=[...allColumns]" @click="columns=[...allColumns]"
>add all</span> >add all</span>
<span class="pointer caption" style="border-bottom: 2px solid rgba(128,128,128,0.67)" @click="columns=[]">remove all</span> <span
v-if="columns.length"
class="pointer caption"
style="border-bottom: 2px solid rgb(218,218,218)"
@click="columns=[]"
>remove all</span>
</div> </div>
<draggable <draggable
v-model="hiddenColumns" v-model="hiddenColumns"
@ -71,8 +77,8 @@
</v-icon> </v-icon>
</div> </div>
</v-card> </v-card>
<div class="mt-1 nc-drag-n-drop-to-hide py-3 text-center grey--text text--lighter-1"> <div class="mt-4 nc-drag-n-drop-to-hide py-3 text-center grey--text text--lighter-1">
Drag and drop field here to hide Drag and drop fields here to hide
</div> </div>
</draggable> </draggable>
@ -84,7 +90,7 @@
> >
<template #activator="{on}"> <template #activator="{on}">
<div class="grey--text caption text-center mt-4" v-on="on"> <div class="grey--text caption text-center mt-4" v-on="on">
<v-icon samll color="grey"> <v-icon size="20" color="grey">
mdi-plus mdi-plus
</v-icon> </v-icon>
Add new field to this table Add new field to this table
@ -128,7 +134,7 @@
<editable <editable
:is="isEditable ? 'editable' : 'h2'" :is="isEditable ? 'editable' : 'h2'"
v-model.lazy="localParams.name" v-model.lazy="localParams.name"
class="display-1 font-weight-bold text-center" class="display-1 font-weight-bold text-left mx-4 mb-3 px-1 text--text text--lighten-1"
:class="{'nc-meta-inputs': isEditable}" :class="{'nc-meta-inputs': isEditable}"
placeholder="Form Title" placeholder="Form Title"
> >
@ -139,7 +145,7 @@
:is="isEditable ? 'editable' : 'div'" :is="isEditable ? 'editable' : 'div'"
v-model.lazy="localParams.description" v-model.lazy="localParams.description"
:class="{'nc-meta-inputs': isEditable}" :class="{'nc-meta-inputs': isEditable}"
class="body-1 text-center" class="body-1 text-left mx-4 py-2 px-1 text--text text--lighten-2"
placeholder="Add form description" placeholder="Add form description"
> >
{{ localParams.description }} {{ localParams.description }}
@ -176,7 +182,7 @@
v-if="localParams.fields && localParams.fields[col.alias]" v-if="localParams.fields && localParams.fields[col.alias]"
:class="{ :class="{
'active-row' : active === col._cn, 'active-row' : active === col._cn,
required: isRequired(col, localState) || localParams.fields[col.alias].required required: isRequired(col, localState, localParams.fields[col.alias].required)
}" }"
> >
<div class="nc-field-editables" :class="{'nc-show' : isActiveRow(col)}"> <div class="nc-field-editables" :class="{'nc-show' : isActiveRow(col)}">
@ -194,22 +200,23 @@
class="nc-required-switch ml-1 mt-0" class="nc-required-switch ml-1 mt-0"
hide-details hide-details
flat flat
color="grey" color="primary"
dense dense
inset inset
/> />
</div> </div>
<editable <editable
v-model="localParams.fields[col.alias].label" v-model="localParams.fields[col.alias].label"
style="width:300px" style="width:300px;white-space: pre-wrap"
placeholder=" Enter form input label" placeholder=" Enter form input label"
class="caption pa-1 backgroundColor darken-1 mb-2 " class="caption pa-1 backgroundColor darken-1 mb-2 "
/> />
<editable <editable
v-model="localParams.fields[col.alias].description" v-model="localParams.fields[col.alias].description"
style="width:300px" style="width:300px;white-space: pre-wrap"
placeholder=" Add some help text" placeholder=" Add some help text"
class="caption pa-1 backgroundColor darken-1 mb-2" class="caption pa-1 backgroundColor darken-1 mb-2"
@keydown.enter.prevent
/> />
</div> </div>
<label <label
@ -224,7 +231,7 @@
:nodes="nodes" :nodes="nodes"
:is-form="true" :is-form="true"
:meta="meta" :meta="meta"
:required="localParams.fields[col.alias].required" :required="isRequired(col, localState, localParams.fields[col.alias].required)"
/> />
<header-cell <header-cell
v-else v-else
@ -233,13 +240,15 @@
:value="localParams.fields[col.alias].label || col._cn" :value="localParams.fields[col.alias].label || col._cn"
:column="col" :column="col"
:sql-ui="sqlUi" :sql-ui="sqlUi"
:required="localParams.fields[col.alias].required" :required="isRequired(col, localState, localParams.fields[col.alias].required)"
/> />
</label> </label>
<div
<virtual-cell
v-if="col.virtual" v-if="col.virtual"
@click.stop
>
<virtual-cell
ref="virtual" ref="virtual"
:disabled-columns="{}" :disabled-columns="{}"
:column="col" :column="col"
@ -252,10 +261,32 @@
:is-new="true" :is-new="true"
:is-form="true" :is-form="true"
:hint="localParams.fields[col.alias].description" :hint="localParams.fields[col.alias].description"
:required="localParams.fields[col.alias].description"
@update:localState="state => $set(virtual,col.alias, state)"
@updateCol="updateCol"
/> />
<div
v-if="$v.virtual && $v.virtual.$dirty && $v.virtual[col.alias] && (!$v.virtual[col.alias].required || !$v.virtual[col.alias].minLength)"
class="error--text caption"
>
Field is required.
</div>
<!-- todo: optimize -->
<template
v-if="col.bt && $v.localState && $v.localState.$dirty && $v.localState[meta.columns.find(c => c.cn === col.bt.cn)._cn]"
>
<div <div
v-else-if="col.ai || (col.pk && !isNew) || disabledColumns[col._cn]" v-if="!$v.localState[meta.columns.find(c => c.cn === col.bt.cn)._cn].required"
class="error--text caption"
>
Field is required.
</div>
</template>
</div>
<template v-else>
<div
v-if="col.ai || (col.pk && !isNew) || disabledColumns[col._cn]"
style="height:100%; width:100%" style="height:100%; width:100%"
class="caption xc-input" class="caption xc-input"
@click.stop @click.stop
@ -287,16 +318,21 @@
@blur="active = ''" @blur="active = ''"
/> />
</div> </div>
<template v-if="$v.localState&& $v.localState.$dirty && $v.localState[col._cn] ">
<div v-if="!$v.localState[col._cn].required" class="error--text caption">
Field is required.
</div>
</template>
</template>
</div> </div>
<!-- </div>--> <!-- </div>-->
</div> </div>
</div>
<div <div
v-if="!columns.length" v-if="!columns.length"
class="mt-1 nc-drag-n-drop-to-show py-4 text-center grey--text text--lighter-1" class="nc-drag-n-drop-to-show py-4 mx-8 my-10 text-center grey--text text--lighter-1"
> >
Drag and drop field here to add Drag and drop fields here to add
</div>
</div> </div>
</draggable> </draggable>
<div class="my-10 text-center"> <div class="my-10 text-center">
@ -359,6 +395,8 @@
<script> <script>
import draggable from 'vuedraggable' import draggable from 'vuedraggable'
import { validationMixin } from 'vuelidate'
import { required, minLength } from 'vuelidate/lib/validators'
import VirtualHeaderCell from '../components/virtualHeaderCell' import VirtualHeaderCell from '../components/virtualHeaderCell'
import HeaderCell from '../components/headerCell' import HeaderCell from '../components/headerCell'
import VirtualCell from '../components/virtualCell' import VirtualCell from '../components/virtualCell'
@ -370,7 +408,7 @@ import form from '../mixins/form'
export default { export default {
name: 'FormView', name: 'FormView',
components: { EditColumn, Editable, EditableCell, VirtualCell, HeaderCell, VirtualHeaderCell, draggable }, components: { EditColumn, Editable, EditableCell, VirtualCell, HeaderCell, VirtualHeaderCell, draggable },
mixins: [form], mixins: [form, validationMixin],
props: ['meta', 'availableColumns', 'nodes', 'sqlUi', 'formParams', 'showFields', 'fieldsOrder', 'allColumns', 'dbAlias', 'api'], props: ['meta', 'availableColumns', 'nodes', 'sqlUi', 'formParams', 'showFields', 'fieldsOrder', 'allColumns', 'dbAlias', 'api'],
data: () => ({ data: () => ({
localState: {}, localState: {},
@ -382,9 +420,27 @@ export default {
isNew: true, isNew: true,
submitted: false, submitted: false,
secondsRemain: null, secondsRemain: null,
loading: false loading: false,
virtual: {}
// hiddenColumns: [] // hiddenColumns: []
}), }),
validations() {
const obj = { localState: {}, virtual: {} }
for (const column of this.columns) {
if (!column.virtual && ((column.rqd && !column.default) || this.localParams.fields[column.alias].required)) {
obj.localState[column._cn] = { required }
} else if (column.bt) {
const col = this.meta.columns.find(c => c.cn === column.bt.cn)
if ((col.rqd && !col.default) || this.localParams.fields[column.alias].required) {
obj.localState[col._cn] = { required }
}
} else if (column.virtual && this.localParams.fields[column.alias].required && (column.mm || column.hm)) {
obj.virtual[column.alias] = { minLength: minLength(1), required }
}
}
return obj
},
computed: { computed: {
isEditable() { isEditable() {
return this._isUIAllowed('editFormView') return this._isUIAllowed('editFormView')
@ -399,7 +455,7 @@ export default {
}, },
hiddenColumns: { hiddenColumns: {
get() { get() {
return this.allColumns.filter(c => !this.showFields[c.alias]) return this.allColumns.filter(c => !this.showFields[c.alias] && !(c.pk && c.ai) && !(this.meta.v || []).some(v => v.bt && v.bt.cn === c.cn))
} }
}, },
columns: { columns: {
@ -453,6 +509,9 @@ export default {
// this.hiddenColumns = this.meta.columns.filter(c => this.availableColumns.find(c1 => c.cn === c1.cn && c._cn === c1._cn)) // this.hiddenColumns = this.meta.columns.filter(c => this.availableColumns.find(c1 => c.cn === c1.cn && c._cn === c1._cn))
}, },
methods: { methods: {
updateCol(_, column, id) {
this.$set(this.localState, column, id)
},
isActiveRow(col) { isActiveRow(col) {
return this.activeRow === col.alias return this.activeRow === col.alias
}, },
@ -471,6 +530,13 @@ export default {
}, },
async save() { async save() {
try { try {
this.$v.$touch()
if (this.$v.localState.$invalid) {
this.$toast.error('Provide values of all required field').goAway(3000)
return
}
this.loading = true this.loading = true
// const id = this.meta.columns.filter(c => c.pk).map(c => this.localState[c._cn]).join('___') // const id = this.meta.columns.filter(c => c.pk).map(c => this.localState[c._cn]).join('___')
@ -481,8 +547,8 @@ export default {
// if (this.isNew) { // if (this.isNew) {
// const data = // const data =
await this.api.insert(this.localState) const data = await this.api.insert(this.localState)
this.localState = {} // { ...this.localState, ...data } this.localState = { ...this.localState, ...data }
// save hasmany and manytomany relations from local state // save hasmany and manytomany relations from local state
if (this.$refs.virtual && Array.isArray(this.$refs.virtual)) { if (this.$refs.virtual && Array.isArray(this.$refs.virtual)) {
@ -492,6 +558,9 @@ export default {
} }
} }
} }
this.virtual = {}
this.submitted = true this.submitted = true
this.$toast.success(this.localParams.submit.message || 'Saved successfully.', { this.$toast.success(this.localParams.submit.message || 'Saved successfully.', {
@ -567,6 +636,11 @@ export default {
} }
::v-deep { ::v-deep {
.nc-hint {
padding-left: 3px;
}
.nc-required-switch, .nc-switch { .nc-required-switch, .nc-switch {
.v-input--selection-controls__input { .v-input--selection-controls__input {
transform: scale(0.65) !important; transform: scale(0.65) !important;
@ -592,19 +666,19 @@ export default {
.nc-field-wrapper { .nc-field-wrapper {
.required { //.required {
& > input, // & > input,
& > .xc-input > input, // .xc-input > input,
& > .xc-input .v-input__slot input, // .xc-input .v-input__slot input,
& > .xc-input > div > input, // .xc-input > div > input,
& > select, // & > select,
& > .xc-input > select, // .xc-input > select,
textarea:not(.inputarea) { // textarea:not(.inputarea) {
border: 1px solid red; // border: 1px solid rgba(255, 0, 0, 0.98);
border-radius: 4px; // border-radius: 4px;
background: var(--v-backgroundColorDefault-base); // background: var(--v-backgroundColorDefault-base);
} // }
} //}
div > input, div > input,
div > .xc-input > input, div > .xc-input > input,
@ -639,9 +713,9 @@ export default {
//width: 400px; //width: 400px;
min-height: 40px; min-height: 40px;
border-radius: 4px; border-radius: 4px;
display: flex; //display: flex;
align-items: center; //align-items: center;
justify-content: center; //justify-content: center;
&:hover { &:hover {
background: var(--v-backgroundColor-base); background: var(--v-backgroundColor-base);
@ -653,9 +727,10 @@ export default {
} }
.nc-drag-n-drop-to-hide, .nc-drag-n-drop-to-show { .nc-drag-n-drop-to-hide, .nc-drag-n-drop-to-show {
border: 2px dotted #a1a1a1; border: 2px dashed #c4c4c4;
border-radius: 4px; border-radius: 4px;
font-size: .6rem; font-size: .62rem;
color: grey color: grey
} }
@ -702,12 +777,12 @@ export default {
//.nc-field-labels, //.nc-field-labels,
.nc-field-editables { .nc-field-editables {
max-height: 0; max-height: 0;
transition: .4s max-height linear; transition: .4s max-height;
overflow: hidden; overflow-y: hidden;
display: block; display: block;
&.nc-show { &.nc-show {
max-height: 150px; max-height: 500px;
} }
} }

22
packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue

@ -36,6 +36,7 @@
:meta="meta" :meta="meta"
:sql-ui="sqlUi" :sql-ui="sqlUi"
:is-public-view="isPublicView" :is-public-view="isPublicView"
:is-locked="isLocked"
@saved="onNewColCreation" @saved="onNewColCreation"
/> />
@ -50,6 +51,7 @@
:is-foreign-key="col._cn in belongsTo || col._cn in hasMany" :is-foreign-key="col._cn in belongsTo || col._cn in hasMany"
:column="col" :column="col"
:is-virtual="isVirtual" :is-virtual="isVirtual"
:is-locked="isLocked"
@onRelationDelete="$emit('onRelationDelete')" @onRelationDelete="$emit('onRelationDelete')"
@saved="onNewColCreation" @saved="onNewColCreation"
/> />
@ -112,7 +114,7 @@
/> />
<v-spacer /> <v-spacer />
<v-icon <v-icon
v-if="!groupedAggCount[ids[row]]" v-if="!groupedAggCount[ids[row]] && !isLocked"
color="pink" color="pink"
small small
class="row-expand-icon nc-row-expand-icon mr-1 pointer" class="row-expand-icon nc-row-expand-icon mr-1 pointer"
@ -149,6 +151,7 @@
> >
<virtual-cell <virtual-cell
v-if="columnObj.virtual" v-if="columnObj.virtual"
:is-locked="isLocked"
:column="columnObj" :column="columnObj"
:row="rowObj" :row="rowObj"
:nodes="nodes" :nodes="nodes"
@ -175,6 +178,7 @@
:active="selected.col === col && selected.row === row" :active="selected.col === col && selected.row === row"
:sql-ui="sqlUi" :sql-ui="sqlUi"
:db-alias="nodes.dbAlias" :db-alias="nodes.dbAlias"
:is-locked="isLocked"
@save="editEnabled = {}" @save="editEnabled = {}"
@cancel="editEnabled = {}" @cancel="editEnabled = {}"
@update="onCellValueChange(col, row, columnObj)" @update="onCellValueChange(col, row, columnObj)"
@ -225,15 +229,15 @@
</template> </template>
<script> <script>
import DynamicStyle from '@/components/dynamicStyle' import HeaderCell from '../components/headerCell'
import HeaderCell from '@/components/project/spreadsheet/components/headerCell' import EditableCell from '../components/editableCell'
import EditableCell from '@/components/project/spreadsheet/components/editableCell' import EditColumn from '../components/editColumn'
import EditColumn from '@/components/project/spreadsheet/components/editColumn' import columnStyling from '../helpers/columnStyling'
import TableCell from '@/components/project/spreadsheet/components/cell' import VirtualCell from '../components/virtualCell'
import VirtualHeaderCell from '../components/virtualHeaderCell'
import colors from '@/mixins/colors' import colors from '@/mixins/colors'
import columnStyling from '@/components/project/spreadsheet/helpers/columnStyling' import TableCell from '@/components/project/spreadsheet/components/cell'
import VirtualCell from '@/components/project/spreadsheet/components/virtualCell' import DynamicStyle from '@/components/dynamicStyle'
import VirtualHeaderCell from '@/components/project/spreadsheet/components/virtualHeaderCell'
export default { export default {
name: 'XcGridView', name: 'XcGridView',

5
packages/nc-gui/package-lock.json generated

@ -12889,6 +12889,11 @@
"sortablejs": "1.10.2" "sortablejs": "1.10.2"
} }
}, },
"vuelidate": {
"version": "0.7.6",
"resolved": "https://registry.npmjs.org/vuelidate/-/vuelidate-0.7.6.tgz",
"integrity": "sha512-suzIuet1jGcyZ4oUSW8J27R2tNrJ9cIfklAh63EbAkFjE380iv97BAiIeolRYoB9bF9usBXCu4BxftWN1Dkn3g=="
},
"vuetify": { "vuetify": {
"version": "2.5.8", "version": "2.5.8",
"resolved": "https://registry.npmjs.org/vuetify/-/vuetify-2.5.8.tgz", "resolved": "https://registry.npmjs.org/vuetify/-/vuetify-2.5.8.tgz",

1
packages/nc-gui/package.json

@ -53,6 +53,7 @@
"vue-tree-list": "^1.4.6", "vue-tree-list": "^1.4.6",
"vue-typer": "^1.2.0", "vue-typer": "^1.2.0",
"vuedraggable": "^2.24.0", "vuedraggable": "^2.24.0",
"vuelidate": "^0.7.6",
"vuetify-datetime-picker": "^2.1.1", "vuetify-datetime-picker": "^2.1.1",
"vuex-persistedstate": "^3.1.0", "vuex-persistedstate": "^3.1.0",
"xterm": "^4.8.1", "xterm": "^4.8.1",

Loading…
Cancel
Save