2021-09-10 18:23:32 +02:00
|
|
|
<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" />
|
2022-06-14 20:02:17 +02:00
|
|
|
<span>{{ t('word.save') }}</span>
|
2021-09-10 18:23:32 +02:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
:disabled="!isChanged"
|
|
|
|
class="btn btn-link btn-sm mr-0"
|
2022-06-14 20:02:17 +02:00
|
|
|
:title="t('message.clearChanges')"
|
2021-09-10 18:23:32 +02:00
|
|
|
@click="clearChanges"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-24px mdi-delete-sweep mr-1" />
|
2022-06-14 20:02:17 +02:00
|
|
|
<span>{{ t('word.clear') }}</span>
|
2021-09-10 18:23:32 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<div class="divider-vert py-3" />
|
|
|
|
<button class="btn btn-dark btn-sm" @click="showTimingModal">
|
|
|
|
<i class="mdi mdi-24px mdi-timer mr-1" />
|
2022-06-14 20:02:17 +02:00
|
|
|
<span>{{ t('word.timing') }}</span>
|
2021-09-10 18:23:32 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="workspace-query-info">
|
2022-06-14 20:02:17 +02:00
|
|
|
<div class="d-flex" :title="t('word.schema')">
|
2021-09-10 18:23:32 +02:00
|
|
|
<i class="mdi mdi-18px mdi-database mr-1" /><b>{{ schema }}</b>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="container">
|
|
|
|
<div class="columns">
|
|
|
|
<div class="column col-auto">
|
|
|
|
<div class="form-group">
|
2022-06-14 20:02:17 +02:00
|
|
|
<label class="form-label">{{ t('word.name') }}</label>
|
2021-09-10 18:23:32 +02:00
|
|
|
<input
|
|
|
|
ref="firstInput"
|
|
|
|
v-model="localScheduler.name"
|
|
|
|
class="form-input"
|
|
|
|
type="text"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="column col-auto">
|
|
|
|
<div class="form-group">
|
2022-06-14 20:02:17 +02:00
|
|
|
<label class="form-label">{{ t('word.definer') }}</label>
|
2022-05-11 23:30:31 +02:00
|
|
|
<BaseSelect
|
2021-09-10 18:23:32 +02:00
|
|
|
v-model="localScheduler.definer"
|
2022-05-11 23:30:31 +02:00
|
|
|
:options="users"
|
2022-06-14 20:02:17 +02:00
|
|
|
:option-label="(user: any) => user.value === '' ? t('message.currentUser') : `${user.name}@${user.host}`"
|
|
|
|
:option-track-by="(user: any) => user.value === '' ? '' : `\`${user.name}\`@\`${user.host}\``"
|
2021-09-10 18:23:32 +02:00
|
|
|
class="form-select"
|
2022-05-11 23:30:31 +02:00
|
|
|
/>
|
2021-09-10 18:23:32 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="column">
|
|
|
|
<div class="form-group">
|
2022-06-14 20:02:17 +02:00
|
|
|
<label class="form-label">{{ t('word.comment') }}</label>
|
2021-09-10 18:23:32 +02:00
|
|
|
<input
|
|
|
|
v-model="localScheduler.comment"
|
|
|
|
class="form-input"
|
|
|
|
type="text"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="column">
|
|
|
|
<div class="form-group">
|
2022-06-14 20:02:17 +02:00
|
|
|
<label class="form-label mr-2">{{ t('word.state') }}</label>
|
2021-09-10 18:23:32 +02:00
|
|
|
<label class="form-radio form-inline">
|
|
|
|
<input
|
|
|
|
v-model="localScheduler.state"
|
|
|
|
type="radio"
|
|
|
|
name="state"
|
|
|
|
value="ENABLE"
|
|
|
|
><i class="form-icon" /> ENABLE
|
|
|
|
</label>
|
|
|
|
<label class="form-radio form-inline">
|
|
|
|
<input
|
|
|
|
v-model="localScheduler.state"
|
|
|
|
type="radio"
|
|
|
|
name="state"
|
|
|
|
value="DISABLE"
|
|
|
|
><i class="form-icon" /> DISABLE
|
|
|
|
</label>
|
|
|
|
<label class="form-radio form-inline">
|
|
|
|
<input
|
|
|
|
v-model="localScheduler.state"
|
|
|
|
type="radio"
|
|
|
|
name="state"
|
|
|
|
value="DISABLE ON SLAVE"
|
|
|
|
><i class="form-icon" /> DISABLE ON SLAVE
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="workspace-query-results column col-12 mt-2 p-relative">
|
|
|
|
<BaseLoader v-if="isLoading" />
|
2022-06-14 20:02:17 +02:00
|
|
|
<label class="form-label ml-2">{{ t('message.schedulerBody') }}</label>
|
2021-09-10 18:23:32 +02:00
|
|
|
<QueryEditor
|
|
|
|
v-show="isSelected"
|
|
|
|
ref="queryEditor"
|
2022-04-21 14:39:24 +02:00
|
|
|
v-model="localScheduler.sql"
|
2021-09-10 18:23:32 +02:00
|
|
|
:workspace="workspace"
|
|
|
|
:schema="schema"
|
|
|
|
:height="editorHeight"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<WorkspaceTabPropsSchedulerTimingModal
|
|
|
|
v-if="isTimingModal"
|
|
|
|
:local-options="localScheduler"
|
|
|
|
:workspace="workspace"
|
|
|
|
@hide="hideTimingModal"
|
|
|
|
@options-update="timingUpdate"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-14 20:02:17 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { Component, computed, onBeforeUnmount, onMounted, onUnmounted, Ref, ref, watch } from 'vue';
|
|
|
|
import { Ace } from 'ace-builds';
|
|
|
|
import { EventInfos } from 'common/interfaces/antares';
|
|
|
|
import { useI18n } from 'vue-i18n';
|
2022-04-30 00:47:37 +02:00
|
|
|
import { useNotificationsStore } from '@/stores/notifications';
|
|
|
|
import { useWorkspacesStore } from '@/stores/workspaces';
|
2022-06-14 20:02:17 +02:00
|
|
|
import BaseLoader from '@/components/BaseLoader.vue';
|
|
|
|
import QueryEditor from '@/components/QueryEditor.vue';
|
|
|
|
import WorkspaceTabPropsSchedulerTimingModal from '@/components/WorkspaceTabPropsSchedulerTimingModal.vue';
|
2021-09-10 18:23:32 +02:00
|
|
|
import Schedulers from '@/ipc-api/Schedulers';
|
2022-05-11 23:30:31 +02:00
|
|
|
import BaseSelect from '@/components/BaseSelect.vue';
|
2021-09-10 18:23:32 +02:00
|
|
|
|
2022-06-14 20:02:17 +02:00
|
|
|
const { t } = useI18n();
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
tabUid: String,
|
|
|
|
connection: Object,
|
|
|
|
tab: Object,
|
|
|
|
isSelected: Boolean,
|
|
|
|
schema: String
|
|
|
|
});
|
|
|
|
|
|
|
|
const { addNotification } = useNotificationsStore();
|
|
|
|
const workspacesStore = useWorkspacesStore();
|
|
|
|
|
|
|
|
const {
|
|
|
|
getWorkspace,
|
|
|
|
refreshStructure,
|
|
|
|
changeBreadcrumbs,
|
|
|
|
setUnsavedChanges,
|
|
|
|
newTab,
|
|
|
|
removeTab
|
|
|
|
} = workspacesStore;
|
|
|
|
|
|
|
|
const queryEditor: Ref<Component & {editor: Ace.Editor; $el: HTMLElement}> = ref(null);
|
|
|
|
const firstInput: Ref<HTMLInputElement> = ref(null);
|
|
|
|
const isLoading = ref(false);
|
|
|
|
const isSaving = ref(false);
|
|
|
|
const isTimingModal = ref(false);
|
|
|
|
const originalScheduler = ref(null);
|
|
|
|
const localScheduler = ref(null);
|
|
|
|
const editorHeight = ref(300);
|
|
|
|
|
|
|
|
const workspace = computed(() => {
|
|
|
|
return getWorkspace(props.connection.uid);
|
|
|
|
});
|
|
|
|
|
|
|
|
const isChanged = computed(() => {
|
|
|
|
return JSON.stringify(originalScheduler.value) !== JSON.stringify(localScheduler.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
const isDefinerInUsers = computed(() => {
|
|
|
|
return originalScheduler.value ? workspace.value.users.some(user => originalScheduler.value.definer === `\`${user.name}\`@\`${user.host}\``) : true;
|
|
|
|
});
|
|
|
|
|
|
|
|
const users = computed(() => {
|
|
|
|
const users = [{ value: '' }, ...workspace.value.users];
|
|
|
|
if (!isDefinerInUsers.value) {
|
|
|
|
const [name, host] = originalScheduler.value.definer.replaceAll('`', '').split('@');
|
|
|
|
users.unshift({ name, host });
|
|
|
|
}
|
|
|
|
|
|
|
|
return users;
|
|
|
|
});
|
|
|
|
|
|
|
|
const saveChanges = async () => {
|
|
|
|
if (isSaving.value) return;
|
|
|
|
isSaving.value = true;
|
|
|
|
const params = {
|
|
|
|
uid: props.connection.uid,
|
|
|
|
schema: props.schema,
|
|
|
|
...localScheduler.value
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
const { status, response } = await Schedulers.createScheduler(params);
|
|
|
|
|
|
|
|
if (status === 'success') {
|
|
|
|
await refreshStructure(props.connection.uid);
|
|
|
|
|
|
|
|
newTab({
|
|
|
|
uid: props.connection.uid,
|
|
|
|
schema: props.schema,
|
|
|
|
elementName: localScheduler.value.name,
|
|
|
|
elementType: 'scheduler',
|
|
|
|
type: 'scheduler-props'
|
|
|
|
});
|
|
|
|
|
|
|
|
removeTab({ uid: props.connection.uid, tab: props.tab.uid });
|
|
|
|
changeBreadcrumbs({ schema: props.schema, scheduler: localScheduler.value.name });
|
2021-09-10 18:23:32 +02:00
|
|
|
}
|
2022-06-14 20:02:17 +02:00
|
|
|
else
|
|
|
|
addNotification({ status: 'error', message: response });
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
|
|
|
isSaving.value = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
const clearChanges = () => {
|
|
|
|
localScheduler.value = JSON.parse(JSON.stringify(originalScheduler.value));
|
|
|
|
queryEditor.value.editor.session.setValue(localScheduler.value.sql);
|
|
|
|
};
|
|
|
|
|
|
|
|
const resizeQueryEditor = () => {
|
|
|
|
if (queryEditor.value) {
|
|
|
|
const footer = document.getElementById('footer');
|
|
|
|
const size = window.innerHeight - queryEditor.value.$el.getBoundingClientRect().top - footer.offsetHeight;
|
|
|
|
editorHeight.value = size;
|
|
|
|
queryEditor.value.editor.resize();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const showTimingModal = () => {
|
|
|
|
isTimingModal.value = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const hideTimingModal = () => {
|
|
|
|
isTimingModal.value = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
const timingUpdate = (options: EventInfos) => {
|
|
|
|
localScheduler.value = options;
|
|
|
|
};
|
|
|
|
|
|
|
|
const onKey = (e: KeyboardEvent) => {
|
|
|
|
if (props.isSelected) {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (e.ctrlKey && e.key === 's') { // CTRL + S
|
|
|
|
if (isChanged.value)
|
|
|
|
saveChanges();
|
2021-09-10 18:23:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-06-14 20:02:17 +02:00
|
|
|
|
|
|
|
watch(() => props.isSelected, (val) => {
|
|
|
|
if (val) changeBreadcrumbs({ schema: props.schema });
|
|
|
|
});
|
|
|
|
|
|
|
|
watch(isChanged, (val) => {
|
|
|
|
setUnsavedChanges({ uid: props.connection.uid, tUid: props.tabUid, isChanged: val });
|
|
|
|
});
|
|
|
|
|
|
|
|
originalScheduler.value = {
|
|
|
|
definer: '',
|
|
|
|
sql: 'BEGIN\r\n\r\nEND',
|
|
|
|
name: '',
|
|
|
|
comment: '',
|
|
|
|
execution: 'EVERY',
|
|
|
|
every: ['1', 'DAY'],
|
|
|
|
preserve: true,
|
|
|
|
state: 'DISABLE'
|
|
|
|
};
|
|
|
|
|
|
|
|
originalScheduler.value = JSON.parse(JSON.stringify(originalScheduler.value));
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
resizeQueryEditor();
|
|
|
|
}, 50);
|
|
|
|
|
|
|
|
window.addEventListener('keydown', onKey);
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if (props.isSelected)
|
|
|
|
changeBreadcrumbs({ schema: props.schema });
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
firstInput.value.focus();
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
window.removeEventListener('keydown', onKey);
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.removeEventListener('resize', resizeQueryEditor);
|
|
|
|
});
|
|
|
|
|
2021-09-10 18:23:32 +02:00
|
|
|
</script>
|