Skip to content

Commit

Permalink
Previous/Next page buttons #619
Browse files Browse the repository at this point in the history
  • Loading branch information
ollie64 committed Sep 15, 2015
1 parent 6862a37 commit 16b12cb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/
package com.collective.celos.ui;

import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.NavigableSet;

import com.collective.celos.ScheduledTime;
import com.collective.celos.Util;
import com.collective.celos.WorkflowID;
import com.collective.celos.WorkflowStatus;

import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.NavigableSet;

/**
* All data required by the UI for rendering.
*/
Expand All @@ -36,14 +36,21 @@ public class UIConfiguration {
private final List<WorkflowGroup> groups;
private final Map<WorkflowID, WorkflowStatus> statuses;
private final URL hueURL; // may be null
private final int zoomLevelMinutes;

private final ScheduledTime timeParam;

public UIConfiguration(ScheduledTime start, ScheduledTime end, NavigableSet<ScheduledTime> tileTimes, List<WorkflowGroup> groups, Map<WorkflowID, WorkflowStatus> statuses, URL hueURL) {
public UIConfiguration(ScheduledTime start, ScheduledTime end, NavigableSet<ScheduledTime> tileTimes,
List<WorkflowGroup> groups, Map<WorkflowID, WorkflowStatus> statuses,
URL hueURL, int zoomLevelMinutes, ScheduledTime timeParam) {
this.start = Util.requireNonNull(start);
this.end = Util.requireNonNull(end);
this.tileTimes = Util.requireNonNull(tileTimes);
this.groups = Util.requireNonNull(groups);
this.statuses = Util.requireNonNull(statuses);
this.hueURL = hueURL;
this.zoomLevelMinutes = zoomLevelMinutes;
this.timeParam = timeParam;
}

public ScheduledTime getStart() {
Expand All @@ -70,4 +77,12 @@ public URL getHueURL() {
return hueURL;
}

public int getZoomLevelMinutes() {
return zoomLevelMinutes;
}

public ScheduledTime getTimeParam() {
return timeParam;
}

}
81 changes: 46 additions & 35 deletions celos-ui/src/main/java/com/collective/celos/ui/UIServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,28 @@
*/
package com.collective.celos.ui;

import static j2html.TagCreator.a;
import static j2html.TagCreator.body;
import static j2html.TagCreator.div;
import static j2html.TagCreator.head;
import static j2html.TagCreator.html;
import static j2html.TagCreator.text;
import static j2html.TagCreator.link;
import static j2html.TagCreator.script;
import static j2html.TagCreator.table;
import static j2html.TagCreator.td;
import static j2html.TagCreator.title;
import static j2html.TagCreator.tr;
import static j2html.TagCreator.unsafeHtml;

import com.collective.celos.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import j2html.tags.Tag;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.collective.celos.CelosClient;
import com.collective.celos.ScheduledTime;
import com.collective.celos.SlotState;
import com.collective.celos.Util;
import com.collective.celos.WorkflowID;
import com.collective.celos.WorkflowStatus;
import com.google.common.collect.ImmutableList;
import static j2html.TagCreator.*;

/**
* Renders the UI HTML.
Expand Down Expand Up @@ -99,7 +79,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws Ser
groups = getDefaultGroups(workflowIDs);
}

UIConfiguration conf = new UIConfiguration(start, end, tileTimes, groups, statuses, hueURL);
UIConfiguration conf = new UIConfiguration(start, end, tileTimes, groups, statuses, hueURL, zoomLevelMinutes, end);
res.getWriter().append(render(conf));
} catch (Exception e) {
throw new ServletException(e);
Expand Down Expand Up @@ -161,13 +141,44 @@ static String render(UIConfiguration conf) throws Exception {

private static Tag makeHead() {
return head().with(title("Celos"),
link().withType("text/css").withRel("stylesheet").withHref("/static/style.css"),
script().withType("text/javascript").withSrc("/static/jquery.min.js"),
script().withType("text/javascript").withSrc("/static/script.js"));
link().withType("text/css").withRel("stylesheet").withHref("/static/style.css"),
script().withType("text/javascript").withSrc("/static/jquery.min.js"),
script().withType("text/javascript").withSrc("/static/script.js"));
}

private static Tag makeBody(UIConfiguration conf) {
return body().with(makeTable(conf), div().with(text("(Shift-click a slot to rerun it.)")));
return body()
.with(makeZoomButtons(conf))
.with(makePaginationButtons(conf))
.with(makeTable(conf), div().with(text("(Shift-click a slot to rerun it.)")));
}

private static Tag makePaginationButtons(UIConfiguration conf) {
// in progress
return div();
}

private static Tag makeZoomButtons(UIConfiguration conf) {
List<Tag> contents = new ArrayList<>();
final int pos = Arrays.binarySearch(ZOOM_LEVEL_MINUTES, conf.getZoomLevelMinutes());
String urlPart = "/ui?" + TIME_PARAM + "=" + conf.getTimeParam();
if (pos == 0) {
int left = ZOOM_LEVEL_MINUTES[0];
contents.add(a("Zoom IN").withHref(urlPart + "&" + ZOOM_PARAM + "=" + left));
} else {
int left = ZOOM_LEVEL_MINUTES[pos - 1];
contents.add(a("Zoom IN").withHref(urlPart + "&" + ZOOM_PARAM + "=" + left));
}
contents.add(strong(" / "));
final int last = ZOOM_LEVEL_MINUTES.length - 1;
if (pos == last) {
int right = ZOOM_LEVEL_MINUTES[last];
contents.add(a("Zoom OUT").withHref(urlPart + "&" + ZOOM_PARAM + "=" + right));
} else {
int right = ZOOM_LEVEL_MINUTES[pos + 1];
contents.add(a("Zoom OUT").withHref(urlPart + "&" + ZOOM_PARAM + "=" + right));
}
return div().with(contents).withClass("bigButtons");
}

private static Tag makeTable(UIConfiguration conf) {
Expand Down
1 change: 1 addition & 0 deletions celos-ui/src/main/webapp/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ a { text-decoration: none; }
.SUCCESS { background-color: #cfc; }
.WAITING { background-color: #ccf; }
.FAILURE, .WAIT_TIMEOUT { background-color: #fcc; }
.bigButtons { font-size: large; }
3 changes: 3 additions & 0 deletions scripts/lga2/conf/inventory-ui
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ admin1.lga2.collective-media.net
celos_server_host="admin1.lga2.collective-media.net"
service_name={{ui_service_name}}
service_port={{ui_service_port}}
ui_hue_url="http://admin1.lga2.collective-media.net:8888/oozie"
ui_config_file="/home/obaskakov/config.json"

0 comments on commit 16b12cb

Please sign in to comment.