Skip to content

Commit 4af6a40

Browse files
committed
enh(files_remidners): Allow clearing reminders
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent ceea1ac commit 4af6a40

File tree

4 files changed

+90
-5
lines changed

4 files changed

+90
-5
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @copyright 2024 Christopher Ng <chrng8@gmail.com>
3+
*
4+
* @author Christopher Ng <chrng8@gmail.com>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import Vue from 'vue'
24+
import { FileAction, type Node } from '@nextcloud/files'
25+
import { emit } from '@nextcloud/event-bus'
26+
import { translate as t } from '@nextcloud/l10n'
27+
28+
import AlarmOffSvg from '@mdi/svg/svg/alarm-off.svg?raw'
29+
30+
import { clearReminder } from '../services/reminderService.ts'
31+
import { getVerboseDateString } from '../shared/utils.ts'
32+
33+
export const action = new FileAction({
34+
id: 'clear-reminder',
35+
36+
displayName: () => t('files', 'Clear reminder'),
37+
38+
title: (nodes: Node[]) => {
39+
const node = nodes.at(0)!
40+
const dueDate = new Date(node.attributes['reminder-due-date'])
41+
return `${t('files', 'Clear reminder')}${getVerboseDateString(dueDate)}`
42+
},
43+
44+
iconSvgInline: () => AlarmOffSvg,
45+
46+
enabled: (nodes: Node[]) => {
47+
// Only allow on a single node
48+
if (nodes.length !== 1) {
49+
return false
50+
}
51+
const node = nodes.at(0)!
52+
const dueDate = node.attributes['reminder-due-date']
53+
return Boolean(dueDate)
54+
},
55+
56+
async exec(node: Node) {
57+
if (node.fileid) {
58+
try {
59+
await clearReminder(node.fileid)
60+
Vue.set(node.attributes, 'reminder-due-date', '')
61+
emit('files:node:updated', node)
62+
return true
63+
} catch (error) {
64+
return false
65+
}
66+
}
67+
return null
68+
},
69+
70+
order: 19,
71+
})

apps/files_reminders/src/actions/setReminderSuggestionActions.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22+
23+
import Vue from 'vue'
2224
import type { Node } from '@nextcloud/files'
2325

2426
import { FileAction } from '@nextcloud/files'
27+
import { emit } from '@nextcloud/event-bus'
2528
import { showError, showSuccess } from '@nextcloud/dialogs'
2629
import { translate as t } from '@nextcloud/l10n'
2730

@@ -101,7 +104,10 @@ const generateFileAction = (option: ReminderOption): FileAction|null => {
101104

102105
// Set the reminder
103106
try {
104-
await setReminder(node.fileid, getDateTime(option.dateTimePreset)!)
107+
const dateTime = getDateTime(option.dateTimePreset)!
108+
await setReminder(node.fileid, dateTime)
109+
Vue.set(node.attributes, 'reminder-due-date', dateTime.toISOString())
110+
emit('files:node:updated', node)
105111
showSuccess(t('files_reminders', 'Reminder set for "{fileName}"', { fileName: node.basename }))
106112
} catch (error) {
107113
logger.error('Failed to set reminder', { error })
@@ -123,14 +129,14 @@ const generateFileAction = (option: ReminderOption): FileAction|null => {
123129
}
124130
option.dateString = getDateString(dateTime)
125131
option.verboseDateString = getVerboseDateString(dateTime)
126-
+
132+
127133
// Update the date string every 30 minutes
128134
setInterval(() => {
129135
const dateTime = getDateTime(option.dateTimePreset)
130136
if (!dateTime) {
131137
return
132138
}
133-
139+
134140
// update the submenu remind options strings
135141
option.dateString = getDateString(dateTime)
136142
option.verboseDateString = getVerboseDateString(dateTime)

apps/files_reminders/src/components/SetCustomReminderModal.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@
6464
</template>
6565

6666
<script lang="ts">
67+
import Vue from 'vue'
6768
import type { Node } from '@nextcloud/files'
69+
import { emit } from '@nextcloud/event-bus'
6870
import { showError, showSuccess } from '@nextcloud/dialogs'
6971
import { translate as t } from '@nextcloud/l10n'
70-
import Vue from 'vue'
7172
7273
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
7374
import NcDateTime from '@nextcloud/vue/dist/Components/NcDateTime.js'
@@ -156,6 +157,8 @@ export default Vue.extend({
156157
157158
try {
158159
await setReminder(this.fileId, this.customDueDate)
160+
Vue.set(this.node.attributes, 'reminder-due-date', this.customDueDate.toISOString())
161+
emit('files:node:updated', this.node)
159162
showSuccess(t('files_reminders', 'Reminder set for "{fileName}"', { fileName: this.fileName }))
160163
this.onClose()
161164
} catch (error) {

apps/files_reminders/src/init.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
import { registerFileAction } from '@nextcloud/files'
22+
23+
import { registerDavProperty, registerFileAction } from '@nextcloud/files'
2324
import { action as menuAction } from './actions/setReminderMenuAction'
25+
import { action as clearAction } from './actions/clearReminderAction'
2426
import { actions as suggestionActions } from './actions/setReminderSuggestionActions'
2527
import { action as customAction } from './actions/setReminderCustomAction'
2628

29+
registerDavProperty('nc:reminder-due-date', { nc: 'http://nextcloud.org/ns' })
30+
31+
registerFileAction(clearAction)
2732
registerFileAction(menuAction)
2833
registerFileAction(customAction)
2934
suggestionActions.forEach((action) => registerFileAction(action))

0 commit comments

Comments
 (0)