Skip to content

Commit 8736d4c

Browse files
authored
Merge pull request #6032 from LibreSign/backport/5472/stable31
[stable31] chore: adjustment in the filters modified and status
2 parents fa52e3e + 448c235 commit 8736d4c

7 files changed

Lines changed: 133 additions & 20 deletions

File tree

lib/Controller/PageController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function __construct(
8383
#[FrontpageRoute(verb: 'GET', url: '/')]
8484
public function index(): TemplateResponse {
8585
$this->initialState->provideInitialState('config', $this->accountService->getConfig($this->userSession->getUser()));
86+
$this->initialState->provideInitialState('filters', $this->accountService->getConfigFilters($this->userSession->getUser()));
8687
$this->initialState->provideInitialState('certificate_engine', $this->accountService->getCertificateEngineName());
8788

8889
try {

lib/Db/SignRequestMapper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,15 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
553553
);
554554
}
555555
if (!empty($filter['start'])) {
556+
$start = (new \DateTime('@' . $filter['start'], new \DateTimeZone('UTC')))->format('Y-m-d H:i:s');
556557
$qb->andWhere(
557-
$qb->expr()->gte('f.created_at', $qb->createNamedParameter($filter['start'], IQueryBuilder::PARAM_INT))
558+
$qb->expr()->gte('f.created_at', $qb->createNamedParameter($start, IQueryBuilder::PARAM_STR))
558559
);
559560
}
560561
if (!empty($filter['end'])) {
562+
$end = (new \DateTime('@' . $filter['end'], new \DateTimeZone('UTC')))->format('Y-m-d H:i:s');
561563
$qb->andWhere(
562-
$qb->expr()->lte('f.created_at', $qb->createNamedParameter($filter['end'], IQueryBuilder::PARAM_INT))
564+
$qb->expr()->lte('f.created_at', $qb->createNamedParameter($end, IQueryBuilder::PARAM_STR))
563565
);
564566
}
565567
}

lib/Service/AccountService.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,21 @@ public function getConfig(?IUser $user = null): array {
194194
$info['hasSignatureFile'] = $this->hasSignatureFile($user);
195195
$info['phoneNumber'] = $this->getPhoneNumber($user);
196196
$info['isApprover'] = $this->validateHelper->userCanApproveValidationDocuments($user, false);
197-
$info['grid_view'] = $this->getUserConfigGridView($user);
198197
$info['id_docs_filters'] = $this->getUserConfigIdDocsFilters($user);
199198
$info['id_docs_sort'] = $this->getUserConfigIdDocsSort($user);
200199
$info['crl_filters'] = $this->getUserConfigCrlFilters($user);
201200
$info['crl_sort'] = $this->getUserConfigCrlSort($user);
201+
$info['grid_view'] = $this->getUserConfigByKey($user, 'grid_view') === '1';
202202

203203
return array_filter($info);
204204
}
205205

206+
public function getConfigFilters(?IUser $user = null): array {
207+
$info['filter_modified'] = $this->getUserConfigByKey($user, 'filter_modified');
208+
$info['filter_status'] = $this->getUserConfigByKey($user, 'filter_status');
206209

210+
return $info;
211+
}
207212

208213
private function updateIdentifyMethodToAccount(int $signRequestId, string $email, string $uid): void {
209214
$identifyMethods = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signRequestId);
@@ -241,12 +246,12 @@ public function hasSignatureFile(?IUser $user = null): bool {
241246
}
242247
}
243248

