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.
883 lines
29 KiB
883 lines
29 KiB
3 years ago
|
<template>
|
||
|
<v-container class="ma-0 pa-0 sql-editor" fluid style="height: 100%">
|
||
|
<!-- <v-toolbar class="elevation-0 search-toolbar pa-0" :height="48">-->
|
||
|
<!-- <v-autocomplete-->
|
||
|
<!-- ref="search"-->
|
||
|
<!-- v-model="selectedQueryItem"-->
|
||
|
<!-- @change="changedSelectedQuery(selectedQueryItem)"-->
|
||
|
<!-- clearable-->
|
||
|
<!-- item-text="query"-->
|
||
|
<!-- outlined-->
|
||
|
<!-- solo-inverted-->
|
||
|
<!-- dense-->
|
||
|
<!-- single-line-->
|
||
|
<!-- hide-details-->
|
||
|
<!-- open-on-clear-->
|
||
|
<!-- label="Search queries by words ( ⌘ P )"-->
|
||
|
<!-- :items="$store.state.sqlClient.list"-->
|
||
|
<!-- :filter="queryFilter"-->
|
||
|
<!-- prepend-inner-icon="search"-->
|
||
|
<!-- no-data-text="No queries in the search history"-->
|
||
|
<!-- >-->
|
||
|
<!-- <template v-slot:item="{item:query,index:i}">-->
|
||
|
|
||
|
<!-- <v-hover v-slot:default="{ hover }">-->
|
||
|
<!-- <div style="width: 100%">-->
|
||
|
<!-- <v-btn class="pl-0 ml-0 " small text :tooltip="query.type"-->
|
||
|
<!-- >-->
|
||
|
<!-- <b :class="query.typeColor + '--text'">-->
|
||
|
<!-- <v-icon class="mx-0 ml-n2" :color="query.response.status === 0 ? 'success' : 'error'">-->
|
||
|
<!-- mdi-circle-small-->
|
||
|
<!-- </v-icon>-->
|
||
|
<!-- <span>{{query.type}}</span>-->
|
||
|
<!-- </b>-->
|
||
|
|
||
|
<!-- </v-btn>-->
|
||
|
|
||
|
<!-- <span class="caption grey--text ml-2" v-if="query.timeTaken">Query took {{query.timeTaken}} Seconds</span>-->
|
||
|
<!-- <div class="float-right">-->
|
||
|
|
||
|
<!-- <span v-if="query.createdAt" class="caption grey--text">{{dateToHowManyAgo(query.createdAt)}}</span>-->
|
||
|
<!-- <v-btn text primary small class="caption grey--text"-->
|
||
|
<!-- v-if="query.query.length > 422"-->
|
||
|
<!-- @click.stop="expanded = expanded === i ? -1 : i">...More-->
|
||
|
<!-- </v-btn>-->
|
||
|
<!-- <v-btn small text class=" " @click.prevent.stop="queryDeleteFromHistory(query)">-->
|
||
|
<!-- <v-icon small color="warning">mdi-delete-outline</v-icon>-->
|
||
|
<!-- </v-btn>-->
|
||
|
|
||
|
<!-- <v-btn text primary small @click="copyAndExecute(query)">-->
|
||
|
<!-- <v-icon color="success">mdi-play</v-icon>-->
|
||
|
<!-- </v-btn>-->
|
||
|
|
||
|
<!-- </div>-->
|
||
|
<!-- <div>-->
|
||
|
<!-- <v-hover v-slot:default="{ hover }">-->
|
||
|
<!-- <p class="pa-1"-->
|
||
|
<!-- :class="{'white--text' : hover, 'grey--text' : !hover}"-->
|
||
|
<!-- style="white-space: normal;cursor: pointer">-->
|
||
|
<!-- {{expanded === i ? query.query : query.query.substr(0,442)}}</p>-->
|
||
|
<!-- </v-hover>-->
|
||
|
<!-- </div>-->
|
||
|
<!-- </div>-->
|
||
|
<!-- </v-hover>-->
|
||
|
<!-- </template>-->
|
||
|
<!-- </v-autocomplete>-->
|
||
|
|
||
|
<!-- </v-toolbar>-->
|
||
|
|
||
2 years ago
|
<splitpanes style="height: calc(100%)" class="xc-theme">
|
||
3 years ago
|
<pane v-if="showsqlTvs" :size="showsqlTvs ? 25 : 0" :max-size="showsqlTvs ? 50 : 0" style="overflow: auto">
|
||
2 years ago
|
<div v-if="showsqlTvs" style="width: 100%; height: 100%">
|
||
3 years ago
|
<v-row class="pa-0 ma-0 pa-2 pl-2 d-block">
|
||
3 years ago
|
<x-icon
|
||
|
class="mr-2 cursor-pointer"
|
||
|
color="primary"
|
||
|
tooltip="Create New SQL Collection"
|
||
|
@click="openNewCollection('/')"
|
||
|
>
|
||
|
mdi-folder-plus-outline
|
||
3 years ago
|
</x-icon>
|
||
|
|
||
3 years ago
|
<x-icon
|
||
|
class="mr-2 cursor-pointer"
|
||
|
color="primary"
|
||
|
tooltip="Open SQL Collection"
|
||
|
@click="openSqlFileCollection"
|
||
|
>
|
||
|
mdi-folder-open-outline
|
||
3 years ago
|
</x-icon>
|
||
|
|
||
|
<span class="caption float-right warning--text mt-1" style="font-style: italic">
|
||
|
SQL Editor is in<v-icon small color="warning">mdi-alpha</v-icon>
|
||
|
</span>
|
||
|
</v-row>
|
||
3 years ago
|
<v-divider />
|
||
3 years ago
|
|
||
3 years ago
|
<v-expansion-panels v-model="expandedPanel" accordion focusable>
|
||
2 years ago
|
<v-expansion-panel v-for="(tv, i) in sqlTvs" :key="i">
|
||
3 years ago
|
<v-expansion-panel-header hide-actions>
|
||
2 years ago
|
<template #default="{ open }">
|
||
3 years ago
|
<div class="d-flex">
|
||
3 years ago
|
<v-icon color="">
|
||
|
{{ open ? 'mdi-menu-down' : 'mdi-menu-right' }}
|
||
|
</v-icon>
|
||
2 years ago
|
<v-icon small color="grey" class="ml-1 mr-2"> mdi-folder </v-icon>
|
||
3 years ago
|
|
||
2 years ago
|
<span class="body-2 flex-grow-1">{{
|
||
|
$store.getters['sqlClient/GtrCurrentSqlFilePaths'][i].fileName
|
||
|
}}</span>
|
||
3 years ago
|
|
||
|
<x-icon
|
||
|
color="white grey"
|
||
|
class="float-right mr-3"
|
||
|
small
|
||
2 years ago
|
@click="(toggle[i] = true), (x = $event.clientX), (y = $event.clientY)"
|
||
3 years ago
|
@click.stop=""
|
||
|
>
|
||
3 years ago
|
mdi-dots-horizontal
|
||
|
</x-icon>
|
||
|
|
||
3 years ago
|
<recursive-menu
|
||
|
v-model="toggle[i]"
|
||
|
:position-x="x"
|
||
|
:position-y="y"
|
||
|
:items="{
|
||
2 years ago
|
'Add Folder': 'add-folder',
|
||
|
'Reveal in Folder': 'reveal-in-folder',
|
||
|
'Delete Collection': 'delete-collection',
|
||
|
'Refresh Collection': 'refresh-collection',
|
||
3 years ago
|
}"
|
||
2 years ago
|
@click="ctxMenuClickHandler($event, i)"
|
||
3 years ago
|
/>
|
||
3 years ago
|
</div>
|
||
|
</template>
|
||
|
</v-expansion-panel-header>
|
||
|
<v-expansion-panel-content>
|
||
|
<vue-tree-list
|
||
3 years ago
|
v-if="sqlTvs[i]"
|
||
3 years ago
|
class="body-2 sql-query-treeview px-1 pt-2"
|
||
3 years ago
|
:model="tv"
|
||
|
default-tree-node-name="new node"
|
||
|
default-leaf-node-name="new leaf"
|
||
|
:default-expanded="false"
|
||
3 years ago
|
@click="tvNodeOnClick"
|
||
|
@change-name="tvNodeRename"
|
||
|
@delete-node="tvNodeDelete"
|
||
|
@add-node="onAddNode"
|
||
3 years ago
|
>
|
||
|
<span slot="leafNodeIcon" />
|
||
2 years ago
|
<v-icon slot="treeNodeIcon" small color="grey" class="mr-1"> mdi-folder-star </v-icon>
|
||
|
|
||
|
<v-icon slot="addTreeNode" small> mdi-folder-plus </v-icon>
|
||
|
<v-icon slot="addLeafNode" small> mdi-file-plus </v-icon>
|
||
|
<v-icon slot="editNode" small class="mt-n1"> mdi-file-edit </v-icon>
|
||
|
<v-icon slot="delNode" small> mdi-delete </v-icon>
|
||
3 years ago
|
<template #extraLeafNode>
|
||
2 years ago
|
<v-icon small> mdi-delete </v-icon>
|
||
3 years ago
|
</template>
|
||
2 years ago
|
<template #label="{ item }">
|
||
3 years ago
|
<v-icon
|
||
|
v-if="item.isLeaf"
|
||
|
small
|
||
|
class="mr-1"
|
||
|
:color="item.response && item.response.status === 0 ? 'success' : 'error'"
|
||
|
>
|
||
3 years ago
|
mdi-bookmark-outline
|
||
|
</v-icon>
|
||
3 years ago
|
{{ item.name }}
|
||
3 years ago
|
</template>
|
||
|
</vue-tree-list>
|
||
|
</v-expansion-panel-content>
|
||
|
</v-expansion-panel>
|
||
|
</v-expansion-panels>
|
||
|
</div>
|
||
|
</pane>
|
||
2 years ago
|
<pane style="overflow: auto" :size="showsqlTvs ? 75 : 100">
|
||
|
<div style="position: relative; height: 100%; min-height: 200px">
|
||
|
<v-tabs v-model="tab" style="height: 100%" dense height="38" class="sql-editor-tab">
|
||
|
<v-tab v-for="(c, i) in editors" :key="i">
|
||
|
<template v-if="c.type === 'file'">
|
||
3 years ago
|
{{ c.fileName }}
|
||
2 years ago
|
<v-icon small class="ml-2" @click.prevent.stop="fileClose('showDialog', i)"> close </v-icon>
|
||
3 years ago
|
</template>
|
||
2 years ago
|
<template v-else> Query - {{ i + 1 }} </template>
|
||
3 years ago
|
</v-tab>
|
||
3 years ago
|
<v-tabs-items v-model="tab" style="height: calc(100% - 38px)">
|
||
2 years ago
|
<v-tab-item v-for="(c, i) in editors" :key="i" style="height: 100%">
|
||
3 years ago
|
<div class="d-flex" style="height: 100%; position: relative">
|
||
|
<div style="" class="text-center flex-shrink-1 d-flex flex-column">
|
||
3 years ago
|
<x-icon
|
||
|
tooltip="Execute Query (⌘ ↵)"
|
||
|
icon-class="mx-2 mt-3 elevation-1"
|
||
|
color="success success"
|
||
|
@click="runSelectedSqlCode"
|
||
|
>
|
||
|
mdi-play
|
||
3 years ago
|
</x-icon>
|
||
|
|
||
3 years ago
|
<x-icon
|
||
|
tooltip="Execute Query (⌘ ⌥ ↵)"
|
||
|
icon-class="mx-2 mt-3 elevation-1"
|
||
|
color="info info"
|
||
|
@click="runAllSqlCode"
|
||
|
>
|
||
|
mdi-play
|
||
3 years ago
|
</x-icon>
|
||
3 years ago
|
<x-icon
|
||
|
tooltip="Bookmark Query (⌘ B)"
|
||
|
icon-class="mx-2 mt-3 elevation-1 py-1"
|
||
|
color="amber amber"
|
||
|
small
|
||
|
@click="bookmarkQuery"
|
||
|
>
|
||
3 years ago
|
mdi-star
|
||
|
</x-icon>
|
||
3 years ago
|
<x-icon
|
||
2 years ago
|
:tooltip="showsqlTvs ? 'Close Sql Collection( ⌘ K )' : 'Open Sql Collection( ⌘ K )'"
|
||
3 years ago
|
icon-class="mx-2 mt-3 elevation-1 py-1"
|
||
2 years ago
|
:color="showsqlTvs ? 'amber amber' : 'amber amber'"
|
||
3 years ago
|
small
|
||
|
@click="showSqlCollectionToggle"
|
||
|
>
|
||
3 years ago
|
mdi-folder-star
|
||
|
</x-icon>
|
||
|
|
||
3 years ago
|
<x-icon
|
||
|
tooltip="Open New File (⌘ O)"
|
||
|
icon-class="mx-2 mt-3 elevation-1 py-1"
|
||
|
color="primary blue-grey "
|
||
|
small
|
||
|
@click="openFile"
|
||
|
>
|
||
3 years ago
|
mdi-file
|
||
|
</x-icon>
|
||
3 years ago
|
<x-icon
|
||
|
tooltip="Save Editor Contents (⌘ S)"
|
||
|
icon-class="mx-2 mt-3 elevation-1 py-1"
|
||
|
color="primary blue-grey "
|
||
|
small
|
||
|
@click="fileSave(editors[tab])"
|
||
|
>
|
||
|
save
|
||
3 years ago
|
</x-icon>
|
||
|
|
||
3 years ago
|
<x-icon
|
||
|
tooltip="Clear Editor (⌘ N)"
|
||
|
icon-class="mx-2 mt-3 elevation-1 py-1"
|
||
|
color="error blue-grey "
|
||
|
small
|
||
|
@click="editorClear"
|
||
|
>
|
||
3 years ago
|
mdi-close-box
|
||
|
</x-icon>
|
||
|
</div>
|
||
2 years ago
|
<div class="flex-grow-1" style="overflow: auto; height: 100%">
|
||
3 years ago
|
<MonacoSqlEditor
|
||
3 years ago
|
:ref="`editor-${i}`"
|
||
|
:tables="tableList"
|
||
|
:column-names="tableColumnList"
|
||
|
:code.sync="editors[i].code"
|
||
|
:column-name-cbk="columnNameCbk"
|
||
|
css-style="height:100%"
|
||
3 years ago
|
@execute="runSelectedSqlCode"
|
||
|
@bookmark="bookmarkQuery"
|
||
2 years ago
|
@searchHistory="$refs.search.$el.querySelector('input').click()"
|
||
3 years ago
|
@toggleBookmark="showSqlCollectionToggle"
|
||
|
@saveFile="fileSave(editors[tab])"
|
||
|
@openFile="openFile"
|
||
|
@runAll="runAllSqlCode"
|
||
|
@clearEditor="editorClear"
|
||
|
/>
|
||
|
</div>
|
||
|
</div>
|
||
|
</v-tab-item>
|
||
|
</v-tabs-items>
|
||
|
</v-tabs>
|
||
|
</div>
|
||
|
</pane>
|
||
|
</splitpanes>
|
||
|
|
||
|
<dlgLabelSubmitCancel
|
||
|
v-if="closeFileDlg"
|
||
3 years ago
|
type="primary"
|
||
|
:dialog-show="closeFileDlg"
|
||
|
:actions-mtd="fileClose"
|
||
3 years ago
|
:heading="`$t('tooltip.saveChanges') ?`"
|
||
3 years ago
|
/>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
/* eslint-disable */
|
||
|
|
||
|
// Todo: handling resize bar when hidden
|
||
|
|
||
2 years ago
|
import { mapGetters } from 'vuex';
|
||
|
import { VueTreeList, Tree, TreeNode } from 'vue-tree-list';
|
||
|
import { Splitpanes, Pane } from 'splitpanes';
|
||
|
import sqlRightClickOptions from '../../helpers/sqlRightClickOptions';
|
||
|
import dlgLabelSubmitCancel from '../utils/DlgLabelSubmitCancel.vue';
|
||
3 years ago
|
|
||
2 years ago
|
import Utils from '../../helpers/Utils';
|
||
3 years ago
|
|
||
2 years ago
|
import MonacoSqlEditor from '../monaco/MonacoSqlEditor';
|
||
|
import { SqlUiFactory } from 'nocodb-sdk';
|
||
3 years ago
|
|
||
|
export default {
|
||
|
components: {
|
||
|
MonacoSqlEditor,
|
||
|
dlgLabelSubmitCancel,
|
||
|
VueTreeList,
|
||
|
Splitpanes,
|
||
2 years ago
|
Pane,
|
||
3 years ago
|
},
|
||
2 years ago
|
data() {
|
||
3 years ago
|
return {
|
||
|
expandedPanel: null,
|
||
|
toggle: {},
|
||
|
tableList: null,
|
||
|
tableColumnList: {},
|
||
|
data: new Tree([
|
||
|
{
|
||
|
name: 'Node 1',
|
||
|
id: 1,
|
||
|
pid: 0,
|
||
|
dragDisabled: true,
|
||
|
addTreeNodeDisabled: true,
|
||
|
addLeafNodeDisabled: true,
|
||
|
editNodeDisabled: true,
|
||
|
delNodeDisabled: true,
|
||
|
children: [
|
||
|
{
|
||
|
name: 'Node 1-2',
|
||
|
id: 2,
|
||
|
isLeaf: true,
|
||
2 years ago
|
pid: 1,
|
||
|
},
|
||
|
],
|
||
3 years ago
|
},
|
||
|
{
|
||
|
name: 'Node 2',
|
||
|
id: 3,
|
||
|
pid: 0,
|
||
2 years ago
|
disabled: true,
|
||
3 years ago
|
},
|
||
|
{
|
||
|
name: 'Node 3',
|
||
|
id: 4,
|
||
2 years ago
|
pid: 0,
|
||
|
},
|
||
3 years ago
|
]),
|
||
|
opened: [],
|
||
|
|
||
|
sqlTvs: [],
|
||
|
fileCollections: [],
|
||
|
filePaths: [],
|
||
|
|
||
|
showsqlTvs: true,
|
||
|
menuVisible: false,
|
||
|
x: 0,
|
||
|
y: 0,
|
||
|
menuItem: null,
|
||
|
closeIndex: null,
|
||
|
closeFileDlg: false,
|
||
|
selectedQueryItem: null,
|
||
|
tab: 0,
|
||
|
expanded: null,
|
||
|
searchQuery: '',
|
||
|
searchOverlay: false,
|
||
|
folderOverlay: false,
|
||
|
loading: false,
|
||
|
editors: [],
|
||
|
headers1: [
|
||
|
{
|
||
|
text: 'API Call History',
|
||
|
align: 'left',
|
||
|
sortable: false,
|
||
|
value: 'query',
|
||
2 years ago
|
class: 'text-center black',
|
||
|
},
|
||
|
],
|
||
|
};
|
||
3 years ago
|
},
|
||
|
computed: {
|
||
|
...mapGetters({
|
||
|
sqlMgr: 'sqlMgr/sqlMgr',
|
||
|
currentProjectFolder: 'project/currentProjectFolder',
|
||
2 years ago
|
projectQueriesFolder: 'project/projectQueriesFolder',
|
||
|
}),
|
||
3 years ago
|
},
|
||
2 years ago
|
watch: {
|
||
|
editors: {
|
||
|
handler(editors) {
|
||
|
this.$store.commit('sqlClient/MutSetEditors', editors);
|
||
3 years ago
|
},
|
||
2 years ago
|
deep: true,
|
||
|
},
|
||
|
},
|
||
|
async created() {
|
||
3 years ago
|
this.$store.dispatch('sqlClient/loadSqlCollectionForProject', {
|
||
|
projectId: 1,
|
||
2 years ago
|
projectName: this.$store.getters['project/GtrProjectName'],
|
||
|
});
|
||
3 years ago
|
|
||
|
try {
|
||
|
/* load all files that are were previously opened */
|
||
|
if (!this.$store.getters['sqlClient/GtrCurrentSqlFilePaths'].length) {
|
||
2 years ago
|
const defaultPath = ''; // path.join(this.currentProjectFolder, 'server', 'tool', this.nodes.dbAlias, this.projectQueriesFolder, 'queries.xc.json');
|
||
3 years ago
|
this.$store.commit('sqlClient/MutSqlFilePathsAdd', {
|
||
|
path: defaultPath,
|
||
2 years ago
|
fileName: '', // path.basename(defaultPath)
|
||
|
});
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
for (let i = 0; i < this.$store.getters['sqlClient/GtrCurrentSqlFilePaths'].length; ++i) {
|
||
2 years ago
|
await this.loadFileCollection(this.$store.getters['sqlClient/GtrCurrentSqlFilePaths'][i]);
|
||
3 years ago
|
}
|
||
|
} catch (e) {
|
||
2 years ago
|
console.log('Failed to load previously opened query collections', e);
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
2 years ago
|
this.sqlUi = SqlUiFactory.create(this.nodes.dbConnection);
|
||
|
console.log('------------', this.nodes);
|
||
|
this.editors = this.$store.state.sqlClient.editors.map(editor => ({ ...editor }));
|
||
|
this.checkClipboardForQuery(this.$store.state.sqlClient.clipboardQuery);
|
||
|
const vm = this;
|
||
3 years ago
|
this.$store.watch(
|
||
|
state => state.sqlClient.clipboardQuery,
|
||
|
clipboardQuery => vm.checkClipboardForQuery(clipboardQuery)
|
||
2 years ago
|
);
|
||
3 years ago
|
|
||
|
// const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// });
|
||
|
// const result = await client.tableList();
|
||
|
// console.log(result)
|
||
2 years ago
|
this.tableList = []; // result.data.list.map(table => table.table_name)
|
||
3 years ago
|
|
||
2 years ago
|
this.expandedPanel = 0;
|
||
3 years ago
|
},
|
||
2 years ago
|
mounted() {},
|
||
|
beforeDestroy() {},
|
||
3 years ago
|
methods: {
|
||
|
dateToHowManyAgo: Utils.dateToHowManyAgo,
|
||
|
findById: Utils.findById,
|
||
|
|
||
2 years ago
|
async openNewCollection() {
|
||
3 years ago
|
// try {
|
||
|
// const toLocalPath = path.join(this.currentProjectFolder, 'server', 'tool', this.nodes.dbAlias, this.projectQueriesFolder)
|
||
|
//
|
||
|
// const userChosenPath = dialog.showSaveDialog({
|
||
|
// defaultPath: toLocalPath,
|
||
|
// filters: [{ name: 'JSON', extensions: ['json'] }]
|
||
|
// })
|
||
|
//
|
||
|
// if (userChosenPath) {
|
||
|
// console.log(userChosenPath)
|
||
|
// fs.writeFileSync(userChosenPath, '[]', 'utf-8')
|
||
|
// const pathObj = {
|
||
|
// path: userChosenPath,
|
||
|
// fileName: path.basename(userChosenPath)
|
||
|
// }
|
||
|
// this.$store.commit('sqlClient/MutSqlFilePathsAdd', pathObj)
|
||
|
// await this.loadFileCollection(pathObj)
|
||
|
// }
|
||
|
// this.$toast.success('New collection loaded successfully').goAway(5000)
|
||
|
// } catch (e) {
|
||
|
// console.log(e)
|
||
|
// throw e
|
||
|
// }
|
||
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async columnNameCbk(tn) {
|
||
3 years ago
|
// tableColumnList
|
||
|
//
|
||
|
// const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// });
|
||
|
// const result = await client.columnList({tn});
|
||
3 years ago
|
// const columns = result.data.list.map(table => table.column_name)
|
||
3 years ago
|
// this.$set(this.tableColumnList, tn, columns);
|
||
|
// return columns;
|
||
2 years ago
|
return [];
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async tvNodeDelete(node) {
|
||
|
console.log(node);
|
||
|
node.remove();
|
||
|
await this.savefileCollections(this.expandedPanel);
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async tvNodeRename(params) {
|
||
|
console.log(params);
|
||
|
await this.savefileCollections(this.expandedPanel);
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async onAddNode(params) {
|
||
|
console.log(params);
|
||
|
await this.savefileCollections(this.expandedPanel);
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
2 years ago
|
tvNodeOnClick(params) {
|
||
|
console.log(params);
|
||
|
if (params.query) {
|
||
|
this.selectQuery(params);
|
||
|
}
|
||
3 years ago
|
},
|
||
2 years ago
|
async openCollectionFolder(pathString) {
|
||
|
shell.showItemInFolder(pathString);
|
||
3 years ago
|
},
|
||
2 years ago
|
tvToObject(index) {
|
||
|
const vm = this;
|
||
3 years ago
|
|
||
2 years ago
|
function _dfs(oldNode) {
|
||
|
const newNode = {};
|
||
3 years ago
|
|
||
3 years ago
|
for (const k in oldNode) {
|
||
|
if (k !== 'children' && k !== 'parent') {
|
||
2 years ago
|
newNode[k] = oldNode[k];
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
if (oldNode.children && oldNode.children.length > 0) {
|
||
2 years ago
|
newNode.children = [];
|
||
3 years ago
|
for (let i = 0, len = oldNode.children.length; i < len; i++) {
|
||
2 years ago
|
newNode.children.push(_dfs(oldNode.children[i]));
|
||
3 years ago
|
}
|
||
|
}
|
||
2 years ago
|
return newNode;
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
2 years ago
|
return _dfs(vm.sqlTvs[index]).children;
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async tvNodeFolderAdd(index) {
|
||
|
const node = new TreeNode({ name: 'New Folder', isLeaf: false });
|
||
|
if (!this.sqlTvs[index].children) {
|
||
|
this.sqlTvs[index].children = [];
|
||
|
}
|
||
|
this.sqlTvs[index].addChildren(node);
|
||
|
await this.savefileCollections(index);
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async ctxMenuClickHandler(actionEvent, index) {
|
||
|
console.log(actionEvent, index);
|
||
3 years ago
|
switch (actionEvent.value) {
|
||
|
case 'add-folder':
|
||
2 years ago
|
this.tvNodeFolderAdd(index);
|
||
|
break;
|
||
3 years ago
|
case 'reveal-in-folder':
|
||
2 years ago
|
await this.openCollectionFolder(this.$store.getters['sqlClient/GtrCurrentSqlFilePaths'][index].path);
|
||
|
break;
|
||
3 years ago
|
case 'delete-collection':
|
||
2 years ago
|
this.$store.commit('sqlClient/MutSqlFilePathsRemove', index);
|
||
|
this.fileCollections.splice(index, 1);
|
||
|
this.sqlTvs.splice(index, 1);
|
||
|
break;
|
||
3 years ago
|
case 'refresh-collection':
|
||
2 years ago
|
await this.refreshFileCollection(index);
|
||
|
break;
|
||
3 years ago
|
default:
|
||
2 years ago
|
break;
|
||
3 years ago
|
}
|
||
|
// this.deleteQueryByPath(this.sqlTvs, this.menuItem.path);
|
||
|
},
|
||
2 years ago
|
async runSelectedSqlCode() {
|
||
|
this.executeQuery(this.$refs[`editor-${this.tab}`][0].getCurrentQuery());
|
||
3 years ago
|
},
|
||
2 years ago
|
async runAllSqlCode() {
|
||
|
const queryString = this.$refs[`editor-${this.tab}`][0].getAllContent();
|
||
3 years ago
|
|
||
2 years ago
|
const queries = this.sqlUi.splitQueries(queryString);
|
||
3 years ago
|
if (queries) {
|
||
|
for (const query of queries) {
|
||
2 years ago
|
await this.executeQuery(query);
|
||
3 years ago
|
}
|
||
2 years ago
|
} else {
|
||
|
await this.executeQuery('');
|
||
|
}
|
||
3 years ago
|
|
||
2 years ago
|
console.log(queries);
|
||
3 years ago
|
},
|
||
2 years ago
|
async runSqlCode() {
|
||
|
this.executeQuery(this.editors[this.tab].code);
|
||
3 years ago
|
},
|
||
2 years ago
|
async executeQuery(query) {
|
||
3 years ago
|
if (query.trim() === '') {
|
||
2 years ago
|
this.$toast.info('Query is empty').goAway(5000);
|
||
|
return;
|
||
3 years ago
|
}
|
||
2 years ago
|
this.loading = true;
|
||
3 years ago
|
|
||
3 years ago
|
try {
|
||
|
const result = await this.$store.dispatch('sqlClient/executeQuery', {
|
||
|
envs: {
|
||
|
env: this.nodes.env,
|
||
2 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
3 years ago
|
},
|
||
2 years ago
|
query,
|
||
|
});
|
||
|
this.$store.commit('outputs/MutListSet', { sqlUi: this.sqlUi, headers: [], result });
|
||
3 years ago
|
// this.result = this.sqlUi.handleRawOutput(result, this.headers);
|
||
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error('Query failed : ' + e.message).goAway(3000);
|
||
3 years ago
|
this.$store.commit('outputs/MutListSet', {
|
||
|
headers: [{ text: 'Mesage', value: 'message', sortable: false }],
|
||
2 years ago
|
result: [{ message: e.message }],
|
||
|
});
|
||
3 years ago
|
} finally {
|
||
2 years ago
|
this.loading = false;
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
2 years ago
|
editorClear() {
|
||
|
this.editors[this.tab].code = '';
|
||
|
this.$store.commit('outputs/MutClear');
|
||
3 years ago
|
},
|
||
2 years ago
|
queryDeleteFromHistory(item) {
|
||
|
this.$store.commit('sqlClient/MutListRemoveItem', item);
|
||
3 years ago
|
},
|
||
2 years ago
|
selectQuery({ query }) {
|
||
|
if (this.editors[this.tab].code.trim()) {
|
||
|
this.editors[this.tab].code += '\n\n' + query;
|
||
|
} else {
|
||
|
this.editors[this.tab].code = query;
|
||
|
}
|
||
|
this.$refs[`editor-${this.tab}`][0].focus();
|
||
3 years ago
|
},
|
||
2 years ago
|
async copyAndExecute(query) {
|
||
|
this.selectQuery(query);
|
||
|
await this.runSqlCode();
|
||
3 years ago
|
},
|
||
2 years ago
|
queryFilter(item, queryText, itemText) {
|
||
|
return item.query.toLowerCase().includes(queryText.toLowerCase());
|
||
3 years ago
|
},
|
||
2 years ago
|
changedSelectedQuery(query) {
|
||
|
this.selectQuery({ query });
|
||
3 years ago
|
},
|
||
2 years ago
|
checkClipboardForQuery(clipboardQuery) {
|
||
3 years ago
|
if (clipboardQuery) {
|
||
2 years ago
|
this.$set(this.editors[this.tab], 'code', clipboardQuery);
|
||
|
this.$store.commit('sqlClient/MutSetClipboardQuery', null);
|
||
3 years ago
|
}
|
||
|
},
|
||
2 years ago
|
openFile() {
|
||
3 years ago
|
// if (this.editors.filter(({ type }) => type === 'file').length >= 4) {
|
||
|
// this.$toast.info('Only 4 files can be opened').goAway(4000)
|
||
|
// return
|
||
|
// }
|
||
|
// const vm = this
|
||
|
// const file = dialog.showOpenDialog({
|
||
|
// properties: ['openFile']
|
||
|
// })
|
||
|
// if (file && file[0]) {
|
||
|
// const fileName = path.basename(file[0])
|
||
|
// fs.readFile(file[0], 'utf8', function (err, data) {
|
||
|
// if (err) { return console.log(err) }
|
||
|
// vm.editors.push({ code: data, type: 'file', fileName, filePaths: file[0], edited: false })
|
||
|
// vm.tab = vm.editors.length - 1
|
||
|
// // data is the contents of the text file we just read
|
||
|
// })
|
||
|
// }
|
||
|
},
|
||
2 years ago
|
openSqlFileCollection() {
|
||
3 years ago
|
// const vm = this
|
||
|
// const file = dialog.showOpenDialog({
|
||
|
// properties: ['openFile']
|
||
|
// })
|
||
|
// if (file && file[0]) {
|
||
|
// const fileName = path.basename(file[0])
|
||
|
// const pathObj = {
|
||
|
// path: file[0] + '',
|
||
|
// fileName
|
||
|
// }
|
||
|
//
|
||
|
// if (this.$store.getters['sqlClient/GtrCurrentSqlFilePaths'].every(({ path: p }) => p !== pathObj.path)) {
|
||
|
// this.$store.commit('sqlClient/MutSqlFilePathsAdd', pathObj)
|
||
|
// this.loadFileCollection(pathObj)
|
||
|
// } else {
|
||
|
// this.$toast.info('File already exist in collection').goAway(4000)
|
||
|
// }
|
||
|
// }
|
||
|
},
|
||
2 years ago
|
showSqlCollectionToggle(status = true) {
|
||
|
this.showsqlTvs = !this.showsqlTvs;
|
||
3 years ago
|
},
|
||
2 years ago
|
fileSave(editor, cbk = null) {
|
||
3 years ago
|
// console.log(editor)
|
||
|
// if (editor.type != 'file') {
|
||
|
// return
|
||
|
// }
|
||
|
// const vm = this
|
||
|
// fs.writeFile(editor.filePaths, editor.code, 'utf-8', function (err, result) {
|
||
|
// if (err) {
|
||
|
// vm.$toast.error('Error saving the file').goAway(5000)
|
||
|
// } else {
|
||
|
// vm.$toast.success('File saved successfully').goAway(5000)
|
||
|
// }
|
||
|
// if (cbk) { cbk(err, result) }
|
||
|
// })
|
||
|
},
|
||
2 years ago
|
async fileClose(action = '', index) {
|
||
3 years ago
|
if (action === 'showDialog') {
|
||
2 years ago
|
this.closeFileDlg = true;
|
||
|
this.closeIndex = index;
|
||
3 years ago
|
} else if (action === 'hideDialog') {
|
||
2 years ago
|
this.editors.splice(this.closeIndex, 1);
|
||
|
this.closeFileDlg = false;
|
||
|
this.closeIndex = null;
|
||
3 years ago
|
} else {
|
||
2 years ago
|
const vm = this;
|
||
3 years ago
|
this.fileSave(this.editors[this.closeIndex], function (err, result) {
|
||
2 years ago
|
vm.editors.splice(vm.closeIndex, 1);
|
||
|
vm.closeIndex = null;
|
||
|
vm.closeFileDlg = false;
|
||
|
});
|
||
3 years ago
|
}
|
||
|
},
|
||
2 years ago
|
queryClickHandler(item) {
|
||
|
console.log('bookmark', item);
|
||
|
if (item.type !== 'folder') {
|
||
|
this.selectQuery({ query: item.query });
|
||
|
}
|
||
3 years ago
|
},
|
||
2 years ago
|
ctxMenuShow(e, item) {
|
||
|
if (!item) {
|
||
|
return;
|
||
|
}
|
||
|
this.menuItem = item;
|
||
|
e.preventDefault();
|
||
|
this.x = e.clientX;
|
||
|
this.y = e.clientY;
|
||
3 years ago
|
this.$nextTick(() => {
|
||
2 years ago
|
this.menuVisible = true;
|
||
|
});
|
||
3 years ago
|
},
|
||
2 years ago
|
ctxMenuOptions() {
|
||
|
if (!this.menuItem || !this.menuItem) {
|
||
|
return;
|
||
|
}
|
||
|
const options = sqlRightClickOptions[this.menuItem.type === 'folder' ? 'folder' : 'file'];
|
||
|
return options;
|
||
3 years ago
|
},
|
||
|
|
||
2 years ago
|
async fileCollectionsReload() {
|
||
|
const data = new Tree(await this.fileCollections.read());
|
||
|
console.log(data);
|
||
3 years ago
|
|
||
2 years ago
|
this.sqlTvs = data;
|
||
3 years ago
|
// this.$set(this, 'sqlTvs', data);
|
||
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async savefileCollections(index = 0) {
|
||
|
await this.fileCollections[index].write({ data: this.tvToObject(index) });
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async bookmarkQuery() {
|
||
|
const q = this.$refs[`editor-${this.tab}`][0].getCurrentQuery();
|
||
3 years ago
|
|
||
|
if (q.trim()) {
|
||
2 years ago
|
this.showsqlTvs = true;
|
||
3 years ago
|
|
||
|
const node = new TreeNode({
|
||
|
id: Date.now(),
|
||
|
type: 'select',
|
||
|
typeColor: 'success',
|
||
|
query: q,
|
||
|
response: { status: 0 },
|
||
|
label: 'Example',
|
||
|
name: 'Last saved query',
|
||
|
pid: 0,
|
||
2 years ago
|
isLeaf: true,
|
||
|
});
|
||
3 years ago
|
|
||
2 years ago
|
let expandedPanelIndex = this.expandedPanel;
|
||
3 years ago
|
if (typeof expandedPanelIndex !== 'number') {
|
||
|
expandedPanelIndex = this.$store.getters['sqlClient/GtrCurrentSqlFilePaths'].findIndex(
|
||
2 years ago
|
file =>
|
||
|
file.path ===
|
||
|
path.join(
|
||
|
this.currentProjectFolder,
|
||
|
'server',
|
||
|
'tool',
|
||
|
this.nodes.dbAlias,
|
||
|
this.projectQueriesFolder,
|
||
|
'queries.xc.json'
|
||
|
)
|
||
|
);
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
if (!this.sqlTvs[expandedPanelIndex].children) {
|
||
|
this.sqlTvs[expandedPanelIndex].children = [];
|
||
|
}
|
||
|
this.sqlTvs[expandedPanelIndex].addChildren(node);
|
||
|
await this.savefileCollections(expandedPanelIndex);
|
||
3 years ago
|
|
||
2 years ago
|
this.$toast.success('Query bookmarked').goAway(1000);
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
2 years ago
|
async loadFileCollection(pathObj, index = 0) {
|
||
3 years ago
|
// try {
|
||
|
// const fileCollection = new FileCollection(pathObj);
|
||
|
// await fileCollection.init();
|
||
|
//
|
||
|
// this.fileCollections.push(fileCollection);
|
||
|
//
|
||
|
// let data = new Tree(await fileCollection.read());
|
||
|
// this.sqlTvs.push(data);
|
||
|
// } catch (e) {
|
||
|
// console.log('Error in loadFileCollection:', e);
|
||
|
// throw e;
|
||
|
// }
|
||
|
},
|
||
2 years ago
|
async refreshFileCollection(index = 0) {
|
||
3 years ago
|
try {
|
||
2 years ago
|
const pathObj = this.$store.getters['sqlClient/GtrCurrentSqlFilePaths'][index];
|
||
|
const fileCollection = new FileCollection(pathObj);
|
||
|
await fileCollection.init();
|
||
3 years ago
|
|
||
2 years ago
|
this.fileCollections[index] = fileCollection;
|
||
3 years ago
|
|
||
2 years ago
|
const data = new Tree(await fileCollection.read());
|
||
|
this.$set(this.sqlTvs, index, data);
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log('Error in loadFileCollection:', e);
|
||
|
throw e;
|
||
3 years ago
|
}
|
||
2 years ago
|
},
|
||
3 years ago
|
},
|
||
|
|
||
2 years ago
|
beforeCreated() {},
|
||
|
destroy() {},
|
||
3 years ago
|
directives: {},
|
||
2 years ago
|
validate({ params }) {
|
||
|
return true;
|
||
3 years ago
|
},
|
||
2 years ago
|
head() {
|
||
|
return {};
|
||
3 years ago
|
},
|
||
2 years ago
|
props: ['nodes'],
|
||
|
};
|
||
3 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
2 years ago
|
.vertical-resizer {
|
||
|
height: 5px;
|
||
|
background: grey;
|
||
|
cursor: ns-resize;
|
||
|
position: relative;
|
||
|
}
|
||
3 years ago
|
|
||
2 years ago
|
.vertical-resizer + * {
|
||
|
overflow-y: auto;
|
||
|
}
|
||
3 years ago
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|