Commit 214d8972 authored by dagal's avatar dagal
Browse files

GetXYArea POST request

parent 1a2c3800
package main
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/paulmach/go.geojson"
"time"
......@@ -119,3 +120,25 @@ func GetXY(c *gin.Context) {
"xy": xy,
})
}
type TimeWindow struct {
From int32 `json:"from"`
To int32 `json:"to"`
}
type XYAreaRequest struct {
Time TimeWindow `json:"time"`
StartStops []int32 `json:"start_stops"`
EndStops []int32 `json:"end_stops"`
}
func GetXYArea(c *gin.Context) {
rawRequest, err := c.GetRawData()
LogAndPanic2(err, c)
var data XYAreaRequest
LogAndPanic2(json.Unmarshal(rawRequest, &data), c)
c.JSON(200, gin.H{
"xy": data.StartStops,
})
}
......@@ -44,6 +44,7 @@ func main() {
router.GET("/", ShowIndex)
router.GET("/stop_stats/:id", GetStopStats)
router.GET("/xy", GetXY)
router.POST("/xy_area", GetXYArea)
err := router.Run(":8088")
LogAndQuit(err)
}
......
......@@ -25,6 +25,7 @@
<stop-popup ref="hiddenStopPopup" v-bind:stop="selectedStop"></stop-popup>
<x-y-popup ref="hiddenXYPopup" v-bind:stop-x="startStop" v-bind:stop-y="endStop"></x-y-popup>
<x-y-area-popup ref="hiddenXYAreaPopup"></x-y-area-popup>
</div>
<script src="bundle.js"></script>
......
function simplyGet(url) {
function simplyGet(url, data=null) {
return new Promise(function(resolve, reject) {
let req = new XMLHttpRequest();
req.open('GET', url);
req.open(data ? 'POST' : 'GET', url);
if (data) {
req.setRequestHeader("Content-Type", "application/json")
}
req.onload = function() {
if (req.status == 200) {
......@@ -15,7 +19,7 @@ function simplyGet(url) {
reject(req);
};
req.send();
req.send(data ? JSON.stringify(data) : null);
});
}
......@@ -23,8 +27,8 @@ function errorGet(req) {
console.log("Failed request (" + req.status + "): " + req.response);
}
function jsonGet(url) {
return simplyGet(url).then(function (text) {
function jsonGet(url, data=null) {
return simplyGet(url, data).then(function (text) {
return text;
}).catch(errorGet).then(function (text) {
return JSON.parse(text);
......@@ -76,4 +80,25 @@ function getXY(x, y, fromTime, toTime) {
return jsonGet(url);
}
module.exports = {simplyGet, jsonGet, getStopStats, getXY};
function getXYArea(x, y, fromTime, toTime) {
var url = "/xy_area";
var data = {start_stops: x, end_stops: y};
var time = {};
if (fromTime && fromTime >= 0) {
time["from_time"] = fromTime;
}
if (toTime && toTime >= 0) {
time["to_time"] = toTime;
}
if (time["from_time"] || time["to_time"]) {
data["time"] = time;
}
return jsonGet(url, data)
}
module.exports = {simplyGet, jsonGet, getStopStats, getXY, getXYArea};
......@@ -7,6 +7,7 @@ import Vue from "vue";
import Hello from "./components/Hello.vue";
import StopPopup from "./components/StopPopup.vue";
import XYPopup from "./components/XYPopup.vue";
import XYAreaPopup from "./components/XYAreaPopup.vue";
import DateTimePicker from "./components/DateTimePicker.vue";
import TimeFilter from "./components/TimeFilter.vue";
import StopSearch from "./components/StopSearch.vue";
......@@ -27,7 +28,8 @@ Vue.use(VueRouter);
let app = new Vue({
el: "#app",
router,
components: {LineFilter, StopPopup, XYPopup, DateTimePicker, TimeFilter, StopSearch, Datepicker, PulseLoader, VueTimepicker, Autocomplete},
components: {LineFilter, StopPopup, XYPopup, XYAreaPopup, DateTimePicker, TimeFilter, StopSearch,
Datepicker, PulseLoader, VueTimepicker, Autocomplete},
data: {
minDate: new Date(0),
maxDate: null,
......@@ -145,7 +147,7 @@ let app = new Vue({
if (bounds.contains(marker._latlng)) {
applySelectedMarkerStyle(marker);
selectedIds.push(sid);
selectedIds.push(parseInt(sid, 10));
}
});
......@@ -154,7 +156,9 @@ let app = new Vue({
let [arrow, arrowDecorator] = this.makeArrow(this.selectedBounds.getCenter(), bounds.getCenter());
arrow.bindPopup(() => {
return "Tomorrow I'll display some stats here :D";
app.$refs.hiddenXYAreaPopup.$props.startStops = this.selectedStops;
app.$refs.hiddenXYAreaPopup.$props.endStops = selectedIds;
return app.$refs.hiddenXYAreaPopup.$el;
}, { maxWidth: "auto" });
setTimeout(() => arrow.openPopup(), 500);
......@@ -325,3 +329,7 @@ Promise.all([stopsPromise, linesPromise]).then(function() {
window.app = app;
window.map = map;
window.testXY = function() {
getty.getXYArea().then(console.log);
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment