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:Linked Project Calendar #27

Open
wants to merge 5 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 @@ -324,10 +324,10 @@ public void onUpdate(final UpdateEvent event) {
* @param calendars
* The calendar types with their corresponding identifier.
*/
public void reload(final Map<CalendarType, Integer> calendars) {
public void reload(final Map<Integer, Integer> calendars) {

calendar.refresh();
this.projectId = calendars.get(CalendarType.Activity);
this.projectId = calendars.get(1);

view.setAddEventButtonEnabled(ProfileUtils.isGranted(auth(), GlobalPermissionEnum.EDIT_PROJECT_AGENDA, GlobalPermissionEnum.EDIT_PROJECT));
reloadEvents(calendars);
Expand Down Expand Up @@ -365,7 +365,7 @@ private List<CalendarWrapper> getCalendars() {
* @param calendars
* The calendar types with their corresponding identifier.
*/
private void reloadEvents(final Map<CalendarType, Integer> calendars) {
private void reloadEvents(final Map<Integer, Integer> calendars) {

view.getCalendarsStore().removeAll();

Expand All @@ -382,13 +382,28 @@ protected void onComplete() {
}
};

for (final Entry<CalendarType, Integer> calendarEntry : calendars.entrySet()) {
for (final Entry<Integer, Integer> calendarEntry : calendars.entrySet()) {

if (calendarEntry == null) {
continue;
}

final CalendarType calendarType = calendarEntry.getKey();
final Integer assign=calendarEntry.getKey();
final CalendarType calendarType;
switch (assign%4) {
case 1:
calendarType =CalendarType.Activity;
break;
case 2:
calendarType = CalendarType.Personal;
break;
case 3:
calendarType = CalendarType.MonitoredPoint;
break;
default:
calendarType = CalendarType.Reminder;
break;
}
final Integer calendarId = calendarEntry.getValue();

queue.add(new GetCalendar(calendarType, CalendarType.getIdentifier(calendarType, calendarId)), new CommandResultHandler<Calendar>() {
Expand All @@ -397,7 +412,12 @@ protected void onComplete() {
public void onCommandSuccess(final Calendar result) {
if(result != null) {
// Defines the color index of the calendar.
if(assign<5){
result.setStyle(calendarType.getColorCode());
}
else{
result.setStyle(calendarType.getColorCode() + 6);
}
result.setType(calendarType);

view.getCalendarsStore().add(new CalendarWrapper(result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
* #L%
*/

import java.util.EnumMap;

import org.sigmah.client.inject.Injector;
import org.sigmah.client.page.Page;
import org.sigmah.client.page.PageRequest;
import org.sigmah.client.ui.presenter.calendar.CalendarPresenter;
import org.sigmah.client.ui.view.base.ViewInterface;
import org.sigmah.client.ui.view.orgunit.OrgUnitCalendarView;
import org.sigmah.shared.dto.calendar.CalendarType;

import com.google.inject.ImplementedBy;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.HashMap;
import java.util.Map;
import org.sigmah.shared.dto.orgunit.OrgUnitDTO;

/**
* <p>
Expand Down Expand Up @@ -111,10 +112,18 @@ public void onBind() {
* {@inheritDoc}
*/
@Override
public void onPageRequest(final PageRequest request) {
final EnumMap<CalendarType, Integer> calendars = new EnumMap<CalendarType, Integer>(CalendarType.class);
calendars.put(CalendarType.Activity, getOrgUnit().getId());
calendars.put(CalendarType.Personal, getOrgUnit().getCalendarId());
public void onPageRequest(final PageRequest request) {
final Map<Integer, Integer> calendars = new HashMap<Integer, Integer>();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spMohanty & @osarrat Organization calendar integration is done only in one way.That means parent calendar contains child entries while child does not contain any parent entry.Is this okay or should it be both way ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is the expected behavior as expressed in issue #522 : http://www.sigmah.org/issues/view.php?id=522

Integer calendarId = 1;
calendars.put(calendarId++, getOrgUnit().getId());
calendars.put(calendarId, getOrgUnit().getCalendarId());
calendarId = calendarId + 3;

for(final OrgUnitDTO child : getOrgUnit().getChildrenOrgUnits()) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Raphcal Changed to for loop as suggested.

calendars.put(calendarId++, child.getId());
calendars.put(calendarId, child.getCalendarId());
calendarId = calendarId + 3;
}
calendarPresenter.reload(calendars);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.HashMap;
import java.util.Map;

/**
* <p>
Expand Down Expand Up @@ -109,14 +111,32 @@ public void onBind() {
* {@inheritDoc}
*/
@Override
public void onPageRequest(final PageRequest request) {
final EnumMap<CalendarType, Integer> calendars = new EnumMap<CalendarType, Integer>(CalendarType.class);
calendars.put(CalendarType.Activity, getProject().getId());
calendars.put(CalendarType.Personal, getProject().getCalendarId());
calendars.put(CalendarType.MonitoredPoint, getProject().getPointsList().getId());
calendars.put(CalendarType.Reminder, getProject().getRemindersList().getId());
calendarPresenter.reload(calendars);
}
public void onPageRequest(final PageRequest request) {
final Map<Integer, Integer> calendars = new HashMap<Integer, Integer>();
Integer calendarId = 1;
calendars.put(calendarId++, getProject().getId());
calendars.put(calendarId++, getProject().getCalendarId());
calendars.put(calendarId++, getProject().getPointsList().getId());
calendars.put(calendarId++, getProject().getRemindersList().getId());

if (!getProject().getFunded().isEmpty()) {
for (int i = 0; i < getProject().getFunded().size(); i++) {
calendars.put(calendarId++, getProject().getFunded().get(i).getFunded().getId());
calendars.put(calendarId++, getProject().getFunded().get(i).getFunded().getCalendarId());
calendars.put(calendarId++, getProject().getFunded().get(i).getFunded().getPointsList().getId());
calendars.put(calendarId++, getProject().getFunded().get(i).getFunded().getRemindersList().getId());
}
}
if (!getProject().getFunding().isEmpty()) {
for (int i = 0; i < getProject().getFunding().size(); i++) {
calendars.put(calendarId++, getProject().getFunding().get(i).getFunding().getId());
calendars.put(calendarId++, getProject().getFunding().get(i).getFunding().getCalendarId());
calendars.put(calendarId++, getProject().getFunding().get(i).getFunding().getPointsList().getId());
calendars.put(calendarId++, getProject().getFunding().get(i).getFunding().getRemindersList().getId());
}
}
calendarPresenter.reload(calendars);
}

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public Object render(CalendarWrapper model, String property, ColumnData config,

selectionModel = new CheckBoxSelectionModel<CalendarWrapper>();

final ColumnModel calendarColumnModel = new ColumnModel(Arrays.asList(selectionModel.getColumn(), calendarName, calendarColor));
final ColumnModel calendarColumnModel = new ColumnModel(Arrays.asList(calendarColor, calendarName, selectionModel.getColumn()));

calendarsStore = new ListStore<CalendarWrapper>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public Calendar getCalendar(CalendarIdentifier identifier,EntityManager em) {
sb.append(format.format(point.getExpectedDate()));
sb.append(')');
}

event.setDescription(sb.toString());
event.setDescription(sb.toString() + calendarIdentifier.getProjectId());

// Adding the event to the event map
final Date key = event.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public Calendar getCalendar(CalendarIdentifier identifier,EntityManager em) {
sb.append(format.format(reminder.getExpectedDate()));
sb.append(')');
}

event.setDescription(sb.toString());
event.setDescription(sb.toString() + calendarIdentifier.getProjectId());

// Adding the event to the event map
final Date key = event.getKey();
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/sigmah/shared/dto/calendar/CalendarType.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private static enum Color {
BLUE(2),
GREEN(3),
RED(4),
ORANGERelated(7),
BLUERelated(8),
GREENRelated(9),
REDRelated(10),
VIOLET(5),
GRAY(6);

Expand All @@ -76,7 +80,7 @@ private Color(final int colorCode) {
this.colorCode = colorCode;
}
}

/**
* Returns the given {@code type} corresponding {@link CalendarIdentifier} instance for the given {@code id}.
*
Expand All @@ -86,27 +90,28 @@ private Color(final int colorCode) {
* The calendar id.
* @return The {@link CalendarIdentifier} instance.
*/
static int projectId;
public static CalendarIdentifier getIdentifier(final CalendarType type, final Integer id) {

if (type == null) {
throw new IllegalArgumentException("Invalid calendar type.");
}

switch (type) {

case Activity:
projectId = id;
return new ActivityCalendarIdentifier(id, I18N.CONSTANTS.logFrameActivities(), I18N.CONSTANTS.logFrameActivitiesCode());

case Personal:
return new PersonalCalendarIdentifier(id);

case MonitoredPoint:
return new MonitoredPointCalendarIdentifier(id, I18N.CONSTANTS.monitoredPoints(), I18N.CONSTANTS.monitoredPointClosed(),
I18N.CONSTANTS.monitoredPointExpectedDate(), DateUtils.DATE_SHORT.getPattern());
I18N.CONSTANTS.monitoredPointExpectedDate(), DateUtils.DATE_SHORT.getPattern() , projectId);

case Reminder:
return new ReminderCalendarIdentifier(id, I18N.CONSTANTS.reminderPoints(), I18N.CONSTANTS.monitoredPointClosed(),
I18N.CONSTANTS.monitoredPointExpectedDate(), DateUtils.DATE_SHORT.getPattern());
I18N.CONSTANTS.monitoredPointExpectedDate(), DateUtils.DATE_SHORT.getPattern(),projectId);

default:
throw new IllegalArgumentException("Invalid calendar type.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ public class MonitoredPointCalendarIdentifier implements CalendarIdentifier {
private String completedEventString;
private String expectedDateString;
private String dateFormat;
private int projectId;

public MonitoredPointCalendarIdentifier() {
// Serialization.
}

public MonitoredPointCalendarIdentifier(int monitoredListId, String calendarName, String completedEventString, String expectedDateString, String dateFormat) {
public MonitoredPointCalendarIdentifier(int monitoredListId, String calendarName, String completedEventString, String expectedDateString, String dateFormat, int projectId) {
this.monitoredListId = monitoredListId;
this.calendarName = calendarName;
this.completedEventString = completedEventString;
this.expectedDateString = expectedDateString;
this.dateFormat = dateFormat;
this.projectId = projectId;
}

public int getMonitoredListId() {
Expand Down Expand Up @@ -90,6 +92,16 @@ public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}

public int getProjectId() {
return projectId;
}

public void setProjectId(int projectId) {
this.projectId = projectId;
}



/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ public class ReminderCalendarIdentifier implements CalendarIdentifier {
private String completedEventString;
private String expectedDateString;
private String dateFormat;
private int projectId;

public ReminderCalendarIdentifier() {
// Serialization.
}

public ReminderCalendarIdentifier(int reminderListId, String calendarName, String completedEventString, String expectedDateString, String dateFormat) {
public ReminderCalendarIdentifier(int reminderListId, String calendarName, String completedEventString, String expectedDateString, String dateFormat, int projectId) {
this.reminderListId = reminderListId;
this.calendarName = calendarName;
this.completedEventString = completedEventString;
this.expectedDateString = expectedDateString;
this.dateFormat = dateFormat;
this.projectId = projectId;
}

public int getReminderListId() {
Expand Down Expand Up @@ -90,6 +92,16 @@ public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}

public int getProjectId() {
return projectId;
}

public void setProjectId(int projectId) {
this.projectId = projectId;
}



/**
* {@inheritDoc}
*/
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/org/sigmah/public/css/sigmah.css
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ body {font-family:Arial;font-size:8pt}
.calendar-fullday-event-5{background-color:#9643a5}
.calendar-event-6{color:#737373}
.calendar-fullday-event-6{background-color:#737373}
.calendar-event-7{color:#ffcd39}
.calendar-fullday-event-7{background-color:#ffcd39}
.calendar-event-8{color:#2787ff}
.calendar-fullday-event-8{background-color:#2787ff}
.calendar-event-9{color:#c4ff59}
.calendar-fullday-event-9{background-color:#c4ff59}
.calendar-event-10{color:#f23f3f}
.calendar-fullday-event-10{background-color:#f23f3f}
.calendar-event-limit{color:#482A1E;text-align:center;font-weight:700;width:100%;height:16px;display:block;text-decoration:none}
.calendar-event-limit:hover{color:#EE9329}

Expand Down