diff --git a/src/main/ipc-handlers/schedulers.js b/src/main/ipc-handlers/schedulers.js index 4133fbed..f270beb3 100644 --- a/src/main/ipc-handlers/schedulers.js +++ b/src/main/ipc-handlers/schedulers.js @@ -40,4 +40,17 @@ export default (connections) => { return { status: 'error', response: err.toString() }; } }); + + ipcMain.handle('toggle-scheduler', async (event, params) => { + try { + if (!params.enabled) + await connections[params.uid].enableEvent({ ...params }); + else + await connections[params.uid].disableEvent({ ...params }); + return { status: 'success' }; + } + catch (err) { + return { status: 'error', response: err.toString() }; + } + }); }; diff --git a/src/main/ipc-handlers/triggers.js b/src/main/ipc-handlers/triggers.js index 00ad9834..89df9a15 100644 --- a/src/main/ipc-handlers/triggers.js +++ b/src/main/ipc-handlers/triggers.js @@ -45,10 +45,8 @@ export default (connections) => { try { if (!params.enabled) await connections[params.uid].enableTrigger(params); - else await connections[params.uid].disableTrigger(params); - return { status: 'success' }; } catch (err) { diff --git a/src/main/libs/clients/MySQLClient.js b/src/main/libs/clients/MySQLClient.js index e9c9a081..d5b79b2d 100644 --- a/src/main/libs/clients/MySQLClient.js +++ b/src/main/libs/clients/MySQLClient.js @@ -1072,6 +1072,16 @@ export class MySQLClient extends AntaresCore { return await this.raw(sql, { split: false }); } + async enableEvent ({ schema, scheduler }) { + const sql = `ALTER EVENT \`${schema}\`.\`${scheduler}\` ENABLE`; + return await this.raw(sql, { split: false }); + } + + async disableEvent ({ schema, scheduler }) { + const sql = `ALTER EVENT \`${schema}\`.\`${scheduler}\` DISABLE`; + return await this.raw(sql, { split: false }); + } + /** * SHOW COLLATION * diff --git a/src/renderer/components/WorkspaceExploreBarMiscContext.vue b/src/renderer/components/WorkspaceExploreBarMiscContext.vue index 864e4221..f9807613 100644 --- a/src/renderer/components/WorkspaceExploreBarMiscContext.vue +++ b/src/renderer/components/WorkspaceExploreBarMiscContext.vue @@ -22,6 +22,18 @@ {{ $t('word.disable') }} +
+ + {{ $t('word.enable') }} + + + {{ $t('word.disable') }} + +
{{ $t('word.delete') }}
@@ -113,6 +125,8 @@ export default { ...mapActions({ addNotification: 'notifications/addNotification', changeBreadcrumbs: 'workspaces/changeBreadcrumbs', + addLoadingElement: 'workspaces/addLoadingElement', + removeLoadingElement: 'workspaces/removeLoadingElement', removeTabs: 'workspaces/removeTabs', newTab: 'workspaces/newTab' }), @@ -290,6 +304,12 @@ export default { this.closeContext(); }, async toggleTrigger () { + this.addLoadingElement({ + name: this.selectedMisc.name, + schema: this.selectedSchema, + type: 'trigger' + }); + try { const { status, response } = await Triggers.toggleTrigger({ uid: this.selectedWorkspace, @@ -304,6 +324,44 @@ export default { catch (err) { this.addNotification({ status: 'error', message: err.stack }); } + + this.removeLoadingElement({ + name: this.selectedMisc.name, + schema: this.selectedSchema, + type: 'trigger' + }); + + this.closeContext(); + this.$emit('reload'); + }, + async toggleScheduler () { + this.addLoadingElement({ + name: this.selectedMisc.name, + schema: this.selectedSchema, + type: 'scheduler' + }); + + try { + const { status, response } = await Schedulers.toggleScheduler({ + uid: this.selectedWorkspace, + schema: this.selectedSchema, + scheduler: this.selectedMisc.name, + enabled: this.selectedMisc.enabled + }); + + if (status !== 'success') + this.addNotification({ status: 'error', message: response }); + } + catch (err) { + this.addNotification({ status: 'error', message: err.stack }); + } + + this.removeLoadingElement({ + name: this.selectedMisc.name, + schema: this.selectedSchema, + type: 'scheduler' + }); + this.closeContext(); this.$emit('reload'); } diff --git a/src/renderer/components/WorkspaceExploreBarSchema.vue b/src/renderer/components/WorkspaceExploreBarSchema.vue index b57036d3..e4827d71 100644 --- a/src/renderer/components/WorkspaceExploreBarSchema.vue +++ b/src/renderer/components/WorkspaceExploreBarSchema.vue @@ -68,7 +68,8 @@ @contextmenu.prevent="showMiscContext($event, {...trigger, type: 'trigger'})" > - +