Mercurial > gemma
view client/src/store/imports.js @ 2275:a6cfa06c5983
client: pdf-gen: added cancel button
Prevents the rendercomplete event to fire. Should be enough since rendering the map takes most of time of the process.
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 15 Feb 2019 09:47:57 +0100 |
parents | 6747a4cf3639 |
children | e120631797f6 |
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 getStretchFromWFS = filter => { return new Promise((resolve, reject) => { var stretchesFeatureCollectionRequest = new WFS().writeGetFeature({ srsName: "EPSG:4326", featureNS: "gemma", featurePrefix: "gemma", featureTypes: ["stretches_geoserver"], outputFormat: "application/json", filter: filter }); HTTP.post( "/internal/wfs", new XMLSerializer().serializeToString(stretchesFeatureCollectionRequest), { headers: { "X-Gemma-Auth": localStorage.getItem("token"), "Content-type": "text/xml; charset=UTF-8" } } ) .then(response => { resolve(response); }) .catch(error => { reject(error); }); }); }; 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: { loadStretch({ commit }, name) { return new Promise((resolve, reject) => { getStretchFromWFS(equalToFilter("name", name)) .then(response => { resolve(response); }) .catch(error => { reject(error); }); }); }, loadStretches({ commit }) { return new Promise((resolve, reject) => { getStretchFromWFS(equalToFilter("staging_done", true)) .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 };