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

WIP: Week view with times #653

Merged
merged 54 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
27f777e
feat: add week view hour grid
mattlewis92 Jul 19, 2018
b87d7cc
refactor: remove console.log
mattlewis92 Jul 19, 2018
3665b4e
refactor: make week view times a grid of columns
mattlewis92 Jul 19, 2018
5e6a7ad
feat: show events on week view hour grid
mattlewis92 Jul 19, 2018
c5f5aee
feat: upgrade calendar-utils with new api
mattlewis92 Jul 19, 2018
eacf9f2
feat: add a thicker border to separate all day events
mattlewis92 Jul 20, 2018
cedcac9
test: add weekViewHour date formatter tests
mattlewis92 Jul 20, 2018
27d0d28
chore: merge with 0.26
mattlewis92 Jul 20, 2018
8e55bba
feat: allow dragging and dropping hourly week view events
mattlewis92 Jul 20, 2018
779725c
fix: fixes for when dragging and not snapping to a grid
mattlewis92 Jul 20, 2018
ab1b318
fix: prevent js error when dragging and dropping all day events
mattlewis92 Jul 20, 2018
0a88d73
fix: stop events being dropped on all day block and vice versa
mattlewis92 Jul 20, 2018
d027a22
refactor: rename getDragMovedEventTimes
mattlewis92 Jul 20, 2018
670dda6
refactor: rename all day resize methods
mattlewis92 Jul 20, 2018
90be1f6
feat: support resizing of events on the week view with times
mattlewis92 Jul 20, 2018
e477424
refactor: rename weekEvent to allDayEvent or timeEvent respectively
mattlewis92 Jul 20, 2018
769169f
refactor: rename methd
mattlewis92 Jul 23, 2018
a821c8a
fix: use Math.ceil instead of .round
mattlewis92 Jul 23, 2018
1a25f70
fix: allow dragging events into the next column
mattlewis92 Jul 23, 2018
57cc27a
fix: only allow resizing the first and last parts of event
mattlewis92 Jul 23, 2018
875e3a1
fix: allow resizing of events to all columns
mattlewis92 Jul 23, 2018
083e9ba
fix: disable tooltips when resizing
mattlewis92 Jul 23, 2018
417eeb5
refactor: rename hour to time events in css
mattlewis92 Jul 23, 2018
72e1d0e
refactor: use mwlClick directive for all clicks
mattlewis92 Jul 23, 2018
895f83b
feat: expose whether the event was dropped on an all day section
mattlewis92 Jul 24, 2018
8b5be62
feat: add a way of setting an all day events label
mattlewis92 Jul 24, 2018
ef8c89d
test: fix tests
mattlewis92 Jul 24, 2018
ceaac93
feat: allow dragging and dropping events between all day and time
mattlewis92 Jul 24, 2018
1dcdebb
build: upgrade dependencies
mattlewis92 Jul 24, 2018
d3dbd16
Revert "build: upgrade dependencies"
mattlewis92 Jul 24, 2018
e50c875
Merge branch '0.26' into week-view-with-times
mattlewis92 Jul 24, 2018
5616912
fix: disable drag when dropping events outside of the view
mattlewis92 Jul 24, 2018
edd22b3
Revert "fix: disable drag when dropping events outside of the view"
mattlewis92 Jul 24, 2018
fddc1dd
fix: upgrade drag and drop lib
mattlewis92 Jul 24, 2018
b4cea06
test: fix tests
mattlewis92 Jul 24, 2018
46ef0d6
refactor: remove mwlDroppable usage
mattlewis92 Jul 24, 2018
bbbb0fd
fix: apply event drag fix to week view as well
mattlewis92 Jul 24, 2018
07e05df
fix: emit allDay on drag and drop event
mattlewis92 Jul 24, 2018
66dfaa4
Merge branch '0.26' into week-view-with-times
mattlewis92 Jul 26, 2018
066bd75
build: upgrade calendar-utils
mattlewis92 Jul 27, 2018
d2c28c9
test: fix tests
mattlewis92 Jul 30, 2018
1fb78cd
test: add week with with times resizing tests
mattlewis92 Jul 30, 2018
39a2ea8
chore: merge with master
mattlewis92 Jul 30, 2018
7a961c8
Merge branch '0.26' into week-view-with-times
mattlewis92 Jul 31, 2018
532b425
test: add drag and drop tests
mattlewis92 Jul 31, 2018
6d41809
Merge branch '0.26' into week-view-with-times
mattlewis92 Jul 31, 2018
3bd7d6f
chore: merge
mattlewis92 Jul 31, 2018
e45de17
test: add test for dragging events without end dates
mattlewis92 Jul 31, 2018
9c35713
refactor: replace WeakMaps with Maps
mattlewis92 Jul 31, 2018
a873663
refactor: clear map when done
mattlewis92 Jul 31, 2018
ba582de
test: add tests for dragging events between all day and time view
mattlewis92 Jul 31, 2018
de320bc
refactor: remove dropData.isInternal
mattlewis92 Jul 31, 2018
d341b17
refactor: share track by function
mattlewis92 Jul 31, 2018
634ccd5
refactor: fix ngc
mattlewis92 Jul 31, 2018
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
6 changes: 5 additions & 1 deletion demos/demo-modules/draggable-external-events/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ export class DemoComponent {
eventDropped({
event,
newStart,
newEnd
newEnd,
allDay
}: CalendarEventTimesChangedEvent): void {
const externalIndex = this.externalEvents.indexOf(event);
if (typeof allDay !== 'undefined') {
event.allDay = allDay;
}
if (externalIndex > -1) {
this.externalEvents.splice(externalIndex, 1);
this.events.push(event);
Expand Down
11 changes: 9 additions & 2 deletions demos/demo-modules/kitchen-sink/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ export class DemoComponent {
end: addDays(new Date(), 1),
title: 'A 3 day event',
color: colors.red,
actions: this.actions
actions: this.actions,
allDay: true,
resizable: {
beforeStart: true,
afterEnd: true
},
draggable: true
},
{
start: startOfDay(new Date()),
Expand All @@ -94,7 +100,8 @@ export class DemoComponent {
start: subDays(endOfMonth(new Date()), 3),
end: addDays(endOfMonth(new Date()), 3),
title: 'A long event that spans 2 months',
color: colors.blue
color: colors.blue,
allDay: true
},
{
start: addHours(startOfDay(new Date()), 2),
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@
"@angular/core": ">=6.0.0 <8.0.0"
},
"dependencies": {
"angular-draggable-droppable": "4.0.0-beta.13",
"angular-draggable-droppable": "^4.0.0-beta.16",
"angular-resizable-element": "^3.2.0",
"calendar-utils": "0.2.0-alpha.13",
"calendar-utils": "0.2.0-alpha.15",
"positioning": "^1.4.0"
},
"sideEffects": [
Expand Down
4 changes: 4 additions & 0 deletions src/date-adapters/date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ export abstract class DateAdapter implements BaseDateAdapter {
date: Date | string | number,
options?: { weekStartsOn?: number }
): Date;

abstract getHours(date: Date | string | number): number;

abstract getMinutes(date: Date | string | number): number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export class CalendarAngularDateFormatter
return `Week ${weekNumber} of ${year}`;
}

/**
* The time formatting down the left hand side of the week view
*/
public weekViewHour({ date, locale }: DateFormatterParams): string {
return new DatePipe(locale).transform(date, 'h a', null, locale);
}

/**
* The time formatting down the left hand side of the day view
*/
Expand Down
5 changes: 5 additions & 0 deletions src/modules/common/calendar-date-formatter.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface CalendarDateFormatterInterface {
*/
weekViewTitle({ date: Date }: DateFormatterParams): string;

/**
* The time formatting down the left hand side of the day view
*/
weekViewHour({ date: Date }: DateFormatterParams): string;

/**
* The time formatting down the left hand side of the day view
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export interface CalendarEventTimesChangedEvent<MetaType = any> {
event: CalendarEvent<MetaType>;
newStart: Date;
newEnd?: Date;
allDay?: boolean;
}
9 changes: 9 additions & 0 deletions src/modules/common/calendar-moment-date-formatter.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ export class CalendarMomentDateFormatter
.format('[Week] W [of] YYYY');
}

/**
* The time formatting down the left hand side of the week view
*/
public weekViewHour({ date, locale }: DateFormatterParams): string {
return this.moment(date)
.locale(locale)
.format('ha');
}

/**
* The time formatting down the left hand side of the day view
*/
Expand Down
7 changes: 7 additions & 0 deletions src/modules/common/calendar-native-date-formatter.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export class CalendarNativeDateFormatter
return `Week ${weekNumber} of ${year}`;
}

/**
* The time formatting down the left hand side of the week view
*/
public weekViewHour({ date, locale }: DateFormatterParams): string {
return new Intl.DateTimeFormat(locale, { hour: 'numeric' }).format(date);
}

/**
* The time formatting down the left hand side of the day view
*/
Expand Down
5 changes: 4 additions & 1 deletion src/modules/common/calendar-resize-helper.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export class CalendarResizeHelper {
) {}

validateResize({ rectangle }: { rectangle: ClientRect }): boolean {
if (this.minWidth && rectangle.width < this.minWidth) {
if (
this.minWidth &&
Math.ceil(rectangle.width) < Math.ceil(this.minWidth)
) {
return false;
}

Expand Down
72 changes: 63 additions & 9 deletions src/modules/common/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {
CalendarEvent,
DayViewEvent,
DayViewHour,
DayViewHourSegment,
validateEvents as validateEventsWithoutLog,
WeekDay
WeekDay,
WeekViewAllDayEvent
} from 'calendar-utils';
import { DateAdapter } from '../../date-adapters/date-adapter';

export const validateEvents = (events: CalendarEvent[]) => {
const warn = (...args) => console.warn('angular-calendar', ...args);
Expand All @@ -11,14 +16,14 @@ export const validateEvents = (events: CalendarEvent[]) => {

export function isInside(outer: ClientRect, inner: ClientRect): boolean {
return (
outer.left <= inner.left &&
inner.left <= outer.right &&
outer.left <= inner.right &&
inner.right <= outer.right &&
outer.top <= inner.top &&
inner.top <= outer.bottom &&
outer.top <= inner.bottom &&
inner.bottom <= outer.bottom
Math.ceil(outer.left) <= Math.ceil(inner.left) &&
Math.ceil(inner.left) <= Math.ceil(outer.right) &&
Math.ceil(outer.left) <= Math.ceil(inner.right) &&
Math.ceil(inner.right) <= Math.ceil(outer.right) &&
Math.ceil(outer.top) <= Math.ceil(inner.top) &&
Math.ceil(inner.top) <= Math.ceil(outer.bottom) &&
Math.ceil(outer.top) <= Math.ceil(inner.bottom) &&
Math.ceil(inner.bottom) <= Math.ceil(outer.bottom)
);
}

Expand All @@ -33,3 +38,52 @@ export const trackByWeekDayHeaderDate = (index: number, day: WeekDay) =>
day.date.toISOString();

export const trackByIndex = (index: number) => index;

export const trackByHourSegment = (
index: number,
segment: DayViewHourSegment
) => segment.date.toISOString();

export const trackByHour = (index: number, hour: DayViewHour) =>
hour.segments[0].date.toISOString();

export const trackByDayOrWeekEvent = (
index: number,
weekEvent: WeekViewAllDayEvent | DayViewEvent
) => (weekEvent.event.id ? weekEvent.event.id : weekEvent.event);

const MINUTES_IN_HOUR = 60;

export function getMinutesMoved(
movedY: number,
hourSegments: number,
hourSegmentHeight: number,
eventSnapSize: number
): number {
const draggedInPixelsSnapSize = roundToNearest(
movedY,
eventSnapSize || hourSegmentHeight
);
const pixelAmountInMinutes =
MINUTES_IN_HOUR / (hourSegments * hourSegmentHeight);
return draggedInPixelsSnapSize * pixelAmountInMinutes;
}

export function getMinimumEventHeightInMinutes(
hourSegments: number,
hourSegmentHeight: number
) {
return (MINUTES_IN_HOUR / (hourSegments * hourSegmentHeight)) * 30;
}

export function getDefaultEventEnd(
dateAdapter: DateAdapter,
event: CalendarEvent,
minimumMinutes: number
): Date {
if (event.end) {
return event.end;
} else {
return dateAdapter.addMinutes(event.start, minimumMinutes);
}
}
Loading