Skip to content

Commit

Permalink
#633 jsx converter removed, if Scheduled.now() means undefined time p…
Browse files Browse the repository at this point in the history
…aram
  • Loading branch information
ollie64 committed Sep 24, 2015
1 parent c48730e commit 21482fb
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 307 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ javadoc-tmp/
**/.settings
**/.DS_Store
**/bower_components/
**/node_modules/
35 changes: 19 additions & 16 deletions celos-ui/src/main/java/com/collective/celos/ui/ReactServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import j2html.tags.Tag;
import org.eclipse.jetty.util.UrlEncoded;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -62,7 +61,6 @@ protected static class MainUI {

protected static class WorkflowGroupRef {
public String name;
public String url;
}

protected static class WorkflowGroupPOJO {
Expand Down Expand Up @@ -112,12 +110,17 @@ protected static class NavigationPOJO {

private static final int PAGE_SIZE = 20;

private static NavigationPOJO makeNavigationButtons(ScheduledTime shift, int zoom) throws IOException {
private static NavigationPOJO makeNavigationButtons(ScheduledTime shift, int zoom, ScheduledTime now) throws IOException {
NavigationPOJO result = new NavigationPOJO();
// makePaginationButtons
result.left = shift.minusMinutes(PAGE_SIZE * zoom).toString();
// right link
result.right = shift.plusMinutes(PAGE_SIZE * zoom).toString();
final ScheduledTime tmp = shift.plusMinutes(PAGE_SIZE * zoom);
if (tmp.compareTo(now) >= 0) {
result.right = null;
} else {
result.right = tmp.toString();
}
// makeZoomButtons
final int last = ZOOM_LEVEL_MINUTES.length - 1;
final int pos = Math.abs(Arrays.binarySearch(ZOOM_LEVEL_MINUTES, zoom));
Expand All @@ -128,7 +131,8 @@ private static NavigationPOJO makeNavigationButtons(ScheduledTime shift, int zoo
return result;
}

protected WorkflowGroupPOJO processWorkflowGroup(UIConfiguration conf, String name, HttpServletResponse response, List<WorkflowID> ids) throws IOException {
protected WorkflowGroupPOJO processWorkflowGroup(UIConfiguration conf, String name, HttpServletResponse response,
List<WorkflowID> ids) throws IOException {

final WorkflowGroupPOJO group = new WorkflowGroupPOJO();
group.name = name;
Expand Down Expand Up @@ -158,17 +162,15 @@ protected WorkflowGroupPOJO processWorkflowGroup(UIConfiguration conf, String na
return group;
}

protected MainUI processMain(List<WorkflowGroup> groups, ScheduledTime shift, int zoom) throws IOException {
protected MainUI processMain(List<WorkflowGroup> groups, ScheduledTime shift,
int zoom, ScheduledTime now) throws IOException {
final MainUI result = new MainUI();
result.currentTime = FULL_FORMAT.print(DateTime.now()) + " UTC";
result.navigation = makeNavigationButtons(shift, zoom);
result.currentTime = FULL_FORMAT.print(now.getDateTime()) + " UTC";
result.navigation = makeNavigationButtons(shift, zoom, now);
result.rows = new ArrayList<>();
for (WorkflowGroup g : groups) {
final WorkflowGroupRef group = new WorkflowGroupRef();
group.name = g.getName();
final UrlEncoded url = new UrlEncoded();
url.put("group", g.getName());
group.url = "/react?" + url.encode();
result.rows.add(group);
}
return result;
Expand All @@ -192,7 +194,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws Ser
res.setStatus(HttpServletResponse.SC_OK);

CelosClient client = new CelosClient(celosURL.toURI());
ScheduledTime timeShift = getDisplayTime(req.getParameter(TIME_PARAM));
final ScheduledTime now = ScheduledTime.now();
ScheduledTime timeShift = getDisplayTime(req.getParameter(TIME_PARAM), now);
int zoomLevelMinutes = getZoomLevel(req.getParameter(ZOOM_PARAM));
NavigableSet<ScheduledTime> tileTimes = getTileTimesSet(getFirstTileTime(timeShift, zoomLevelMinutes), zoomLevelMinutes, MAX_MINUTES_TO_FETCH, MAX_TILES_TO_DISPLAY);
ScheduledTime start = tileTimes.first();
Expand Down Expand Up @@ -230,7 +233,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws Ser

} else {

final MainUI mainUI = processMain(groups, timeShift, zoomLevelMinutes);
final MainUI mainUI = processMain(groups, timeShift, zoomLevelMinutes, now);

writer.writeValue(res.getOutputStream(), mainUI);
}
Expand All @@ -239,15 +242,15 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws Ser
}
}

static ScheduledTime getDisplayTime(String timeStr) {
static ScheduledTime getDisplayTime(String timeStr, ScheduledTime now) {
if (timeStr == null || timeStr.isEmpty()) {
return ScheduledTime.now();
return now;
} else {
try {
return new ScheduledTime(java.net.URLDecoder.decode(timeStr, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return ScheduledTime.now();
return now;
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions celos-ui/src/main/webapp/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
<!-- JavaScript files -->
<script src="bower_components/react/react.js"></script>
<script src="bower_components/react/react-dom.js"></script>
<script src="bower_components/react/JSXTransformer.js"></script>
<script src="bower_components/jquery/dist/jquery.js"></script>

<script type="text/jsx;harmony=true" src="js/lib.js"></script>
<script type="text/jsx;harmony=true" src="js/workflows-group.js"></script>
<script type="text/jsx;harmony=true" src="js/app.js"></script>
<script src="js/app.js"></script>

</body>
</html>
Loading

0 comments on commit 21482fb

Please sign in to comment.