Commit 1d5c9f10 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

adjustments for STWkit and osload url

parent b2a844f6
......@@ -20,6 +20,7 @@
"uikit-stw": "https://git.smhi.se/stw/uikit-stw.git",
"reqwest": "latest",
"moment": "latest",
"stwkit": "https://git.smhi.se/stw/stwkit.git",
"ion.rangeSlider": "latest",
"leaflet-container-control": "https://git.smhi.se/stw/leaflet-container-control.git",
"leaflet-coordinates-control": "https://git.smhi.se/stw/leaflet-coordinates-control.git",
......
......@@ -45,6 +45,7 @@
<script src="../bower_components/uikit-stw/js/components/accordion.min.js"></script>
<script src="../bower_components/reqwest/reqwest.js"></script>
<script src="../bower_components/moment/moment.js"></script>
<script src="../bower_components/stwkit/src/stwkit.js"></script>
<script src="../bower_components/ion.rangeSlider/js/ion.rangeSlider.min.js"></script>
<script src="../bower_components/leaflet-container-control/dist/leaflet-container-control.js"></script>
<script src="../bower_components/jquery.inputmask/dist/jquery.inputmask.bundle.js"></script>
......@@ -149,7 +150,7 @@
};
reqwest({
url: "forcing/config" + jsonToQueryString(forcing),
url: "forcing/config" + STWkit.jsonToQueryString(forcing),
method: 'get',
type: 'json',
success: function (forcing) {
......@@ -161,39 +162,6 @@
var oilspill = new L.Control.OilSpill(osproperties);
containerControl.addComponent("Continuous Oil spill", oilspill);
function getURLParams(param) {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
var urlParams = [];
while (match = search.exec(query)) {
if (param == decode(match[1])) {
urlParams.push();
urlParams[urlParams.length] = decode(match[2]);
} else {
urlParams.push();
urlParams[urlParams.length] = [decode(match[1]), decode(match[2])];
}
}
return urlParams;
};
// // Test card:populateData event.
// reqwest({
// url: "input",
// method: 'get',
// type: 'json',
// success: function (inputjson) {
// var cardevt = document.createEvent("CustomEvent");
// cardevt.initCustomEvent('card:populateData', false, false, {
// 'geojson' : inputjson
// });
// window.dispatchEvent(cardevt);
// }
// });
}
});
......
......@@ -15,7 +15,7 @@ var url = '/demo'
require('../bower_components/leaflet-forcing-boundary/src/routes/forcingboundary')(url,app);
app.get('/demo/input', function (req, res) {
app.get('/demo/input/785b50c5-4804-462d-8a24-1dc2c9fd14f8', function (req, res) {
res.send(
{
"type": "FeatureCollection",
......
This diff is collapsed.
declare function introJs() : any;
\ No newline at end of file
declare var STWkit : any;
\ No newline at end of file
......@@ -727,16 +727,18 @@ var OSType = (function (_super) {
var evt = document.createEvent('Event');
evt.initEvent("change", true, true);
var simulation = geojson.features[0].properties.simulation;
if (simulation.oilclass == 'Oil classes') {
document.getElementById('osOilClassTab').click();
self.selectOilClass.value = simulation.substance;
self.selectOilClass.dispatchEvent(evt);
}
if (simulation.oilclass == 'Oil, specific') {
document.getElementById('osOilSpecificTab').click();
self.selectOilSpecific.value = simulation.substance;
self.selectOilSpecific.dispatchEvent(evt);
}
UIkit.ready(function () {
if (simulation.oilclass == 'Oil classes') {
document.getElementById('osOilClassTab').click();
self.selectOilClass.value = simulation.substance;
self.selectOilClass.dispatchEvent(evt);
}
if (simulation.oilclass == 'Oil, specific') {
document.getElementById('osOilSpecificTab').click();
self.selectOilSpecific.value = simulation.substance;
self.selectOilSpecific.dispatchEvent(evt);
}
});
};
OSType.prototype.populateData = function (geojson) {
var self = this;
......
This diff is collapsed.
......@@ -799,18 +799,20 @@ class OSType extends OilSpillCard {
var evt = document.createEvent('Event');
evt.initEvent("change", true, true);
var simulation = geojson.features[0].properties.simulation;
if (simulation.oilclass == 'Oil classes') {
document.getElementById('osOilClassTab').click();
self.selectOilClass.value = simulation.substance;
self.selectOilClass.dispatchEvent(evt);
}
if (simulation.oilclass == 'Oil, specific') {
document.getElementById('osOilSpecificTab').click();
self.selectOilSpecific.value = simulation.substance;
self.selectOilSpecific.dispatchEvent(evt);
}
UIkit.ready(function () {
if (simulation.oilclass == 'Oil classes') {
document.getElementById('osOilClassTab').click();
self.selectOilClass.value = simulation.substance;
self.selectOilClass.dispatchEvent(evt);
}
if (simulation.oilclass == 'Oil, specific') {
document.getElementById('osOilSpecificTab').click();
self.selectOilSpecific.value = simulation.substance;
self.selectOilSpecific.dispatchEvent(evt);
}
});
}
......
/// <reference path="def/uikit.d.ts" />
/// <reference path="def/leaflet.d.ts" />
/// <reference path="def/moment.d.ts" />
/// <reference path="def/introJs.d.ts" />
/// <reference path="def/stwkit.d.ts" />
/// <reference path="def/reqwest.d.ts" />
/// <reference path="leaflet-oilspill-cards.ts" />
var __extends = (this && this.__extends) || (function () {
......@@ -261,6 +263,8 @@ var L;
card.populateData(geojson);
}
}
if (self.id)
geojson["features"][0]["properties"]["uuid"] = self.id;
geojson["features"][0]["properties"]["simulation"]["uncertainty"] = false;
if (self.uncertaintyInput.checked)
geojson["features"][0]["properties"]["simulation"]["uncertainty"] = true;
......@@ -276,15 +280,9 @@ var L;
self.warningMsg("Login", "You need to login to use this function.");
},
success: function (location) {
var param = self.getURLParams();
var param = STWkit.getURLParams();
param.push(['id', location.id]);
if (self.hasParam('guide', 'os', param))
self.replaceParam('guide', 'player', param);
var search = self.getSearchUrl(param);
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + search;
window.history.pushState({ path: newurl }, '', newurl);
}
STWkit.updateUrl(param);
self.clear();
var showevt = document.createEvent("CustomEvent");
showevt.initCustomEvent('container:showComponent', false, false, {
......@@ -307,72 +305,35 @@ var L;
var id = c[0].id;
self.openCard(id, open);
});
});
};
OilSpill.prototype.getParamIndex = function (name, id, params) {
for (var i = 0; i < params.length; i++) {
if ((params[i][0] == name) && (params[i][1] == id))
return i;
}
return -1;
};
OilSpill.prototype.getSearchUrl = function (params) {
var search = "";
if (params.length > 0)
search += "?";
for (var i = 0; i < params.length; i++) {
search += params[i][0] + '=' + params[i][1];
if (i < params.length - 1)
search += '&';
}
return search;
};
OilSpill.prototype.hasParam = function (name, id, params) {
for (var i = 0; i < params.length; i++) {
if ((params[i][0] == name) && (params[i][1] == id))
return true;
}
return false;
};
OilSpill.prototype.deleteParam = function (name, params) {
for (var i = 0; i < params.length; i++) {
if (params[i][0] == name)
params.splice(i, 1);
;
}
};
OilSpill.prototype.replaceParam = function (name, newid, params) {
for (var i = 0; i < params.length; i++) {
if (params[i][0] == name)
params[i][1] = newid;
}
};
OilSpill.prototype.getURLParams = function (param) {
var match, pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g, decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, query = window.location.search.substring(1);
var urlParams = [];
while (match = search.exec(query)) {
if (param == decode(match[1])) {
urlParams.push();
urlParams[urlParams.length] = decode(match[2]);
}
else {
urlParams.push();
urlParams[urlParams.length] = [decode(match[1]), decode(match[2])];
var param = STWkit.getURLParams();
var osload = STWkit.getParamValue('osload', param);
if (osload !== null) {
reqwest({
url: "input/" + osload,
method: 'get',
type: 'json',
success: function (inputjson) {
var cardevt = document.createEvent("CustomEvent");
cardevt.initCustomEvent('card:populateData', false, false, {
'geojson': inputjson
});
window.dispatchEvent(cardevt);
STWkit.deleteParam('osload', param);
STWkit.updateUrl(param);
}
});
}
}
return urlParams;
});
};
;
OilSpill.prototype.ready = function (name) {
var self = this;
self.compname = name;
var p = self.getURLParams();
var pindex = self.getParamIndex('os', 1, p);
var p = STWkit.getURLParams();
var pindex = STWkit.getParamIndex('os', 1, p);
if (pindex >= 0) {
p[pindex][1] = 0;
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + self.getSearchUrl(p);
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + STWkit.getSearchUrl(p);
window.history.pushState({ path: newurl }, '', newurl);
var showevt = document.createEvent("CustomEvent");
showevt.initCustomEvent('container:showComponent', false, false, {
......@@ -382,7 +343,7 @@ var L;
window.dispatchEvent(showevt);
}
}
var gindex = self.getParamIndex('guide', 'os', p);
var gindex = STWkit.getParamIndex('guide', 'os', p);
if (gindex >= 0) {
reqwest({
url: 'guide/os',
......@@ -392,25 +353,22 @@ var L;
var intro = introJs();
intro.setOptions(guide);
var prevElement = null;
function finish() {
var param = self.getURLParams();
if (self.hasParam('guide', 'os', param))
self.deleteParam('guide', param);
var search = self.getSearchUrl(param);
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + search;
window.history.pushState({ path: newurl }, '', newurl);
}
}
intro.onbeforechange(function (targetElement) {
(prevElement && prevElement.guideFn && prevElement.guideFn());
prevElement = targetElement;
});
intro.oncomplete(function () {
var param = STWkit.getURLParams();
if (STWkit.hasParam('guide', 'os', param))
STWkit.replaceParam('guide', 'player', param);
STWkit.updateUrl(param);
self.startButton.click();
});
intro.onexit(function () {
finish();
var param = STWkit.getURLParams();
if (STWkit.hasParam('guide', 'os', param))
STWkit.deleteParam('guide', param);
STWkit.updateUrl(param);
});
intro.start();
}
......@@ -434,10 +392,12 @@ var L;
self.selectCalculationMode.value = simulation.mode;
self.selectCalculationMode.dispatchEvent(evt);
self.uncertaintyInput.checked = simulation.uncertainty;
self.id = geojson.features[0].properties.uuid;
}
};
OilSpill.prototype.clear = function () {
var self = this;
self.id = undefined;
self.selectCalculationMode.selectedIndex = 1;
self.uncertaintyInput.checked = false;
var c = 1;
......
This diff is collapsed.
/// <reference path="def/uikit.d.ts" />
/// <reference path="def/leaflet.d.ts" />
/// <reference path="def/moment.d.ts" />
/// <reference path="def/introJs.d.ts" />
/// <reference path="def/stwkit.d.ts" />
/// <reference path="def/reqwest.d.ts" />
/// <reference path="leaflet-oilspill-cards.ts" />
module L.Control {
export class OilSpill extends L.Control {
......@@ -22,6 +24,7 @@ module L.Control {
private uncertaintyInput: HTMLInputElement;
private startButton: HTMLButtonElement;
private forcing: any;
private id: any;
constructor(options) {
super(options);
......@@ -271,6 +274,7 @@ module L.Control {
card.populateData(geojson);
}
}
if (self.id) geojson["features"][0]["properties"]["uuid"] = self.id;
geojson["features"][0]["properties"]["simulation"]["uncertainty"] = false;
if (self.uncertaintyInput.checked) geojson["features"][0]["properties"]["simulation"]["uncertainty"] = true;
geojson["features"][0]["properties"]["simulation"]["mode"] = self.selectCalculationMode.value;
......@@ -286,14 +290,9 @@ module L.Control {
self.warningMsg("Login", "You need to login to use this function.");
},
success: function (location) {
var param = self.getURLParams();
var param = STWkit.getURLParams();
param.push(['id', location.id]);
if (self.hasParam('guide', 'os', param)) self.replaceParam('guide', 'player', param);
var search = self.getSearchUrl(param);
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + search;
window.history.pushState({ path: newurl }, '', newurl);
}
STWkit.updateUrl(param);
self.clear();
var showevt = document.createEvent("CustomEvent");
showevt.initCustomEvent('container:showComponent', false, false, {
......@@ -318,74 +317,38 @@ module L.Control {
var id = c[0].id;
self.openCard(id, open);
});
var param = STWkit.getURLParams();
var osload = STWkit.getParamValue('osload', param);
if (osload !== null) {
reqwest({
url: "input/" + osload,
method: 'get',
type: 'json',
success: function (inputjson) {
var cardevt = document.createEvent("CustomEvent");
cardevt.initCustomEvent('card:populateData', false, false, {
'geojson': inputjson
});
window.dispatchEvent(cardevt);
STWkit.deleteParam('osload', param);
STWkit.updateUrl(param);
}
});
}
});
}
private getParamIndex(name, id, params) {
for (var i = 0; i < params.length; i++) {
if ((params[i][0] == name) && (params[i][1] == id)) return i;
}
return -1;
}
private getSearchUrl(params) {
var search = "";
if (params.length > 0) search += "?";
for (var i = 0; i < params.length; i++) {
search += params[i][0] + '=' + params[i][1];
if (i < params.length - 1) search += '&';
}
return search;
}
private hasParam(name, id, params) {
for (var i = 0; i < params.length; i++) {
if ((params[i][0] == name) && (params[i][1] == id)) return true;
}
return false;
}
private deleteParam(name, params) {
for (var i = 0; i < params.length; i++) {
if (params[i][0] == name) params.splice(i, 1);;
}
}
private replaceParam(name, newid, params) {
for (var i = 0; i < params.length; i++) {
if (params[i][0] == name) params[i][1] = newid;
}
}
private getURLParams(param?) {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
var urlParams = [];
while (match = search.exec(query)) {
if (param == decode(match[1])) {
urlParams.push();
urlParams[urlParams.length] = decode(match[2]);
} else {
urlParams.push();
urlParams[urlParams.length] = [decode(match[1]), decode(match[2])];
}
}
return urlParams;
};
public ready(name) {
var self = this;
self.compname = name;
var p = self.getURLParams();
var pindex = self.getParamIndex('os', 1, p);
var p = STWkit.getURLParams();
var pindex = STWkit.getParamIndex('os', 1, p);
if (pindex >= 0) {
p[pindex][1] = 0;
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + self.getSearchUrl(p);
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + STWkit.getSearchUrl(p);
window.history.pushState({ path: newurl }, '', newurl);
var showevt = document.createEvent("CustomEvent");
showevt.initCustomEvent('container:showComponent', false, false, {
......@@ -396,7 +359,7 @@ module L.Control {
}
}
var gindex = self.getParamIndex('guide', 'os', p);
var gindex = STWkit.getParamIndex('guide', 'os', p);
if (gindex >= 0) {
reqwest({
url: 'guide/os',
......@@ -406,24 +369,21 @@ module L.Control {
var intro = introJs();
intro.setOptions(guide);
var prevElement = null;
function finish() {
var param = self.getURLParams();
if (self.hasParam('guide', 'os', param)) self.deleteParam('guide', param);
var search = self.getSearchUrl(param);
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + search;
window.history.pushState({ path: newurl }, '', newurl);
}
}
intro.onbeforechange(function (targetElement) {
(prevElement && prevElement.guideFn && prevElement.guideFn())
prevElement = targetElement;
});
intro.oncomplete(function() {
var param = STWkit.getURLParams();
if (STWkit.hasParam('guide', 'os', param)) STWkit.replaceParam('guide', 'player', param);
STWkit.updateUrl(param);
self.startButton.click();
});
intro.onexit(function () {
finish();
var param = STWkit.getURLParams();
if (STWkit.hasParam('guide', 'os', param)) STWkit.deleteParam('guide', param);
STWkit.updateUrl(param);
});
intro.start();
}
......@@ -449,11 +409,13 @@ module L.Control {
self.selectCalculationMode.value = simulation.mode;
self.selectCalculationMode.dispatchEvent(evt);
self.uncertaintyInput.checked = simulation.uncertainty;
self.id = geojson.features[0].properties.uuid;
}
}
private clear() {
var self = this;
self.id = undefined;
self.selectCalculationMode.selectedIndex = 1;
self.uncertaintyInput.checked = false;
......
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