Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_retention.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/store/retentionStore.js')
-rw-r--r--src/store/retentionStore.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/store/retentionStore.js b/src/store/retentionStore.js
new file mode 100644
index 0000000..a0e066f
--- /dev/null
+++ b/src/store/retentionStore.js
@@ -0,0 +1,69 @@
+/**
+ * SPDX-FileCopyrightText: Joas Schilling <coding@schilljs.com>
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+import Vue from 'vue'
+import {
+ createRetentionRule,
+ deleteRetentionRule,
+ getRetentionRules,
+} from '../services/retentionService.js'
+
+const state = {
+ retentionRules: {
+ },
+}
+
+const getters = {
+ getRetentionRules: state => () => Object.values(state.retentionRules),
+ getTagIdsWithRule: state => () => Object.values(state.retentionRules).map((rule) => rule.tagid),
+}
+
+const mutations = {
+ /**
+ * Adds a rule to the store
+ *
+ * @param {object} state current store state
+ * @param {object} rule the rule
+ */
+ addRule(state, rule) {
+ // eslint-disable-next-line import/no-named-as-default-member
+ Vue.set(state.retentionRules, rule.id, rule)
+ },
+
+ /**
+ * Deletes a rule from the store
+ *
+ * @param {object} state current store state
+ * @param {number} id the rule id of the rule to delete
+ */
+ deleteRule(state, id) {
+ Vue.delete(state.retentionRules, id)
+ },
+}
+
+const actions = {
+ /**
+ * Load the retention rules from the backend
+ *
+ * @param {object} context default store context
+ */
+ async loadRetentionRules(context) {
+ const response = await getRetentionRules()
+ response.data.forEach((rule) => {
+ context.commit('addRule', rule)
+ })
+ },
+
+ async deleteRetentionRule(context, ruleId) {
+ await deleteRetentionRule(ruleId)
+ context.commit('deleteRule', ruleId)
+ },
+
+ async createNewRule(context, rule) {
+ const response = await createRetentionRule(rule)
+ context.commit('addRule', response.data)
+ },
+}
+
+export default { state, mutations, getters, actions }