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

GH-160 fixed the event colors being out of sync with their calendars #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public Set<CalendarDisplayEvent> getEvents(
CalendarConfiguration calendar,
Interval interval,
PortletRequest request,
DateTimeZone usersConfiguredDateTimeZone) {
DateTimeZone usersConfiguredDateTimeZone,
int calendarIndex) {

// Get the set of calendar events for the requested period.
// We invoke the adapter before checking cache because we expect the adapter
Expand Down Expand Up @@ -159,7 +160,7 @@ public Set<CalendarDisplayEvent> getEvents(
for (VEvent event : eventSet.getEvents()) {
try {
displayEvents.addAll(
getDisplayEvents(event, interval, request.getLocale(), usersConfiguredDateTimeZone));
getDisplayEvents(event, interval, request.getLocale(), usersConfiguredDateTimeZone, calendarIndex));
} catch (ParseException e) {
log.error("Exception parsing event", e);
} catch (IOException e) {
Expand Down Expand Up @@ -214,7 +215,7 @@ public Set<CalendarDisplayEvent> getEvents(
* @throws ParseException
*/
protected Set<CalendarDisplayEvent> getDisplayEvents(
VEvent e, Interval interval, Locale locale, DateTimeZone usersConfiguredDateTimeZone)
VEvent e, Interval interval, Locale locale, DateTimeZone usersConfiguredDateTimeZone, int calendarIndex)
throws IOException, URISyntaxException, ParseException {

final VEvent event = (VEvent) e.copy();
Expand Down Expand Up @@ -280,7 +281,7 @@ protected Set<CalendarDisplayEvent> getDisplayEvents(
*/
if (theSpecificDay.getStart().isEqual(eventStart) || theSpecificDay.overlaps(eventInterval)) {
final CalendarDisplayEvent json =
new CalendarDisplayEvent(event, eventInterval, theSpecificDay, df, tf);
new CalendarDisplayEvent(event, eventInterval, theSpecificDay, df, tf, calendarIndex);
events.add(json);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class CalendarDisplayEvent implements Comparable<CalendarDisplayEvent> {
private final String startDate;
private final String endDate;

private final int calendarIndex;

/**
* Constructs an object from specified data.
*
Expand All @@ -66,14 +68,17 @@ public CalendarDisplayEvent(
Interval eventInterval,
Interval theSpecificDay,
DateTimeFormatter df,
DateTimeFormatter tf) {
DateTimeFormatter tf,
int calendarIndex) {
assert theSpecificDay.abuts(eventInterval) || theSpecificDay.overlaps(eventInterval)
: "Event interval is not in the specified day!";

this.summary = event.getSummary() != null ? event.getSummary().getValue() : null;
this.description = event.getDescription() != null ? event.getDescription().getValue() : null;
this.location = event.getLocation() != null ? event.getLocation().getValue() : null;

this.calendarIndex = calendarIndex;

boolean multi = false;
if (eventInterval.getStart().isBefore(theSpecificDay.getStart())) {
dayStart = theSpecificDay.getStart();
Expand Down Expand Up @@ -162,6 +167,8 @@ public DateTime getDayEnd() {
return this.dayEnd;
}

public int getCalendarIndex(){ return this.calendarIndex; }

public int compareTo(CalendarDisplayEvent event) {
// Order events by start date, then end date, then summary.
// If all properties are equal, use the calendar and event ids to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public Set<CalendarDisplayEvent> getEventList(
DateTimeZone tz = DateTimeZone.forID(timezone);
Set<CalendarDisplayEvent> events = new TreeSet<CalendarDisplayEvent>();

int calendarIndex=0; //to keep the color of the calendar consistent with the order in the main controller
for (CalendarConfiguration callisting : calendars) {
// don't bother to fetch hidden calendars
if (hiddenCalendars.get(callisting.getId()) == null) {
Expand All @@ -105,7 +106,7 @@ public Set<CalendarDisplayEvent> getEventList(
ICalendarAdapter adapter =
(ICalendarAdapter)
applicationContext.getBean(callisting.getCalendarDefinition().getClassName());
events.addAll(calendarEventsDao.getEvents(adapter, callisting, interval, request, tz));
events.addAll(calendarEventsDao.getEvents(adapter, callisting, interval, request, tz, calendarIndex));
} catch (NoSuchBeanDefinitionException ex) {
log.error("Calendar class instance could not be found: " + ex.getMessage());
} catch (UserFeedbackCalendarException sce) {
Expand All @@ -123,6 +124,7 @@ public Set<CalendarDisplayEvent> getEventList(
+ "\" is currently unavailable.");
}
}
calendarIndex++;
}
return events;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ public ModelAndView getEventList(ResourceRequest request, ResourceResponse respo

final Set<CalendarDisplayEvent> calendarEvents = helper.getEventList(errors, interval, request);

int index = 0;

final Set<JsonCalendarEventWrapper> events = new TreeSet<JsonCalendarEventWrapper>();
for (CalendarDisplayEvent e : calendarEvents) {
events.add(new JsonCalendarEventWrapper(e, index++));
events.add(new JsonCalendarEventWrapper(e, e.getCalendarIndex()));
}

/*
Expand Down
124 changes: 104 additions & 20 deletions src/main/webapp/less/_base.less
Original file line number Diff line number Diff line change
Expand Up @@ -110,82 +110,166 @@
margin-bottom: 15px;
}

@color-0:#1062a5;
@color-1:#2ca200;
@color-2:#990000;
@color-3:#683099;
@color-4:#824100;
@color-5:#008b78;
@color-6:#d62876;
@color-7:#bb5b1d;
@color-8:#7b7b7b;
@color-9:#000000;
@color-10:#cfca00;
@color-11:#002aa2;
@color-12:#BB0000;
@color-13:#8800d6;
@color-14:#be8219;
@color-15:#04a5b4;
@color-16:#b6479b;
@color-17:#ff7321;

.color-0, a.color-0 {
color: #1062a5;
color: @color-0;
}

.color-1, a.color-1 {
color: #477300;
color: @color-1;
}

.color-2, a.color-2 {
color: #990000;
color: @color-2;
}

.color-3, a.color-3 {
color: #683099;
color: @color-3;
}

.color-4, a.color-4 {
color: #8b4500;
color: @color-4;
}

.color-5, a.color-5 {
color: #008b78;
color: @color-5;
}

.color-6, a.color-6 {
color: #b62162;
color: @color-6;
}

.color-7, a.color-7 {
color: #bb5b1d;
color: @color-7;
}

.color-8, a.color-8 {
color: #7b7b7b;
color: @color-8;
}

.color-9, a.color-9 {
color: #000000;
color: @color-9;
}

.color-10, a.color-10 {
color: @color-10;
}

.color-11, a.color-11 {
color: @color-11;
}

.color-12, a.color-12 {
color: @color-12;
}

.color-13, a.color-13 {
color: @color-13;
}

.color-14, a.color-14 {
color: @color-14;
}

.color-15, a.color-15 {
color: @color-15;
}

.color-16, a.color-16 {
color: @color-16;
}

.color-17, a.color-17 {
color: @color-17;
}


.upcal-color-0 .upcal-event-cal {
background-color: #1062a5;
background-color: @color-0;
}

.upcal-color-1 .upcal-event-cal {
background-color: #477300;
background-color: @color-1;
}

.upcal-color-2 .upcal-event-cal {
background-color: #990000;
background-color: @color-2;
}

.upcal-color-3 .upcal-event-cal {
background-color: #683099;
background-color: @color-3;
}

.upcal-color-4 .upcal-event-cal {
background-color: #8b4500;
background-color: @color-4;
}

.upcal-color-5 .upcal-event-cal {
background-color: #008b78;
background-color: @color-5;
}

.upcal-color-6 .upcal-event-cal {
background-color: #b62162;
background-color: @color-6;
}

.upcal-color-7 .upcal-event-cal {
background-color: #bb5b1d;
background-color: @color-7;
}

.upcal-color-8 .upcal-event-cal {
background-color: #7b7b7b;
background-color: @color-8;
}

.upcal-color-9 .upcal-event-cal {
background-color: #000000;
background-color: @color-9;
}

.upcal-color-10 .upcal-event-cal {
background-color: @color-10;
}

.upcal-color-11 .upcal-event-cal {
background-color: @color-11;
}

.upcal-color-12 .upcal-event-cal {
background-color: @color-12;
}

.upcal-color-13 .upcal-event-cal {
background-color: @color-13;
}

.upcal-color-14 .upcal-event-cal {
background-color: @color-14;
}

.upcal-color-15 .upcal-event-cal {
background-color: @color-15;
}

.upcal-color-16 .upcal-event-cal {
background-color: @color-16;
}

.upcal-color-17 .upcal-event-cal {
background-color: @color-17;
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public void testGetDisplayEvents() throws IOException, URISyntaxException, Parse
DateMidnight intervalStop = new DateMidnight(2012, 1, 5, tz);
Interval interval = new Interval(intervalStart, intervalStop);

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz);
int calendarIndex=0;

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz,calendarIndex);

assertEquals(1, events.size());
}
Expand All @@ -134,7 +136,9 @@ public void testGetDisplayEventsSameStartEnd() throws Exception {
DateMidnight intervalStop = new DateMidnight(2012, 1, 31, tz);
Interval interval = new Interval(intervalStart, intervalStop);

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz);
int calendarIndex=0;

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz, calendarIndex);

assertEquals(1, events.size());
}
Expand All @@ -155,7 +159,9 @@ public void testGetDisplayEventsForLongEvent()
DateMidnight intervalStop = new DateMidnight(2012, 1, 5, tz);
Interval interval = new Interval(intervalStart, intervalStop);

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz);
int calendarIndex=0;

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz, calendarIndex);

assertEquals(2, events.size());
}
Expand All @@ -174,7 +180,9 @@ public void testGetDisplayEventsForNoEndDate()
DateMidnight intervalStop = new DateMidnight(2012, 1, 5, tz);
Interval interval = new Interval(intervalStart, intervalStop);

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz);
int calendarIndex=0;

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz, calendarIndex);

assertEquals(1, events.size());
}
Expand All @@ -193,7 +201,9 @@ public void testGetDisplayEventsForNoEndDateStartAbutment()
DateMidnight intervalStop = new DateMidnight(2012, 1, 5, tz);
Interval interval = new Interval(intervalStart, intervalStop);

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz);
int calendarIndex=0;

Set<CalendarDisplayEvent> events = eventDao.getDisplayEvents(event, interval, Locale.US, tz, calendarIndex);

assertEquals(1, events.size());
}
Expand Down
Loading