diff client/src/store/application.js @ 2257:ce6fd3d4a3a2

client: pdf-gen: moved template handling from store to components
author Markus Kottlaender <markus@intevation.de>
date Thu, 14 Feb 2019 08:56:32 +0100
parents e6fba449aa3c
children c06b001dc26b
line wrap: on
line diff
--- a/client/src/store/application.js	Wed Feb 13 18:18:41 2019 +0100
+++ b/client/src/store/application.js	Thu Feb 14 08:56:32 2019 +0100
@@ -15,8 +15,6 @@
  */
 
 import { version } from "../../package.json";
-import { HTTP } from "../lib/http";
-import { displayError } from "@/lib/errors.js";
 
 // initial state
 const init = () => {
@@ -24,7 +22,6 @@
     appTitle: process.env.VUE_APP_TITLE,
     secondaryLogo: process.env.VUE_APP_SECONDARY_LOGO_URL,
     logoForPDF: process.env.VUE_APP_LOGO_FOR_PDF_URL,
-    pdfTemplates: [],
     showSidebar: false,
     showUsermenu: false,
     showSplitscreen: false,
@@ -106,100 +103,6 @@
     },
     searchQuery: (state, searchQuery) => {
       state.searchQuery = searchQuery;
-    },
-    pdfTemplates: (state, pdfTemplates) => {
-      state.pdfTemplates = pdfTemplates;
-    }
-  },
-  actions: {
-    loadPdfTemplates({ commit }) {
-      return new Promise((resolve, reject) => {
-        HTTP.get("/templates/print", {
-          headers: {
-            "X-Gemma-Auth": localStorage.getItem("token"),
-            "Content-type": "text/xml; charset=UTF-8"
-          }
-        })
-          .then(response => {
-            commit("pdfTemplates", response.data);
-            resolve();
-          })
-          .catch(e => {
-            reject(e);
-            const { status, data } = e.response;
-            displayError({
-              title: "Backend Error",
-              message: `${status}: ${data.message || data}`
-            });
-          });
-      });
-    },
-    uploadPDFTemplate({ dispatch }, files) {
-      return new Promise((resolve, reject) => {
-        const reader = new FileReader();
-        reader.onload = event => {
-          let template;
-          try {
-            template = JSON.parse(event.target.result);
-          } catch (e) {
-            displayError({
-              title: "Format Error",
-              message: "Uploaded file does not contain valid json data."
-            });
-            reject(e);
-          }
-          if (template.name) {
-            HTTP.post(
-              "/templates/print/" + template.name,
-              {
-                template_name: template.name,
-                template_data: template
-              },
-              {
-                headers: {
-                  "X-Gemma-Auth": localStorage.getItem("token"),
-                  "Content-type": "text/xml; charset=UTF-8"
-                }
-              }
-            )
-              .then(response => {
-                dispatch("loadPdfTemplates");
-                resolve(response);
-              })
-              .catch(e => {
-                reject(e);
-                const { status, data } = e.response;
-                displayError({
-                  title: "Backend Error",
-                  message: `${status}: ${data.message || data}`
-                });
-              });
-          } else {
-            reject();
-            displayError({
-              title: "Format Error",
-              message: "The provided template has no name property."
-            });
-          }
-        };
-        reader.onerror = error => reject(error);
-        reader.readAsText(files[0]);
-      });
-    },
-    removePDFTemplate({ state, commit }, template) {
-      HTTP.delete("/templates/print/" + template.name, {
-        headers: {
-          "X-Gemma-Auth": localStorage.getItem("token"),
-          "Content-type": "text/xml; charset=UTF-8"
-        }
-      }).then(() => {
-        let templates = state.pdfTemplates;
-        let removeIndex = templates.findIndex(t => t.name === template.name);
-        if (removeIndex !== -1) {
-          templates.splice(removeIndex, 1);
-          commit("pdfTemplates", templates);
-        }
-      });
     }
   }
 };