244-
private function getUserConfigGridView(?IUser $user = null): bool {
249+
private function getUserConfigByKey(?IUser $user = null, string $key): string {
245250
if (!$user) {
246-
return false;
251+
return '';
247252
}
248253

249-
return $this->config->getUserValue($user->getUID(), Application::APP_ID, 'grid_view', false) === '1';
254+
return $this->config->getUserValue($user->getUID(), Application::APP_ID, $key);
250255
}
251256

252257
private function getUserConfigIdDocsFilters(?IUser $user = null): array {

src/store/filters.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,71 @@
66
import { defineStore } from 'pinia'
77

88
import { emit } from '@nextcloud/event-bus'
9-
9+
import { loadState } from '@nextcloud/initial-state'
10+
import axios from '@nextcloud/axios'
11+
import { generateOcsUrl } from '@nextcloud/router'
1012
import logger from '../helpers/logger.js'
1113

1214
export const useFiltersStore = defineStore('filter', {
1315
state: () => ({
1416
chips: {},
17+
filter_modified: loadState('libresign', 'filters', { filter_modified: '' }).filter_modified,
18+
filter_status: loadState('libresign', 'filters', { filter_status: '' }).filter_status,
1519
}),
1620

1721
getters: {
1822
activeChips(state) {
1923
return Object.values(state.chips).flat()
2024
},
25+
filterStatusArray(state) {
26+
try {
27+
return state.filter_status != '' ? JSON.parse(state.filter_status) : []
28+
} catch (e) {
29+
console.error('Erro ao converter filter_status:', e)
30+
return []
31+
}
32+
},
2133
},
2234

2335
actions: {
24-
onFilterUpdateChips(event) {
36+
async onFilterUpdateChips(event) {
2537
this.chips = { ...this.chips, [event.id]: [...event.detail] }
38+
2639
emit('libresign:filters:update')
40+
logger.debug('File list filter chips updated', { chips: event.detail })
41+
42+
},
43+
44+
async onFilterUpdateChipsAndSave(event) {
45+
this.chips = { ...this.chips, [event.id]: [...event.detail] }
46+
47+
48+
if(event.id == 'modified'){
49+
let value = this.chips['modified'][0]?.id || '';
50+
51+
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key: 'filter_modified' }), {
52+
value,
53+
})
54+
55+
emit('libresign:filters:update')
56+
}
57+
58+
if(event.id == 'status'){
59+
60+
const value = event.detail.length > 0 ? JSON.stringify(event.detail.map(item => item.id)) : '';
61+
62+
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key: 'filter_status' }), {
63+
value,
64+
})
65+
66+
this.filter_status = value
67+
68+
emit('libresign:filters:update')
69+
}
70+
71+
2772
logger.debug('File list filter chips updated', { chips: event.detail })
2873
},
74+
2975
},
3076
})

