Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit ae2e917a authored by Christoph Wurst's avatar Christoph Wurst Committed by GitHub
Browse files

Merge pull request #4324 from nextcloud/revert-4306-backport/4305/stable3.4

Revert "[stable3.4] Fix color dot and event alignment"
parents abcacef9 99cf38f7
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -233,10 +233,6 @@
		word-break: break-all;
		white-space: normal;
	}

	:not(.fc-timegrid-event-short) > .fc-event-main .fc-event-title-container {
		width: 100%;
	}
}

.fc-v-event {
@@ -260,10 +256,6 @@
	.fc-daygrid-day-frame {
		min-height: 150px !important;
	}

	.fc-event-main-frame {
		flex-wrap: wrap;
	}
}
.fc-daygrid-day-events {
	position:relative !important;
+22 −51
Original line number Diff line number Diff line
@@ -20,10 +20,8 @@
  -
  -->
<template>
	<div>
		<div class="fc-event-main-frame">
		<div v-if="!allDay && viewType === 'dayGridMonth'"
			class="fc-daygrid-event-dot"
			:style="{'border-color': borderColor }" />
			<div class="fc-event-time">
				{{ eventDetails.timeText }}
			</div>
@@ -40,6 +38,7 @@
					:style="{ color: iconColor }" />
			</div>
		</div>
	</div>
</template>

<script>
@@ -74,44 +73,16 @@ export default {
		isDarkText() {
			return this.eventDetails?.event?._def?.extendedProps?.darkText
		},

		/**
		 * @return {string|undefined}
		 */
		borderColor() {
			return this.eventDetails?.event?.borderColor ?? undefined
		},

		/**
		 * @return {boolean}
		 */
		allDay() {
			return this.eventDetails?.event?.allDay ?? false
		},
	},
}
</script>

<style lang="scss" scoped>
.fc-event-main-frame {
	display: flex;
	width: 100%;

	.fc-daygrid-event-dot {
		align-self: center;
	}

	&--icons {
		display: flex;
		justify-content: space-between;
	}

	.fc-event-title-container {
		min-width: 0;
	}

<style scoped>
.fc-event-title.fc-sticky {
	flex-grow: 1;
}
.fc-event-main-frame--icons {
	display: flex;
	justify-content: space-between;
}
</style>
+7 −6
Original line number Diff line number Diff line
@@ -150,13 +150,14 @@ export function eventSourceFunction(calendarObjects, calendar, start, end, timez
				},
			}

			// Color of event object is a name while calendar color already is a hex value
			const customColor = getHexForColorName(object.color) ?? calendar.color
			if (object.color) {
				const customColor = getHexForColorName(object.color)
				if (customColor) {
					fcEvent.backgroundColor = customColor
					fcEvent.borderColor = customColor
					fcEvent.textColor = generateTextColorForHex(customColor)
				}
			}

			fcEvents.push(fcEvent)
		}
