mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-04 20:47:00 +00:00
refactor: prettier nc-gui v1
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
<template>
|
||||
<v-dialog v-model="dialogShow" persistent max-width="800">
|
||||
<v-card>
|
||||
<v-progress-linear
|
||||
v-if="progressbar"
|
||||
indeterminate
|
||||
color="green"
|
||||
/>
|
||||
<v-progress-linear v-if="progressbar" indeterminate color="green" />
|
||||
<div class="px-2">
|
||||
<v-card-title class=" headline">
|
||||
<v-card-title class="headline">
|
||||
Instant API Editor
|
||||
<v-spacer />
|
||||
<v-btn small :disabled="progressbar" @click="dialogShow = false">
|
||||
@@ -15,9 +11,7 @@
|
||||
{{ $t('general.cancel') }}
|
||||
</v-btn>
|
||||
<v-btn color="primary" small :disabled="progressbar" @click="saveCode">
|
||||
<v-icon small class="mr-1">
|
||||
mdi-content-save
|
||||
</v-icon>
|
||||
<v-icon small class="mr-1"> mdi-content-save </v-icon>
|
||||
<!-- Save -->
|
||||
{{ $t('general.save') }}
|
||||
</v-btn>
|
||||
@@ -28,10 +22,7 @@
|
||||
<!-- v-model="code"-->
|
||||
<!-- ></v-textarea>-->
|
||||
|
||||
<monaco-ts-editor
|
||||
v-model="code"
|
||||
style="min-height: 450px"
|
||||
/>
|
||||
<monaco-ts-editor v-model="code" style="min-height: 450px" />
|
||||
</v-card-text>
|
||||
</div>
|
||||
</v-card>
|
||||
@@ -39,7 +30,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MonacoTsEditor from '../monaco/MonacoTsEditor'
|
||||
import MonacoTsEditor from '../monaco/MonacoTsEditor';
|
||||
|
||||
export default {
|
||||
name: 'HandlerCodeEditor',
|
||||
@@ -51,106 +42,120 @@ export default {
|
||||
nodes: Object,
|
||||
isMiddleware: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
data: () => ({
|
||||
progressbar: false,
|
||||
code: ''
|
||||
code: '',
|
||||
}),
|
||||
computed: {
|
||||
dialogShow: {
|
||||
get() {
|
||||
return this.value
|
||||
return this.value;
|
||||
},
|
||||
set(val) {
|
||||
this.$emit('input', val)
|
||||
}
|
||||
}
|
||||
this.$emit('input', val);
|
||||
},
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
async route(val) {
|
||||
try {
|
||||
if (this.isMiddleware) {
|
||||
this.code = JSON.parse(val.functions)[0]
|
||||
this.code = JSON.parse(val.functions)[0];
|
||||
} else {
|
||||
this.code = JSON.parse(val[this.method].functions)[0]
|
||||
this.code = JSON.parse(val[this.method].functions)[0];
|
||||
}
|
||||
} catch (e) {
|
||||
let functions
|
||||
let functions;
|
||||
if (this.isMiddleware) {
|
||||
functions = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||||
env: this.nodes.env,
|
||||
dbAlias: this.nodes.dbAlias,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name
|
||||
}, 'defaultRestMiddlewareCodeGet', {
|
||||
title: this.route.title,
|
||||
relation_type: this.route.relation_type,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name
|
||||
}])
|
||||
functions = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||||
{
|
||||
env: this.nodes.env,
|
||||
dbAlias: this.nodes.dbAlias,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name,
|
||||
},
|
||||
'defaultRestMiddlewareCodeGet',
|
||||
{
|
||||
title: this.route.title,
|
||||
relation_type: this.route.relation_type,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name,
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
functions = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||||
env: this.nodes.env,
|
||||
dbAlias: this.nodes.dbAlias,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name
|
||||
}, 'defaultRestHandlerCodeGet', {
|
||||
type: this.method,
|
||||
path: this.route[this.method].path,
|
||||
title: this.route[this.method].title,
|
||||
relation_type: this.route[this.method].relation_type,
|
||||
tnp: this.route[this.method].table_namep,
|
||||
tnc: this.route[this.method].table_namec,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name
|
||||
}])
|
||||
functions = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||||
{
|
||||
env: this.nodes.env,
|
||||
dbAlias: this.nodes.dbAlias,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name,
|
||||
},
|
||||
'defaultRestHandlerCodeGet',
|
||||
{
|
||||
type: this.method,
|
||||
path: this.route[this.method].path,
|
||||
title: this.route[this.method].title,
|
||||
relation_type: this.route[this.method].relation_type,
|
||||
tnp: this.route[this.method].table_namep,
|
||||
tnc: this.route[this.method].table_namec,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name,
|
||||
},
|
||||
]);
|
||||
}
|
||||
if (functions && functions.length) {
|
||||
this.code = functions[0]
|
||||
this.code = functions[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
async saveCode() {
|
||||
try {
|
||||
this.progressbar = true
|
||||
this.progressbar = true;
|
||||
if (this.isMiddleware) {
|
||||
await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||||
env: this.nodes.env,
|
||||
dbAlias: this.nodes.dbAlias
|
||||
}, 'xcRoutesMiddlewareUpdate', {
|
||||
table_name: this.nodes.table_name || this.nodes.view_name,
|
||||
type: this.method,
|
||||
functions: [this.code],
|
||||
title: this.route.title
|
||||
}])
|
||||
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||||
{
|
||||
env: this.nodes.env,
|
||||
dbAlias: this.nodes.dbAlias,
|
||||
},
|
||||
'xcRoutesMiddlewareUpdate',
|
||||
{
|
||||
table_name: this.nodes.table_name || this.nodes.view_name,
|
||||
type: this.method,
|
||||
functions: [this.code],
|
||||
title: this.route.title,
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||||
env: this.nodes.env,
|
||||
dbAlias: this.nodes.dbAlias
|
||||
}, 'xcRoutesHandlerUpdate', {
|
||||
type: this.method,
|
||||
title: this.route[this.method].title,
|
||||
functions: [this.code],
|
||||
path: this.route[this.method].path,
|
||||
relation_type: this.route[this.method].relation_type,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name
|
||||
}])
|
||||
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||||
{
|
||||
env: this.nodes.env,
|
||||
dbAlias: this.nodes.dbAlias,
|
||||
},
|
||||
'xcRoutesHandlerUpdate',
|
||||
{
|
||||
type: this.method,
|
||||
title: this.route[this.method].title,
|
||||
functions: [this.code],
|
||||
path: this.route[this.method].path,
|
||||
relation_type: this.route[this.method].relation_type,
|
||||
table_name: this.nodes.table_name || this.nodes.view_name,
|
||||
},
|
||||
]);
|
||||
}
|
||||
this.$toast.success('API Handler updated successfully').goAway(3000)
|
||||
this.dialogShow = false
|
||||
this.$toast.success('API Handler updated successfully').goAway(3000);
|
||||
this.dialogShow = false;
|
||||
} catch (e) {
|
||||
console.log('Error', e)
|
||||
this.$toast.error('Some internal error occurred').goAway(3000)
|
||||
console.log('Error', e);
|
||||
this.$toast.error('Some internal error occurred').goAway(3000);
|
||||
}
|
||||
this.progressbar = false
|
||||
}
|
||||
}
|
||||
}
|
||||
this.progressbar = false;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
<style scoped></style>
|
||||
<!--
|
||||
/**
|
||||
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||||
|
||||
Reference in New Issue
Block a user