Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function __construct(
#[FrontpageRoute(verb: 'GET', url: '/')]
public function index(): TemplateResponse {
$this->initialState->provideInitialState('config', $this->accountService->getConfig($this->userSession->getUser()));
$this->initialState->provideInitialState('filters', $this->accountService->getConfigFilters($this->userSession->getUser()));
$this->initialState->provideInitialState('certificate_engine', $this->accountService->getCertificateEngineName());

try {
Expand Down
6 changes: 4 additions & 2 deletions lib/Db/SignRequestMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,15 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
);
}
if (!empty($filter['start'])) {
$start = (new \DateTime('@' . $filter['start'], new \DateTimeZone('UTC')))->format('Y-m-d H:i:s');
$qb->andWhere(
$qb->expr()->gte('f.created_at', $qb->createNamedParameter($filter['start'], IQueryBuilder::PARAM_INT))
$qb->expr()->gte('f.created_at', $qb->createNamedParameter($start, IQueryBuilder::PARAM_STR))
);
}
if (!empty($filter['end'])) {
$end = (new \DateTime('@' . $filter['end'], new \DateTimeZone('UTC')))->format('Y-m-d H:i:s');
$qb->andWhere(
$qb->expr()->lte('f.created_at', $qb->createNamedParameter($filter['end'], IQueryBuilder::PARAM_INT))
$qb->expr()->lte('f.created_at', $qb->createNamedParameter($end, IQueryBuilder::PARAM_STR))
);
}
}
Expand Down
14 changes: 10 additions & 4 deletions lib/Service/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,18 @@ public function getConfig(?IUser $user = null): array {
$info['hasSignatureFile'] = $this->hasSignatureFile($user);
$info['phoneNumber'] = $this->getPhoneNumber($user);
$info['isApprover'] = $this->validateHelper->userCanApproveValidationDocuments($user, false);
$info['grid_view'] = $this->getUserConfigGridView($user);
$info['grid_view'] = $this->getUserConfigByKey($user, 'grid_view') === '1';
;

return $info;
}

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

return $info;
}

