Commit 863f8f35 by Tuukka Kivilahti

Merge branch 'timelapse2' into 'master'

Add ui for viewing timelapse maps



See merge request !360
2 parents eb3e2291 ac7042e7
......@@ -308,6 +308,7 @@ public class MenuBean implements MenuBeanLocal {
mapnavi.addPage(menuitemfacade.findOrCreate("/map/list"), MapPermission.MANAGE_MAPS);
mapnavi.addPage(menuitemfacade.findOrCreate("/map/create"), MapPermission.MANAGE_MAPS);
mapnavi.addPage(menuitemfacade.findOrCreate("/map/edit"), null).setVisible(false);
mapnavi.addPage(menuitemfacade.findOrCreate("/map/timelapse"), null).setVisible(false);
mapnavi.addPage(menuitemfacade.findOrCreate("/neomap/quemgmt"), null).setVisible(false);
// event
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:map="http://java.sun.com/jsf/composite/cditools/map"
xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="mapId" value="#{timelapseMapView.mapId}"/>
<f:event type="preRenderView" listener="#{timelapseMapView.init}"/>
</f:metadata>
<ui:define name="content">
<script type="text/javascript">
//<![CDATA[
var datetimeFormat = '#{sessionHandler.datetimeFormat}';
var firstTime = new Date(#{timelapseMapView.firstTime.time});
var lastTime = new Date(#{timelapseMapView.lastTime.time});
var varDiff = #{timelapseMapView.lastTime.time - timelapseMapView.firstTime.time};
var imgurl = "#{request.contextPath}/PlaceMap?mapid=#{timelapseMapView.mapId}&timestamp=";
function changeStamp(i) {
var ts = $('#timestamp');
setStamp(parseInt(ts.val()) + parseInt(i));
}
function updateTsDate() {
var d = new Date(getTimelapseStamp());
var tsDate = $('#timelapseDate');
tsDate.val(d.toJSON());
reloadImage();
}
function reloadImage() {
var img = $('#tsimage');
img.attr('src', imgurl + getTimelapseStamp());
}
function getTimelapseStamp() {
var ret = firstTime.getTime() + getOffsetMs();
if (ret > lastTime.getTime()) {
ret = lastTime.getTime()
} else if (ret < firstTime.getTime()) {
ret = firstTime.getTime();
}
return ret;
}
function setStamp(stamp){
$('#timestamp').val(stamp);
updateTsDate();
PF('slider').setValue(stamp);
}
function getOffsetMs() {
return parseInt($('#timestamp').val())*1000;
}
function loadDateString(entry) {
console.log(entry);
var d = new Date($('#timelapseDate').val());
var ts = $('#timestamp').val(d.getTime());
updateTsDate();
}
$().ready(function () {
$('#TimelapseDate').val(firstTime.toJSON());
updateTsDate();
});
//]]>
</script>
<div>
<h:outputText value="#{i18n['map.timelapse.startTime']}" />
<h:outputText value="#{timelapseMapView.firstTime}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}"
timeZone="#{sessionHandler.timezone}"/>
</h:outputText></div>
<div>
<h:outputText value="#{i18n['map.timelapse.endTime']}" />
<h:outputText value="#{timelapseMapView.lastTime}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}"
timeZone="#{sessionHandler.timezone}"/>
</h:outputText>
</div>
<div>
<button onclick="setStamp(0)">&lt;-</button>
<button onclick="changeStamp(-604800)">-7d</button>
<button onclick="changeStamp(-86400)">-1d</button>
<button onclick="changeStamp(-21600)">-6h</button>
<button onclick="changeStamp(-300)">-5min</button>
<input id="timelapseDate" onchange="loadDateString(this);" type="text"/>
<button onclick="changeStamp(300)">+5min</button>
<button onclick="changeStamp(21600)">+6h</button>
<button onclick="changeStamp(86400)">+1d</button>
<button onclick="changeStamp(604800)">+7d</button>
<button onclick="setStamp(#{(timelapseMapView.lastTime.time - timelapseMapView.firstTime.time)/1000})">-&gt;</button>
</div>
<h:inputText id="timestamp" value="#{timelapseMapView.timestampValue}"/>
<p:slider widgetVar="slider" style="width: 200px;" for="timestamp" onSlideEnd="updateTsDate()"
maxValue="#{(timelapseMapView.lastTime.time - timelapseMapView.firstTime.time)/1000}"/>
<img id="tsimage" alt="Timelapse image"
src="#{request.contextPath}/PlaceMap?mapid=#{timelapseMapView.mapId}&amp;timestamp=#{timelapseMapView.firstTime.time}"/>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -33,6 +33,11 @@
</h:link>
</h:column>
<h:column>
<h:link value="#{i18n['map.timelapse']}" outcome="/map/timelapse">
<f:param name="mapId" value="#{map.id}" />
</h:link>
</h:column>
<h:column>
<h:link value="#{i18n['map.showQueue']}" outcome="/neomap/quemgmt">
<f:param name="mapId" value="#{map.id}" />
</h:link>
......
......@@ -87,6 +87,7 @@ public class PlaceMapServlet extends HttpServlet {
private static final String PARAMETER_USER_ID = "userid";
private static final String PARAMETER_TOKEN = "token";
private static final String PARAMETER_DATE = "date";
private static final String PARAMETER_TIMESTAMP = "timestamp";
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
......@@ -105,11 +106,17 @@ public class PlaceMapServlet extends HttpServlet {
// PrintWriter out = response.getWriter();
ServletOutputStream ostream = null;
try {
// Integer placeId = getIntegerParameter(request,
// PARAMETER_SELECTED_PLACE_ID);
Integer mapId = getIntegerParameter(request, PARAMETER_EVENT_MAP_ID);
Long timelapseTs = getLongParameter(request, PARAMETER_TIMESTAMP);
String timelapseDate = request.getParameter(PARAMETER_DATE);
Date date = null;
if (timelapseTs != null) {
date = new Date(timelapseTs);
} else if (timelapseDate != null) {
date = ISODateTimeFormat.dateTime().parseDateTime(timelapseDate).toDate();
}
EventMap map = placeBean.findMap(mapId);
logger.debug("Mapid: {}", mapId);
......@@ -130,8 +137,9 @@ public class PlaceMapServlet extends HttpServlet {
response.setContentType(map.getMimeType());
if (timelapseDate == null || timelapseDate.trim().isEmpty()) {
if (date != null) {
printTimelapseToStream(ostream, type, map, date);
} else {
Integer userId = getIntegerParameter(request, PARAMETER_USER_ID);
String userToken = request.getParameter(PARAMETER_TOKEN);
......@@ -152,9 +160,6 @@ public class PlaceMapServlet extends HttpServlet {
printPlaceMapToStream(ostream, type, map, user);
} else {
Date date = ISODateTimeFormat.dateTime().parseDateTime(timelapseDate).toDate();
printTimelapseToStream(ostream, type, map, date );
}
ostream.flush();
......@@ -222,6 +227,15 @@ public class PlaceMapServlet extends HttpServlet {
}
return null;
}
private static Long getLongParameter(HttpServletRequest request, String parameter) {
try {
String valueString = request.getParameter(parameter);
Long value = Long.parseLong(valueString);
return value;
} catch (NumberFormatException nfe) {
}
return null;
}
// <editor-fold defaultstate="collapsed"
// desc="HttpServlet methods. Click on the + sign on the left to edit the
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.web.cdiview.map;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import org.joda.time.format.ISODateTimeFormat;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@Named
@RequestScoped
public class TimelapseMapView extends GenericCDIView {
public static final String JSON_DATETIME = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
@EJB
private transient PlaceBeanLocal placebean;
@EJB
private PermissionBeanLocal permbean;
private Integer mapId;
private Long timestampValue = 0L;
private Date firstTime;
private Date lastTime;
public void init() {
if(!super.requirePermissions(MapPermission.MANAGE_MAPS)){
return;
}
EventMap map = placebean.findMap(mapId);
firstTime = new Date();
lastTime = firstTime;
for (Place p : map.getPlaces()) {
if (p.getReserverSlot() != null) {
Date slotUsed = p.getReserverSlot().getUsed();
if (firstTime == null || firstTime.after(slotUsed)) {
// Really, object check, not equals
if (firstTime == lastTime) {
lastTime = slotUsed;
}
firstTime = slotUsed;
}
if (lastTime == null || lastTime.before(slotUsed)) {
lastTime = slotUsed;
}
}
}
}
public Integer getMapId() {
return mapId;
}
public void setMapId(Integer mapId) {
this.mapId = mapId;
}
public Date getFirstTime() {
return firstTime;
}
public void setFirstTime(Date firstTime) {
this.firstTime = firstTime;
}
public Date getLastTime() {
return lastTime;
}
public void setLastTime(Date lastTime) {
this.lastTime = lastTime;
}
public String getFirstTimeIso() {
DateFormat df = new SimpleDateFormat(JSON_DATETIME);
return df.format(firstTime);
}
public String getLastTimeIso() {
DateFormat df = new SimpleDateFormat(JSON_DATETIME);
return df.format(lastTime);
}
public Long getTimestampValue() {
return timestampValue;
}
public void setTimestampValue(Long timestampValue) {
this.timestampValue = timestampValue;
}
}
......@@ -755,6 +755,9 @@ map.tableCount = Table count
map.tableXdiff = Table start difference (X)
map.tableYdiff = Table start difference (Y)
map.tablesHorizontal = Generate horizontal tables
map.timelapse = Timelapse
map.timelapse.startTime = Start time
map.timelapse.endTime = End time
map.width = Place width (px)
mapEdit.removePlaces = Remove ALL places
......
......@@ -758,6 +758,9 @@ map.tableCount = P\u00F6ytien lukum\u00E4\u00E4r\u00E4
map.tableXdiff = P\u00F6ytien aloituspisteiden erotus (X)
map.tableYdiff = P\u00F6ytien aloituspisteiden erotus (Y)
map.tablesHorizontal = P\u00F6yd\u00E4t vaakatasossa
map.timelapse = Timelapse
map.timelapse.startTime = Aloitusaika
map.timelapse.endTime = Lopetusaika
map.width = Leveys (px)
mapEdit.removePlaces = Poista kaikki paikat
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!