2022-03-18 06:37:49 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020 Anticrm Platform Contributors.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
|
2023-07-10 15:50:29 +00:00
|
|
|
import { ReccuringInstance } from '@hcengineering/calendar'
|
|
|
|
import { Doc, TxOperations, concatLink } from '@hcengineering/core'
|
|
|
|
import { Resources, getMetadata } from '@hcengineering/platform'
|
|
|
|
import presentation, { getClient } from '@hcengineering/presentation'
|
|
|
|
import { closePopup, showPopup } from '@hcengineering/ui'
|
2022-03-18 16:07:42 +00:00
|
|
|
import CalendarView from './components/CalendarView.svelte'
|
2023-07-10 15:50:29 +00:00
|
|
|
import CreateEvent from './components/CreateEvent.svelte'
|
2022-03-23 09:03:41 +00:00
|
|
|
import DateTimePresenter from './components/DateTimePresenter.svelte'
|
2022-03-26 17:34:06 +00:00
|
|
|
import DocReminder from './components/DocReminder.svelte'
|
|
|
|
import EditEvent from './components/EditEvent.svelte'
|
2022-06-15 12:00:32 +00:00
|
|
|
import EventPresenter from './components/EventPresenter.svelte'
|
2023-07-10 15:50:29 +00:00
|
|
|
import Events from './components/Events.svelte'
|
|
|
|
import IntegrationConnect from './components/IntegrationConnect.svelte'
|
|
|
|
import PersonsPresenter from './components/PersonsPresenter.svelte'
|
|
|
|
import SaveEventReminder from './components/SaveEventReminder.svelte'
|
|
|
|
import UpdateRecInstancePopup from './components/UpdateRecInstancePopup.svelte'
|
|
|
|
import ReminderViewlet from './components/activity/ReminderViewlet.svelte'
|
|
|
|
import CalendarIntegrationIcon from './components/icons/Calendar.svelte'
|
2023-08-01 07:58:03 +00:00
|
|
|
import EventElement from './components/EventElement.svelte'
|
2023-08-07 12:39:04 +00:00
|
|
|
import CalendarEventPresenter from './components/CalendarEventPresenter.svelte'
|
|
|
|
import DayCalendar from './components/DayCalendar.svelte'
|
2023-07-10 15:50:29 +00:00
|
|
|
import calendar from './plugin'
|
|
|
|
import contact from '@hcengineering/contact'
|
|
|
|
import { deleteObjects } from '@hcengineering/view-resources'
|
2022-03-26 17:34:06 +00:00
|
|
|
|
2023-08-07 12:39:04 +00:00
|
|
|
export { EventElement, CalendarView, DayCalendar }
|
2023-08-01 07:58:03 +00:00
|
|
|
|
2022-03-26 17:34:06 +00:00
|
|
|
async function saveEventReminder (object: Doc): Promise<void> {
|
|
|
|
showPopup(SaveEventReminder, { objectId: object._id, objectClass: object._class })
|
|
|
|
}
|
2022-03-18 06:37:49 +00:00
|
|
|
|
2023-07-10 15:50:29 +00:00
|
|
|
async function deleteRecHandler (res: any, object: ReccuringInstance): Promise<void> {
|
|
|
|
const client = getClient()
|
|
|
|
if (res.mode === 'current') {
|
|
|
|
await client.addCollection(
|
|
|
|
object._class,
|
|
|
|
object.space,
|
|
|
|
object.attachedTo,
|
|
|
|
object.attachedToClass,
|
|
|
|
object.collection,
|
|
|
|
{
|
|
|
|
eventId: object.eventId,
|
|
|
|
title: object.title,
|
|
|
|
description: object.description,
|
|
|
|
date: object.date,
|
|
|
|
dueDate: object.dueDate,
|
|
|
|
allDay: object.allDay,
|
|
|
|
participants: object.participants,
|
|
|
|
externalParticipants: object.externalParticipants,
|
|
|
|
originalStartTime: object.originalStartTime,
|
|
|
|
recurringEventId: object.recurringEventId,
|
|
|
|
reminders: object.reminders,
|
|
|
|
location: object.location,
|
|
|
|
isCancelled: true,
|
2023-08-13 16:28:12 +00:00
|
|
|
rdate: object.rdate,
|
|
|
|
rules: object.rules,
|
|
|
|
exdate: object.exdate,
|
2023-07-10 15:50:29 +00:00
|
|
|
access: 'owner'
|
|
|
|
},
|
|
|
|
object._id
|
|
|
|
)
|
|
|
|
} else if (res.mode === 'all') {
|
|
|
|
const base = await client.findOne(calendar.class.ReccuringEvent, {
|
|
|
|
space: object.space,
|
|
|
|
eventId: object.recurringEventId
|
|
|
|
})
|
|
|
|
if (base !== undefined) {
|
|
|
|
await client.remove(base)
|
|
|
|
}
|
|
|
|
} else if (res.mode === 'next') {
|
|
|
|
await removePast(client, object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteRecEvent (object: ReccuringInstance): Promise<void> {
|
|
|
|
if (object.virtual === true) {
|
|
|
|
showPopup(UpdateRecInstancePopup, { label: calendar.string.RemoveRecEvent }, undefined, async (res) => {
|
|
|
|
if (res !== null) {
|
|
|
|
await deleteRecHandler(res, object)
|
|
|
|
closePopup()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
showPopup(
|
|
|
|
contact.component.DeleteConfirmationPopup,
|
|
|
|
{
|
|
|
|
object,
|
|
|
|
deleteAction: async () => {
|
|
|
|
const objs = Array.isArray(object) ? object : [object]
|
|
|
|
await deleteObjects(getClient(), objs).catch((err) => console.error(err))
|
|
|
|
closePopup()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
undefined
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function removePast (client: TxOperations, object: ReccuringInstance): Promise<void> {
|
|
|
|
const origin = await client.findOne(calendar.class.ReccuringEvent, {
|
|
|
|
eventId: object.recurringEventId,
|
|
|
|
space: object.space
|
|
|
|
})
|
|
|
|
if (origin !== undefined) {
|
|
|
|
const target = object.date
|
|
|
|
await client.update(origin, {
|
|
|
|
rules: [{ ...origin.rules[0], endDate: target - 1 }],
|
|
|
|
rdate: origin.rdate.filter((p) => p < target)
|
|
|
|
})
|
|
|
|
const instances = await client.findAll(calendar.class.ReccuringInstance, {
|
|
|
|
eventId: origin.eventId,
|
|
|
|
date: { $gte: target }
|
|
|
|
})
|
|
|
|
for (const instance of instances) {
|
|
|
|
await client.remove(instance)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:00:32 +00:00
|
|
|
export enum CalendarMode {
|
|
|
|
Day,
|
2023-07-17 06:41:46 +00:00
|
|
|
Days,
|
2022-06-15 12:00:32 +00:00
|
|
|
Week,
|
|
|
|
Month,
|
|
|
|
Year
|
|
|
|
}
|
|
|
|
|
2022-03-18 06:37:49 +00:00
|
|
|
export default async (): Promise<Resources> => ({
|
|
|
|
component: {
|
2022-03-26 17:34:06 +00:00
|
|
|
EditEvent,
|
2022-03-18 16:07:42 +00:00
|
|
|
PersonsPresenter,
|
2022-03-23 09:03:41 +00:00
|
|
|
CalendarView,
|
2022-05-12 09:40:22 +00:00
|
|
|
Events,
|
2022-03-26 17:34:06 +00:00
|
|
|
DateTimePresenter,
|
|
|
|
DocReminder,
|
2022-06-15 12:00:32 +00:00
|
|
|
EventPresenter,
|
2023-07-10 15:50:29 +00:00
|
|
|
CreateEvent,
|
|
|
|
IntegrationConnect,
|
2023-08-07 12:39:04 +00:00
|
|
|
CalendarIntegrationIcon,
|
|
|
|
CalendarEventPresenter
|
2022-03-26 17:34:06 +00:00
|
|
|
},
|
|
|
|
activity: {
|
|
|
|
ReminderViewlet
|
|
|
|
},
|
|
|
|
actionImpl: {
|
2023-07-10 15:50:29 +00:00
|
|
|
SaveEventReminder: saveEventReminder,
|
|
|
|
DeleteRecEvent: deleteRecEvent
|
|
|
|
},
|
|
|
|
handler: {
|
|
|
|
DisconnectHandler: async () => {
|
|
|
|
const url = getMetadata(calendar.metadata.CalendarServiceURL)
|
|
|
|
const token = getMetadata(presentation.metadata.Token)
|
|
|
|
if (url === undefined || token === undefined) return
|
|
|
|
await fetch(concatLink(url, '/signout'), {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
Authorization: 'Bearer ' + token,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-03-18 06:37:49 +00:00
|
|
|
}
|
|
|
|
})
|