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.
282 lines
8.1 KiB
282 lines
8.1 KiB
4 years ago
|
<template>
|
||
|
<div class="">
|
||
|
<v-card style="">
|
||
3 years ago
|
<v-toolbar height="42" flat class="toolbar-border-bottom">
|
||
4 years ago
|
<v-toolbar-title>
|
||
3 years ago
|
<v-breadcrumbs
|
||
3 years ago
|
:items="[
|
||
|
{
|
||
|
text: nodes.env,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.dbAlias,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.table_name + ' (mocks)',
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
]"
|
||
3 years ago
|
divider=">"
|
||
|
small
|
||
|
>
|
||
|
<template #divider>
|
||
3 years ago
|
<v-icon small> forward </v-icon>
|
||
4 years ago
|
</template>
|
||
|
</v-breadcrumbs>
|
||
|
</v-toolbar-title>
|
||
3 years ago
|
<v-spacer />
|
||
|
<x-btn
|
||
3 years ago
|
v-ge="['mocks', 'load']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Reload Rows"
|
||
|
small
|
||
|
color="primary"
|
||
|
class="primary"
|
||
|
@click="loadColumnList"
|
||
4 years ago
|
>
|
||
3 years ago
|
<v-icon small left> refresh </v-icon>
|
||
3 years ago
|
<!-- Reload -->
|
||
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
|
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['mocks', 'load-faker-fns']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Load suggested faker function based on field name"
|
||
|
color="primary"
|
||
|
class="primary"
|
||
|
small
|
||
|
@click="mapFieldWithSuggestedFakerFn"
|
||
|
>
|
||
3 years ago
|
<v-icon left small> mdi-function </v-icon>
|
||
4 years ago
|
Predict Faker Functions
|
||
|
</x-btn>
|
||
|
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['mocks', 'save']"
|
||
3 years ago
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
3 years ago
|
color="success"
|
||
|
class="success"
|
||
|
small
|
||
|
:disabled="disableSaveButton"
|
||
|
@click="saveFakeFunctions"
|
||
4 years ago
|
>
|
||
3 years ago
|
<v-icon small left> save </v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
3 years ago
|
<v-data-table dense :headers="colsHeader" :items="cols" class="column-table">
|
||
|
<template #item="{ item }">
|
||
4 years ago
|
<tr>
|
||
|
<td>
|
||
3 years ago
|
{{ item.column_name }}<span class="font-weight-thin"> - {{ item.dt }}</span>
|
||
4 years ago
|
</td>
|
||
|
<td>
|
||
3 years ago
|
<span v-if="item.pk" class="font-weight-thin"> (Primary Key)</span>
|
||
|
<span v-else-if="item.rcn" class="font-weight-thin"> (Foreign Key)</span>
|
||
4 years ago
|
<v-autocomplete
|
||
|
v-else
|
||
3 years ago
|
v-model="item.fakerFunction"
|
||
3 years ago
|
v-ge="['mocks', 'change-faker-fn']"
|
||
4 years ago
|
:items="fakerFunctionList | filterFakerList(item.dt)"
|
||
|
item-text="name"
|
||
|
item-value="value"
|
||
|
@change="disableSaveButton = false"
|
||
|
>
|
||
3 years ago
|
<template #selection="{ item }">
|
||
|
<div class="body-2">
|
||
3 years ago
|
{{ item.name }}<span v-if="item.type" class="font-weight-thin"> - {{ item.type }}</span>
|
||
3 years ago
|
</div>
|
||
4 years ago
|
</template>
|
||
|
|
||
3 years ago
|
<template #item="data">
|
||
4 years ago
|
<v-list-item-content>
|
||
3 years ago
|
<v-list-item-title v-html="data.item.name" />
|
||
|
<v-list-item-subtitle v-html="data.item.group" />
|
||
4 years ago
|
</v-list-item-content>
|
||
|
</template>
|
||
|
</v-autocomplete>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</template>
|
||
|
</v-data-table>
|
||
|
</v-card>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapGetters } from 'vuex';
|
||
|
import fakerFunctionList from '../../../helpers/fakerFunctionList';
|
||
|
import dataTypeMapping from '../../../helpers/findDataTypeMapping';
|
||
|
const levenshtein = require('fast-levenshtein');
|
||
4 years ago
|
|
||
3 years ago
|
export default {
|
||
|
components: {},
|
||
3 years ago
|
data() {
|
||
3 years ago
|
return {
|
||
|
colsHeader: [{ text: 'Column Name' }, { text: 'Mapper Function' }],
|
||
|
cols: [],
|
||
|
primaryKeys: [],
|
||
|
fakerFunctionList,
|
||
3 years ago
|
disableSaveButton: true,
|
||
|
};
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async handleKeyDown({ metaKey, key, altKey, shiftKey, ctrlKey }) {
|
||
3 years ago
|
console.log(metaKey, key, altKey, shiftKey, ctrlKey);
|
||
3 years ago
|
// cmd + s -> save
|
||
|
// cmd + l -> reload
|
||
|
// cmd + n -> new
|
||
|
// cmd + d -> delete
|
||
|
// cmd + enter -> send api
|
||
4 years ago
|
|
||
3 years ago
|
switch ([metaKey, key].join('_')) {
|
||
3 years ago
|
case 'true_s':
|
||
|
await this.saveFakeFunctions();
|
||
|
break;
|
||
|
case 'true_l':
|
||
|
await this.loadColumnList();
|
||
|
break;
|
||
|
// case 'true_n' :
|
||
|
// this.addColumn();
|
||
|
// break;
|
||
|
// case 'true_d' :
|
||
|
// await this.deleteTable('showDialog');
|
||
|
// break;
|
||
3 years ago
|
}
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
async loadColumnList() {
|
||
3 years ago
|
this.disableSaveButton = true;
|
||
3 years ago
|
const columnsList = await this.client.fakerColumnsList({
|
||
3 years ago
|
table_name: this.nodes.table_name,
|
||
3 years ago
|
seedsFolder: this.seedsFolder,
|
||
|
});
|
||
|
console.log(columnsList);
|
||
|
this.cols = columnsList.data.list;
|
||
4 years ago
|
|
||
3 years ago
|
// columnsList.data.list.map(({cn, dt, ai, pk}) => {
|
||
|
// if (pk) this.primaryKeys.push(cn);
|
||
|
// return {
|
||
|
// text: cn, value: cn, type: dt, ai
|
||
|
// }
|
||
|
// })
|
||
|
},
|
||
3 years ago
|
mapFieldWithSuggestedFakerFn() {
|
||
3 years ago
|
this.cols = this.cols.map(col => {
|
||
|
let suggestion = null;
|
||
|
let lScore = Infinity;
|
||
|
const nativeType = dataTypeMapping(col.dt);
|
||
3 years ago
|
fakerFunctionList.forEach((fakerFn, i) => {
|
||
3 years ago
|
if (nativeType !== 'string' && nativeType !== fakerFn.type) {
|
||
|
return;
|
||
|
}
|
||
4 years ago
|
|
||
3 years ago
|
if (i) {
|
||
3 years ago
|
const ls = levenshtein.get(col.column_name.toLowerCase(), fakerFn.name.toLowerCase());
|
||
3 years ago
|
if (lScore > ls) {
|
||
3 years ago
|
lScore = ls;
|
||
|
suggestion = fakerFn;
|
||
4 years ago
|
}
|
||
3 years ago
|
} else {
|
||
3 years ago
|
suggestion = fakerFn;
|
||
|
lScore = levenshtein.get(col.column_name.toLowerCase(), fakerFn.name.toLowerCase());
|
||
4 years ago
|
}
|
||
3 years ago
|
});
|
||
4 years ago
|
|
||
3 years ago
|
if (lScore < 3) {
|
||
3 years ago
|
this.disableSaveButton = false;
|
||
|
return { ...col, fakerFunction: suggestion.value };
|
||
3 years ago
|
}
|
||
3 years ago
|
return col;
|
||
|
});
|
||
4 years ago
|
},
|
||
3 years ago
|
async saveFakeFunctions() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.client.fakerColumnsCreate({
|
||
|
fakerColumns: this.cols,
|
||
|
seedsFolder: this.seedsFolder,
|
||
|
table_name: this.nodes.table_name,
|
||
|
});
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Saving changes to faker functions failed').goAway(3000);
|
||
|
throw e;
|
||
4 years ago
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
},
|
||
|
computed: {
|
||
3 years ago
|
...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
|
||
3 years ago
|
},
|
||
3 years ago
|
beforeCreated() {},
|
||
3 years ago
|
watch: {},
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
try {
|
||
|
this.seedsFolder = this.sqlMgr.projectGetFolder({
|
||
|
env: this.nodes.env,
|
||
3 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
|
});
|
||
3 years ago
|
this.client = await this.sqlMgr.projectGetSqlClient({
|
||
|
env: this.nodes.env,
|
||
3 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
|
});
|
||
|
await this.loadColumnList();
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e);
|
||
|
this.$toast.error('Loading columns and faker functions failed').goAway(3000);
|
||
|
throw e;
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
mounted() {},
|
||
|
beforeDestroy() {},
|
||
|
destroy() {},
|
||
3 years ago
|
directives: {},
|
||
|
filters: {
|
||
3 years ago
|
filterFakerList(list, type) {
|
||
3 years ago
|
const nativeType = dataTypeMapping(type);
|
||
|
return list.filter(item => nativeType === 'string' || nativeType === item.type);
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
validate({ params }) {
|
||
3 years ago
|
return true;
|
||
3 years ago
|
},
|
||
3 years ago
|
head() {
|
||
3 years ago
|
return {};
|
||
3 years ago
|
},
|
||
3 years ago
|
props: ['nodes', 'newTable', 'mtdNewTableUpdate', 'deleteTable'],
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
3 years ago
|
<style scoped></style>
|
||
4 years ago
|
<!--
|
||
|
/**
|
||
|
* @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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|