Mercurial > gemma
view client/src/store/imports.js @ 2100:46343e3f7a3e
Imports: Fixed small issue with de-serializing stretches.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 04 Feb 2019 12:49:50 +0100 |
parents | 98f0c7956128 |
children | 6747a4cf3639 |
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): * Thomas Junk <thomas.junk@intevation.de> */ import { HTTP } from "@/lib/http"; import { WFS } from "ol/format.js"; import { equalTo as equalToFilter } from "ol/format/filter.js"; /* eslint-disable no-unused-vars */ /* eslint-disable no-unreachable */ const STATES = { NEEDSAPPROVAL: "pending", APPROVED: "accepted", REJECTED: "declined" }; // initial state const init = () => { return { stretches: [], imports: [], staging: [], importToReview: null }; }; const imports = { init, namespaced: true, state: init(), mutations: { setStretches: (state, stretches) => { state.stretches = stretches; }, setImports: (state, imports) => { state.imports = imports; }, setStaging: (state, staging) => { const enriched = staging.map(x => { return { ...x, status: STATES.NEEDSAPPROVAL }; }); state.staging = enriched; }, setImportToReview: (state, id) => { if (!isNaN(parseFloat(id)) && isFinite(id)) { state.importToReview = id; } }, toggleApproval: (state, change) => { const { id, newStatus } = change; const stagedResult = state.staging.find(e => { return e.id === id; }); if (stagedResult.status === newStatus) { stagedResult.status = STATES.NEEDSAPPROVAL; } else { stagedResult.status = newStatus; } } }, actions: { loadStretches({ commit }) { return new Promise((resolve, reject) => { var stretchesFeatureCollectionRequest = new WFS().writeGetFeature({ srsName: "EPSG:4326", featureNS: "gemma", featurePrefix: "gemma", featureTypes: ["stretches_geoserver"], outputFormat: "application/json", filter: equalToFilter("staging_done", true) }); HTTP.post( "/internal/wfs", new XMLSerializer().serializeToString( stretchesFeatureCollectionRequest ), { headers: { "X-Gemma-Auth": localStorage.getItem("token"), "Content-type": "text/xml; charset=UTF-8" } } ) .then(response => { if (response.data.features) { commit("setStretches", response.data.features); } else { commit("setStretches", []); } resolve(response); }) .catch(error => { reject(error); }); }); }, saveStretch({ commit }, stretch) { return new Promise((resolve, reject) => { HTTP.post("/imports/st", stretch, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { resolve(response); }) .catch(error => { reject(error); }); }); }, getImports({ commit }) { return new Promise((resolve, reject) => { HTTP.get("/imports", { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("setImports", response.data.imports); resolve(response); }) .catch(error => { reject(error); }); }); }, getStaging({ commit }) { return new Promise((resolve, reject) => { HTTP.get("/imports?states=pending", { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("setStaging", response.data.imports); resolve(response); }) .catch(error => { reject(error); }); }); } } }; export { imports, STATES };