Mercurial > gemma
view client/src/store/gauges.js @ 2704:84145179ec72
import_overview: open logs and details in parallel
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 18 Mar 2019 15:56:54 +0100 |
parents | e622689d73bd |
children | f393fabfdd35 |
line wrap: on
line source
/* This is Free Software under GNU Affero General Public License v >= 3.0 * without warranty, see README.md and license for details. * * SPDX-License-Identifier: AGPL-3.0-or-later * License-Filename: LICENSES/AGPL-3.0.txt * * Copyright (C) 2018 by via donau * – Österreichische Wasserstraßen-Gesellschaft mbH * Software engineering by Intevation GmbH * * Author(s): * Markus Kottländer <markus@intevation.de> */ import { HTTP } from "@/lib/http"; import { WFS } from "ol/format.js"; const init = () => { return { gauges: [], selectedGaugeISRS: null, waterlevels: [] }; }; export default { init, namespaced: true, state: init(), getters: { selectedGauge: state => { return state.gauges.find( g => g.properties.isrs_code === state.selectedGaugeISRS ); } }, mutations: { gauges: (state, gauges) => { state.gauges = gauges; }, selectedGaugeISRS: (state, isrs) => { state.selectedGaugeISRS = isrs; }, waterlevels: (state, data) => { state.waterlevels = data; } }, actions: { selectedGaugeISRS: ({ commit }, isrs) => { commit("selectedGaugeISRS", isrs); commit("application/showGauges", true, { root: true }); commit("application/showSplitscreen", false, { root: true }); }, loadGauges: ({ commit }) => { return new Promise((resolve, reject) => { var gaugesFeatureCollectionRequest = new WFS().writeGetFeature({ srsName: "EPSG:4326", featureNS: "gemma", featurePrefix: "gemma", featureTypes: ["gauges_geoserver"], outputFormat: "application/json" }); HTTP.post( "/internal/wfs", new XMLSerializer().serializeToString(gaugesFeatureCollectionRequest), { headers: { "X-Gemma-Auth": localStorage.getItem("token"), "Content-type": "text/xml; charset=UTF-8" } } ) .then(response => { commit("gauges", response.data.features); resolve(response); }) .catch(error => { reject(error); }); }); }, loadWaterlevels({ getters, commit }, { from, to }) { from = from || new Date(); to = to || new Date(); // include the last day to.setDate(to.getDate() + 1); return new Promise((resolve, reject) => { HTTP.get( `/data/waterlevels/${ getters.selectedGauge.properties.isrs_code }?from=${from .toISOString() .substr(0, 23)}&to=${to.toISOString().substr(0, 23)}`, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } } ) .then(response => { let data = response.data .split("\n") .filter(wl => wl) .map(wl => { wl = wl.split(","); return { date: new Date(wl[0]), waterlevel: Number(wl[1]), predicted: wl[2] === "f" ? false : true }; }); data = data.sort((a, b) => a.date - b.date); commit("waterlevels", data); resolve(data); }) .catch(error => { commit("waterlevels", []); reject(error); }); }); } } };