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.
138 lines
3.8 KiB
138 lines
3.8 KiB
4 years ago
|
<template>
|
||
|
<v-dialog v-model="dialogShow" persistent max-width="800">
|
||
|
<v-card>
|
||
2 years ago
|
<v-progress-linear v-if="progressbar" indeterminate color="green" />
|
||
4 years ago
|
<div class="px-2">
|
||
2 years ago
|
<v-card-title class="headline">
|
||
3 years ago
|
Instant API Editor
|
||
|
<v-spacer />
|
||
|
<v-btn small :disabled="progressbar" @click="dialogShow = false">
|
||
3 years ago
|
<!-- Cancel -->
|
||
|
{{ $t('general.cancel') }}
|
||
3 years ago
|
</v-btn>
|
||
4 years ago
|
<v-btn color="primary" small :disabled="progressbar" @click="saveCode">
|
||
2 years ago
|
<v-icon small class="mr-1"> mdi-content-save </v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
</v-btn>
|
||
|
</v-card-title>
|
||
|
|
||
|
<v-card-text>
|
||
|
<!-- <v-textarea-->
|
||
|
<!-- v-model="code"-->
|
||
|
<!-- ></v-textarea>-->
|
||
|
|
||
2 years ago
|
<monaco-ts-editor v-model="code" style="min-height: 450px" />
|
||
4 years ago
|
</v-card-text>
|
||
|
</div>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import MonacoTsEditor from '../monaco/MonacoTsEditor';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'GqlHandlerCodeEditor',
|
||
|
components: { MonacoTsEditor },
|
||
4 years ago
|
props: {
|
||
|
value: Boolean,
|
||
|
resolver: Object,
|
||
|
nodes: Object,
|
||
|
isMiddleware: {
|
||
|
type: Boolean,
|
||
2 years ago
|
default: false,
|
||
4 years ago
|
},
|
||
2 years ago
|
functions: String,
|
||
4 years ago
|
},
|
||
3 years ago
|
data: () => ({
|
||
|
progressbar: false,
|
||
2 years ago
|
code: '',
|
||
3 years ago
|
}),
|
||
|
computed: {
|
||
|
dialogShow: {
|
||
3 years ago
|
get() {
|
||
2 years ago
|
return this.value;
|
||
3 years ago
|
},
|
||
3 years ago
|
set(val) {
|
||
2 years ago
|
this.$emit('input', val);
|
||
|
},
|
||
|
},
|
||
4 years ago
|
},
|
||
|
watch: {
|
||
3 years ago
|
async resolver(val) {
|
||
4 years ago
|
try {
|
||
2 years ago
|
console.log('=============', this.functions);
|
||
|
this.code = JSON.parse(this.functions)[0];
|
||
4 years ago
|
} catch (e) {
|
||
2 years ago
|
const functionCode = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
this.isMiddleware ? 'defaultResolverMiddlewareCode' : 'defaultResolverHandlerCodeGet',
|
||
|
{
|
||
|
table_name: this.nodes.table_name || this.nodes.view_name,
|
||
|
resolver: this.resolver,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
if (functionCode) {
|
||
2 years ago
|
this.code = functionCode;
|
||
4 years ago
|
}
|
||
|
}
|
||
2 years ago
|
},
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async saveCode() {
|
||
3 years ago
|
try {
|
||
2 years ago
|
this.progressbar = true;
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
this.isMiddleware ? 'xcResolverMiddlewareUpdate' : 'xcResolverHandlerUpdate',
|
||
|
{
|
||
|
table_name: this.nodes.table_name || this.nodes.view_name,
|
||
|
resolver: this.resolver,
|
||
|
functions: [this.code],
|
||
|
},
|
||
|
]);
|
||
|
this.$toast.success('API Handler updated successfully').goAway(3000);
|
||
|
this.dialogShow = false;
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log('Error', e);
|
||
|
this.$toast.error('Some internal error occurred').goAway(3000);
|
||
3 years ago
|
}
|
||
2 years ago
|
this.progressbar = false;
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
2 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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|