Browse Source

feat: cells supporting new select columns

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/2751/head
mertmit 2 years ago
parent
commit
04fe13ce09
  1. 38
      packages/nc-gui/components/project/spreadsheet/components/cell/EnumCell.vue
  2. 16
      packages/nc-gui/components/project/spreadsheet/components/cell/SetListCell.vue
  3. 21
      packages/nc-gui/components/project/spreadsheet/components/editableCell/EnumListEditableCell.vue
  4. 66
      packages/nc-gui/components/project/spreadsheet/components/editableCell/SetListEditableCell.vue

38
packages/nc-gui/components/project/spreadsheet/components/cell/EnumCell.vue

@ -1,50 +1,40 @@
<template> <template>
<div> <div>
<span <v-chip
v-for="v in [(value || '').replace(/\\'/g, '\'').replace(/^'|'$/g, '')]" v-if="enumValues.find(el => el.title === value)"
:key="v" :color="enumValues.find(el => el.title === value) ? enumValues.find(el => el.title === value).color : ''"
:style="{ small
background: colors[v],
}"
class="set-item ma-1 py-1 px-3" class="set-item ma-1 py-1 px-3"
>{{ v }}</span
> >
{{ enumValues.find(el => el.title === value).title }}
</v-chip>
</div> </div>
</template> </template>
<script> <script>
import { enumColor as colors } from '@/components/project/spreadsheet/helpers/colors';
export default { export default {
name: 'EnumCell', name: 'EnumCell',
props: ['value', 'column'], props: ['value', 'column'],
computed: { computed: {
colors() { enumValues() {
const col = this.$store.state.settings.darkTheme ? colors.dark : colors.light; const opts = this.column.colOptions.options || [];
if (this.column && this.column.dtxp) { for (const op of opts.filter(el => el.order === null)) {
return this.column.dtxp op.title = op.title.replace(/^'/, '').replace(/'$/, '');
.split(',') }
.map(v => v.replace(/\\'/g, "'").replace(/^'|'$/g, '')) return opts;
.reduce(
(obj, v, i) => ({
...obj,
[v]: col[i],
}),
{}
);
} }
return {};
},
}, },
}; };
</script> </script>
<style scoped> <style scoped>
/*
.set-item { .set-item {
display: inline-block; display: inline-block;
border-radius: 25px; border-radius: 25px;
white-space: nowrap; white-space: nowrap;
} }
*/
</style> </style>
<!-- <!--
/** /**

16
packages/nc-gui/components/project/spreadsheet/components/cell/SetListCell.vue

@ -2,10 +2,10 @@
<div> <div>
<v-chip <v-chip
v-for="v in selectedValues" v-for="v in selectedValues"
v-show="v || setValues.includes(v)" v-show="v && setValues.find(el => el.title === v)"
:key="v" :key="v"
small small
:color="colors[setValues.indexOf(v) % colors.length]" :color="setValues.find(el => el.title === v) ? setValues.find(el => el.title === v).color : ''"
class="set-item ma-1 py-1 px-3" class="set-item ma-1 py-1 px-3"
> >
{{ v }} {{ v }}
@ -14,21 +14,19 @@
</template> </template>
<script> <script>
import colors from '@/mixins/colors';
export default { export default {
name: 'SetListCell', name: 'SetListCell',
mixins: [colors],
props: ['value', 'column'], props: ['value', 'column'],
computed: { computed: {
setValues() { setValues() {
if (this.column && this.column.dtxp) { const opts = this.column.colOptions.options || [];
return this.column.dtxp.split(',').map(v => v.replace(/\\'/g, "'").replace(/^'|'$/g, '')); for (const op of opts.filter(el => el.order === null)) {
op.title = op.title.replace(/^'/, '').replace(/'$/, '');
} }
return []; return opts;
}, },
selectedValues() { selectedValues() {
return this.value ? this.value.split(',').map(v => v.replace(/\\'/g, "'").replace(/^'|'$/g, '')) : []; return this.value ? this.value.split(',') : [];
}, },
}, },
}; };

21
packages/nc-gui/components/project/spreadsheet/components/editableCell/EnumListEditableCell.vue

@ -1,10 +1,12 @@
<template> <template>
<v-select <v-select
v-model="localState" v-model="localState"
:items="enumValues"
:menu-props="{ bottom: true, offsetY: true }"
item-value="title"
solo solo
dense dense
flat flat
:items="enumValues"
hide-details hide-details
class="mt-0" class="mt-0"
:clearable="!column.rqd" :clearable="!column.rqd"
@ -17,14 +19,14 @@
'text-center': !isForm, 'text-center': !isForm,
}" }"
> >
<v-chip small :color="colors[enumValues.indexOf(item) % colors.length]" class="ma-1"> <v-chip small :color="item.color" class="ma-1">
{{ item }} {{ item.title }}
</v-chip> </v-chip>
</div> </div>
</template> </template>
<template #item="{ item }"> <template #item="{ item }">
<v-chip small :color="colors[enumValues.indexOf(item) % colors.length]"> <v-chip small :color="item.color">
{{ item }} {{ item.title }}
</v-chip> </v-chip>
</template> </template>
<template #append> <template #append>
@ -48,17 +50,18 @@ export default {
computed: { computed: {
localState: { localState: {
get() { get() {
return this.value && this.value.replace(/\\'/g, "'").replace(/^'|'$/g, ''); return this.value;
}, },
set(val) { set(val) {
this.$emit('input', val); this.$emit('input', val);
}, },
}, },
enumValues() { enumValues() {
if (this.column && this.column.dtxp) { const opts = this.column.colOptions.options || [];
return this.column.dtxp.split(',').map(v => v.replace(/\\'/g, "'").replace(/^'|'$/g, '')); for (const op of opts.filter(el => el.order === null)) {
op.title = op.title.replace(/^'/, '').replace(/'$/, '');
} }
return []; return opts;
}, },
parentListeners() { parentListeners() {
const $listeners = {}; const $listeners = {};

66
packages/nc-gui/components/project/spreadsheet/components/editableCell/SetListEditableCell.vue

@ -1,8 +1,10 @@
<template> <template>
<div> <div>
<v-combobox <v-select
v-model="localState" v-model="localState"
:items="setValues" :items="setValues"
:menu-props="{ bottom: true, offsetY: true }"
item-value="title"
multiple multiple
chips chips
flat flat
@ -14,34 +16,32 @@
> >
<template #selection="data"> <template #selection="data">
<v-chip <v-chip
:key="data.item" :color="data.item.color"
small small
class="ma-1" class="ma-1"
:color="colors[setValues.indexOf(data.item) % colors.length]"
@click:close="data.parent.selectItem(data.item)" @click:close="data.parent.selectItem(data.item)"
> >
{{ data.item }} {{ data.item.title }}
</v-chip> </v-chip>
</template> </template>
<template #item="{ item }"> <template #item="{item}">
<v-chip small :color="colors[setValues.indexOf(item) % colors.length]"> <v-chip small :color="item.color">
{{ item }} {{ item.title }}
</v-chip> </v-chip>
</template> </template>
<template #append> <template #append>
<v-icon small class="mt-2"> mdi-menu-down </v-icon> <v-icon small class="mt-1">
mdi-menu-down
</v-icon>
</template> </template>
</v-combobox> </v-select>
</div> </div>
</template> </template>
<script> <script>
import colors from '@/mixins/colors';
export default { export default {
name: 'SetListEditableCell', name: 'SetListEditableCell',
mixins: [colors],
props: { props: {
value: String, value: String,
column: Object, column: Object,
@ -49,19 +49,18 @@ export default {
computed: { computed: {
localState: { localState: {
get() { get() {
return this.value && this.value.match(/(?:[^',]|\\')+(?='?(?:,|$))/g).map(v => v.replace(/\\'/g, "'")); return typeof this.value === 'string' ? this.value.split(',') : [];
}, },
set(val) { set(val) {
this.$emit('input', val.filter(v => this.setValues.includes(v)).join(',')); this.$emit('input', val.filter(v => this.setValues.find(el => el.title === v)).join(','));
}, },
}, },
setValues() { setValues() {
if (this.column && this.column.dtxp) { const opts = this.column.colOptions.options || [];
return this.column.dtxp for (const op of opts.filter(el => el.order === null)) {
.match(/(?:[^']|\\')+(?='?(?:,|$))/g) op.title = op.title.replace(/^'/, '').replace(/'$/, '');
.map(v => v.replace(/\\'/g, "'").replace(/^'|'$/g, ''));
} }
return []; return opts;
}, },
parentListeners() { parentListeners() {
const $listeners = {}; const $listeners = {};
@ -86,17 +85,26 @@ export default {
}; };
</script> </script>
<style scoped> <style scoped lang="scss">
select {
width: 100%; ::v-deep {
height: 100%; .v-select {
color: var(--v-textColor-base); min-width: 150px;
-webkit-appearance: menulist; .v-select__selections {
/*webkit browsers */ min-height: 38px !important;
-moz-appearance: menulist; }
/*Firefox */ }
appearance: menulist; .v-input__slot{
padding-right: 0 !important;
}
.v-input__icon.v-input__icon--clear {
width: 15px !important;
.v-icon {
font-size: 13px !important;
}
}
} }
</style> </style>
<!-- <!--
/** /**

Loading…
Cancel
Save