2022-06-15 12:00:32 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2023-08-13 16:28:12 +00:00
|
|
|
import { Calendar, RecurringRule, generateEventId } from '@hcengineering/calendar'
|
|
|
|
import { Person, PersonAccount } from '@hcengineering/contact'
|
|
|
|
import { Class, Doc, Ref, getCurrentAccount } from '@hcengineering/core'
|
|
|
|
import presentation, { getClient } from '@hcengineering/presentation'
|
2023-08-25 09:49:14 +00:00
|
|
|
import { Button, EditBox, Icon, IconClose, showPopup, IconMoreH } from '@hcengineering/ui'
|
2023-08-13 16:28:12 +00:00
|
|
|
import { createEventDispatcher } from 'svelte'
|
2022-06-15 12:00:32 +00:00
|
|
|
import calendar from '../plugin'
|
2023-07-28 03:46:26 +00:00
|
|
|
import { saveUTC } from '../utils'
|
2023-08-13 16:28:12 +00:00
|
|
|
import EventParticipants from './EventParticipants.svelte'
|
|
|
|
import EventTimeEditor from './EventTimeEditor.svelte'
|
|
|
|
import ReccurancePopup from './ReccurancePopup.svelte'
|
2023-08-23 03:11:16 +00:00
|
|
|
import EventReminders from './EventReminders.svelte'
|
2023-08-25 09:49:14 +00:00
|
|
|
import EventTimeExtraButton from './EventTimeExtraButton.svelte'
|
2022-06-15 12:00:32 +00:00
|
|
|
|
|
|
|
export let attachedTo: Ref<Doc> = calendar.ids.NoAttached
|
|
|
|
export let attachedToClass: Ref<Class<Doc>> = calendar.class.Event
|
|
|
|
export let title: string = ''
|
|
|
|
export let date: Date | undefined = undefined
|
|
|
|
export let withTime = false
|
|
|
|
|
|
|
|
const now = new Date()
|
2023-07-25 10:50:55 +00:00
|
|
|
const defaultDuration = 60 * 60 * 1000
|
|
|
|
const allDayDuration = 24 * 60 * 60 * 1000 - 1
|
2023-08-25 09:49:14 +00:00
|
|
|
// const offsetTZ = new Date().getTimezoneOffset() * 60 * 1000
|
2022-06-15 12:00:32 +00:00
|
|
|
|
2022-10-24 06:44:08 +00:00
|
|
|
let startDate =
|
2022-06-15 12:00:32 +00:00
|
|
|
date === undefined ? now.getTime() : withTime ? date.getTime() : date.setHours(now.getHours(), now.getMinutes())
|
2023-08-13 16:28:12 +00:00
|
|
|
const duration = defaultDuration
|
2022-10-24 06:44:08 +00:00
|
|
|
let dueDate = startDate + duration
|
2023-07-10 15:50:29 +00:00
|
|
|
let allDay = false
|
2022-10-24 06:44:08 +00:00
|
|
|
|
2023-08-23 03:11:16 +00:00
|
|
|
let reminders = [30 * 60 * 1000]
|
|
|
|
|
2023-08-13 16:28:12 +00:00
|
|
|
let description: string = ''
|
|
|
|
|
|
|
|
let rules: RecurringRule[] = []
|
|
|
|
|
2023-08-04 18:06:21 +00:00
|
|
|
const currentUser = getCurrentAccount() as PersonAccount
|
2023-08-13 16:28:12 +00:00
|
|
|
let participants: Ref<Person>[] = [currentUser.person]
|
|
|
|
let externalParticipants: string[] = []
|
2022-06-15 12:00:32 +00:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
export function canClose (): boolean {
|
|
|
|
return title !== undefined && title.trim().length === 0 && participants.length === 0
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveEvent () {
|
|
|
|
let date: number | undefined
|
2022-10-24 06:44:08 +00:00
|
|
|
if (startDate != null) date = startDate
|
2022-06-15 12:00:32 +00:00
|
|
|
if (date === undefined) return
|
2023-08-13 16:28:12 +00:00
|
|
|
if (title === '') return
|
2023-07-10 15:50:29 +00:00
|
|
|
const space = `${getCurrentAccount()._id}_calendar` as Ref<Calendar>
|
2023-08-13 16:28:12 +00:00
|
|
|
if (rules.length > 0) {
|
|
|
|
await client.addCollection(calendar.class.ReccuringEvent, space, attachedTo, attachedToClass, 'events', {
|
|
|
|
eventId: generateEventId(),
|
|
|
|
date: allDay ? saveUTC(date) : date,
|
|
|
|
dueDate: allDay ? saveUTC(dueDate) : dueDate,
|
|
|
|
externalParticipants,
|
|
|
|
rdate: [],
|
|
|
|
exdate: [],
|
|
|
|
rules,
|
2023-08-23 03:11:16 +00:00
|
|
|
reminders,
|
2023-08-13 16:28:12 +00:00
|
|
|
description,
|
|
|
|
participants,
|
|
|
|
title,
|
|
|
|
allDay,
|
|
|
|
access: 'owner'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
await client.addCollection(calendar.class.Event, space, attachedTo, attachedToClass, 'events', {
|
|
|
|
eventId: generateEventId(),
|
|
|
|
date: allDay ? saveUTC(date) : date,
|
|
|
|
dueDate: allDay ? saveUTC(dueDate) : dueDate,
|
|
|
|
externalParticipants,
|
|
|
|
description,
|
|
|
|
participants,
|
2023-08-23 03:11:16 +00:00
|
|
|
reminders,
|
2023-08-13 16:28:12 +00:00
|
|
|
title,
|
|
|
|
allDay,
|
|
|
|
access: 'owner'
|
|
|
|
})
|
2022-10-24 06:44:08 +00:00
|
|
|
}
|
2023-08-13 16:28:12 +00:00
|
|
|
dispatch('close')
|
2022-10-24 06:44:08 +00:00
|
|
|
}
|
2023-07-10 15:50:29 +00:00
|
|
|
|
2023-07-11 07:33:46 +00:00
|
|
|
async function allDayChangeHandler () {
|
|
|
|
if (allDay) {
|
2023-07-25 10:50:55 +00:00
|
|
|
startDate = new Date(startDate).setHours(0, 0, 0, 0)
|
|
|
|
if (dueDate - startDate < allDayDuration) dueDate = allDayDuration + startDate
|
|
|
|
else dueDate = new Date(dueDate).setHours(23, 59, 59, 999)
|
2023-07-11 07:33:46 +00:00
|
|
|
} else {
|
|
|
|
dueDate = startDate + defaultDuration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-13 16:28:12 +00:00
|
|
|
function setRecurrance () {
|
2023-08-23 03:11:16 +00:00
|
|
|
showPopup(ReccurancePopup, { rules, startDate }, undefined, (res) => {
|
2023-08-13 16:28:12 +00:00
|
|
|
if (res) {
|
|
|
|
rules = res
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-06-15 12:00:32 +00:00
|
|
|
</script>
|
|
|
|
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="eventPopup-container">
|
2023-08-13 16:28:12 +00:00
|
|
|
<div class="header flex-between">
|
2023-08-25 09:49:14 +00:00
|
|
|
<EditBox
|
|
|
|
bind:value={title}
|
|
|
|
placeholder={calendar.string.NewEvent}
|
|
|
|
kind={'ghost-large'}
|
|
|
|
fullSize
|
|
|
|
focusable
|
|
|
|
focusIndex={10001}
|
2022-10-24 06:44:08 +00:00
|
|
|
/>
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="flex-row-center gap-1 flex-no-shrink ml-3">
|
|
|
|
<Button id="card-more" focusIndex={10002} icon={IconMoreH} kind={'ghost'} size={'small'} on:click={() => {}} />
|
|
|
|
<Button
|
|
|
|
id="card-close"
|
|
|
|
focusIndex={10003}
|
|
|
|
icon={IconClose}
|
|
|
|
kind={'ghost'}
|
|
|
|
size={'small'}
|
|
|
|
on:click={() => {
|
|
|
|
dispatch('close')
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-08-13 16:28:12 +00:00
|
|
|
</div>
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="block first flex-no-shrink">
|
2023-08-13 16:28:12 +00:00
|
|
|
<EventTimeEditor {allDay} bind:startDate bind:dueDate />
|
2023-08-25 09:49:14 +00:00
|
|
|
<EventTimeExtraButton bind:allDay bind:rules on:repeat={setRecurrance} on:allday={allDayChangeHandler} />
|
2023-08-13 16:28:12 +00:00
|
|
|
</div>
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="block rightCropPadding">
|
2023-08-13 16:28:12 +00:00
|
|
|
<EventParticipants bind:participants bind:externalParticipants />
|
|
|
|
</div>
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="block flex-no-shrink">
|
|
|
|
<div class="flex-row-center gap-1-5">
|
|
|
|
<Icon icon={calendar.icon.Description} size={'small'} />
|
|
|
|
<EditBox bind:value={description} placeholder={calendar.string.Description} kind={'ghost'} fullSize focusable />
|
2023-08-13 16:28:12 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="block rightCropPadding">
|
2023-08-23 03:11:16 +00:00
|
|
|
<EventReminders bind:reminders />
|
|
|
|
</div>
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="flex-between p-5 flex-no-shrink">
|
2023-08-13 16:28:12 +00:00
|
|
|
<div />
|
|
|
|
<Button kind="accented" label={presentation.string.Create} on:click={saveEvent} disabled={title === ''} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2023-08-25 09:49:14 +00:00
|
|
|
.eventPopup-container {
|
2023-08-13 16:28:12 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2023-08-25 09:49:14 +00:00
|
|
|
max-width: 25rem;
|
|
|
|
min-width: 25rem;
|
2023-08-13 16:28:12 +00:00
|
|
|
min-height: 0;
|
|
|
|
background: var(--theme-popup-color);
|
|
|
|
border-radius: 1rem;
|
2023-08-25 09:49:14 +00:00
|
|
|
box-shadow: var(--theme-popup-shadow);
|
2023-08-13 16:28:12 +00:00
|
|
|
|
|
|
|
.header {
|
2023-08-25 09:49:14 +00:00
|
|
|
flex-shrink: 0;
|
|
|
|
padding: 0.75rem 0.75rem 0.5rem;
|
2023-08-13 16:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.block {
|
2023-08-25 09:49:14 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
min-width: 0;
|
|
|
|
min-height: 0;
|
|
|
|
border-bottom: 1px solid var(--theme-divider-color);
|
|
|
|
|
|
|
|
&.first {
|
|
|
|
padding-top: 0;
|
|
|
|
}
|
|
|
|
&:not(.rightCropPadding) {
|
|
|
|
padding: 0.75rem 1.25rem;
|
|
|
|
}
|
|
|
|
&.rightCropPadding {
|
|
|
|
padding: 0.75rem 1rem 0.75rem 1.25rem;
|
2023-08-13 16:28:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|