Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add alarms (reminders) #2743

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
112 changes: 112 additions & 0 deletions src/components/AppSidebar/Alarm/AlarmDateTimePickerModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<template>
<NcModal @close="onClose()">
<form class="content" @submit.prevent="onSubmit">
<h3 class="content__heading">
<template v-if="isNewAlarm">
{{ t('tasks', 'Create reminder') }}
</template>
<template v-else>
{{ t('tasks', 'Update reminder') }}
</template>
</h3>
<div class="content__form">
<NcDateTimePickerNative id="alarm-date-time-picker"
v-model="date"
type="datetime-local"
required
:label="t('tasks', 'Set a reminder at a custom date and time:')" />
</div>
<div class="content__buttons">
<NcButton @click="onClose()">
{{ t('tasks', 'Cancel') }}
</NcButton>
<NcButton type="primary" native-type="submit">
<template v-if="isNewAlarm">
{{ t('tasks', 'Create reminder') }}
</template>
<template v-else>
{{ t('tasks', 'Update reminder') }}
</template>
</NcButton>
</div>
</form>
</NcModal>
</template>

<script>
import { convertTimeZone, getDefaultAbsoluteAlarms } from '../../../utils/alarms.js'
import { translate as t } from '@nextcloud/l10n'
import { NcButton, NcDateTimePickerNative, NcModal } from '@nextcloud/vue'

export default {
name: 'AlarmDateTimePickerModal',
components: {
NcButton,
NcDateTimePickerNative,
NcModal,
},
props: {
originalDate: {
type: Date,
default: undefined,
},
},
emits: [
'select-date-time',
'close',
],
data() {
return {
date: (this.originalDate && convertTimeZone(this.originalDate)) || this.defaultAbsoluteAlarm(),
isNewAlarm: !this.originalDate,
}
},
methods: {
t,

defaultAbsoluteAlarm() {
const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC'
const alarms = getDefaultAbsoluteAlarms(timeZone)

return alarms[0]
},

onSubmit() {
this.$emit('select-date-time', this.date)

Check warning on line 75 in src/components/AppSidebar/Alarm/AlarmDateTimePickerModal.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Custom event name 'select-date-time' must be camelCase
},

onClose() {
this.$emit('close')
},
},
}
</script>

<style lang="scss" scoped>
.content {
padding: 14px;

&__heading {
margin-top: 0;
}

&__buttons {
display: flex;
gap: 8px;
margin-top: 14px;
justify-content: flex-end;
}

&__form {
// TODO This should be part of the `NcDateTimePickerNative` component
:deep(input) {
&:invalid {
border-color: var(--color-error) !important; // Override hover border color
&:focus-visible {
box-shadow: rgb(248, 250, 252) 0px 0px 0px 2px, var(--color-primary-element) 0px 0px 0px 4px, rgba(0, 0, 0, 0.05) 0px 1px 2px 0px
}
}
}
}
}
</style>
192 changes: 192 additions & 0 deletions src/components/AppSidebar/Alarm/AlarmList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
<div class="component">
<div class="component__icon">
<slot name="icon" />
</div>
<div class="component__items">
<AlarmListItem v-for="(alarm, index) in alarmComponents"
:key="index"
:index="index"
:alarm="alarm"
:is-all-day="allDay"
:is-read-only="readOnly"
@update-alarm="updateAlarm"
@remove-alarm="removeAlarm" />
<div class="new">
<div v-if="alarms.length === 0">
<p>
{{ t('tasks', 'No reminders') }}
</p>
</div>
<AlarmListNew v-if="!readOnly"
:has-start-date="hasStartDate"
:has-due-date="hasDueDate"
:is-all-day="allDay"
@add-alarm="addAlarm" />
</div>
</div>
</div>
</template>

<script>
import AlarmListNew from './AlarmListNew.vue'
import AlarmListItem from './AlarmListItem.vue'
import { mapAlarmComponentToAlarmObject } from '../../../models/alarm.js'

import { translate as t } from '@nextcloud/l10n'
import { AlarmComponent } from '@nextcloud/calendar-js'
import ICAL from 'ical.js'

export default {
name: 'AlarmList',
components: {
AlarmListItem,
AlarmListNew,
},
props: {
hasStartDate: {
type: Boolean,
required: true,
},
hasDueDate: {
type: Boolean,
required: true,
},
readOnly: {
type: Boolean,
required: true,
},
allDay: {
type: Boolean,
required: true,
},
alarms: {
type: Array,
required: true,
},
},
emits: [
'add-alarm',
'remove-alarm',
'update-alarm',
],
computed: {
alarmComponents() {
return this.alarms.map((alarm) => {
try {
return mapAlarmComponentToAlarmObject(AlarmComponent.fromICALJs(alarm))
} catch (e) {
// Instead of breaking the whole page when parsing an invalid alarm,
// we just print a warning on the console.
console.warn(e)
return false
}
}).filter(Boolean)
},
},
methods: {
t,

/**
* Generates a valarm from an alarm-event
*
* @param {object} alarm The alarm time or duration
* @param {number|Date} alarm.value Value of the trigger
* @param {object|undefined} alarm.parameter Name and value of the trigger parameter
*/
generateVAlarm({ value, parameter }) {
const valarm = {
action: 'DISPLAY',
// When the action is "DISPLAY", the alarm MUST also include a "DESCRIPTION" property
description: t('tasks', 'This is an event reminder.'),
repeat: 1,
trigger: { value: undefined, parameter },
}

if (typeof value === 'number') {
valarm.trigger.value = ICAL.Duration.fromSeconds(value)
} else if (value instanceof Date) {
valarm.trigger.value = ICAL.Time.fromJSDate(value, true)
}

return valarm
},

/**
* Adds an alarm to this event
*
* @param {object} alarm The alarm time or duration
*/
addAlarm(alarm) {
this.$emit('add-alarm', this.generateVAlarm(alarm))

Check warning on line 126 in src/components/AppSidebar/Alarm/AlarmList.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Custom event name 'add-alarm' must be camelCase
},

/**
* Removes an alarm from this event
*
* @param {object} alarm The alarm object
* @param {number} index This index of the updated alarm-item
*/
updateAlarm(alarm, index) {
this.$emit('update-alarm', this.generateVAlarm(alarm), index)

Check warning on line 136 in src/components/AppSidebar/Alarm/AlarmList.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Custom event name 'update-alarm' must be camelCase
},

/**
* Removes an alarm from this event
*
* @param {number} index The index of the alarm-list
*/
removeAlarm(index) {
this.$emit('remove-alarm', index)

Check warning on line 145 in src/components/AppSidebar/Alarm/AlarmList.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Custom event name 'remove-alarm' must be camelCase
},
},
}
</script>

<style lang="scss" scoped>
.component {
display: flex;
border-bottom: 1px solid var(--color-border);
width: 100%;
color: var(--color-text-lighter);

.component {
&__icon {
display: flex;
height: 44px;
width: 44px;
min-width: 44px;
justify-content: center;

.material-design-icon__svg {
vertical-align: middle;
}
}

&__items {
display: flex;
flex-direction: column;
flex-grow: 1;
gap: 4px;
padding-inline-end: 4px;
padding-block: 4px;
overflow: auto;
text-overflow: ellipsis;
white-space: nowrap;

.new {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding-block: 2px;
}
}
}
}
</style>
Loading
Loading