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.
288 lines
8.2 KiB
288 lines
8.2 KiB
4 years ago
|
<template>
|
||
|
<v-container class="pa-0 ma-0" fluid>
|
||
|
<v-toolbar flat height="42" class="toolbar-border-bottom">
|
||
|
<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.function_name + ' (function)',
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
]"
|
||
3 years ago
|
divider=">"
|
||
|
dark
|
||
|
large
|
||
|
light
|
||
|
class="title"
|
||
|
>
|
||
|
<template #divider>
|
||
3 years ago
|
<v-icon small color="grey lighten-2"> forward </v-icon>
|
||
4 years ago
|
</template>
|
||
|
</v-breadcrumbs>
|
||
|
</v-toolbar-title>
|
||
3 years ago
|
<v-spacer />
|
||
3 years ago
|
<x-btn outlined :tooltip="$t('tooltip.saveChanges')" small color="primary" icon="save" @click="applyChanges()">
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
3 years ago
|
</x-btn>
|
||
|
<x-btn
|
||
|
outlined
|
||
|
tooltip="Delete Function"
|
||
|
small
|
||
|
color="error"
|
||
|
icon="mdi-delete-outline"
|
||
|
@click="deleteFunction('showDialog')"
|
||
|
>
|
||
4 years ago
|
Delete Function
|
||
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
|
<monaco-editor
|
||
|
v-if="functionData.create_function != undefined"
|
||
|
:code.sync="functionData.create_function"
|
||
3 years ago
|
css-style="height:400px"
|
||
|
/>
|
||
4 years ago
|
|
||
|
<dlgLabelSubmitCancel
|
||
|
v-if="dialogShow"
|
||
3 years ago
|
:dialog-show="dialogShow"
|
||
|
:actions-mtd="deleteFunction"
|
||
4 years ago
|
heading="Click Submit to Delete the Function"
|
||
|
type="error"
|
||
|
/>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapGetters, mapActions } from 'vuex';
|
||
4 years ago
|
|
||
3 years ago
|
import { SqlUiFactory } from 'nocodb-sdk';
|
||
|
import MonacoEditor from '../../monaco/Monaco';
|
||
|
import dlgLabelSubmitCancel from '../../utils/DlgLabelSubmitCancel';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
components: { MonacoEditor, dlgLabelSubmitCancel },
|
||
3 years ago
|
data() {
|
||
4 years ago
|
return {
|
||
|
functionData: {},
|
||
3 years ago
|
newFunction: !!this.nodes.newFunction,
|
||
|
oldCreateFunction: '',
|
||
3 years ago
|
dialogShow: false,
|
||
|
};
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
3 years ago
|
...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
|
...mapActions({
|
||
3 years ago
|
loadFunctionsFromChildTreeNode: 'project/loadFunctionsFromChildTreeNode',
|
||
3 years ago
|
loadFunctionsFromParentTreeNode: 'project/loadFunctionsFromParentTreeNode',
|
||
|
removeFunctionTab: 'tabs/removeFunctionTab',
|
||
4 years ago
|
}),
|
||
|
|
||
3 years ago
|
async handleKeyDown({ metaKey, key, altKey, shiftKey, ctrlKey }) {
|
||
4 years ago
|
// cmd + s -> save
|
||
|
// cmd + l -> reload
|
||
|
// cmd + n -> new
|
||
|
// cmd + d -> delete
|
||
|
// cmd + enter -> send api
|
||
|
|
||
|
switch ([metaKey, key].join('_')) {
|
||
3 years ago
|
case 'true_s':
|
||
|
await this.applyChanges();
|
||
|
break;
|
||
|
case 'true_l':
|
||
|
await this.loadFunction();
|
||
|
break;
|
||
4 years ago
|
// case 'true_n' :
|
||
|
// this.addColumn();
|
||
|
// break;
|
||
3 years ago
|
case 'true_d':
|
||
|
await this.deleteFunction('showDialog');
|
||
|
break;
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async loadFunction() {
|
||
4 years ago
|
if (this.newFunction) {
|
||
|
this.functionData = {
|
||
|
function_name: this.nodes.function_name,
|
||
3 years ago
|
create_function: '',
|
||
|
};
|
||
|
return;
|
||
4 years ago
|
}
|
||
|
// const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// });
|
||
|
// const result = await client.functionRead({
|
||
|
// function_name: this.nodes.function_name
|
||
|
// });
|
||
|
|
||
|
//
|
||
|
// const result = await this.sqlMgr.sqlOp({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// }, 'functionRead', { function_name: this.nodes.function_name})
|
||
|
|
||
3 years ago
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'functionRead',
|
||
|
{ function_name: this.nodes.function_name },
|
||
|
]);
|
||
4 years ago
|
|
||
|
// console.log("functionData read", result);
|
||
3 years ago
|
this.functionData = result.data.list[0];
|
||
|
this.oldCreateFunction = `${this.functionData.create_function}` + '';
|
||
4 years ago
|
},
|
||
3 years ago
|
async applyChanges() {
|
||
4 years ago
|
try {
|
||
|
if (this.newFunction) {
|
||
3 years ago
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
3 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
4 years ago
|
},
|
||
3 years ago
|
'functionCreate',
|
||
4 years ago
|
{
|
||
|
function_name: this.nodes.function_name,
|
||
3 years ago
|
create_function: this.functionData.create_function,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
await this.loadFunctionsFromChildTreeNode({
|
||
|
_nodes: {
|
||
3 years ago
|
...this.nodes,
|
||
|
},
|
||
|
});
|
||
|
this.newFunction = false;
|
||
|
this.oldCreateFunction = `${this.functionData.create_function}` + '';
|
||
|
this.$toast.success('Function created successfully').goAway(3000);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
const functionName = this.sqlUi.extractFunctionName(this.functionData.create_function);
|
||
3 years ago
|
if (!functionName) {
|
||
3 years ago
|
this.$toast.error('Invalid syntax, please check function name.').goAway(5000);
|
||
|
return;
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
3 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
4 years ago
|
},
|
||
3 years ago
|
'functionUpdate',
|
||
4 years ago
|
{
|
||
3 years ago
|
function_name: functionName,
|
||
4 years ago
|
create_function: this.functionData.create_function,
|
||
|
function_declaration: this.functionData.function_declaration,
|
||
3 years ago
|
oldCreateFunction: this.oldCreateFunction,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
|
||
3 years ago
|
this.oldCreateFunction = `${this.functionData.create_function}` + '';
|
||
|
this.$toast.success('Function updated successfully').goAway(3000);
|
||
4 years ago
|
}
|
||
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Saving function failed').goAway(3000);
|
||
|
throw e;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async deleteFunction(action = '') {
|
||
4 years ago
|
try {
|
||
3 years ago
|
if (action === 'showDialog') {
|
||
3 years ago
|
this.dialogShow = true;
|
||
3 years ago
|
} else if (action === 'hideDialog') {
|
||
3 years ago
|
this.dialogShow = false;
|
||
4 years ago
|
} else {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
3 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
4 years ago
|
},
|
||
3 years ago
|
'functionDelete',
|
||
4 years ago
|
{
|
||
|
function_name: this.nodes.function_name,
|
||
|
create_function: this.functionData.create_function,
|
||
3 years ago
|
function_declaration: this.functionData.function_declaration,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
|
||
|
this.removeFunctionTab({
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
3 years ago
|
function_name: this.nodes.function_name,
|
||
|
});
|
||
4 years ago
|
await this.loadFunctionsFromParentTreeNode({
|
||
|
_nodes: {
|
||
3 years ago
|
...this.nodes,
|
||
|
},
|
||
|
});
|
||
|
this.dialogShow = false;
|
||
|
this.$toast.success('Function deleted successfully').goAway(3000);
|
||
4 years ago
|
}
|
||
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Deleting function failed').goAway(3000);
|
||
|
throw e;
|
||
4 years ago
|
}
|
||
3 years ago
|
},
|
||
4 years ago
|
},
|
||
3 years ago
|
beforeCreated() {},
|
||
3 years ago
|
watch: {},
|
||
3 years ago
|
created() {
|
||
3 years ago
|
this.sqlUi = SqlUiFactory.create(this.nodes.dbConnection);
|
||
4 years ago
|
},
|
||
3 years ago
|
mounted() {
|
||
3 years ago
|
this.loadFunction();
|
||
4 years ago
|
},
|
||
3 years ago
|
beforeDestroy() {},
|
||
|
destroy() {},
|
||
3 years ago
|
directives: {},
|
||
3 years ago
|
validate({ params }) {
|
||
3 years ago
|
return true;
|
||
4 years ago
|
},
|
||
3 years ago
|
head() {
|
||
3 years ago
|
return {};
|
||
4 years ago
|
},
|
||
3 years ago
|
props: ['nodes'],
|
||
|
};
|
||
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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|