summaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/src
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-08-30 11:35:18 +0200
committerJulius Härtl <jus@bitgrid.net>2019-09-10 09:01:24 +0200
commitb3bafb1614df951127c2f3666ea254a31fceef5e (patch)
tree1cc1ca7da6fdc68d0df742d674ecbb654beeb330 /apps/workflowengine/src
parentaf3cb9c772b07860882d24471bed1832b1fcd328 (diff)
downloadnextcloud-server-b3bafb1614df951127c2f3666ea254a31fceef5e.tar.gz
nextcloud-server-b3bafb1614df951127c2f3666ea254a31fceef5e.zip
Add missing files
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/workflowengine/src')
-rw-r--r--apps/workflowengine/src/helpers/api.js30
-rw-r--r--apps/workflowengine/src/store.js137
2 files changed, 167 insertions, 0 deletions
diff --git a/apps/workflowengine/src/helpers/api.js b/apps/workflowengine/src/helpers/api.js
new file mode 100644
index 00000000000..c2c8d9b6b49
--- /dev/null
+++ b/apps/workflowengine/src/helpers/api.js
@@ -0,0 +1,30 @@
+/*
+ * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+const getApiUrl = (url) => {
+ const scopeValue = OCP.InitialState.loadState('workflowengine', 'scope') === 0 ? 'global' : 'user'
+ return OC.linkToOCS('apps/workflowengine/api/v1/workflows', 2) + scopeValue + url + '?format=json'
+}
+
+export {
+ getApiUrl
+}
diff --git a/apps/workflowengine/src/store.js b/apps/workflowengine/src/store.js
new file mode 100644
index 00000000000..ec9d736dd08
--- /dev/null
+++ b/apps/workflowengine/src/store.js
@@ -0,0 +1,137 @@
+/*
+ * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import Vue from 'vue'
+import Vuex from 'vuex'
+import axios from 'nextcloud-axios'
+import { getApiUrl } from './helpers/api'
+import { ALL_CHECKS, Operators } from './services/Operation'
+import confirmPassword from 'nextcloud-password-confirmation'
+
+Vue.use(Vuex)
+
+const store = new Vuex.Store({
+ state: {
+ rules: [],
+ scope: OCP.InitialState.loadState('workflowengine', 'scope'),
+ // TODO: move to backend data
+ operations: Operators,
+ entities: OCP.InitialState.loadState('workflowengine', 'entities').map(entity => {
+ return {
+ ...entity,
+ // TODO: move to backend data once checks are provided
+ checks: [...ALL_CHECKS]
+ }
+ }),
+ events: OCP.InitialState.loadState('workflowengine', 'entities')
+ .map((entity) => entity.events.map(event => {
+ return {
+ id: `${entity.id}::${event.eventName}`,
+ entity,
+ ...event
+ }
+ })).flat()
+ },
+ mutations: {
+ addRule(state, rule) {
+ state.rules.push(rule)
+ },
+ updateRule(state, rule) {
+ const index = state.rules.findIndex((item) => rule.id === item.id)
+ const newRule = Object.assign({}, rule)
+ Vue.set(state.rules, index, newRule)
+ },
+ removeRule(state, rule) {
+ const index = state.rules.findIndex((item) => rule.id === item.id)
+ state.rules.splice(index, 1)
+ }
+ },
+ actions: {
+ async fetchRules(context) {
+ const { data } = await axios.get(getApiUrl(''))
+ Object.values(data.ocs.data).flat().forEach((rule) => {
+ context.commit('addRule', rule)
+ })
+ },
+ createNewRule(context, rule) {
+ let entity = null
+ let events = []
+ if (rule.isComplex === false && rule.fixedEntity === '') {
+ entity = context.state.entities.find((item) => rule.entities[0] === item.id)
+ events = [entity.events[0].eventName]
+ }
+
+ context.commit('addRule', {
+ id: -(new Date().getTime()),
+ class: rule.id,
+ entity: entity ? entity.id : rule.fixedEntity,
+ events,
+ name: '', // unused in the new ui, there for legacy reasons
+ checks: [],
+ operation: rule.operation || ''
+ })
+ },
+ updateRule(context, rule) {
+ context.commit('updateRule', {
+ ...rule,
+ events: typeof rule.events === 'string' ? JSON.parse(rule.events) : rule.events
+ })
+ },
+ removeRule(context, rule) {
+ context.commit('removeRule', rule)
+ },
+ async pushUpdateRule(context, rule) {
+ await confirmPassword()
+ let result
+ if (rule.id < 0) {
+ result = await axios.post(getApiUrl(''), rule)
+ } else {
+ result = await axios.put(getApiUrl(`/${rule.id}`), rule)
+ }
+ Vue.set(rule, 'id', result.data.ocs.data.id)
+ context.commit('updateRule', rule)
+ },
+ async deleteRule(context, rule) {
+ await confirmPassword()
+ await axios.delete(getApiUrl(`/${rule.id}`))
+ context.commit('removeRule', rule)
+ }
+ },
+ getters: {
+ getRules(state) {
+ return state.rules.sort((rule1, rule2) => {
+ return rule1.id - rule2.id || rule2.class - rule1.class
+ })
+ },
+ getOperationForRule(state) {
+ return (rule) => state.operations[rule.class]
+ },
+ getEntityForOperation(state) {
+ return (operation) => state.entities.find((entity) => operation.fixedEntity === entity.id)
+ },
+ getEventsForOperation(state) {
+ return (operation) => state.events
+ }
+ }
+})
+
+export default store