+0 −233
Original line number Diff line number Diff line
/**
 * @copyright Copyright (c) 2022 Richard Steinmetz <richard@steinmetz.cloud>
 *
 * @author Richard Steinmetz <richard@steinmetz.cloud>
 *
 * @license AGPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

import { eventSourceFunction } from '../../../../../src/fullcalendar/eventSources/eventSourceFunction.js'
import {
	generateTextColorForHex,
	getHexForColorName, hexToRGB,
	isLight,
} from '../../../../../src/utils/color.js'
import { getAllObjectsInTimeRange } from '../../../../../src/utils/calendarObject.js'

jest.mock('../../../../../src/utils/color.js')
jest.mock('../../../../../src/utils/calendarObject.js')

describe('fullcalendar/eventSourceFunction test suite', () => {
	beforeEach(() => {
		generateTextColorForHex.mockClear()
		getAllObjectsInTimeRange.mockClear()
		getHexForColorName.mockClear()
		hexToRGB.mockClear()
		isLight.mockClear()
	})

	it('should prefer the event color', () => {
		const calendar = {
			id: 'calendar-id-123',
			color: '#ff00ff',
			readOnly: false,
		}

		const start = new Date()
		start.setHours(start.getHours() - 24)
		const end = new Date()
		end.setHours(end.getHours() + 24)
		const timezone = { calendarJsTimezone: true, tzid: 'America/New_York' }

		const calendarObjects = [
			{
				calendarObject: true,
				dav: {
					url: 'url1',
				},
				id: '1',
			},
		]

		const eventComponents = [
			{
				name: 'VEVENT',
				id: '1-1',
				status: 'CONFIRMED',
				isAllDay: jest.fn().mockReturnValue(false),
				getReferenceRecurrenceId: jest.fn().mockReturnValue({ unixTime: 123 }),
				canModifyAllDay: jest.fn().mockReturnValue(true),
				startDate: {
					getInTimezone: jest.fn().mockReturnValue({
						jsDate: new Date(start),
					}),
				},
				endDate: {
					getInTimezone: jest.fn().mockReturnValue({
						jsDate: new Date(end),
					}),
				},
				hasComponent: jest.fn().mockReturnValue(false),
				hasProperty: jest.fn().mockReturnValue(false),
				color: 'red',
			},
		]

		getAllObjectsInTimeRange
			.mockReturnValueOnce(eventComponents)
		hexToRGB
			.mockReturnValueOnce({ red: 255, green: 0, blue: 255 })
		isLight
			.mockReturnValueOnce(false)
		getHexForColorName
			.mockReturnValueOnce('#ff0000')
		generateTextColorForHex
			.mockReturnValueOnce('#eeeeee')

		expect(eventSourceFunction(calendarObjects, calendar, new Date(start), new Date(end), timezone)).toEqual([
			{
				id: '1###1-1',
				title: 'Untitled event',
				allDay: false,
				start,
				end,
				classNames: [],
				extendedProps: {
					objectId: '1',
					recurrenceId: 123,
					canModifyAllDay: true,
					calendarId: 'calendar-id-123',
					davUrl: 'url1',
					objectType: 'VEVENT',
					percent: null,
					hasAlarms: false,
					hasAttendees: false,
					darkText: false,
				},
				backgroundColor: '#ff0000',
				borderColor: '#ff0000',
				textColor: '#eeeeee',
			},
		])

		expect(hexToRGB).toHaveBeenCalledTimes(1)
		expect(hexToRGB).toHaveBeenNthCalledWith(1, '#ff00ff')
		expect(isLight).toHaveBeenCalledTimes(1)
		expect(isLight).toHaveBeenNthCalledWith(1, { red: 255, green: 0, blue: 255 })
		expect(getAllObjectsInTimeRange).toHaveBeenCalledTimes(1)
		expect(getAllObjectsInTimeRange).toHaveBeenNthCalledWith(1, calendarObjects[0], start, end)
		expect(getHexForColorName).toHaveBeenCalledTimes(1)
		expect(getHexForColorName).toHaveBeenNthCalledWith(1, 'red')
		expect(generateTextColorForHex).toHaveBeenCalledTimes(1)
		expect(generateTextColorForHex).toHaveBeenNthCalledWith(1, '#ff0000')
	})

	it('should fallback to the calendar color', () => {
		const calendar = {
			id: 'calendar-id-123',
			color: '#ff00ff',
			readOnly: false,
		}

		const start = new Date()
		start.setHours(start.getHours() - 24)
		const end = new Date()
		end.setHours(end.getHours() + 24)
		const timezone = { calendarJsTimezone: true, tzid: 'America/New_York' }

		const calendarObjects = [
			{
				calendarObject: true,
				dav: {
					url: 'url1',
				},
				id: '1',
			},
		]

		const eventComponents = [
			{
				name: 'VEVENT',
				id: '1-1',
				status: 'CONFIRMED',
				isAllDay: jest.fn().mockReturnValue(false),
				getReferenceRecurrenceId: jest.fn().mockReturnValue({ unixTime: 123 }),
				canModifyAllDay: jest.fn().mockReturnValue(true),
				startDate: {
					getInTimezone: jest.fn().mockReturnValue({
						jsDate: new Date(start),
					}),
				},
				endDate: {
					getInTimezone: jest.fn().mockReturnValue({
						jsDate: new Date(end),
					}),
				},
				hasComponent: jest.fn().mockReturnValue(false),
				hasProperty: jest.fn().mockReturnValue(false),
			},
		]

		getAllObjectsInTimeRange
			.mockReturnValueOnce(eventComponents)
		hexToRGB
			.mockReturnValueOnce({ red: 255, green: 0, blue: 255 })
		isLight
			.mockReturnValueOnce(false)
		getHexForColorName
			.mockReturnValueOnce(null)
		generateTextColorForHex
			.mockReturnValueOnce('#eeeeee')

		expect(eventSourceFunction(calendarObjects, calendar, new Date(start), new Date(end), timezone)).toEqual([
			{
				id: '1###1-1',
				title: 'Untitled event',
				allDay: false,
				start,
				end,
				classNames: [],
				extendedProps: {
					objectId: '1',
					recurrenceId: 123,
					canModifyAllDay: true,
					calendarId: 'calendar-id-123',
					davUrl: 'url1',
					objectType: 'VEVENT',
					percent: null,
					hasAlarms: false,
					hasAttendees: false,
					darkText: false,
				},
				backgroundColor: '#ff00ff',
				borderColor: '#ff00ff',
				textColor: '#eeeeee',
			},
		])

		expect(hexToRGB).toHaveBeenCalledTimes(1)
		expect(hexToRGB).toHaveBeenNthCalledWith(1, '#ff00ff')
		expect(isLight).toHaveBeenCalledTimes(1)
		expect(isLight).toHaveBeenNthCalledWith(1, { red: 255, green: 0, blue: 255 })
		expect(getAllObjectsInTimeRange).toHaveBeenCalledTimes(1)
		expect(getAllObjectsInTimeRange).toHaveBeenNthCalledWith(1, calendarObjects[0], start, end)
		expect(getHexForColorName).toHaveBeenCalledTimes(1)
		expect(getHexForColorName).toHaveBeenNthCalledWith(1, undefined)
		expect(generateTextColorForHex).toHaveBeenCalledTimes(1)
		expect(generateTextColorForHex).toHaveBeenNthCalledWith(1, '#ff00ff')
	})
})
+7 −40
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
 * @copyright Copyright (c) 2019 Georg Ehrke
 *
 * @author Georg Ehrke <oc.list@georgehrke.com>
 * @author Richard Steinmetz <richard@steinmetz.cloud>
 *
 * @license GNU AGPL version 3 or any later version
 *
@@ -228,9 +227,6 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
					hasAlarms: false,
					hasAttendees: false,
				},
				backgroundColor: '#ff0000',
				borderColor: '#ff0000',
				textColor: '#eeeeee',
			},
			{
				id: '1###1-2',
@@ -253,9 +249,6 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
					hasAlarms: false,
					hasAttendees: false,
				},
				backgroundColor: '#ff0000',
				borderColor: '#ff0000',
				textColor: '#eeeeee',
			},
			{
				id: '1###1-3',
@@ -278,9 +271,6 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
					hasAlarms: true,
					hasAttendees: false,
				},
				backgroundColor: '#ff0000',
				borderColor: '#ff0000',
				textColor: '#eeeeee',
			},
			{
				id: '2###2-1',
@@ -303,9 +293,6 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
					hasAlarms: false,
					hasAttendees: false,
				},
				backgroundColor: '#ff0000',
				borderColor: '#ff0000',
				textColor: '#eeeeee',
			},
			{
				id: '4###3-1',
@@ -371,14 +358,11 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
		expect(getAllObjectsInTimeRange).toHaveBeenNthCalledWith(3, calendarObjects[2], start, end)
		expect(getAllObjectsInTimeRange).toHaveBeenNthCalledWith(4, calendarObjects[3], start, end)

		expect(getHexForColorName).toHaveBeenCalledTimes(5)
		for (let i = 1; i < 5; i++) {
			expect(getHexForColorName).toHaveBeenNthCalledWith(i, undefined)
		}
		expect(getHexForColorName).toHaveBeenNthCalledWith(5, 'red')
		expect(getHexForColorName).toHaveBeenCalledTimes(1)
		expect(getHexForColorName).toHaveBeenNthCalledWith(1, 'red')

		expect(generateTextColorForHex).toHaveBeenCalledTimes(5)
		expect(generateTextColorForHex).toHaveBeenCalledWith('#ff0000')
		expect(generateTextColorForHex).toHaveBeenCalledTimes(1)
		expect(generateTextColorForHex).toHaveBeenNthCalledWith(1, '#ff0000')

		// Make sure the following dates have not been touched
		expect(event11Start.getFullYear()).toEqual(2020)
@@ -633,9 +617,6 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
			id: '1###1',
			start: event1End,
			title: 'Untitled task',
			backgroundColor: '#ff0000',
			borderColor: '#ff0000',
			textColor: '#eeeeee',
		}, {
			allDay: false,
			classNames: [
@@ -659,9 +640,6 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
			id: '1###2',
			start: event2End,
			title: 'Untitled task',
			backgroundColor: '#ff0000',
			borderColor: '#ff0000',
			textColor: '#eeeeee',
		}, {
			allDay: false,
			classNames: [
@@ -685,9 +663,6 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
			id: '1###3',
			start: event3End,
			title: 'Untitled task (99%)',
			backgroundColor: '#ff0000',
			borderColor: '#ff0000',
			textColor: '#eeeeee',
		}, {
			allDay: false,
			classNames: [
@@ -706,14 +681,11 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
				percent: null,
				recurrenceId: 123,
				hasAlarms: false,
				hasAttendees: false,
				hasAttendees: false
			},
			id: '1###4',
			start: event4End,
			title: 'This task has a title',
			backgroundColor: '#ff0000',
			borderColor: '#ff0000',
			textColor: '#eeeeee',
		}, {
			allDay: false,
			classNames: [
@@ -737,9 +709,6 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
			id: '1###5',
			start: event5End,
			title: 'This task has a title and percent (99%)',
			backgroundColor: '#ff0000',
			borderColor: '#ff0000',
			textColor: '#eeeeee',
		}])

		expect(eventComponentSet[0].startDate.getInTimezone).toHaveBeenCalledTimes(0)
@@ -771,10 +740,8 @@ describe('fullcalendar/freeBusyResourceEventSourceFunction test suite', () => {
		expect(getAllObjectsInTimeRange).toHaveBeenCalledTimes(1)
		expect(getAllObjectsInTimeRange).toHaveBeenNthCalledWith(1, calendarObjects[0], start, end)

		expect(getHexForColorName).toHaveBeenCalledTimes(5)
		expect(getHexForColorName).toHaveBeenCalledWith(undefined)
		expect(generateTextColorForHex).toHaveBeenCalledTimes(5)
		expect(getHexForColorName).toHaveBeenCalledWith(undefined)
		expect(getHexForColorName).toHaveBeenCalledTimes(0)
		expect(generateTextColorForHex).toHaveBeenCalledTimes(0)
	})

})