Skip to content

Commit

Permalink
feat: schedulers creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Jan 16, 2021
1 parent ceab4ef commit dbe7b9d
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 15 deletions.
23 changes: 10 additions & 13 deletions src/main/libs/clients/MySQLClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ export class MySQLClient extends AntaresCore {
COMMENT '${scheduler.comment}'
DO ${scheduler.sql}`;

return await this.raw(sql);
return await this.raw(sql, { split: false });
}

/**
Expand All @@ -741,18 +741,15 @@ export class MySQLClient extends AntaresCore {
* @memberof MySQLClient
*/
async createEvent (scheduler) {
const parameters = scheduler.parameters.reduce((acc, curr) => {
acc.push(`\`${curr.name}\` ${curr.type}${curr.length ? `(${curr.length})` : ''}`);
return acc;
}, []).join(',');

const sql = `CREATE ${scheduler.definer ? `DEFINER=${scheduler.definer} ` : ''}FUNCTION \`${scheduler.name}\`(${parameters}) RETURNS ${scheduler.returns}${scheduler.returnsLength ? `(${scheduler.returnsLength})` : ''}
LANGUAGE SQL
${scheduler.deterministic ? 'DETERMINISTIC' : 'NOT DETERMINISTIC'}
${scheduler.dataAccess}
SQL SECURITY ${scheduler.security}
COMMENT '${scheduler.comment}'
${scheduler.sql}`;
const sql = `CREATE ${scheduler.definer ? ` DEFINER=${scheduler.definer}` : ''} EVENT \`${scheduler.name}\`
ON SCHEDULE
${scheduler.execution === 'EVERY'
? `EVERY ${scheduler.every.join(' ')}${scheduler.starts ? ` STARTS '${scheduler.starts}'` : ''}${scheduler.ends ? ` ENDS '${scheduler.ends}'` : ''}`
: `AT '${scheduler.at}'`}
ON COMPLETION${!scheduler.preserve ? ' NOT' : ''} PRESERVE
${scheduler.state}
COMMENT '${scheduler.comment}'
DO ${scheduler.sql}`;

return await this.raw(sql, { split: false });
}
Expand Down
109 changes: 109 additions & 0 deletions src/renderer/components/ModalNewScheduler.vue
Original file line number Diff line number Diff line change
@@ -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>
36 changes: 35 additions & 1 deletion src/renderer/components/WorkspaceExploreBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
@close="hideCreateFunctionModal"
@open-create-function-editor="openCreateFunctionEditor"
/>
<ModalNewScheduler
v-if="isNewSchedulerModal"
:workspace="workspace"
@close="hideCreateSchedulerModal"
@open-create-scheduler-editor="openCreateSchedulerEditor"
/>
<DatabaseContext
v-if="isDatabaseContext"
:selected-database="selectedDatabase"
Expand All @@ -89,6 +95,7 @@
@show-create-trigger-modal="showCreateTriggerModal"
@show-create-routine-modal="showCreateRoutineModal"
@show-create-function-modal="showCreateFunctionModal"
@show-create-scheduler-modal="showCreateSchedulerModal"
@reload="refresh"
/>
<TableContext
Expand Down Expand Up @@ -117,6 +124,7 @@ import Views from '@/ipc-api/Views';
import Triggers from '@/ipc-api/Triggers';
import Routines from '@/ipc-api/Routines';
import Functions from '@/ipc-api/Functions';
import Schedulers from '@/ipc-api/Schedulers';
import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel';
import WorkspaceExploreBarDatabase from '@/components/WorkspaceExploreBarDatabase';
Expand All @@ -129,6 +137,7 @@ import ModalNewView from '@/components/ModalNewView';
import ModalNewTrigger from '@/components/ModalNewTrigger';
import ModalNewRoutine from '@/components/ModalNewRoutine';
import ModalNewFunction from '@/components/ModalNewFunction';
import ModalNewScheduler from '@/components/ModalNewScheduler';
export default {
name: 'WorkspaceExploreBar',
Expand All @@ -143,7 +152,8 @@ export default {
ModalNewView,
ModalNewTrigger,
ModalNewRoutine,
ModalNewFunction
ModalNewFunction,
ModalNewScheduler
},
props: {
connection: Object,
Expand All @@ -159,6 +169,7 @@ export default {
isNewTriggerModal: false,
isNewRoutineModal: false,
isNewFunctionModal: false,
isNewSchedulerModal: false,
localWidth: null,
isDatabaseContext: false,
Expand Down Expand Up @@ -363,6 +374,13 @@ export default {
hideCreateFunctionModal () {
this.isNewFunctionModal = false;
},
showCreateSchedulerModal () {
this.closeDatabaseContext();
this.isNewSchedulerModal = true;
},
hideCreateSchedulerModal () {
this.isNewSchedulerModal = false;
},
async openCreateFunctionEditor (payload) {
const params = {
uid: this.connection.uid,
Expand All @@ -378,6 +396,22 @@ export default {
}
else
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 });
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<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>
</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>
</div>
</div>
Expand Down Expand Up @@ -111,6 +111,9 @@ export default {
showCreateFunctionModal () {
this.$emit('show-create-function-modal');
},
showCreateSchedulerModal () {
this.$emit('show-create-scheduler-modal');
},
showDeleteModal () {
this.isDeleteModal = true;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export default {
this.hasEnd = !!this.optionsProxy.ends;
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'];
setTimeout(() => {
Expand Down

0 comments on commit dbe7b9d

Please sign in to comment.