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

retentionStore.js « store « src - github.com/nextcloud/files_retention.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1cbb448c2a4ea8906dfe4557ae60c4b2d9fb9054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 * 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) {
		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 }