mirror of https://github.com/nocodb/nocodb
mertmit
3 years ago
15 changed files with 575 additions and 281 deletions
@ -0,0 +1,74 @@ |
|||||||
|
<template> |
||||||
|
<div> |
||||||
|
<span |
||||||
|
v-for="op in selected" |
||||||
|
:key="op.id" |
||||||
|
:style="{ |
||||||
|
background: op ? op.color || '#ccc' : '#ccc' |
||||||
|
}" |
||||||
|
class="set-item ma-1 py-1 px-3" |
||||||
|
>{{ op ? migrate(op.title) || op : '' }}</span> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
export default { |
||||||
|
name: 'MultiSelectCell', |
||||||
|
props: ['value', 'column'], |
||||||
|
computed: { |
||||||
|
selected() { |
||||||
|
if (this.column && this.value) { |
||||||
|
return this.values.map(el => this.column.colOptions?.options.find(opt => el === opt.id || |
||||||
|
el === this.migrate(opt.title)) || el) |
||||||
|
} |
||||||
|
return [] |
||||||
|
}, |
||||||
|
values() { |
||||||
|
return this.value ? this.value.split(',') : [] |
||||||
|
} |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
migrate(val) { |
||||||
|
if (this.column.dt === 'set') { |
||||||
|
if ((typeof val === 'string' || val instanceof String)) { |
||||||
|
return val.replace(/'/g, '') |
||||||
|
} |
||||||
|
} |
||||||
|
return val |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
||||||
|
|
||||||
|
<style scoped> |
||||||
|
|
||||||
|
.set-item { |
||||||
|
display: inline-block; |
||||||
|
border-radius: 25px; |
||||||
|
white-space: nowrap; |
||||||
|
} |
||||||
|
</style> |
||||||
|
<!-- |
||||||
|
/** |
||||||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd |
||||||
|
* |
||||||
|
* @author Naveen MR <oof1lab@gmail.com> |
||||||
|
* @author Pranav C Balan <pranavxc@gmail.com> |
||||||
|
* |
||||||
|
* @license GNU AGPL version 3 or any later version |
||||||
|
* |
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU Affero General Public License as |
||||||
|
* published by the Free Software Foundation, either version 3 of the |
||||||
|
* License, or (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU Affero General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU Affero General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||||
|
* |
||||||
|
*/ |
||||||
|
--> |
@ -0,0 +1,59 @@ |
|||||||
|
<template> |
||||||
|
<div> |
||||||
|
<span |
||||||
|
v-if="value" |
||||||
|
:style="{ |
||||||
|
background: selected ? selected.color || '#ccc' : '#ccc' |
||||||
|
}" |
||||||
|
class="set-item ma-1 py-1 px-3" |
||||||
|
>{{ selected ? selected.title : value }}</span> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
export default { |
||||||
|
name: 'SingleSelectCell', |
||||||
|
props: ['value', 'column'], |
||||||
|
computed: { |
||||||
|
selected() { |
||||||
|
if (this.column && this.column.colOptions) { |
||||||
|
return this.column.colOptions?.options.find(el => el.id === this.value || el.title === this.value) |
||||||
|
} |
||||||
|
return null |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
||||||
|
|
||||||
|
<style scoped> |
||||||
|
|
||||||
|
.set-item { |
||||||
|
display: inline-block; |
||||||
|
border-radius: 25px; |
||||||
|
white-space: nowrap; |
||||||
|
} |
||||||
|
</style> |
||||||
|
<!-- |
||||||
|
/** |
||||||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd |
||||||
|
* |
||||||
|
* @author Naveen MR <oof1lab@gmail.com> |
||||||
|
* @author Pranav C Balan <pranavxc@gmail.com> |
||||||
|
* |
||||||
|
* @license GNU AGPL version 3 or any later version |
||||||
|
* |
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU Affero General Public License as |
||||||
|
* published by the Free Software Foundation, either version 3 of the |
||||||
|
* License, or (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU Affero General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU Affero General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||||
|
* |
||||||
|
*/ |
||||||
|
--> |
@ -1,87 +0,0 @@ |
|||||||
import Noco from '../Noco'; |
|
||||||
import NocoCache from '../cache/NocoCache'; |
|
||||||
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; |
|
||||||
|
|
||||||
export default class SingleSelectColumn { |
|
||||||
title: string; |
|
||||||
fk_column_id: string; |
|
||||||
|
|
||||||
constructor(data: Partial<SingleSelectColumn>) { |
|
||||||
Object.assign(this, data); |
|
||||||
} |
|
||||||
|
|
||||||
public static async insert( |
|
||||||
data: Partial<SingleSelectColumn>, |
|
||||||
ncMeta = Noco.ncMeta |
|
||||||
) { |
|
||||||
const { id } = await ncMeta.metaInsert2( |
|
||||||
null, |
|
||||||
null, |
|
||||||
MetaTable.COL_SELECT_OPTIONS, |
|
||||||
{ |
|
||||||
fk_column_id: data.fk_column_id, |
|
||||||
title: data.title |
|
||||||
} |
|
||||||
); |
|
||||||
|
|
||||||
await NocoCache.appendToList( |
|
||||||
CacheScope.COL_SELECT_OPTION, |
|
||||||
[data.fk_column_id], |
|
||||||
`${CacheScope.COL_SELECT_OPTION}:${id}` |
|
||||||
); |
|
||||||
|
|
||||||
return this.get(id, ncMeta); |
|
||||||
} |
|
||||||
|
|
||||||
public static async get( |
|
||||||
selectOptionId: string, |
|
||||||
ncMeta = Noco.ncMeta |
|
||||||
): Promise<SingleSelectColumn> { |
|
||||||
let data = |
|
||||||
selectOptionId && |
|
||||||
(await NocoCache.get( |
|
||||||
`${CacheScope.COL_SELECT_OPTION}:${selectOptionId}`, |
|
||||||
CacheGetType.TYPE_OBJECT |
|
||||||
)); |
|
||||||
if (!data) { |
|
||||||
data = await ncMeta.metaGet2( |
|
||||||
null, |
|
||||||
null, |
|
||||||
MetaTable.COL_SELECT_OPTIONS, |
|
||||||
selectOptionId |
|
||||||
); |
|
||||||
await NocoCache.set( |
|
||||||
`${CacheScope.COL_SELECT_OPTION}:${selectOptionId}`, |
|
||||||
data |
|
||||||
); |
|
||||||
} |
|
||||||
return data && new SingleSelectColumn(data); |
|
||||||
} |
|
||||||
|
|
||||||
public static async read(columnId: string, ncMeta = Noco.ncMeta) { |
|
||||||
let options = await NocoCache.getList(CacheScope.COL_SELECT_OPTION, [ |
|
||||||
columnId |
|
||||||
]); |
|
||||||
if (!options.length) { |
|
||||||
options = await ncMeta.metaList2( |
|
||||||
null, //,
|
|
||||||
null, //model.db_alias,
|
|
||||||
MetaTable.COL_SELECT_OPTIONS, |
|
||||||
{ condition: { fk_column_id: columnId } } |
|
||||||
); |
|
||||||
await NocoCache.setList( |
|
||||||
CacheScope.COL_SELECT_OPTION, |
|
||||||
[columnId], |
|
||||||
options |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
return options?.length |
|
||||||
? { |
|
||||||
options: options.map(c => new SingleSelectColumn(c)) |
|
||||||
} |
|
||||||
: null; |
|
||||||
} |
|
||||||
|
|
||||||
id: string; |
|
||||||
} |
|
Loading…
Reference in new issue