diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/web/client/ArchivePanel.java | 64 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/client/DevicePanel.java | 54 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/client/MapPanel.java | 108 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/client/Traccar.java | 49 | ||||
-rw-r--r-- | src/main/resources/org/traccar/web/Traccar.gwt.xml | 28 | ||||
-rw-r--r-- | src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml | 26 | ||||
-rw-r--r-- | src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages.properties | 2 | ||||
-rw-r--r-- | src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages_fr.properties | 2 | ||||
-rw-r--r-- | src/main/webapp/WEB-INF/jetty-web.xml | 10 | ||||
-rw-r--r-- | src/main/webapp/WEB-INF/web.xml | 33 | ||||
-rw-r--r-- | src/main/webapp/traccar.html | 20 | ||||
-rw-r--r-- | src/test/java/org/traccar/web/client/GwtTestTraccar.java | 75 | ||||
-rw-r--r-- | src/test/realm.properties | 2 | ||||
-rw-r--r-- | src/test/resources/org/traccar/web/TraccarJUnit.gwt.xml | 9 |
14 files changed, 482 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/web/client/ArchivePanel.java b/src/main/java/org/traccar/web/client/ArchivePanel.java new file mode 100644 index 00000000..d8f7ea77 --- /dev/null +++ b/src/main/java/org/traccar/web/client/ArchivePanel.java @@ -0,0 +1,64 @@ +package org.traccar.web.client; + +import com.smartgwt.client.widgets.toolbar.ToolStrip; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.layout.SectionStack; +import com.smartgwt.client.widgets.layout.SectionStackSection; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.DateTimeItem; +import com.smartgwt.client.widgets.toolbar.ToolStripButton; + +/** + * Archive widget + */ +public class ArchivePanel extends SectionStack { + + private ToolStrip toolbar; + private ListGrid list; + + public ArchivePanel() { + SectionStackSection section = new SectionStackSection("Archive"); + section.setCanCollapse(false); + section.setExpanded(true); + + toolbar = new ToolStrip(); + toolbar.setWidth100(); + + SelectItem deviceSelect = new SelectItem("device", "Device"); + //fontItem.setShowTitle(false); + //fontItem.setWidth(120); + toolbar.addFormItem(deviceSelect); + toolbar.addSeparator(); + + DateTimeItem from = new DateTimeItem("from", "From"); + toolbar.addFormItem(from); + toolbar.addSeparator(); + DateTimeItem to = new DateTimeItem("to", "To"); + toolbar.addFormItem(to); + toolbar.addSeparator(); + + ToolStripButton button = new ToolStripButton(); + button.setTitle("Load"); + toolbar.addButton(button); + + list = new ListGrid(); + list.setFields( + new ListGridField("deviceId", "Device Id"), + new ListGridField("time", "Time"), + new ListGridField("valid", "Valid"), + new ListGridField("latitude", "Latitude"), + new ListGridField("longitude", "Longitude"), + new ListGridField("speed", "Speed"), + new ListGridField("course", "Course"), + new ListGridField("power", "Power")); + + list.setCanSort(false); + list.setShowHeaderContextMenu(false); + list.setShowHeaderMenuButton(false); + + section.setItems(toolbar, list); + setSections(section); + } + +} diff --git a/src/main/java/org/traccar/web/client/DevicePanel.java b/src/main/java/org/traccar/web/client/DevicePanel.java new file mode 100644 index 00000000..ba30fefb --- /dev/null +++ b/src/main/java/org/traccar/web/client/DevicePanel.java @@ -0,0 +1,54 @@ +package org.traccar.web.client; + +import com.smartgwt.client.widgets.toolbar.ToolStrip; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.layout.SectionStack; +import com.smartgwt.client.widgets.layout.SectionStackSection; +import com.smartgwt.client.widgets.toolbar.ToolStripButton; + +/** + * Device list widget + */ +public class DevicePanel extends SectionStack { + + private ToolStrip toolbar; + private ListGrid list; + + public DevicePanel() { + SectionStackSection section = new SectionStackSection("Devices"); + section.setCanCollapse(false); + section.setExpanded(true); + + toolbar = new ToolStrip(); + toolbar.setWidth100(); + + ToolStripButton button = new ToolStripButton(); + button.setTitle("Add"); + toolbar.addButton(button); + button = new ToolStripButton(); + button.setTitle("Remove"); + toolbar.addButton(button); + button = new ToolStripButton(); + button.setTitle("Edit"); + toolbar.addButton(button); + toolbar.addFill(); + toolbar.addSeparator(); + button = new ToolStripButton(); + button.setTitle("Settings"); + toolbar.addButton(button); + + list = new ListGrid(); + list.setFields( + new ListGridField("id", "Id"), + new ListGridField("imei", "IMEI")); + + list.setCanSort(false); + list.setShowHeaderContextMenu(false); + list.setShowHeaderMenuButton(false); + + section.setItems(toolbar, list); + setSections(section); + } + +} diff --git a/src/main/java/org/traccar/web/client/MapPanel.java b/src/main/java/org/traccar/web/client/MapPanel.java new file mode 100644 index 00000000..72ed0d3b --- /dev/null +++ b/src/main/java/org/traccar/web/client/MapPanel.java @@ -0,0 +1,108 @@ +package org.traccar.web.client; + +import com.smartgwt.client.widgets.layout.SectionStack; +import com.smartgwt.client.widgets.layout.SectionStackSection; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.WidgetCanvas; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.events.DragResizeStopEvent; +import com.smartgwt.client.widgets.events.DragResizeStopHandler; +import com.smartgwt.client.widgets.events.DrawEvent; +import com.smartgwt.client.widgets.events.DrawHandler; +import com.smartgwt.client.types.Overflow; + +import com.google.gwt.core.client.Scheduler; + +import org.gwtopenmaps.openlayers.client.LonLat; +import org.gwtopenmaps.openlayers.client.Map; +import org.gwtopenmaps.openlayers.client.MapOptions; +import org.gwtopenmaps.openlayers.client.MapWidget; +import org.gwtopenmaps.openlayers.client.Projection; +import org.gwtopenmaps.openlayers.client.control.LayerSwitcher; +import org.gwtopenmaps.openlayers.client.control.OverviewMap; +import org.gwtopenmaps.openlayers.client.control.ScaleLine; +import org.gwtopenmaps.openlayers.client.layer.OSM; + +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Element; + +import com.google.gwt.event.logical.shared.AttachEvent; +import org.gwtopenmaps.openlayers.client.layer.*; + +/** + * Map panel widget + */ +public class MapPanel extends SectionStack { + + private final static int BORDER_SIZE = 1; + + private MapWidget mapWidget; + private WidgetCanvas mapWrapper; + + private MapWidget createMapWidget() { + MapOptions defaultMapOptions = new MapOptions(); + defaultMapOptions.setNumZoomLevels(16); + + MapWidget mapWidget = new MapWidget("100%", "100%", defaultMapOptions); + + // Google layer + /*GoogleV3Options layerOptiond = new GoogleV3Options(); + layerOptiond.setIsBaseLayer(true); + layerOptiond.setType(GoogleV3MapType.G_NORMAL_MAP); + GoogleV3 layer = new GoogleV3("Google", layerOptiond);*/ + + // Open Street Map layer + OSM layer = OSM.Mapnik("Mapnik"); + layer.setIsBaseLayer(true); + + Map map = mapWidget.getMap(); + map.addLayer(layer); + map.addControl(new ScaleLine()); + + // Default center + LonLat lonLat = new LonLat(12.5, 41.9); + lonLat.transform(new Projection("EPSG:4326").getProjectionCode(), map.getProjection()); + map.setCenter(lonLat, 1); + + return mapWidget; + } + + public MapPanel() { + SectionStackSection section = new SectionStackSection("Map"); + section.setCanCollapse(false); + section.setExpanded(true); + + mapWidget = createMapWidget(); + + mapWrapper = new WidgetCanvas(mapWidget); + mapWrapper.setStyleName("defaultBorder"); + mapWrapper.setHeight100(); + mapWrapper.setWidth100(); + + // Map widget size hack + mapWrapper.addDrawHandler(new DrawHandler() { + @Override + public void onDraw(DrawEvent event) { + Element e = DOM.getElementById(mapWrapper.getID() + "_widget"); + if (e.getParentNode() != null) { + e.getParentElement().getStyle().setProperty("width", "100%"); + e.getParentElement().getStyle().setProperty("height", "100%"); + } + } + }); + + // Map resize handler + mapWrapper.addResizedHandler(new ResizedHandler() { + @Override + public void onResized(ResizedEvent event) { + mapWidget.getMap().updateSize(); + } + }); + + section.setItems(mapWrapper); + setSections(section); + } + +} diff --git a/src/main/java/org/traccar/web/client/Traccar.java b/src/main/java/org/traccar/web/client/Traccar.java new file mode 100644 index 00000000..6c8cdf18 --- /dev/null +++ b/src/main/java/org/traccar/web/client/Traccar.java @@ -0,0 +1,49 @@ +package org.traccar.web.client; + +import com.google.gwt.core.client.EntryPoint; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +/** + * Entry point class + */ +public class Traccar implements EntryPoint { + + private DevicePanel devicePanel; + private ArchivePanel archivePanel; + private MapPanel mapPanel; + + /** + * Entry point method + */ + public void onModuleLoad() { + + devicePanel = new DevicePanel(); + devicePanel.setWidth("20%"); + devicePanel.setShowResizeBar(true); + + mapPanel = new MapPanel(); + mapPanel.setWidth("80%"); + + HLayout hLayout = new HLayout(); + hLayout.setHeight("70%"); + hLayout.addMember(devicePanel); + hLayout.addMember(mapPanel); + hLayout.setShowResizeBar(true); + hLayout.setResizeBarTarget("next"); + + archivePanel = new ArchivePanel(); + archivePanel.setHeight("30%"); + + VLayout mainLayout = new VLayout(); + mainLayout.setWidth100(); + mainLayout.setHeight100(); + mainLayout.addMember(hLayout); + mainLayout.addMember(archivePanel); + mainLayout.draw(); + } +} diff --git a/src/main/resources/org/traccar/web/Traccar.gwt.xml b/src/main/resources/org/traccar/web/Traccar.gwt.xml new file mode 100644 index 00000000..086d2a48 --- /dev/null +++ b/src/main/resources/org/traccar/web/Traccar.gwt.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module rename-to='Traccar'> + <!-- Inherit the core Web Toolkit stuff. --> + <inherits name='com.google.gwt.user.User' /> + + <!-- We need the JUnit module in the main module, --> + <!-- otherwise eclipse complains (Google plugin bug?) --> + <inherits name='com.google.gwt.junit.JUnit' /> + + <!-- Inherit the default GWT style sheet. You can change --> + <!-- the theme of your GWT application by uncommenting --> + <!-- any one of the following lines. --> + <!-- <inherits name='com.google.gwt.user.theme.standard.Standard' /> --> + <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --> + <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> --> + + <!-- Other module inherits --> + <inherits name='com.smartgwt.SmartGwt' /> + <inherits name='org.gwtopenmaps.openlayers.OpenLayers' /> + + <!-- Specify the app entry point class. --> + <entry-point class='org.traccar.web.client.Traccar' /> + + <!-- Specify the paths for translatable code --> + <source path='client' /> + <source path='shared' /> + +</module> diff --git a/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml b/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml new file mode 100644 index 00000000..ff123394 --- /dev/null +++ b/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module rename-to='Traccar'> + <!-- Inherit the core Web Toolkit stuff. --> + <inherits name='com.google.gwt.user.User' /> + + <!-- We need the JUnit module in the main module, --> + <!-- otherwise eclipse complains (Google plugin bug?) --> + <inherits name='com.google.gwt.junit.JUnit' /> + + <!-- Inherit the default GWT style sheet. You can change --> + <!-- the theme of your GWT application by uncommenting --> + <!-- any one of the following lines. --> + <inherits name='com.google.gwt.user.theme.standard.Standard' /> + <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --> + <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> --> + + <!-- Other module inherits --> + + <!-- Specify the app entry point class. --> + <entry-point class='org.traccar.web.client.Traccar' /> + + <!-- Specify the paths for translatable code --> + <source path='client' /> + <source path='shared' /> + +</module> diff --git a/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages.properties b/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages.properties new file mode 100644 index 00000000..c222555b --- /dev/null +++ b/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages.properties @@ -0,0 +1,2 @@ +sendButton = Send +nameField = Enter your name
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages_fr.properties b/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages_fr.properties new file mode 100644 index 00000000..b4a76270 --- /dev/null +++ b/src/main/webapp/WEB-INF/classes/org/traccar/web/client/Messages_fr.properties @@ -0,0 +1,2 @@ +sendButton = Envoyer +nameField = Entrez votre nom
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jetty-web.xml b/src/main/webapp/WEB-INF/jetty-web.xml new file mode 100644 index 00000000..f959e1b3 --- /dev/null +++ b/src/main/webapp/WEB-INF/jetty-web.xml @@ -0,0 +1,10 @@ +<Configure class="org.mortbay.jetty.webapp.WebAppContext"> + <Get name="securityHandler"> + <Set name="userRealm"> + <New class="org.mortbay.jetty.security.HashUserRealm"> + <Set name="name">Test Realm</Set> + <Set name="config"><SystemProperty name="jetty.home" default="."/>/src/test/realm.properties</Set> + </New> + </Set> + </Get> +</Configure> diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..81fa375a --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE web-app + PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd"> + +<web-app> + + <!--<security-role> + <role-name>admin</role-name> + </security-role> + <security-role> + <role-name>user</role-name> + <security-role>--> + + <!--<security-constraint> + <web-resource-collection> + <url-pattern>/*</url-pattern> + </web-resource-collection> + <auth-constraint> + <role-name>admin</role-name> + <role-name>user</role-name> + </auth-constraint> + </security-constraint> + + <login-config> + <auth-method>BASIC</auth-method> + </login-config>--> + + <welcome-file-list> + <welcome-file>traccar.html</welcome-file> + </welcome-file-list> + +</web-app> diff --git a/src/main/webapp/traccar.html b/src/main/webapp/traccar.html new file mode 100644 index 00000000..0bac1a44 --- /dev/null +++ b/src/main/webapp/traccar.html @@ -0,0 +1,20 @@ +<!doctype html> +<html> + <head> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"> + <title>Traccar</title> + <!--<script src="http://openlayers.org/api/2.11/OpenLayers.js"></script>--> + <script src="http://www.openlayers.org/api/OpenLayers.js"></script> + <script src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script> + <!--<script src="http://maps.google.com/maps/api/js?v=3&sensor=false"></script>--> + <script type="text/javascript" language="javascript" src="Traccar/Traccar.nocache.js"></script> + </head> + <body> + <noscript> + <div> + Your web browser must have JavaScript enabled + in order for this application to display correctly. + </div> + </noscript> + </body> +</html> diff --git a/src/test/java/org/traccar/web/client/GwtTestTraccar.java b/src/test/java/org/traccar/web/client/GwtTestTraccar.java new file mode 100644 index 00000000..2c6a4454 --- /dev/null +++ b/src/test/java/org/traccar/web/client/GwtTestTraccar.java @@ -0,0 +1,75 @@ +package org.traccar.web.client; + +import org.traccar.web.shared.FieldVerifier; +import com.google.gwt.core.client.GWT; +import com.google.gwt.junit.client.GWTTestCase; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.rpc.ServiceDefTarget; + +/** + * GWT JUnit <b>integration</b> tests must extend GWTTestCase. + * Using <code>"GwtTest*"</code> naming pattern exclude them from running with + * surefire during the test phase. + * + * If you run the tests using the Maven command line, you will have to + * navigate with your browser to a specific url given by Maven. + * See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html + * for details. + */ +public class GwtTestTraccar extends GWTTestCase { + + /** + * Must refer to a valid module that sources this class. + */ + public String getModuleName() { + return "org.traccar.web.TraccarJUnit"; + } + + /** + * Tests the FieldVerifier. + */ + public void testFieldVerifier() { + assertFalse(FieldVerifier.isValidName(null)); + assertFalse(FieldVerifier.isValidName("")); + assertFalse(FieldVerifier.isValidName("a")); + assertFalse(FieldVerifier.isValidName("ab")); + assertFalse(FieldVerifier.isValidName("abc")); + assertTrue(FieldVerifier.isValidName("abcd")); + } + + /** + * This test will send a request to the server using the greetServer method in + * GreetingService and verify the response. + */ + public void testGreetingService() { + // Create the service that we will test. + GreetingServiceAsync greetingService = GWT.create(GreetingService.class); + ServiceDefTarget target = (ServiceDefTarget) greetingService; + target.setServiceEntryPoint(GWT.getModuleBaseURL() + "Traccar/greet"); + + // Since RPC calls are asynchronous, we will need to wait for a response + // after this test method returns. This line tells the test runner to wait + // up to 10 seconds before timing out. + delayTestFinish(10000); + + // Send a request to the server. + greetingService.greetServer("GWT User", new AsyncCallback<String>() { + public void onFailure(Throwable caught) { + // The request resulted in an unexpected error. + fail("Request failure: " + caught.getMessage()); + } + + public void onSuccess(String result) { + // Verify that the response is correct. + assertTrue(result.startsWith("Hello, GWT User!")); + + // Now that we have received a response, we need to tell the test runner + // that the test is complete. You must call finishTest() after an + // asynchronous test finishes successfully, or the test will time out. + finishTest(); + } + }); + } + + +} diff --git a/src/test/realm.properties b/src/test/realm.properties new file mode 100644 index 00000000..9a068c7f --- /dev/null +++ b/src/test/realm.properties @@ -0,0 +1,2 @@ +admin: admin,admin +user: user,user diff --git a/src/test/resources/org/traccar/web/TraccarJUnit.gwt.xml b/src/test/resources/org/traccar/web/TraccarJUnit.gwt.xml new file mode 100644 index 00000000..4c957890 --- /dev/null +++ b/src/test/resources/org/traccar/web/TraccarJUnit.gwt.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module> + <!-- Inherit our applications main module. --> + <inherits name='org.traccar.web.Traccar' /> + + <!-- Specify the path to any remote services. --> + <servlet path="/Traccar/greet" class="org.traccar.web.server.GreetingServiceImpl" /> + +</module> |