diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-08-30 14:14:12 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-09-10 09:01:24 +0200 |
commit | f36b50c5029f4540b3310a4249667a48dfdb7606 (patch) | |
tree | 6c886f6c3563deccab03acd12c1778278d5a0cb6 /apps/workflowengine/src | |
parent | b3bafb1614df951127c2f3666ea254a31fceef5e (diff) | |
download | nextcloud-server-f36b50c5029f4540b3310a4249667a48dfdb7606.tar.gz nextcloud-server-f36b50c5029f4540b3310a4249667a48dfdb7606.zip |
Migrate plugins to vuex store
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/workflowengine/src')
-rw-r--r-- | apps/workflowengine/src/components/Check.vue | 33 | ||||
-rw-r--r-- | apps/workflowengine/src/components/Rule.vue | 8 | ||||
-rw-r--r-- | apps/workflowengine/src/components/Values/FileMimeType.vue | 10 | ||||
-rw-r--r-- | apps/workflowengine/src/legacy/filemimetypeplugin.js | 8 | ||||
-rw-r--r-- | apps/workflowengine/src/services/Operation.js | 11 | ||||
-rw-r--r-- | apps/workflowengine/src/store.js | 12 | ||||
-rw-r--r-- | 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 b2e8e13c29b..5f8140f2222 100644 --- a/apps/workflowengine/src/components/Check.vue +++ b/apps/workflowengine/src/components/Check.vue @@ -3,12 +3,12 @@ <Multiselect ref="checkSelector" v-model="currentOption" :options="options" label="name" track-by="class" :allow-empty="false" :placeholder="t('workflowengine', 'Select a filter')" @input="updateCheck" /> - <Multiselect v-if="currentOption" v-model="currentOperator" :options="operators" + <Multiselect :disabled="!currentOption" v-model="currentOperator" :options="operators" label="name" track-by="operator" :allow-empty="false" :placeholder="t('workflowengine', 'Select a comparator')" @input="updateCheck" /> - <component :is="currentOption.component()" v-if="currentOperator && currentComponent" v-model="check.value" /> - <input v-else-if="currentOperator" v-model="check.value" type="text" - @input="updateCheck"> + <component :is="currentOption.component" v-if="currentOperator && currentComponent" v-model="check.value" :disabled="!currentOption" /> + <input v-else v-model="check.value" type="text" + @input="updateCheck" :disabled="!currentOption"> <Actions> <ActionButton v-if="deleteVisible || !currentOption" icon="icon-delete" @click="$emit('remove')" /> </Actions> @@ -16,9 +16,9 @@ </template> <script> -import { Checks } from '../services/Operation' import { Multiselect, Actions, ActionButton } from 'nextcloud-vue' import ClickOutside from 'vue-click-outside' +import { mapState } from 'vuex' export default { name: 'Check', @@ -45,19 +45,22 @@ export default { } }, computed: { + ...mapState({ + Checks: (state) => state.plugins.checks + }), operators() { if (!this.currentOption) { return [] } - return Checks[this.currentOption.class].operators + return this.Checks[this.currentOption.class].operators }, currentComponent() { if (!this.currentOption) { return [] } - const currentComponent = Checks[this.currentOption.class].component - return currentComponent && currentComponent() + const currentComponent = this.Checks[this.currentOption.class].component + return currentComponent } }, mounted() { - this.options = Object.values(Checks) - this.currentOption = Checks[this.check.class] + this.options = Object.values(this.Checks) + this.currentOption = this.Checks[this.check.class] this.currentOperator = this.operators.find((operator) => operator.operator === this.check.operator) }, methods: { @@ -82,6 +85,12 @@ export default { <style scoped lang="scss"> .check { display: flex; + flex-wrap: wrap; + width: 100%; + padding-right: 20px; + & > *:not(.icon-delete) { + width: 200px; + } & > .multiselect, & > input[type=text] { margin-right: 5px; @@ -93,4 +102,8 @@ export default { ::placeholder { font-size: 10px; } + .icon-delete { + margin-top: -5px; + margin-bottom: -5px; + } </style> diff --git a/apps/workflowengine/src/components/Rule.vue b/apps/workflowengine/src/components/Rule.vue index 8a446dd7ae9..6a8757c5b3f 100644 --- a/apps/workflowengine/src/components/Rule.vue +++ b/apps/workflowengine/src/components/Rule.vue @@ -12,7 +12,7 @@ </p> <p> <span /> - <input v-if="lastCheckComplete" type="button" class="check--add" + <di<input v-if="lastCheckComplete" type="button" class="check--add" value="Add a new filter" @click="rule.checks.push({class: null, operator: null, value: null})"> </p> </div> @@ -174,9 +174,10 @@ export default { .trigger, .action { flex-grow: 1; min-height: 100px; - max-width: 700px; + max-width: 900px; } .action { + max-width: 400px; position: relative; .buttons { position: absolute; @@ -212,7 +213,8 @@ export default { background-position: 7px center; background-color: transparent; padding-left: 6px; - width: 160px; + margin: 0; + width: 200px; border-radius: var(--border-radius); font-weight: normal; text-align: left; diff --git a/apps/workflowengine/src/components/Values/FileMimeType.vue b/apps/workflowengine/src/components/Values/FileMimeType.vue index 9913dc1e858..75729af8073 100644 --- a/apps/workflowengine/src/components/Values/FileMimeType.vue +++ b/apps/workflowengine/src/components/Values/FileMimeType.vue @@ -1,5 +1,5 @@ <template> - <input type="text"> + <input type="text" v-model="test"> </template> <script> @@ -12,6 +12,7 @@ export default { }, data() { return { + test: 'test', predefinedTypes: [ { icon: 'icon-picture', @@ -30,6 +31,13 @@ export default { } ] } + }, + methods: { + validateRegex(string) { + var regexRegex = /^\/(.*)\/([gui]{0,3})$/ + var result = regexRegex.exec(string) + return result !== null + } } } </script> diff --git a/apps/workflowengine/src/legacy/filemimetypeplugin.js b/apps/workflowengine/src/legacy/filemimetypeplugin.js index 2b29c4fcbb8..e58bdec26d3 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 <http://www.gnu.org/licenses/>. * */ -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 99dca212f4c..ed996593cb4 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 ec9d736dd08..34cee256757 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 866f049b0bf..bdf30397883 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 = OCA.WorkflowEngine -Vue.use(Vuex) +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 +}) +Vue.use(Vuex) Vue.prototype.t = t + const View = Vue.extend(Settings) new View({ store |