-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathfilters.js
More file actions
85 lines (63 loc) · 2.2 KB
/
filters.js
File metadata and controls
85 lines (63 loc) · 2.2 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* SPDX-FileCopyrightText: 2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { defineStore } from 'pinia'
import { emit } from '@nextcloud/event-bus'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import logger from '../helpers/logger'
import { getTimePresetRange } from '../utils/timePresets.js'
export const useFiltersStore = defineStore('filter', {
state: () => ({
chips: {},
filter_modified: loadState('libresign', 'filters', {}).files_list_filter_modified ?? '',
filter_status: loadState('libresign', 'filters', {}).files_list_filter_status ?? ''
}),
getters: {
activeChips(state) {
return Object.values(state.chips).flat()
},
filterStatusArray(state) {
try {
return state.filter_status != '' ? JSON.parse(state.filter_status) : []
} catch (e) {
return []
}
},
/**
* Returns { start, end } in ms for the saved modified preset, or null.
* Computed fresh on each access so date boundaries are always current.
*/
filterModifiedRange(state) {
return getTimePresetRange(state.filter_modified)
},
},
actions: {
async onFilterUpdateChips(event) {
this.chips = { ...this.chips, [event.id]: [...event.detail] }
logger.debug('File list filter chips updated', { chips: event.detail })
},
async onFilterUpdateChipsAndSave(event) {
this.chips = { ...this.chips, [event.id]: [...event.detail] }
if(event.id == 'modified'){
let value = this.chips['modified'][0]?.id || '';
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key: 'files_list_filter_modified' }), {
value,
})
this.filter_modified = value
emit('libresign:filters:update')
}
if(event.id == 'status'){
const value = event.detail.length > 0 ? JSON.stringify(event.detail.map(item => item.id)) : '';
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key: 'files_list_filter_status' }), {
value,
})
this.filter_status = value
emit('libresign:filters:update')
}
logger.debug('File list filter chips updated', { chips: event.detail })
},
},
})