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.
304 lines
8.4 KiB
304 lines
8.4 KiB
3 years ago
|
<!-- eslint-disable -->
|
||
4 years ago
|
<template>
|
||
3 years ago
|
<v-skeleton-loader v-if="loading" type="text@3" />
|
||
|
<div v-else class="caption text-left">
|
||
|
{{ Array.isArray(value) ? '[' : '{' }}
|
||
4 years ago
|
|
||
|
<ul>
|
||
|
<template v-if="Array.isArray(value)">
|
||
3 years ago
|
<li v-for="(v, i) in value">
|
||
3 years ago
|
<custom-acl v-model="value[i]" :nodes="nodes" :table="table" />
|
||
|
</li>
|
||
3 years ago
|
<li class="caption add" @click="addConditionObj">add +</li>
|
||
4 years ago
|
</template>
|
||
|
<template v-else>
|
||
3 years ago
|
<li v-for="(key, i) in keys" v-if="key !== 'relationType'" :key="key" :class="{ empty: !keys[i] }">
|
||
4 years ago
|
<div class="d-inline">
|
||
|
<!-- <span contenteditable v-text="key" class="key"></span>-->
|
||
3 years ago
|
<select :ref="'keySelect' + i" v-model="keys[i]" class="caption" @change="onKeyChange(i, key)">
|
||
4 years ago
|
<template v-if="table">
|
||
3 years ago
|
<optgroup v-if="columns && columns.length" label="columns">
|
||
|
<option v-for="col in columns" v-show="!keys.includes(col)" :data-value="col">
|
||
|
{{ col }}
|
||
|
</option>
|
||
4 years ago
|
</optgroup>
|
||
3 years ago
|
<optgroup v-if="hmList && hmList.length" label="Has Many">
|
||
|
<option v-for="hm in hmList" v-show="!keys.includes(hm)" data-relation-type="hm" :data-table="hm">
|
||
3 years ago
|
{{ hm }}
|
||
4 years ago
|
</option>
|
||
|
</optgroup>
|
||
3 years ago
|
<optgroup v-if="btList && btList.length" label="BelongsTo">
|
||
|
<option v-for="bt in btList" v-show="!keys.includes(bt)" data-relation-type="bt" :data-table="bt">
|
||
3 years ago
|
{{ bt }}
|
||
4 years ago
|
</option>
|
||
|
</optgroup>
|
||
|
<optgroup label="Logical Operators">
|
||
3 years ago
|
<option v-for="op in logicOp" data-logical-op="true" :data-op="op">
|
||
|
{{ op }}
|
||
|
</option>
|
||
4 years ago
|
</optgroup>
|
||
|
</template>
|
||
3 years ago
|
<optgroup v-else label="Comparison Operators">
|
||
|
<option v-for="op in compOp" v-show="!keys.includes(op)" :data-op="op">
|
||
|
{{ op }}
|
||
|
</option>
|
||
4 years ago
|
</optgroup>
|
||
|
</select>
|
||
|
<div class="delete-wrapper">
|
||
3 years ago
|
<x-icon
|
||
|
v-if="typeof value[key] !== 'string'"
|
||
|
color="red"
|
||
|
icon-class="delete"
|
||
|
x-small
|
||
|
@click="deleteCondition(key)"
|
||
|
>
|
||
4 years ago
|
mdi-delete-outline
|
||
|
</x-icon>
|
||
|
</div>
|
||
|
<span class="separator"> : </span>
|
||
|
</div>
|
||
3 years ago
|
<template v-if="typeof value[key] === 'string'">
|
||
3 years ago
|
<input v-model="value[key]" type="text" class="value caption" />
|
||
3 years ago
|
</template>
|
||
4 years ago
|
<!-- @input="e => $set(value,key,e.target.innerHTML)" -->
|
||
|
|
||
|
<template v-else>
|
||
3 years ago
|
<span v-if="value[key].relationType" class="caption grey--text">
|
||
4 years ago
|
{{ `'${table}' ${value[key].relationType === 'bt' ? 'BelongsTo' : 'HasMany'} '${key}'` }}
|
||
|
</span>
|
||
3 years ago
|
<custom-acl
|
||
|
v-model="value[key]"
|
||
|
:nodes="nodes"
|
||
3 years ago
|
:table="(value[key].relationType ? key : null) || (logicOp.includes(key) ? table : null)"
|
||
3 years ago
|
/>
|
||
4 years ago
|
</template>
|
||
|
</li>
|
||
3 years ago
|
<li v-if="table" class="caption add" @click="addConditionProp">add +</li>
|
||
4 years ago
|
</template>
|
||
|
</ul>
|
||
|
{{ Array.isArray(value) ? '] ,' : '} ,' }}
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { insertKey } from '../../../helpers/xutils';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'CustomAcl',
|
||
3 years ago
|
props: ['value', 'table', 'column', 'nodes'],
|
||
4 years ago
|
data: () => ({
|
||
|
columns: null,
|
||
|
hmList: null,
|
||
|
btList: null,
|
||
3 years ago
|
logicOp: ['_and', '_or', '_not'],
|
||
|
compOp: ['eq', 'neq', 'like', 'nlike', 'in', 'gt', 'lt', 'le', 'ge'],
|
||
|
loading: false,
|
||
4 years ago
|
}),
|
||
3 years ago
|
computed: {
|
||
3 years ago
|
keys() {
|
||
3 years ago
|
return Object.keys(this.value);
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
created() {},
|
||
3 years ago
|
async mounted() {
|
||
3 years ago
|
await this.loadTableMetaDetails();
|
||
3 years ago
|
},
|
||
4 years ago
|
methods: {
|
||
3 years ago
|
onKeyChange(i, key) {
|
||
3 years ago
|
let value = JSON.parse(JSON.stringify(this.value));
|
||
4 years ago
|
|
||
3 years ago
|
const selected = this.$refs[`keySelect${i}`][0].selectedOptions;
|
||
|
let selectedVal = '';
|
||
|
if (selected && selected[0]) {
|
||
|
selectedVal = selected[0].dataset;
|
||
|
}
|
||
4 years ago
|
if (selectedVal.value) {
|
||
3 years ago
|
delete value[key];
|
||
|
value = insertKey(this.keys[i], { eq: '' }, value, i);
|
||
4 years ago
|
} else if (selectedVal.relationType === 'hm') {
|
||
3 years ago
|
delete value[key];
|
||
|
value = insertKey(
|
||
|
selectedVal.table,
|
||
|
{
|
||
|
relationType: 'hm',
|
||
|
'': '',
|
||
|
},
|
||
|
value,
|
||
|
i
|
||
|
);
|
||
4 years ago
|
} else if (selectedVal.relationType === 'bt') {
|
||
3 years ago
|
delete value[key];
|
||
|
value = insertKey(
|
||
|
selectedVal.table,
|
||
|
{
|
||
|
relationType: 'bt',
|
||
|
'': '',
|
||
|
},
|
||
|
value,
|
||
|
i
|
||
|
);
|
||
4 years ago
|
} else if (selectedVal.op) {
|
||
3 years ago
|
const oldVal = value[key];
|
||
|
delete value[key];
|
||
4 years ago
|
if (selectedVal.logicalOp) {
|
||
|
if (selectedVal.op === '_not') {
|
||
3 years ago
|
value = insertKey(
|
||
|
selectedVal.op,
|
||
|
{
|
||
|
'': '',
|
||
|
},
|
||
|
value,
|
||
|
i
|
||
|
);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
value = insertKey(
|
||
|
selectedVal.op,
|
||
|
[
|
||
|
{
|
||
|
'': '',
|
||
|
},
|
||
|
],
|
||
|
value,
|
||
|
i
|
||
|
);
|
||
4 years ago
|
}
|
||
|
} else {
|
||
3 years ago
|
value[selectedVal.op] = oldVal;
|
||
4 years ago
|
}
|
||
|
}
|
||
3 years ago
|
this.$emit('input', value);
|
||
4 years ago
|
},
|
||
3 years ago
|
addConditionProp() {
|
||
3 years ago
|
const value = JSON.parse(JSON.stringify(this.value));
|
||
|
value[''] = '';
|
||
|
this.$emit('input', value);
|
||
4 years ago
|
},
|
||
3 years ago
|
addConditionObj() {
|
||
3 years ago
|
const value = JSON.parse(JSON.stringify(this.value));
|
||
4 years ago
|
value.push({
|
||
3 years ago
|
'': '',
|
||
|
});
|
||
|
this.$emit('input', value);
|
||
4 years ago
|
},
|
||
3 years ago
|
deleteCondition(key) {
|
||
3 years ago
|
const value = JSON.parse(JSON.stringify(this.value));
|
||
|
delete value[key];
|
||
|
this.$emit('input', value);
|
||
4 years ago
|
},
|
||
3 years ago
|
async loadTableMetaDetails() {
|
||
4 years ago
|
if (this.table) {
|
||
3 years ago
|
this.loading = true;
|
||
4 years ago
|
try {
|
||
3 years ago
|
const meta = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'tableXcModelGet',
|
||
|
{
|
||
|
tn: this.table,
|
||
|
},
|
||
|
]);
|
||
|
const metaObj = JSON.parse(meta.meta);
|
||
|
this.columns = metaObj.columns.map(v => v.column_name);
|
||
|
console.log(metaObj);
|
||
|
this.hmList = metaObj.hasMany.map(v => v.table_name);
|
||
|
this.btList = metaObj.belongsTo.map(v => v.rtn);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log('load meta', this.table, e);
|
||
4 years ago
|
} finally {
|
||
3 years ago
|
this.loading = false;
|
||
4 years ago
|
}
|
||
|
}
|
||
3 years ago
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped lang="scss">
|
||
3 years ago
|
.key,
|
||
|
.value {
|
||
4 years ago
|
min-width: 40px;
|
||
|
border-bottom: 1px dotted #bbbbbb;
|
||
|
display: inline-block;
|
||
|
}
|
||
|
|
||
|
ul {
|
||
|
position: relative;
|
||
|
list-style: none;
|
||
|
padding-left: 35px;
|
||
|
overflow: visible;
|
||
|
|
||
|
li {
|
||
|
padding: 1px 5px;
|
||
|
}
|
||
|
|
||
|
border-left: 1px dotted #bbbbbb;
|
||
|
}
|
||
|
|
||
|
select {
|
||
|
border-bottom: 1px dotted #bbbbbb;
|
||
|
-webkit-appearance: listbox;
|
||
|
-moz-appearance: listbox;
|
||
|
appearance: listbox;
|
||
|
}
|
||
|
|
||
|
.separator {
|
||
|
margin: 0 10px;
|
||
|
}
|
||
|
|
||
|
.add {
|
||
|
font-size: 10px;
|
||
|
}
|
||
|
|
||
|
.empty {
|
||
|
background: #ddd;
|
||
|
}
|
||
|
|
||
|
.delete-wrapper {
|
||
|
width: 20px;
|
||
|
display: inline-block;
|
||
|
}
|
||
|
|
||
|
.delete {
|
||
|
max-width: 0;
|
||
|
overflow: hidden;
|
||
|
//opacity: 0;
|
||
3 years ago
|
transition: max-width 0.4s, opacity 0.4s;
|
||
4 years ago
|
}
|
||
|
|
||
|
div:hover > .delete-wrapper .delete {
|
||
|
max-width: 20px;
|
||
|
//opacity: 1;
|
||
|
}
|
||
|
|
||
3 years ago
|
select,
|
||
|
input {
|
||
4 years ago
|
color: var(--v-primary-text);
|
||
|
}
|
||
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|