From f36b50c5029f4540b3310a4249667a48dfdb7606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 30 Aug 2019 14:14:12 +0200 Subject: [PATCH] Migrate plugins to vuex store MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/workflowengine/src/components/Check.vue | 33 ++++++++++++------ apps/workflowengine/src/components/Rule.vue | 8 +++-- .../src/components/Values/FileMimeType.vue | 10 +++++- .../src/legacy/filemimetypeplugin.js | 8 ----- apps/workflowengine/src/services/Operation.js | 11 ------ apps/workflowengine/src/store.js | 12 +++++++ apps/workflowengine/src/workflowengine.js | 34 +++++++++++++++++-- 7 files changed, 81 insertions(+), 35 deletions(-) diff --git a/apps/workflowengine/src/components/Check.vue b/apps/workflowengine/src/components/Check.vue index b2e8e13c29..5f8140f222 100644 --- a/apps/workflowengine/src/components/Check.vue +++ b/apps/workflowengine/src/components/Check.vue @@ -3,12 +3,12 @@ - - - + + @@ -16,9 +16,9 @@ diff --git a/apps/workflowengine/src/legacy/filemimetypeplugin.js b/apps/workflowengine/src/legacy/filemimetypeplugin.js index 2b29c4fcbb..e58bdec26d 100644 --- a/apps/workflowengine/src/legacy/filemimetypeplugin.js +++ b/apps/workflowengine/src/legacy/filemimetypeplugin.js @@ -17,8 +17,6 @@ * along with this program. If not, see . * */ -import FileMimeType from './../components/Values/FileMimeType' - (function() { OCA.WorkflowEngine = OCA.WorkflowEngine || {} @@ -66,12 +64,6 @@ import FileMimeType from './../components/Values/FileMimeType' var regexRegex = /^\/(.*)\/([gui]{0,3})$/ var result = regexRegex.exec(string) return result !== null - }, - - component: function() { - return FileMimeType } } })() - -OC.Plugins.register('OCA.WorkflowEngine.CheckPlugins', OCA.WorkflowEngine.Plugins.FileMimeTypePlugin) diff --git a/apps/workflowengine/src/services/Operation.js b/apps/workflowengine/src/services/Operation.js index 99dca212f4..ed996593cb 100644 --- a/apps/workflowengine/src/services/Operation.js +++ b/apps/workflowengine/src/services/Operation.js @@ -13,16 +13,6 @@ const ALL_CHECKS = [ 'OCA\\WorkflowEngine\\Check\\UserGroupMembership' ] -const Checks = Object.values(OCA.WorkflowEngine.Plugins).map((plugin) => { - if (plugin.component) { - return { ...plugin.getCheck(), component: plugin.component } - } - return plugin.getCheck() -}).reduce((obj, item) => { - obj[item.class] = item - return obj -}, {}) - const Operators = OCP.InitialState.loadState('workflowengine', 'operators') /** @@ -71,7 +61,6 @@ Operators['OCA\\FilesAutomatedTagging\\Operation'] = { } export { - Checks, Operators, ALL_CHECKS } diff --git a/apps/workflowengine/src/store.js b/apps/workflowengine/src/store.js index ec9d736dd0..34cee25675 100644 --- a/apps/workflowengine/src/store.js +++ b/apps/workflowengine/src/store.js @@ -35,6 +35,12 @@ const store = new Vuex.Store({ scope: OCP.InitialState.loadState('workflowengine', 'scope'), // TODO: move to backend data operations: Operators, + + plugins: Vue.observable({ + checks: {}, + operators: {} + }), + entities: OCP.InitialState.loadState('workflowengine', 'entities').map(entity => { return { ...entity, @@ -63,6 +69,12 @@ const store = new Vuex.Store({ removeRule(state, rule) { const index = state.rules.findIndex((item) => rule.id === item.id) state.rules.splice(index, 1) + }, + addPluginCheck(state, plugin) { + Vue.set(state.plugins.checks, plugin.class, plugin) + }, + addPluginOperator(state, plugin) { + Vue.set(state.plugins.operators, plugin.class, plugin) } }, actions: { diff --git a/apps/workflowengine/src/workflowengine.js b/apps/workflowengine/src/workflowengine.js index 866f049b0b..bdf3039788 100644 --- a/apps/workflowengine/src/workflowengine.js +++ b/apps/workflowengine/src/workflowengine.js @@ -14,11 +14,41 @@ import Vuex from 'vuex' import store from './store' import Settings from './components/Workflow' +import FileMimeType from './components/Values/FileMimeType'; + +window.OCA.WorkflowEngine = Object.assign({}, OCA.WorkflowEngine, { + registerCheck: function (Plugin) { + store.commit('addPluginCheck', Plugin) + }, + registerOperator: function (Plugin) { + store.commit('addPluginOperator', Plugin) + } +}) + +// Load legacy plugins for now and register them in the new plugin system +Object.values(OCA.WorkflowEngine.Plugins).map((plugin) => { + if (plugin.component) { + return { ...plugin.getCheck(), component: plugin.component() } + } + return plugin.getCheck() +}).forEach((legacyCheckPlugin) => window.OCA.WorkflowEngine.registerCheck(legacyCheckPlugin)) + +// new way of registering checks +window.OCA.WorkflowEngine.registerCheck({ + class: 'OCA\\WorkflowEngine\\Check\\FileMimeType', + name: t('workflowengine', 'File MIME type'), + operators: [ + { operator: 'is', name: t('workflowengine', 'is') }, + { operator: '!is', name: t('workflowengine', 'is not') }, + { operator: 'matches', name: t('workflowengine', 'matches') }, + { operator: '!matches', name: t('workflowengine', 'does not match') } + ], + component: FileMimeType +}) -window.OCA.WorkflowEngine = OCA.WorkflowEngine Vue.use(Vuex) - Vue.prototype.t = t + const View = Vue.extend(Settings) new View({ store