Skip to content

Commit

Permalink
SAK-28415 - Update SignUp datepicker (sakaiproject#4172)
Browse files Browse the repository at this point in the history
Update SignUp with the new date picker introduced in SAK-23662
  • Loading branch information
Miguel Pellicer authored and ottenhoff committed Apr 14, 2017
1 parent 557011a commit dc9d193
Show file tree
Hide file tree
Showing 11 changed files with 455 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class SignupTimeslot implements Comparable{

private List<SignupAttendee> waitingList;

private String startTimeString;

private String endTimeString;

/**
* ICS VEvent created for this timeslot, not persisted
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.faces.component.UIData;
import javax.faces.component.UIInput;
Expand Down Expand Up @@ -233,6 +234,13 @@ public class NewSignupMeetingBean implements MeetingTypes, SignupMessageTypes, S
/* Used for populate the drop down box for the allowed number of meeting slots */
private List<SelectItem> slots;

private String startTimeString;
private String endTimeString;
private String repeatUntilString;
private static String HIDDEN_ISO_STARTTIME = "startTimeISO8601";
private static String HIDDEN_ISO_ENDTIME = "endTimeISO8601";
private static String HIDDEN_ISO_UNTILTIME = "untilISO8601";

public int getMaxNumOfSlots() {
return maxNumOfSlots;
}
Expand Down Expand Up @@ -381,6 +389,30 @@ public void setRepeatUntil(Date repeatUntil) {
this.repeatUntil = repeatUntil;
}

public String getStartTimeString() {
return startTimeString;
}

public String getEndTimeString() {
return endTimeString;
}

public void setStartTimeString(String startTimeString) {
this.startTimeString = startTimeString;
}

public void setEndTimeString(String endTimeString) {
this.endTimeString = endTimeString;
}

public String getRepeatUntilString() {
return repeatUntilString;
}

public void setRepeatUntilString(String repeatUntilString) {
this.repeatUntilString = repeatUntilString;
}

/** Initialize all the default setting for creating new events. */
private void init() {

Expand Down Expand Up @@ -641,6 +673,26 @@ public void validateNewMeeting(ActionEvent e) {
//set instructor
this.signupMeeting.setCreatorUserId(creatorUserId);

Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

String isoStartTime = params.get(HIDDEN_ISO_STARTTIME);

if(Utilities.isValidISODate(isoStartTime)){
this.signupMeeting.setStartTime(Utilities.parseISODate(isoStartTime));
}

String isoEndTime = params.get(HIDDEN_ISO_ENDTIME);

if(Utilities.isValidISODate(isoEndTime)){
this.signupMeeting.setEndTime(Utilities.parseISODate(isoEndTime));
}

String isoUntilTime = params.get(HIDDEN_ISO_UNTILTIME);

if(Utilities.isValidISODate(isoUntilTime)){
setRepeatUntil(Utilities.parseISODate(isoUntilTime));
}

Date eventEndTime = signupMeeting.getEndTime();
Date eventStartTime = signupMeeting.getStartTime();
/*user defined own TS case*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
Expand Down Expand Up @@ -135,6 +137,13 @@ public class CopyMeetingSignupMBean extends SignupUIBaseBean {
private List<SelectItem> categories = null;
private List<SelectItem> locations=null;

private String startTimeString;
private String endTimeString;
private String repeatUntilString;
private static String HIDDEN_ISO_STARTTIME = "startTimeISO8601";
private static String HIDDEN_ISO_ENDTIME = "endTimeISO8601";
private static String HIDDEN_ISO_UNTILTIME = "untilISO8601";

/**
* this reset information which contains in this UIBean lived in a session
* scope
Expand Down Expand Up @@ -331,6 +340,25 @@ public String processSaveCopy() {
* an ActionEvent object.
*/
public void validateCopyMeeting(ActionEvent e) {
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

String isoStartTime = params.get(HIDDEN_ISO_STARTTIME);

if(Utilities.isValidISODate(isoStartTime)){
this.signupMeeting.setStartTime(Utilities.parseISODate(isoStartTime));
}

String isoEndTime = params.get(HIDDEN_ISO_ENDTIME);

if(Utilities.isValidISODate(isoEndTime)){
this.signupMeeting.setEndTime(Utilities.parseISODate(isoEndTime));
}

String isoUntilTime = params.get(HIDDEN_ISO_UNTILTIME);

if(Utilities.isValidISODate(isoUntilTime)){
setRepeatUntil(Utilities.parseISODate(isoUntilTime));
}
Date eventEndTime = signupMeeting.getEndTime();
Date eventStartTime = signupMeeting.getStartTime();

Expand Down Expand Up @@ -851,6 +879,30 @@ public void setRepeatUntil(Date repeatUntil) {
this.repeatUntil = repeatUntil;
}

public String getStartTimeString() {
return startTimeString;
}

public String getEndTimeString() {
return endTimeString;
}

public void setStartTimeString(String startTimeString) {
this.startTimeString = startTimeString;
}

public void setEndTimeString(String endTimeString) {
this.endTimeString = endTimeString;
}

public String getRepeatUntilString() {
return repeatUntilString;
}

public void setRepeatUntilString(String repeatUntilString) {
this.repeatUntilString = repeatUntilString;
}

public String getRepeatType() {
return repeatType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import javax.faces.context.FacesContext;
Expand Down Expand Up @@ -132,6 +133,11 @@ public class EditMeetingSignupMBean extends SignupUIBaseBean {
private List<SelectItem> categories = null;
private List<SelectItem> locations=null;

private String startTimeString;
private String endTimeString;
private static String HIDDEN_ISO_STARTTIME = "startTimeISO8601";
private static String HIDDEN_ISO_ENDTIME = "endTimeISO8601";

/**
* This method will reset everything to orignal value and also initialize
* the value to the variables in this UIBean, which lives in a session
Expand Down Expand Up @@ -578,6 +584,20 @@ private SignupMeeting reloadMeeting(SignupMeeting meeting) {
*/
public void validateModifyMeeting(ActionEvent e) {

Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

String isoStartTime = params.get(HIDDEN_ISO_STARTTIME);

if(Utilities.isValidISODate(isoStartTime)){
this.signupMeeting.setStartTime(Utilities.parseISODate(isoStartTime));
}

String isoEndTime = params.get(HIDDEN_ISO_ENDTIME);

if(Utilities.isValidISODate(isoEndTime)){
this.signupMeeting.setEndTime(Utilities.parseISODate(isoEndTime));
}

Date eventEndTime = this.signupMeeting.getEndTime();
Date eventStartTime = this.signupMeeting.getStartTime();

Expand Down Expand Up @@ -1119,4 +1139,19 @@ public void setSendEmailByOwner(boolean sendEmailByOwner) {
this.sendEmailByOwner = sendEmailByOwner;
}

public String getStartTimeString() {
return startTimeString;
}

public String getEndTimeString() {
return endTimeString;
}

public void setStartTimeString(String startTimeString) {
this.startTimeString = startTimeString;
}

public void setEndTimeString(String endTimeString) {
this.endTimeString = endTimeString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
Expand Down Expand Up @@ -76,6 +77,9 @@ public class UserDefineTimeslotBean implements SignupBeanConstants {

String errorStyleValue = "background: #EEF3F6;";

private static String HIDDEN_ISO_STARTTIME = "startTimeISO8601";
private static String HIDDEN_ISO_ENDTIME = "endTimeISO8601";

public void init(SignupMeeting sMeeting, String backPageURL,
List<TimeslotWrapper> origTSwrpList, String whoPlaceOrder) {
/* new page and initialize */
Expand Down Expand Up @@ -212,6 +216,8 @@ private TimeslotWrapper deepCopyTimeslotWrapper(TimeslotWrapper copyOne) {
newTs.setId(old.getId());
newTs.setStartTime(old.getStartTime());
newTs.setEndTime(old.getEndTime());
newTs.setStartTimeString(old.getStartTimeString());
newTs.setEndTimeString(old.getEndTimeString());
newTs.setCanceled(old.isCanceled());
newTs.setLocked(old.isLocked());
newTs.setDisplayAttendees(old.isDisplayAttendees());
Expand Down Expand Up @@ -384,6 +390,19 @@ public void validateTimeslots(ActionEvent e) {
if(tsWrp.getDeleted())
continue;//skip

Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

String isoStartTime = params.get((position - 1) + HIDDEN_ISO_STARTTIME);

if(Utilities.isValidISODate(isoStartTime)){
tsWrp.getTimeSlot().setStartTime(Utilities.parseISODate(isoStartTime));
}

String isoEndTime = params.get((position - 1) + HIDDEN_ISO_ENDTIME);

if(Utilities.isValidISODate(isoEndTime)){
tsWrp.getTimeSlot().setEndTime(Utilities.parseISODate(isoEndTime));
}
Date endTime = tsWrp.getTimeSlot().getEndTime();
Date startTime = tsWrp.getTimeSlot().getStartTime();
if (endTime.before(startTime) || endTime.equals(startTime)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@

package org.sakaiproject.signup.tool.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.faces.context.FacesContext;
Expand Down Expand Up @@ -77,6 +85,8 @@ public final class Utilities implements SignupBeanConstants, MeetingTypes {
private static final int TYPE_ERROR=1;
private static final int TYPE_INFO=2;

private static DateTimeFormatter isoFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;

protected static Logger logger = LoggerFactory.getLogger(Utilities.class);

/**
Expand Down Expand Up @@ -527,4 +537,65 @@ public static String getSelectedCoordinators(List<SignupUser> coordinators, Stri
}
return sb.length()<1? null : sb.toString();
}

/**
* Performs date validation checking the ISO_ZONED_DATE_TIME format such as '2011-12-03T10:15:30+01:00[Europe/Paris]'.
*
* @param date
* The candidate String date.
* @return TRUE - Conforms to a valid input date format string.<br>
* FALSE - Does not conform.
*/
public static boolean isValidISODate(final String date) {
try {
isoFormatter.parse(date);
return true;
} catch (Exception e) {
return false;
}
}

/**
* Parse the date string input using the ISO_ZONED_DATE_TIME format such as '2011-12-03T10:15:30+01:00[Europe/Paris]'.
*
* @param inputDate
* The string that needs to be parsed.
*
* @throws DateTimeParseException
* If not a valid date compared to ISO_ZONED_DATE_TIME format
*/
public static Date parseISODate(final String inputDate) throws DateTimeParseException {
Date convertedDate = null;

try {
LocalDateTime ldt = LocalDateTime.parse(inputDate, isoFormatter);
convertedDate = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
} catch (DateTimeParseException e) {
throw new DateTimeParseException (e.getMessage(), inputDate, 0);
}

return convertedDate;
}
/**
* Formats the date input to String using the format given.
*
* @param inputDate
* The date that needs to be formatted.
* @param format
* The given date-time format.
* @param locale
* The given locale.
* @throws ParseException
* If not a valid date compared to ISO_ZONED_DATE_TIME format
*/
public static String format(Date inputDate, String format, Locale locale){
SimpleDateFormat formatter = null;
try {
formatter = new SimpleDateFormat(format, locale);
return formatter.format(inputDate);
} catch(Exception ex) {
formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
return formatter.format(inputDate);
}
}
}
Loading

0 comments on commit dc9d193

Please sign in to comment.