private function getPhoneNumber(?IUser $user): string {
if (!$user) {
Expand All @@ -260,12 +266,12 @@ public function hasSignatureFile(?IUser $user = null): bool {
}
}

private function getUserConfigGridView(?IUser $user = null): bool {
private function getUserConfigByKey(?IUser $user = null, string $key): string {
if (!$user) {
return false;
return '';
}

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

/**
Expand Down
47 changes: 45 additions & 2 deletions src/store/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,67 @@
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.js'

export const useFiltersStore = defineStore('filter', {
state: () => ({
chips: {},
filter_modified: loadState('libresign', 'filters', { filter_modified: '' }).filter_modified,
filter_status: loadState('libresign', 'filters', { filter_status: '' }).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) {
console.error('Erro ao converter filter_status:', e)
return []
}
},
},

actions: {
onFilterUpdateChips(event) {
async onFilterUpdateChips(event) {
this.chips = { ...this.chips, [event.id]: [...event.detail] }

emit('libresign:filters:update')
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: '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: 'filter_status' }), {
value,
})

emit('libresign:filters:update')
}


logger.debug('File list filter chips updated', { chips: event.detail })
},
},
Expand Down
5 changes: 5 additions & 0 deletions src/views/FilesList/FileListFilter/FileListFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
@click="$emit('reset-filter')">
{{ t('files', 'Clear filter') }}
</NcActionButton>
<NcActionButton class="files-list-filter__clear-button"
close-after-click
@click="$emit('set-marked-filter')">
{{ t('files', 'Set marked filter') }}
</NcActionButton>
</template>
</NcActions>
</template>
Expand Down
35 changes: 33 additions & 2 deletions src/views/FilesList/FileListFilter/FileListFilterModified.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<template>
<FileListFilter :is-active="isActive"
:filter-name="t('libresign', 'Modified')"
@reset-filter="resetFilter">
@reset-filter="resetFilter"
@set-marked-filter="setMarkedFilter">
<template #icon>
<NcIconSvgWrapper :path="mdiCalendarRange" />
</template>
Expand Down Expand Up @@ -51,7 +52,7 @@ export default {
},
data() {
return {
selectedOption: null,
selectedOption: this.filtersStore.filter_modified || null,
timePresets: [
{
id: 'today',
Expand Down Expand Up @@ -94,6 +95,11 @@ export default {
return this.timePresets.find(({ id }) => id === this.selectedOption) ?? null
},
},
mounted() {
if (this.selectedOption) {
this.setPreset(this.currentPreset)
}
},
watch: {
selectedOption() {
if (this.selectedOption === null) {
Expand All @@ -114,6 +120,7 @@ export default {
end: preset.end,
icon: calendarSvg,
text: preset.label,
id: preset.id,
onclick: () => this.setPreset(),
})
} else {
Expand All @@ -126,8 +133,32 @@ export default {
this.selectedOption = null
this.timeRangeEnd = null
this.timeRangeStart = null
this.filtersStore.onFilterUpdateChipsAndSave({ detail: '', id: 'modified' })
}
},
setMarkedFilter(){

const chips = []

let preset = this.currentPreset

if (preset) {

chips.push({
start: preset.start,
end: preset.end,
icon: calendarSvg,
text: preset.label,
id: preset.id,
onclick: () => this.setPreset(),
})

} else {
this.resetFilter()
}

this.filtersStore.onFilterUpdateChipsAndSave({ detail: chips, id: 'modified' })
}
},
}
</script>
Expand Down
63 changes: 53 additions & 10 deletions src/views/FilesList/FileListFilter/FileListFilterStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
<FileListFilter class="file-list-filter-status"
:is-active="isActive"
:filter-name="t('libresign', 'Status')"
@reset-filter="resetFilter">
@reset-filter="resetFilter"
@set-marked-filter="setMarkedFilter">
<template #icon>
<NcIconSvgWrapper :path="mdiListStatus" />
</template>
<NcActionButton v-for="status of fileStatus"
:key="status.id"
type="checkbox"
:model-value="selectedOptions.includes(status)"
@click="toggleOption(status)">
:model-value="selectedOptions.includes(status.id)"
@click="toggleOption(status.id)">
<template #icon>
<NcIconSvgWrapper :svg="status.icon" />
</template>
Expand Down Expand Up @@ -50,7 +51,7 @@ export default {
},
data() {
return {
selectedOptions: [],
selectedOptions: this.filtersStore.filterStatusArray || [],
}
},
computed: {
Expand All @@ -61,6 +62,11 @@ export default {
return fileStatus.filter(item => [0, 1, 2, 3].includes(item.id))
},
},
mounted() {
if (this.selectedOptions.length > 0) {
this.setMarkedFilter()
}
},
watch: {
selectedOptions(newValue, oldValue) {
if (newValue.length === 0) {
Expand All @@ -74,12 +80,17 @@ export default {
setPreset(presets) {
const chips = []
if (presets && presets.length > 0) {
for (const preset of presets) {
for (const id of presets) {
const status = fileStatus.find(item => item.id === id)
if (!status) continue

chips.push({
id: preset.id,
icon: preset.icon,
text: preset.label,
onclick: () => this.setPreset(presets.filter(({ id }) => id !== preset.id)),
id: status.id,
icon: status.icon || '',
text: status.label,
onclick: () => {
this.selectedOptions = this.selectedOptions.filter(v => v !== status.id)
},
})
}
} else {
Expand All @@ -88,9 +99,13 @@ export default {
this.filtersStore.onFilterUpdateChips({ detail: chips, id: 'status' })
},
resetFilter() {
if (this.selectedOptions.length > 0) {

if( this.selectedOptions.length > 0) {
this.selectedOptions = []

this.filtersStore.onFilterUpdateChipsAndSave({ detail: [], id: 'status' })
}

},
toggleOption(option) {
const idx = this.selectedOptions.indexOf(option)
Expand All @@ -100,6 +115,34 @@ export default {
this.selectedOptions.push(option)
}
},
setMarkedFilter(){

const chips = []

let presets = this.selectedOptions

if (presets && presets.length > 0) {

for (const id of this.selectedOptions) {
const status = fileStatus.find(item => item.id === id)
if (!status) continue

chips.push({
id: status.id,
icon: status.icon || '',
text: status.label,
onclick: () => {
this.selectedOptions = this.selectedOptions.filter(v => v !== id)
},
})
}

} else {
this.resetFilter()
}

this.filtersStore.onFilterUpdateChipsAndSave({ detail: chips, id: 'status' })
}
},
}
</script>
Expand Down
Loading