mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
feat: new create trigger function tabs
This commit is contained in:
@ -1,132 +0,0 @@
|
|||||||
<template>
|
|
||||||
<ConfirmModal
|
|
||||||
:confirm-text="$t('word.confirm')"
|
|
||||||
size="400"
|
|
||||||
@confirm="confirmNewFunction"
|
|
||||||
@hide="$emit('close')"
|
|
||||||
>
|
|
||||||
<template :slot="'header'">
|
|
||||||
<div class="d-flex">
|
|
||||||
<i class="mdi mdi-24px mdi-plus mr-1" /> {{ $t('message.createNewFunction') }}
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<div :slot="'body'">
|
|
||||||
<form class="form-horizontal">
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="form-label col-4">
|
|
||||||
{{ $t('word.name') }}
|
|
||||||
</label>
|
|
||||||
<div class="column">
|
|
||||||
<input
|
|
||||||
ref="firstInput"
|
|
||||||
v-model="localFunction.name"
|
|
||||||
class="form-input"
|
|
||||||
type="text"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-if="customizations.languages" class="form-group">
|
|
||||||
<label class="form-label col-4">
|
|
||||||
{{ $t('word.language') }}
|
|
||||||
</label>
|
|
||||||
<div class="column">
|
|
||||||
<select v-model="localFunction.language" class="form-select">
|
|
||||||
<option v-for="language in customizations.triggerFunctionlanguages" :key="language">
|
|
||||||
{{ language }}
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-if="customizations.definer" class="form-group">
|
|
||||||
<label class="form-label col-4">
|
|
||||||
{{ $t('word.definer') }}
|
|
||||||
</label>
|
|
||||||
<div class="column">
|
|
||||||
<select
|
|
||||||
v-if="workspace.users.length"
|
|
||||||
v-model="localFunction.definer"
|
|
||||||
class="form-select"
|
|
||||||
>
|
|
||||||
<option value="">
|
|
||||||
{{ $t('message.currentUser') }}
|
|
||||||
</option>
|
|
||||||
<option
|
|
||||||
v-for="user in workspace.users"
|
|
||||||
:key="`${user.name}@${user.host}`"
|
|
||||||
:value="`\`${user.name}\`@\`${user.host}\``"
|
|
||||||
>
|
|
||||||
{{ user.name }}@{{ user.host }}
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
<select v-if="!workspace.users.length" class="form-select">
|
|
||||||
<option value="">
|
|
||||||
{{ $t('message.currentUser') }}
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-if="customizations.comment" class="form-group">
|
|
||||||
<label class="form-label col-4">
|
|
||||||
{{ $t('word.comment') }}
|
|
||||||
</label>
|
|
||||||
<div class="column">
|
|
||||||
<input
|
|
||||||
v-model="localFunction.comment"
|
|
||||||
class="form-input"
|
|
||||||
type="text"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</ConfirmModal>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import ConfirmModal from '@/components/BaseConfirmModal';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'ModalNewTriggerFunction',
|
|
||||||
components: {
|
|
||||||
ConfirmModal
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
workspace: Object
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
localFunction: {
|
|
||||||
definer: '',
|
|
||||||
sql: '',
|
|
||||||
name: '',
|
|
||||||
comment: '',
|
|
||||||
language: null
|
|
||||||
},
|
|
||||||
isOptionsChanging: false
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
schema () {
|
|
||||||
return this.workspace.breadcrumbs.schema;
|
|
||||||
},
|
|
||||||
customizations () {
|
|
||||||
return this.workspace.customizations;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted () {
|
|
||||||
if (this.customizations.triggerFunctionlanguages)
|
|
||||||
this.localFunction.language = this.customizations.triggerFunctionlanguages[0];
|
|
||||||
|
|
||||||
if (this.customizations.triggerFunctionSql)
|
|
||||||
this.localFunction.sql = this.customizations.triggerFunctionSql;
|
|
||||||
setTimeout(() => {
|
|
||||||
this.$refs.firstInput.focus();
|
|
||||||
}, 20);
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
confirmNewFunction () {
|
|
||||||
this.$emit('open-create-function-editor', this.localFunction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
@ -187,6 +187,23 @@
|
|||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
v-else-if="tab.type === 'new-trigger-function'"
|
||||||
|
class="tab-link"
|
||||||
|
:class="{'badge': tab.isChanged}"
|
||||||
|
>
|
||||||
|
<i class="mdi mdi-shape-square-plus mdi-18px mr-1" />
|
||||||
|
<span :title="`${$t('word.new').toUpperCase()}: ${$tc(`word.${tab.elementType}`)}`">
|
||||||
|
{{ $t('message.newTriggerFunction') }}
|
||||||
|
<span
|
||||||
|
class="btn btn-clear"
|
||||||
|
:title="$t('word.close')"
|
||||||
|
@mousedown.left.stop
|
||||||
|
@click.stop="closeTab(tab)"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
v-else-if="tab.type === 'new-scheduler'"
|
v-else-if="tab.type === 'new-scheduler'"
|
||||||
class="tab-link"
|
class="tab-link"
|
||||||
@ -353,6 +370,15 @@
|
|||||||
:trigger="tab.elementName"
|
:trigger="tab.elementName"
|
||||||
:schema="tab.schema"
|
:schema="tab.schema"
|
||||||
/>
|
/>
|
||||||
|
<WorkspaceTabNewTriggerFunction
|
||||||
|
v-else-if="tab.type === 'new-trigger-function'"
|
||||||
|
:key="tab.uid"
|
||||||
|
:tab="tab"
|
||||||
|
:connection="connection"
|
||||||
|
:is-selected="selectedTab === tab.uid"
|
||||||
|
:trigger="tab.elementName"
|
||||||
|
:schema="tab.schema"
|
||||||
|
/>
|
||||||
<WorkspaceTabPropsTriggerFunction
|
<WorkspaceTabPropsTriggerFunction
|
||||||
v-else-if="['temp-trigger-function-props', 'trigger-function-props'].includes(tab.type)"
|
v-else-if="['temp-trigger-function-props', 'trigger-function-props'].includes(tab.type)"
|
||||||
:key="tab.uid"
|
:key="tab.uid"
|
||||||
@ -445,6 +471,7 @@ import WorkspaceTabNewTrigger from '@/components/WorkspaceTabNewTrigger';
|
|||||||
import WorkspaceTabNewRoutine from '@/components/WorkspaceTabNewRoutine';
|
import WorkspaceTabNewRoutine from '@/components/WorkspaceTabNewRoutine';
|
||||||
import WorkspaceTabNewFunction from '@/components/WorkspaceTabNewFunction';
|
import WorkspaceTabNewFunction from '@/components/WorkspaceTabNewFunction';
|
||||||
import WorkspaceTabNewScheduler from '@/components/WorkspaceTabNewScheduler';
|
import WorkspaceTabNewScheduler from '@/components/WorkspaceTabNewScheduler';
|
||||||
|
import WorkspaceTabNewTriggerFunction from '@/components/WorkspaceTabNewTriggerFunction';
|
||||||
|
|
||||||
import WorkspaceTabPropsTable from '@/components/WorkspaceTabPropsTable';
|
import WorkspaceTabPropsTable from '@/components/WorkspaceTabPropsTable';
|
||||||
import WorkspaceTabPropsView from '@/components/WorkspaceTabPropsView';
|
import WorkspaceTabPropsView from '@/components/WorkspaceTabPropsView';
|
||||||
@ -471,6 +498,7 @@ export default {
|
|||||||
WorkspaceTabPropsView,
|
WorkspaceTabPropsView,
|
||||||
WorkspaceTabNewTrigger,
|
WorkspaceTabNewTrigger,
|
||||||
WorkspaceTabPropsTrigger,
|
WorkspaceTabPropsTrigger,
|
||||||
|
WorkspaceTabNewTriggerFunction,
|
||||||
WorkspaceTabPropsTriggerFunction,
|
WorkspaceTabPropsTriggerFunction,
|
||||||
WorkspaceTabNewRoutine,
|
WorkspaceTabNewRoutine,
|
||||||
WorkspaceTabNewFunction,
|
WorkspaceTabNewFunction,
|
||||||
|
@ -61,18 +61,6 @@
|
|||||||
@close="hideNewDBModal"
|
@close="hideNewDBModal"
|
||||||
@reload="refresh"
|
@reload="refresh"
|
||||||
/>
|
/>
|
||||||
<ModalNewFunction
|
|
||||||
v-if="isNewFunctionModal"
|
|
||||||
:workspace="workspace"
|
|
||||||
@close="hideCreateFunctionModal"
|
|
||||||
@open-create-function-editor="openCreateFunctionEditor"
|
|
||||||
/>
|
|
||||||
<ModalNewTriggerFunction
|
|
||||||
v-if="isNewTriggerFunctionModal"
|
|
||||||
:workspace="workspace"
|
|
||||||
@close="hideCreateTriggerFunctionModal"
|
|
||||||
@open-create-function-editor="openCreateTriggerFunctionEditor"
|
|
||||||
/>
|
|
||||||
<DatabaseContext
|
<DatabaseContext
|
||||||
v-if="isDatabaseContext"
|
v-if="isDatabaseContext"
|
||||||
:selected-schema="selectedSchema"
|
:selected-schema="selectedSchema"
|
||||||
@ -83,7 +71,7 @@
|
|||||||
@open-create-trigger-tab="openCreateElementTab('trigger')"
|
@open-create-trigger-tab="openCreateElementTab('trigger')"
|
||||||
@open-create-routine-tab="openCreateElementTab('routine')"
|
@open-create-routine-tab="openCreateElementTab('routine')"
|
||||||
@open-create-function-tab="openCreateElementTab('function')"
|
@open-create-function-tab="openCreateElementTab('function')"
|
||||||
@show-create-trigger-function-modal="showCreateTriggerFunctionModal"
|
@open-create-trigger-function-tab="openCreateElementTab('trigger-function')"
|
||||||
@open-create-scheduler-tab="openCreateElementTab('scheduler')"
|
@open-create-scheduler-tab="openCreateElementTab('scheduler')"
|
||||||
@reload="refresh"
|
@reload="refresh"
|
||||||
/>
|
/>
|
||||||
@ -113,7 +101,7 @@
|
|||||||
@open-create-trigger-tab="openCreateElementTab('trigger')"
|
@open-create-trigger-tab="openCreateElementTab('trigger')"
|
||||||
@open-create-routine-tab="openCreateElementTab('routine')"
|
@open-create-routine-tab="openCreateElementTab('routine')"
|
||||||
@open-create-function-tab="openCreateElementTab('function')"
|
@open-create-function-tab="openCreateElementTab('function')"
|
||||||
@show-create-trigger-function-modal="showCreateTriggerFunctionModal"
|
@open-create-trigger-function-tab="openCreateElementTab('trigger-function')"
|
||||||
@open-create-scheduler-tab="openCreateElementTab('scheduler')"
|
@open-create-scheduler-tab="openCreateElementTab('scheduler')"
|
||||||
@close-context="closeMiscFolderContext"
|
@close-context="closeMiscFolderContext"
|
||||||
@reload="refresh"
|
@reload="refresh"
|
||||||
@ -136,8 +124,6 @@ import MiscContext from '@/components/WorkspaceExploreBarMiscContext';
|
|||||||
import MiscFolderContext from '@/components/WorkspaceExploreBarMiscFolderContext';
|
import MiscFolderContext from '@/components/WorkspaceExploreBarMiscFolderContext';
|
||||||
import ModalNewSchema from '@/components/ModalNewSchema';
|
import ModalNewSchema from '@/components/ModalNewSchema';
|
||||||
|
|
||||||
import ModalNewTriggerFunction from '@/components/ModalNewTriggerFunction';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'WorkspaceExploreBar',
|
name: 'WorkspaceExploreBar',
|
||||||
components: {
|
components: {
|
||||||
@ -146,9 +132,7 @@ export default {
|
|||||||
TableContext,
|
TableContext,
|
||||||
MiscContext,
|
MiscContext,
|
||||||
MiscFolderContext,
|
MiscFolderContext,
|
||||||
ModalNewSchema,
|
ModalNewSchema
|
||||||
|
|
||||||
ModalNewTriggerFunction
|
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
connection: Object,
|
connection: Object,
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<div
|
<div
|
||||||
v-if="selectedMisc === 'triggerFunction'"
|
v-if="selectedMisc === 'triggerFunction'"
|
||||||
class="context-element"
|
class="context-element"
|
||||||
@click="$emit('show-create-trigger-function-modal')"
|
@click="$emit('open-create-trigger-function-tab')"
|
||||||
>
|
>
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-cog-clockwise text-light pr-1" /> {{ $t('message.createNewFunction') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-cog-clockwise text-light pr-1" /> {{ $t('message.createNewFunction') }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
<div
|
<div
|
||||||
v-if="workspace.customizations.triggerFunctionAdd"
|
v-if="workspace.customizations.triggerFunctionAdd"
|
||||||
class="context-element"
|
class="context-element"
|
||||||
@click="showCreateTriggerFunctionModal"
|
@click="openCreateTriggerFunctionTab"
|
||||||
>
|
>
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-cog-clockwise pr-1" /> {{ $tc('word.triggerFunction', 1) }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-cog-clockwise pr-1" /> {{ $tc('word.triggerFunction', 1) }}</span>
|
||||||
</div>
|
</div>
|
||||||
@ -147,8 +147,8 @@ export default {
|
|||||||
openCreateFunctionTab () {
|
openCreateFunctionTab () {
|
||||||
this.$emit('open-create-function-tab');
|
this.$emit('open-create-function-tab');
|
||||||
},
|
},
|
||||||
showCreateTriggerFunctionModal () {
|
openCreateTriggerFunctionTab () {
|
||||||
this.$emit('show-create-trigger-function-modal');
|
this.$emit('open-create-trigger-function-tab');
|
||||||
},
|
},
|
||||||
openCreateSchedulerTab () {
|
openCreateSchedulerTab () {
|
||||||
this.$emit('open-create-scheduler-tab');
|
this.$emit('open-create-scheduler-tab');
|
||||||
|
@ -275,7 +275,7 @@ export default {
|
|||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.originalFunction = {
|
this.originalFunction = {
|
||||||
sql: this.customizations.procedureSql,
|
sql: this.customizations.functionSql,
|
||||||
language: this.customizations.languages ? this.customizations.languages[0] : null,
|
language: this.customizations.languages ? this.customizations.languages[0] : null,
|
||||||
name: '',
|
name: '',
|
||||||
definer: '',
|
definer: '',
|
||||||
|
@ -258,6 +258,8 @@ export default {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.$refs.firstInput.focus();
|
this.$refs.firstInput.focus();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
window.addEventListener('resize', this.resizeQueryEditor);
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
window.removeEventListener('resize', this.resizeQueryEditor);
|
window.removeEventListener('resize', this.resizeQueryEditor);
|
||||||
|
@ -234,6 +234,8 @@ export default {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.$refs.firstInput.focus();
|
this.$refs.firstInput.focus();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
window.addEventListener('resize', this.resizeQueryEditor);
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
window.removeEventListener('resize', this.resizeQueryEditor);
|
window.removeEventListener('resize', this.resizeQueryEditor);
|
||||||
|
@ -223,6 +223,8 @@ export default {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.$refs.firstInput.focus();
|
this.$refs.firstInput.focus();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
window.addEventListener('resize', this.resizeQueryEditor);
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
window.removeEventListener('resize', this.resizeQueryEditor);
|
window.removeEventListener('resize', this.resizeQueryEditor);
|
||||||
|
279
src/renderer/components/WorkspaceTabNewTriggerFunction.vue
Normal file
279
src/renderer/components/WorkspaceTabNewTriggerFunction.vue
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
<template>
|
||||||
|
<div v-show="isSelected" class="workspace-query-tab column col-12 columns col-gapless">
|
||||||
|
<div class="workspace-query-runner column col-12">
|
||||||
|
<div class="workspace-query-runner-footer">
|
||||||
|
<div class="workspace-query-buttons">
|
||||||
|
<button
|
||||||
|
class="btn btn-primary btn-sm"
|
||||||
|
:disabled="!isChanged"
|
||||||
|
:class="{'loading':isSaving}"
|
||||||
|
title="CTRL+S"
|
||||||
|
@click="saveChanges"
|
||||||
|
>
|
||||||
|
<i class="mdi mdi-24px mdi-content-save mr-1" />
|
||||||
|
<span>{{ $t('word.save') }}</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
:disabled="!isChanged"
|
||||||
|
class="btn btn-link btn-sm mr-0"
|
||||||
|
:title="$t('message.clearChanges')"
|
||||||
|
@click="clearChanges"
|
||||||
|
>
|
||||||
|
<i class="mdi mdi-24px mdi-delete-sweep mr-1" />
|
||||||
|
<span>{{ $t('word.clear') }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column col-auto">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">
|
||||||
|
{{ $t('word.name') }}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
ref="firstInput"
|
||||||
|
v-model="localFunction.name"
|
||||||
|
class="form-input"
|
||||||
|
type="text"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="customizations.triggerFunctionlanguages" class="column col-auto">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">
|
||||||
|
{{ $t('word.language') }}
|
||||||
|
</label>
|
||||||
|
<select v-model="localFunction.language" class="form-select">
|
||||||
|
<option v-for="language in customizations.triggerFunctionlanguages" :key="language">
|
||||||
|
{{ language }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="customizations.definer" class="column col-auto">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">
|
||||||
|
{{ $t('word.definer') }}
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
v-if="workspace.users.length"
|
||||||
|
v-model="localFunction.definer"
|
||||||
|
class="form-select"
|
||||||
|
>
|
||||||
|
<option value="">
|
||||||
|
{{ $t('message.currentUser') }}
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
v-for="user in workspace.users"
|
||||||
|
:key="`${user.name}@${user.host}`"
|
||||||
|
:value="`\`${user.name}\`@\`${user.host}\``"
|
||||||
|
>
|
||||||
|
{{ user.name }}@{{ user.host }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<select v-if="!workspace.users.length" class="form-select">
|
||||||
|
<option value="">
|
||||||
|
{{ $t('message.currentUser') }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="customizations.comment" class="form-group">
|
||||||
|
<label class="form-label">
|
||||||
|
{{ $t('word.comment') }}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
v-model="localFunction.comment"
|
||||||
|
class="form-input"
|
||||||
|
type="text"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="workspace-query-results column col-12 mt-2 p-relative">
|
||||||
|
<BaseLoader v-if="isLoading" />
|
||||||
|
<label class="form-label ml-2">{{ $t('message.functionBody') }}</label>
|
||||||
|
<QueryEditor
|
||||||
|
v-show="isSelected"
|
||||||
|
ref="queryEditor"
|
||||||
|
:value.sync="localFunction.sql"
|
||||||
|
:workspace="workspace"
|
||||||
|
:schema="schema"
|
||||||
|
:height="editorHeight"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { mapGetters, mapActions } from 'vuex';
|
||||||
|
import BaseLoader from '@/components/BaseLoader';
|
||||||
|
import QueryEditor from '@/components/QueryEditor';
|
||||||
|
import Functions from '@/ipc-api/Functions';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'WorkspaceTabNewTriggerFunction',
|
||||||
|
components: {
|
||||||
|
BaseLoader,
|
||||||
|
QueryEditor
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
connection: Object,
|
||||||
|
tab: Object,
|
||||||
|
isSelected: Boolean,
|
||||||
|
schema: String
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
isLoading: false,
|
||||||
|
isSaving: false,
|
||||||
|
isParamsModal: false,
|
||||||
|
isAskingParameters: false,
|
||||||
|
originalFunction: {},
|
||||||
|
localFunction: {},
|
||||||
|
lastFunction: null,
|
||||||
|
sqlProxy: '',
|
||||||
|
editorHeight: 300
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapGetters({
|
||||||
|
selectedWorkspace: 'workspaces/getSelected',
|
||||||
|
getWorkspace: 'workspaces/getWorkspace'
|
||||||
|
}),
|
||||||
|
workspace () {
|
||||||
|
return this.getWorkspace(this.connection.uid);
|
||||||
|
},
|
||||||
|
customizations () {
|
||||||
|
return this.workspace.customizations;
|
||||||
|
},
|
||||||
|
tabUid () {
|
||||||
|
return this.$vnode.key;
|
||||||
|
},
|
||||||
|
isChanged () {
|
||||||
|
return JSON.stringify(this.originalFunction) !== JSON.stringify(this.localFunction);
|
||||||
|
},
|
||||||
|
isDefinerInUsers () {
|
||||||
|
return this.originalFunction
|
||||||
|
? this.workspace.users.some(user => this.originalFunction.definer === `\`${user.name}\`@\`${user.host}\``)
|
||||||
|
: true;
|
||||||
|
},
|
||||||
|
schemaTables () {
|
||||||
|
const schemaTables = this.workspace.structure
|
||||||
|
.filter(schema => schema.name === this.schema)
|
||||||
|
.map(schema => schema.tables);
|
||||||
|
|
||||||
|
return schemaTables.length ? schemaTables[0].filter(table => table.type === 'table') : [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
isSelected (val) {
|
||||||
|
if (val)
|
||||||
|
this.changeBreadcrumbs({ schema: this.schema });
|
||||||
|
},
|
||||||
|
isChanged (val) {
|
||||||
|
this.setUnsavedChanges({ uid: this.connection.uid, tUid: this.tabUid, isChanged: val });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.originalFunction = {
|
||||||
|
sql: this.customizations.triggerFunctionSql,
|
||||||
|
language: this.customizations.triggerFunctionlanguages.length ? this.customizations.triggerFunctionlanguages[0] : null,
|
||||||
|
name: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
this.localFunction = JSON.parse(JSON.stringify(this.originalFunction));
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.resizeQueryEditor();
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
window.addEventListener('keydown', this.onKey);
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
if (this.isSelected)
|
||||||
|
this.changeBreadcrumbs({ schema: this.schema });
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$refs.firstInput.focus();
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
window.addEventListener('resize', this.resizeQueryEditor);
|
||||||
|
},
|
||||||
|
destroyed () {
|
||||||
|
window.removeEventListener('resize', this.resizeQueryEditor);
|
||||||
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
window.removeEventListener('keydown', this.onKey);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions({
|
||||||
|
addNotification: 'notifications/addNotification',
|
||||||
|
refreshStructure: 'workspaces/refreshStructure',
|
||||||
|
changeBreadcrumbs: 'workspaces/changeBreadcrumbs',
|
||||||
|
setUnsavedChanges: 'workspaces/setUnsavedChanges',
|
||||||
|
newTab: 'workspaces/newTab',
|
||||||
|
removeTab: 'workspaces/removeTab',
|
||||||
|
renameTabs: 'workspaces/renameTabs'
|
||||||
|
}),
|
||||||
|
async saveChanges () {
|
||||||
|
if (this.isSaving) return;
|
||||||
|
this.isSaving = true;
|
||||||
|
const params = {
|
||||||
|
uid: this.connection.uid,
|
||||||
|
schema: this.schema,
|
||||||
|
...this.localFunction
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { status, response } = await Functions.createTriggerFunction(params);
|
||||||
|
|
||||||
|
if (status === 'success') {
|
||||||
|
await this.refreshStructure(this.connection.uid);
|
||||||
|
|
||||||
|
this.newTab({
|
||||||
|
uid: this.connection.uid,
|
||||||
|
schema: this.schema,
|
||||||
|
elementName: this.localFunction.name,
|
||||||
|
elementType: 'triggerFunction',
|
||||||
|
type: 'trigger-function-props'
|
||||||
|
});
|
||||||
|
|
||||||
|
this.removeTab({ uid: this.connection.uid, tab: this.tab.uid });
|
||||||
|
this.changeBreadcrumbs({ schema: this.schema, triggerFunction: this.localFunction.name });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.addNotification({ status: 'error', message: response });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.addNotification({ status: 'error', message: err.stack });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isSaving = false;
|
||||||
|
},
|
||||||
|
clearChanges () {
|
||||||
|
this.localFunction = JSON.parse(JSON.stringify(this.originalFunction));
|
||||||
|
this.$refs.queryEditor.editor.session.setValue(this.localFunction.sql);
|
||||||
|
},
|
||||||
|
resizeQueryEditor () {
|
||||||
|
if (this.$refs.queryEditor) {
|
||||||
|
const footer = document.getElementById('footer');
|
||||||
|
const size = window.innerHeight - this.$refs.queryEditor.$el.getBoundingClientRect().top - footer.offsetHeight;
|
||||||
|
this.editorHeight = size;
|
||||||
|
this.$refs.queryEditor.editor.resize();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onKey (e) {
|
||||||
|
if (this.isSelected) {
|
||||||
|
e.stopPropagation();
|
||||||
|
if (e.ctrlKey && e.keyCode === 83) { // CTRL + S
|
||||||
|
if (this.isChanged)
|
||||||
|
this.saveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -237,7 +237,8 @@ module.exports = {
|
|||||||
newTrigger: 'New trigger',
|
newTrigger: 'New trigger',
|
||||||
newRoutine: 'New routine',
|
newRoutine: 'New routine',
|
||||||
newFunction: 'New function',
|
newFunction: 'New function',
|
||||||
newScheduler: 'New scheduler'
|
newScheduler: 'New scheduler',
|
||||||
|
newTriggerFunction: 'New trigger function'
|
||||||
},
|
},
|
||||||
faker: {
|
faker: {
|
||||||
address: 'Address',
|
address: 'Address',
|
||||||
|
Reference in New Issue
Block a user