mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
feat: schedulers creation
This commit is contained in:
@ -731,7 +731,7 @@ export class MySQLClient extends AntaresCore {
|
|||||||
COMMENT '${scheduler.comment}'
|
COMMENT '${scheduler.comment}'
|
||||||
DO ${scheduler.sql}`;
|
DO ${scheduler.sql}`;
|
||||||
|
|
||||||
return await this.raw(sql);
|
return await this.raw(sql, { split: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -741,18 +741,15 @@ export class MySQLClient extends AntaresCore {
|
|||||||
* @memberof MySQLClient
|
* @memberof MySQLClient
|
||||||
*/
|
*/
|
||||||
async createEvent (scheduler) {
|
async createEvent (scheduler) {
|
||||||
const parameters = scheduler.parameters.reduce((acc, curr) => {
|
const sql = `CREATE ${scheduler.definer ? ` DEFINER=${scheduler.definer}` : ''} EVENT \`${scheduler.name}\`
|
||||||
acc.push(`\`${curr.name}\` ${curr.type}${curr.length ? `(${curr.length})` : ''}`);
|
ON SCHEDULE
|
||||||
return acc;
|
${scheduler.execution === 'EVERY'
|
||||||
}, []).join(',');
|
? `EVERY ${scheduler.every.join(' ')}${scheduler.starts ? ` STARTS '${scheduler.starts}'` : ''}${scheduler.ends ? ` ENDS '${scheduler.ends}'` : ''}`
|
||||||
|
: `AT '${scheduler.at}'`}
|
||||||
const sql = `CREATE ${scheduler.definer ? `DEFINER=${scheduler.definer} ` : ''}FUNCTION \`${scheduler.name}\`(${parameters}) RETURNS ${scheduler.returns}${scheduler.returnsLength ? `(${scheduler.returnsLength})` : ''}
|
ON COMPLETION${!scheduler.preserve ? ' NOT' : ''} PRESERVE
|
||||||
LANGUAGE SQL
|
${scheduler.state}
|
||||||
${scheduler.deterministic ? 'DETERMINISTIC' : 'NOT DETERMINISTIC'}
|
|
||||||
${scheduler.dataAccess}
|
|
||||||
SQL SECURITY ${scheduler.security}
|
|
||||||
COMMENT '${scheduler.comment}'
|
COMMENT '${scheduler.comment}'
|
||||||
${scheduler.sql}`;
|
DO ${scheduler.sql}`;
|
||||||
|
|
||||||
return await this.raw(sql, { split: false });
|
return await this.raw(sql, { split: false });
|
||||||
}
|
}
|
||||||
|
109
src/renderer/components/ModalNewScheduler.vue
Normal file
109
src/renderer/components/ModalNewScheduler.vue
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<template>
|
||||||
|
<ConfirmModal
|
||||||
|
:confirm-text="$t('word.confirm')"
|
||||||
|
size="400"
|
||||||
|
@confirm="confirmNewTrigger"
|
||||||
|
@hide="$emit('close')"
|
||||||
|
>
|
||||||
|
<template :slot="'header'">
|
||||||
|
<div class="d-flex">
|
||||||
|
<i class="mdi mdi-24px mdi-plus mr-1" /> {{ $t('message.createNewScheduler') }}
|
||||||
|
</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="localScheduler.name"
|
||||||
|
class="form-input"
|
||||||
|
type="text"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label col-4">
|
||||||
|
{{ $t('word.definer') }}
|
||||||
|
</label>
|
||||||
|
<div class="column">
|
||||||
|
<select
|
||||||
|
v-if="workspace.users.length"
|
||||||
|
v-model="localScheduler.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 class="form-group">
|
||||||
|
<label class="form-label col-4">
|
||||||
|
{{ $t('word.comment') }}
|
||||||
|
</label>
|
||||||
|
<div class="column">
|
||||||
|
<input
|
||||||
|
v-model="localScheduler.comment"
|
||||||
|
class="form-input"
|
||||||
|
type="text"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</ConfirmModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import ConfirmModal from '@/components/BaseConfirmModal';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'ModalNewScheduler',
|
||||||
|
components: {
|
||||||
|
ConfirmModal
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
workspace: Object
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
localScheduler: {
|
||||||
|
definer: '',
|
||||||
|
sql: 'BEGIN\r\n\r\nEND',
|
||||||
|
name: '',
|
||||||
|
comment: '',
|
||||||
|
execution: 'EVERY',
|
||||||
|
every: ['1', 'DAY'],
|
||||||
|
preserve: true,
|
||||||
|
state: 'DISABLE'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$refs.firstInput.focus();
|
||||||
|
}, 20);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
confirmNewTrigger () {
|
||||||
|
this.$emit('open-create-scheduler-editor', this.localScheduler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -79,6 +79,12 @@
|
|||||||
@close="hideCreateFunctionModal"
|
@close="hideCreateFunctionModal"
|
||||||
@open-create-function-editor="openCreateFunctionEditor"
|
@open-create-function-editor="openCreateFunctionEditor"
|
||||||
/>
|
/>
|
||||||
|
<ModalNewScheduler
|
||||||
|
v-if="isNewSchedulerModal"
|
||||||
|
:workspace="workspace"
|
||||||
|
@close="hideCreateSchedulerModal"
|
||||||
|
@open-create-scheduler-editor="openCreateSchedulerEditor"
|
||||||
|
/>
|
||||||
<DatabaseContext
|
<DatabaseContext
|
||||||
v-if="isDatabaseContext"
|
v-if="isDatabaseContext"
|
||||||
:selected-database="selectedDatabase"
|
:selected-database="selectedDatabase"
|
||||||
@ -89,6 +95,7 @@
|
|||||||
@show-create-trigger-modal="showCreateTriggerModal"
|
@show-create-trigger-modal="showCreateTriggerModal"
|
||||||
@show-create-routine-modal="showCreateRoutineModal"
|
@show-create-routine-modal="showCreateRoutineModal"
|
||||||
@show-create-function-modal="showCreateFunctionModal"
|
@show-create-function-modal="showCreateFunctionModal"
|
||||||
|
@show-create-scheduler-modal="showCreateSchedulerModal"
|
||||||
@reload="refresh"
|
@reload="refresh"
|
||||||
/>
|
/>
|
||||||
<TableContext
|
<TableContext
|
||||||
@ -117,6 +124,7 @@ import Views from '@/ipc-api/Views';
|
|||||||
import Triggers from '@/ipc-api/Triggers';
|
import Triggers from '@/ipc-api/Triggers';
|
||||||
import Routines from '@/ipc-api/Routines';
|
import Routines from '@/ipc-api/Routines';
|
||||||
import Functions from '@/ipc-api/Functions';
|
import Functions from '@/ipc-api/Functions';
|
||||||
|
import Schedulers from '@/ipc-api/Schedulers';
|
||||||
|
|
||||||
import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel';
|
import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel';
|
||||||
import WorkspaceExploreBarDatabase from '@/components/WorkspaceExploreBarDatabase';
|
import WorkspaceExploreBarDatabase from '@/components/WorkspaceExploreBarDatabase';
|
||||||
@ -129,6 +137,7 @@ import ModalNewView from '@/components/ModalNewView';
|
|||||||
import ModalNewTrigger from '@/components/ModalNewTrigger';
|
import ModalNewTrigger from '@/components/ModalNewTrigger';
|
||||||
import ModalNewRoutine from '@/components/ModalNewRoutine';
|
import ModalNewRoutine from '@/components/ModalNewRoutine';
|
||||||
import ModalNewFunction from '@/components/ModalNewFunction';
|
import ModalNewFunction from '@/components/ModalNewFunction';
|
||||||
|
import ModalNewScheduler from '@/components/ModalNewScheduler';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'WorkspaceExploreBar',
|
name: 'WorkspaceExploreBar',
|
||||||
@ -143,7 +152,8 @@ export default {
|
|||||||
ModalNewView,
|
ModalNewView,
|
||||||
ModalNewTrigger,
|
ModalNewTrigger,
|
||||||
ModalNewRoutine,
|
ModalNewRoutine,
|
||||||
ModalNewFunction
|
ModalNewFunction,
|
||||||
|
ModalNewScheduler
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
connection: Object,
|
connection: Object,
|
||||||
@ -159,6 +169,7 @@ export default {
|
|||||||
isNewTriggerModal: false,
|
isNewTriggerModal: false,
|
||||||
isNewRoutineModal: false,
|
isNewRoutineModal: false,
|
||||||
isNewFunctionModal: false,
|
isNewFunctionModal: false,
|
||||||
|
isNewSchedulerModal: false,
|
||||||
|
|
||||||
localWidth: null,
|
localWidth: null,
|
||||||
isDatabaseContext: false,
|
isDatabaseContext: false,
|
||||||
@ -363,6 +374,13 @@ export default {
|
|||||||
hideCreateFunctionModal () {
|
hideCreateFunctionModal () {
|
||||||
this.isNewFunctionModal = false;
|
this.isNewFunctionModal = false;
|
||||||
},
|
},
|
||||||
|
showCreateSchedulerModal () {
|
||||||
|
this.closeDatabaseContext();
|
||||||
|
this.isNewSchedulerModal = true;
|
||||||
|
},
|
||||||
|
hideCreateSchedulerModal () {
|
||||||
|
this.isNewSchedulerModal = false;
|
||||||
|
},
|
||||||
async openCreateFunctionEditor (payload) {
|
async openCreateFunctionEditor (payload) {
|
||||||
const params = {
|
const params = {
|
||||||
uid: this.connection.uid,
|
uid: this.connection.uid,
|
||||||
@ -378,6 +396,22 @@ export default {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
this.addNotification({ status: 'error', message: response });
|
this.addNotification({ status: 'error', message: response });
|
||||||
|
},
|
||||||
|
async openCreateSchedulerEditor (payload) {
|
||||||
|
const params = {
|
||||||
|
uid: this.connection.uid,
|
||||||
|
...payload
|
||||||
|
};
|
||||||
|
|
||||||
|
const { status, response } = await Schedulers.createScheduler(params);
|
||||||
|
|
||||||
|
if (status === 'success') {
|
||||||
|
await this.refresh();
|
||||||
|
this.changeBreadcrumbs({ schema: this.selectedDatabase, scheduler: payload.name });
|
||||||
|
this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.addNotification({ status: 'error', message: response });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<div class="context-element" @click="showCreateFunctionModal">
|
<div class="context-element" @click="showCreateFunctionModal">
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-arrow-right-bold-box pr-1" /> {{ $tc('word.function', 1) }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-arrow-right-bold-box pr-1" /> {{ $tc('word.function', 1) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="context-element disabled" @click="false">
|
<div class="context-element" @click="showCreateSchedulerModal">
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-calendar-clock text-light pr-1" /> {{ $tc('word.scheduler', 1) }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-calendar-clock text-light pr-1" /> {{ $tc('word.scheduler', 1) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -111,6 +111,9 @@ export default {
|
|||||||
showCreateFunctionModal () {
|
showCreateFunctionModal () {
|
||||||
this.$emit('show-create-function-modal');
|
this.$emit('show-create-function-modal');
|
||||||
},
|
},
|
||||||
|
showCreateSchedulerModal () {
|
||||||
|
this.$emit('show-create-scheduler-modal');
|
||||||
|
},
|
||||||
showDeleteModal () {
|
showDeleteModal () {
|
||||||
this.isDeleteModal = true;
|
this.isDeleteModal = true;
|
||||||
},
|
},
|
||||||
|
@ -168,6 +168,8 @@ export default {
|
|||||||
this.hasEnd = !!this.optionsProxy.ends;
|
this.hasEnd = !!this.optionsProxy.ends;
|
||||||
|
|
||||||
if (!this.optionsProxy.at) this.optionsProxy.at = moment().format('YYYY-MM-DD HH:mm:ss');
|
if (!this.optionsProxy.at) this.optionsProxy.at = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
if (!this.optionsProxy.starts) this.optionsProxy.starts = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
if (!this.optionsProxy.ends) this.optionsProxy.ends = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
if (!this.optionsProxy.every.length) this.optionsProxy.every = ['1', 'DAY'];
|
if (!this.optionsProxy.every.length) this.optionsProxy.every = ['1', 'DAY'];
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
Reference in New Issue
Block a user