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.
302 lines
8.4 KiB
302 lines
8.4 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
|
||
|
:items="[{
|
||
|
text: nodes.env,
|
||
|
disabled: true,
|
||
|
href: '#'
|
||
|
},{
|
||
|
text: nodes.dbAlias,
|
||
|
disabled: true,
|
||
|
href: '#'
|
||
|
},
|
||
|
{
|
||
|
text: nodes.view_name + ' (view)',
|
||
|
disabled: true,
|
||
|
href: '#'
|
||
|
}]"
|
||
|
divider=">"
|
||
|
small
|
||
|
>
|
||
|
<template #divider>
|
||
|
<v-icon small color="grey lighten-2">
|
||
|
forward
|
||
|
</v-icon>
|
||
4 years ago
|
</template>
|
||
|
</v-breadcrumbs>
|
||
|
</v-toolbar-title>
|
||
3 years ago
|
<v-spacer />
|
||
|
<x-btn
|
||
|
outlined
|
||
|
tooltip="Reload View"
|
||
|
small
|
||
|
color="primary"
|
||
|
icon="refresh"
|
||
|
@click="loadEnv()"
|
||
|
>
|
||
3 years ago
|
<!-- Reload -->
|
||
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
3 years ago
|
:disabled="nodes.dbConnection.client === 'sqlite3' && !newView "
|
||
|
small
|
||
|
color="primary"
|
||
|
icon="save"
|
||
|
@click="applyChanges()"
|
||
|
>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
3 years ago
|
</x-btn>
|
||
|
<x-btn
|
||
|
outlined
|
||
|
tooltip="Delete View"
|
||
|
small
|
||
|
color="error"
|
||
|
icon="mdi-delete-outline"
|
||
|
@click="deleteView('showDialog')"
|
||
|
>
|
||
|
Delete View
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
|
<MonacoEditor
|
||
|
v-if="view.view_definition != undefined"
|
||
|
:code.sync="view.view_definition"
|
||
3 years ago
|
css-style="border:1px solid grey;height:500px; width:100%"
|
||
4 years ago
|
/>
|
||
|
|
||
|
<dlgLabelSubmitCancel
|
||
|
v-if="dialogShow"
|
||
3 years ago
|
:dialog-show="dialogShow"
|
||
|
:actions-mtd="deleteView"
|
||
|
css-style="height:300px"
|
||
4 years ago
|
heading="Click Submit to Delete the View"
|
||
|
type="error"
|
||
|
/>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapActions } from 'vuex'
|
||
4 years ago
|
|
||
3 years ago
|
import MonacoEditor from '../../monaco/Monaco'
|
||
3 years ago
|
import dlgLabelSubmitCancel from '../../utils/DlgLabelSubmitCancel'
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
components: { MonacoEditor, dlgLabelSubmitCancel },
|
||
3 years ago
|
data() {
|
||
4 years ago
|
return {
|
||
|
view: {},
|
||
3 years ago
|
oldViewDefination: '',
|
||
|
newView: !!this.nodes.newView,
|
||
4 years ago
|
dialogShow: false
|
||
3 years ago
|
}
|
||
4 years ago
|
},
|
||
|
computed: {},
|
||
|
methods: {
|
||
|
...mapActions({
|
||
3 years ago
|
loadViewsFromChildTreeNode: 'project/loadViewsFromChildTreeNode',
|
||
|
loadViewsFromParentTreeNode: 'project/loadViewsFromParentTreeNode',
|
||
|
removeViewTab: 'tabs/removeViewTab'
|
||
4 years ago
|
}),
|
||
|
|
||
3 years ago
|
async handleKeyDown({ metaKey, key, altKey, shiftKey, ctrlKey }) {
|
||
4 years ago
|
console.log(metaKey, key, altKey, shiftKey, ctrlKey)
|
||
|
// cmd + s -> save
|
||
|
// cmd + l -> reload
|
||
|
// cmd + n -> new
|
||
|
// cmd + d -> delete
|
||
|
// cmd + enter -> send api
|
||
|
|
||
|
switch ([metaKey, key].join('_')) {
|
||
|
case 'true_s' :
|
||
3 years ago
|
await this.applyChanges()
|
||
|
break
|
||
4 years ago
|
case 'true_l' :
|
||
3 years ago
|
await this.loadEnv()
|
||
|
break
|
||
4 years ago
|
// case 'true_n' :
|
||
|
// this.addColumn();
|
||
|
// break;
|
||
|
case 'true_d' :
|
||
3 years ago
|
await this.deleteView('showDialog')
|
||
|
break
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async loadEnv() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
this.$store.commit('notification/MutToggleProgressBar', true)
|
||
4 years ago
|
if (this.newView) {
|
||
3 years ago
|
this.view = { view_name: this.nodes.view_name, view_definition: '' }
|
||
|
this.$store.commit('notification/MutToggleProgressBar', false)
|
||
|
return
|
||
4 years ago
|
}
|
||
|
// // console.log("env: this.env", this.env, this.dbAlias);
|
||
|
// const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// });
|
||
|
// const result = await client.viewRead({view_name: this.nodes.view_name});
|
||
|
|
||
|
// const result = await this.sqlMgr.sqlOp({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// }, 'viewRead', {view_name: this.nodes.view_name})
|
||
|
|
||
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
3 years ago
|
}, 'viewRead', { view_name: this.nodes.view_name }])
|
||
4 years ago
|
|
||
3 years ago
|
console.log('view read', result)
|
||
|
this.view = { ...result.data.list[0] }
|
||
|
this.oldViewDefination = `${this.view.view_definition}` + '' // for migration statements
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e)
|
||
4 years ago
|
} finally {
|
||
3 years ago
|
this.$store.commit('notification/MutToggleProgressBar', false)
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async applyChanges() {
|
||
4 years ago
|
try {
|
||
|
if (this.newView) {
|
||
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
3 years ago
|
'viewCreate',
|
||
4 years ago
|
{
|
||
|
view_name: this.nodes.view_name,
|
||
3 years ago
|
title: this.nodes.title,
|
||
4 years ago
|
view_definition: this.view.view_definition
|
||
|
}]
|
||
3 years ago
|
)
|
||
4 years ago
|
|
||
|
await this.loadViewsFromChildTreeNode({
|
||
|
_nodes: {
|
||
|
...this.nodes
|
||
|
}
|
||
3 years ago
|
})
|
||
|
console.log('create view result', result)
|
||
|
this.newView = false
|
||
|
this.oldViewDefination = `${this.view.view_definition}` + '' // for migration statments
|
||
|
this.$toast.success('View created successfully').goAway(3000)
|
||
|
delete this.nodes.newView
|
||
4 years ago
|
this.$emit('created')
|
||
|
} else {
|
||
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
3 years ago
|
'viewUpdate',
|
||
4 years ago
|
{
|
||
|
view_name: this.nodes.view_name,
|
||
|
view_definition: this.view.view_definition,
|
||
|
oldViewDefination: this.oldViewDefination
|
||
|
}]
|
||
3 years ago
|
)
|
||
|
this.$toast.success('View updated successfully').goAway(3000)
|
||
|
this.oldViewDefination = `${this.view.view_definition}` + '' // for migration statments
|
||
|
console.log('update view result', result)
|
||
4 years ago
|
}
|
||
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Error while saving view').goAway(3000)
|
||
|
throw e
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async deleteView(action = '') {
|
||
4 years ago
|
try {
|
||
3 years ago
|
if (action === 'showDialog') {
|
||
|
this.dialogShow = true
|
||
|
} else if (action === 'hideDialog') {
|
||
|
this.dialogShow = false
|
||
4 years ago
|
} else {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
3 years ago
|
'viewDelete',
|
||
4 years ago
|
{
|
||
|
view_name: this.nodes.view_name,
|
||
|
oldViewDefination: this.oldViewDefination
|
||
|
}
|
||
3 years ago
|
])
|
||
4 years ago
|
this.removeViewTab({
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
view_name: this.nodes.view_name
|
||
3 years ago
|
})
|
||
4 years ago
|
await this.loadViewsFromParentTreeNode({
|
||
|
_nodes: {
|
||
|
...this.nodes
|
||
|
}
|
||
3 years ago
|
})
|
||
|
this.dialogShow = false
|
||
4 years ago
|
|
||
3 years ago
|
this.$toast.success('View deleted successfully').goAway(3000)
|
||
4 years ago
|
}
|
||
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('View deleted failed').goAway(3000)
|
||
|
throw e
|
||
4 years ago
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
beforeCreated() {
|
||
4 years ago
|
},
|
||
3 years ago
|
watch: {},
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
await this.loadEnv()
|
||
4 years ago
|
},
|
||
3 years ago
|
mounted() {
|
||
4 years ago
|
},
|
||
3 years ago
|
beforeDestroy() {
|
||
4 years ago
|
},
|
||
3 years ago
|
destroy() {
|
||
4 years ago
|
},
|
||
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>
|
||
|
|
||
|
<style scoped>
|
||
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|