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-10-03 03:49:44 +00:00
|
|
|
import { Calendar, RecurringRule, Visibility, generateEventId } from '@hcengineering/calendar'
|
2023-08-13 16:28:12 +00:00
|
|
|
import { Person, PersonAccount } from '@hcengineering/contact'
|
|
|
|
import { Class, Doc, Ref, getCurrentAccount } from '@hcengineering/core'
|
2023-10-03 03:49:44 +00:00
|
|
|
import presentation, { createQuery, getClient } from '@hcengineering/presentation'
|
2023-09-26 09:22:44 +00:00
|
|
|
import { StyledTextBox } from '@hcengineering/text-editor'
|
2023-12-04 06:59:05 +00:00
|
|
|
import { Button, EditBox, Icon, IconClose, IconMoreH, createFocusManager, showPopup } 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'
|
2023-08-23 03:11:16 +00:00
|
|
|
import EventReminders from './EventReminders.svelte'
|
2023-09-26 09:22:44 +00:00
|
|
|
import EventTimeEditor from './EventTimeEditor.svelte'
|
2023-08-25 09:49:14 +00:00
|
|
|
import EventTimeExtraButton from './EventTimeExtraButton.svelte'
|
2023-09-26 09:22:44 +00:00
|
|
|
import ReccurancePopup from './ReccurancePopup.svelte'
|
2023-10-03 03:49:44 +00:00
|
|
|
import VisibilityEditor from './VisibilityEditor.svelte'
|
|
|
|
import CalendarSelector from './CalendarSelector.svelte'
|
2023-10-26 08:14:44 +00:00
|
|
|
import LocationEditor from './LocationEditor.svelte'
|
2023-12-04 06:59:05 +00:00
|
|
|
import FocusHandler from '@hcengineering/ui/src/components/FocusHandler.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
|
2023-10-26 08:14:44 +00:00
|
|
|
let location = ''
|
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 = ''
|
2023-10-03 03:49:44 +00:00
|
|
|
let visibility: Visibility = 'private'
|
|
|
|
const me = getCurrentAccount()
|
|
|
|
let space: Ref<Calendar> = `${me._id}_calendar` as Ref<Calendar>
|
|
|
|
|
|
|
|
const q = createQuery()
|
|
|
|
q.query(calendar.class.ExternalCalendar, { default: true, members: me._id, archived: false }, (res) => {
|
|
|
|
if (res.length > 0) {
|
|
|
|
space = res[0]._id
|
|
|
|
}
|
|
|
|
})
|
2023-08-13 16:28:12 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
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,
|
2023-10-03 03:49:44 +00:00
|
|
|
visibility,
|
2023-08-13 16:28:12 +00:00
|
|
|
title,
|
2023-10-26 08:14:44 +00:00
|
|
|
location,
|
2023-08-13 16:28:12 +00:00
|
|
|
allDay,
|
2023-09-29 18:56:31 +00:00
|
|
|
access: 'owner',
|
|
|
|
originalStartTime: allDay ? saveUTC(date) : date
|
2023-08-13 16:28:12 +00:00
|
|
|
})
|
|
|
|
} 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,
|
2023-10-03 03:49:44 +00:00
|
|
|
visibility,
|
2023-08-13 16:28:12 +00:00
|
|
|
participants,
|
2023-08-23 03:11:16 +00:00
|
|
|
reminders,
|
2023-08-13 16:28:12 +00:00
|
|
|
title,
|
2023-10-26 08:14:44 +00:00
|
|
|
location,
|
2023-08-13 16:28:12 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-12-04 06:59:05 +00:00
|
|
|
|
|
|
|
const manager = createFocusManager()
|
2022-06-15 12:00:32 +00:00
|
|
|
</script>
|
|
|
|
|
2023-12-04 06:59:05 +00:00
|
|
|
<FocusHandler {manager} />
|
|
|
|
|
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-12-04 06:59:05 +00:00
|
|
|
<EventTimeEditor {allDay} bind:startDate bind:dueDate focusIndex={10004} />
|
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-12-04 06:59:05 +00:00
|
|
|
<LocationEditor focusIndex={10010} bind:value={location} />
|
|
|
|
<EventParticipants focusIndex={10011} bind:participants bind:externalParticipants />
|
2023-08-13 16:28:12 +00:00
|
|
|
</div>
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="block flex-no-shrink">
|
2023-09-29 06:25:14 +00:00
|
|
|
<div class="flex-row-top gap-1-5">
|
|
|
|
<div class="top-icon">
|
|
|
|
<Icon icon={calendar.icon.Description} size={'small'} />
|
|
|
|
</div>
|
2023-09-26 09:22:44 +00:00
|
|
|
<StyledTextBox
|
|
|
|
alwaysEdit={true}
|
|
|
|
kind={'indented'}
|
|
|
|
maxHeight={'limited'}
|
|
|
|
showButtons={false}
|
2023-12-04 06:59:05 +00:00
|
|
|
focusIndex={10100}
|
2023-09-26 09:22:44 +00:00
|
|
|
placeholder={calendar.string.Description}
|
|
|
|
bind:content={description}
|
|
|
|
/>
|
2023-08-13 16:28:12 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-08-25 09:49:14 +00:00
|
|
|
<div class="block rightCropPadding">
|
2023-12-04 06:59:05 +00:00
|
|
|
<CalendarSelector bind:value={space} focusIndex={10101} />
|
2023-10-03 03:49:44 +00:00
|
|
|
<div class="flex-row-center flex-gap-1">
|
|
|
|
<Icon icon={calendar.icon.Hidden} size={'small'} />
|
2023-12-04 06:59:05 +00:00
|
|
|
<VisibilityEditor bind:value={visibility} kind={'ghost'} focusIndex={10102} withoutIcon />
|
2023-10-03 03:49:44 +00:00
|
|
|
</div>
|
2023-12-04 06:59:05 +00:00
|
|
|
<EventReminders bind:reminders focusIndex={10103} />
|
2023-08-23 03:11:16 +00:00
|
|
|
</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 />
|
2023-12-04 06:59:05 +00:00
|
|
|
<Button
|
|
|
|
kind="primary"
|
|
|
|
label={presentation.string.Create}
|
|
|
|
focusIndex={10104}
|
|
|
|
on:click={saveEvent}
|
|
|
|
disabled={title === ''}
|
|
|
|
/>
|
2023-08-13 16:28:12 +00:00
|
|
|
</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
|
|
|
}
|
|
|
|
}
|
2023-09-29 06:25:14 +00:00
|
|
|
.top-icon {
|
|
|
|
flex-shrink: 0;
|
|
|
|
margin-top: 0.875rem;
|
|
|
|
}
|
2023-08-13 16:28:12 +00:00
|
|
|
}
|
|
|
|
</style>
|