src/views/FilesList/FileListFilter/FileListFilter.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ export default {
4848
</script>
4949

5050
<style scoped lang="scss">
51-
.files-list-filter__clear-button :deep(.action-button__text) {
52-
color: var(--color-error-text);
51+
.files-list-filter__clear-button {
52+
:deep(.action-button__text) {
53+
color: var(--color-error-text);
54+
}
5355
}
5456
5557
:deep(.button-vue) {

src/views/FilesList/FileListFilter/FileListFilterModified.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default {
5151
},
5252
data() {
5353
return {
54-
selectedOption: null,
54+
selectedOption: this.filtersStore.filter_modified || null,
5555
timePresets: [
5656
{
5757
id: 'today',
@@ -94,15 +94,20 @@ export default {
9494
return this.timePresets.find(({ id }) => id === this.selectedOption) ?? null
9595
},
9696
},
97+
mounted() {
98+
if (this.selectedOption) {
99+
this.setPreset(this.currentPreset)
100+
}
101+
},
97102
watch: {
98103
selectedOption() {
99104
if (this.selectedOption === null) {
100105
this.selectedOption = null
101106
this.setPreset()
102107
} else {
103108
this.setPreset(this.currentPreset)
104-
105109
}
110+
this.setMarkedFilter()
106111
},
107112
},
108113
methods: {
@@ -114,6 +119,7 @@ export default {
114119
end: preset.end,
115120
icon: calendarSvg,
116121
text: preset.label,
122+
id: preset.id,
117123
onclick: () => this.setPreset(),
118124
})
119125
} else {
@@ -126,7 +132,25 @@ export default {
126132
this.selectedOption = null
127133
this.timeRangeEnd = null
128134
this.timeRangeStart = null
135+
this.filtersStore.onFilterUpdateChipsAndSave({ detail: '', id: 'modified' })
136+
}
137+
},
138+
setMarkedFilter() {
139+
const chips = []
140+
const preset = this.currentPreset
141+
142+
if (preset) {
143+
chips.push({
144+
start: preset.start,
145+
end: preset.end,
146+
icon: calendarSvg,
147+
text: preset.label,
148+
id: preset.id,
149+
onclick: () => this.setPreset(),
150+
})
129151
}
152+
153+
this.filtersStore.onFilterUpdateChipsAndSave({ detail: chips, id: 'modified' })
130154
},
131155
},
132156
}

src/views/FilesList/FileListFilter/FileListFilterStatus.vue

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<NcActionButton v-for="status of fileStatus"
1414
:key="status.id"
1515
type="checkbox"
16-
:model-value="selectedOptions.includes(status)"
17-
@click="toggleOption(status)">
16+
:model-value="selectedOptions.includes(status.id)"
17+
@click="toggleOption(status.id)">
1818
<template #icon>
1919
<NcIconSvgWrapper :svg="status.icon" />
2020
</template>
@@ -50,7 +50,7 @@ export default {
5050
},
5151
data() {
5252
return {
53-
selectedOptions: [],
53+
selectedOptions: this.filtersStore.filterStatusArray || [],
5454
}
5555
},
5656
computed: {
@@ -61,25 +61,36 @@ export default {
6161
return fileStatus.filter(item => [0, 1, 2, 3].includes(item.id))
6262
},
6363
},
64+
mounted() {
65+
if (this.selectedOptions.length > 0) {
66+
this.setMarkedFilter()
67+
}
68+
},
6469
watch: {
6570
selectedOptions(newValue, oldValue) {
6671
if (newValue.length === 0) {
6772
this.setPreset()
6873
} else {
6974
this.setPreset(newValue)
7075
}
76+
this.setMarkedFilter()
7177
},
7278
},
7379
methods: {
7480
setPreset(presets) {
7581
const chips = []
7682
if (presets && presets.length > 0) {
77-
for (const preset of presets) {
83+
for (const id of presets) {
84+
const status = fileStatus.find(item => item.id === id)
85+
if (!status) continue
86+
7887
chips.push({
79-
id: preset.id,
80-
icon: preset.icon,
81-
text: preset.label,
82-
onclick: () => this.setPreset(presets.filter(({ id }) => id !== preset.id)),
88+
id: status.id,
89+
icon: status.icon || '',
90+
text: status.label,
91+
onclick: () => {
92+
this.selectedOptions = this.selectedOptions.filter(v => v !== status.id)
93+
},
8394
})
8495
}
8596
} else {
@@ -90,6 +101,7 @@ export default {
90101
resetFilter() {
91102
if (this.selectedOptions.length > 0) {
92103
this.selectedOptions = []
104+
this.filtersStore.onFilterUpdateChipsAndSave({ detail: [], id: 'status' })
93105
}
94106
},
95107
toggleOption(option) {
@@ -100,6 +112,27 @@ export default {
100112
this.selectedOptions.push(option)
101113
}
102114
},
115+
setMarkedFilter() {
116+
const chips = []
117+
118+
if (this.selectedOptions.length > 0) {
119+
for (const id of this.selectedOptions) {
120+
const status = fileStatus.find(item => item.id === id)
121+
if (!status) continue
122+
123+
chips.push({
124+
id: status.id,
125+
icon: status.icon || '',
126+
text: status.label,
127+
onclick: () => {
128+
this.selectedOptions = this.selectedOptions.filter(v => v !== id)
129+
},
130+
})
131+
}
132+
}
133+
134+
this.filtersStore.onFilterUpdateChipsAndSave({ detail: chips, id: 'status' })
135+
}
103136
},
104137
}
105138
</script>

0 commit comments

Comments
 (0)