Mercurial > gemma
view client/src/store/application.js @ 2227:9b545e470b94 pdf-export
PDF generation: logo image, adjusted templates
The default logo file will now be added to the PDF if an image element is specified without url.
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Tue, 12 Feb 2019 14:33:36 +0100 |
parents | 85142493096c |
children | e6fba449aa3c |
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> * Markus Kottländer <markus.kottlaender@intevation.de> * Bernhard E. Reiter <bernhard.reiter@intevation.de> */ import { version } from "../../package.json"; // import { HTTP } from "../lib/http"; // initial state const init = () => { return { 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, showSearchbar: false, showSearchbarLastState: false, showIdentify: false, showLayers: true, showPdfTool: false, showContextBox: false, showProfiles: false, contextBoxContent: null, // bottlenecks, imports, staging expandToolbar: false, countries: ["AT", "SK", "HU", "HR", "RS", "BiH", "BG", "RO", "UA"], searchQuery: "", version }; }; export default { init, namespaced: true, state: init(), getters: { versionStr: state => { // version number from package.json let versionStr = "v" + state.version; // hg revision if ( process.env.VUE_APP_HGREV && (state.version.includes("dev") || state.version.includes("beta") || state.version.includes("alpha")) ) // a '+' according to semver 2.0.0 starts a build meta info section // which shall only have [0-9A-Za-z-] chars // and is to be ignored when determining the order versionStr += "+" + process.env.VUE_APP_HGREV; return versionStr; } }, mutations: { showSidebar: (state, show) => { state.showSidebar = show; }, showSplitscreen: (state, show) => { state.showSplitscreen = show; }, showUsermenu: (state, show) => { state.showUsermenu = show; }, showSearchbar: (state, show) => { state.showSearchbar = show; }, showIdentify: (state, show) => { state.showIdentify = show; }, showLayers: (state, show) => { state.showLayers = show; }, showPdfTool: (state, show) => { state.showPdfTool = show; }, showContextBox: (state, show) => { state.showContextBox = show; }, showProfiles: (state, show) => { state.showProfiles = show; }, contextBoxContent: (state, context) => { state.contextBoxContent = context; if (context) { state.showSearchbarLastState = state.showSearchbar; } }, expandToolbar: (state, expandToolbar) => { state.expandToolbar = expandToolbar; }, searchQuery: (state, searchQuery) => { state.searchQuery = searchQuery; }, pdfTemplates: (state, pdfTemplates) => { state.pdfTemplates = pdfTemplates; } }, actions: { loadPdfTemplates({ commit }) { return new Promise(resolve => { // pretend we do something async setTimeout(function() { commit("pdfTemplates", [ { name: "Default Template", properties: { format: "landscape", resolution: "120", paperSize: "a4" }, elements: [ { type: "textbox", position: "bottomleft", offset: { x: 2, y: 2 }, width: 100, fontSize: 8, text: "Date of publication: {date} - generated by: {user}" }, { type: "bottleneck", position: "topleft", offset: { x: 2, y: 2 } }, { type: "legend", position: "topleft", offset: { x: 2, y: 18 } }, { type: "scalebar", position: "bottomright", offset: { x: 2, y: 2 } }, { type: "northarrow", position: "topright", offset: { x: 10, y: 5 }, size: 2 } ] }, { name: "Full Template", properties: { format: "landscape", resolution: "120", paperSize: "a4" }, elements: [ { type: "box", position: "topleft", offset: { x: 20, y: 2 }, width: 60, height: 25, color: "green" }, { type: "text", position: "topleft", offset: { x: 23, y: 5 }, width: 56, fontSize: 10, color: "greenyellow", text: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua." }, { type: "textbox", position: "bottomleft", offset: { x: 2, y: 2 }, width: 90, padding: 3, fontSize: 7, color: "gray", background: "white", text: "Date of publication: {date} - generated by: {user}" }, { type: "image", format: "PNG", position: "bottomleft", offset: { x: 2, y: 10 }, width: 90, height: 12, border: 2 }, { type: "bottleneck", position: "topright", offset: { x: 2, y: 2 } }, { type: "legend", position: "topright", offset: { x: 2, y: 18 } }, { type: "scalebar", position: "bottomright", offset: { x: 2, y: 2 } }, { type: "northarrow", position: "topleft", offset: { x: 8, y: 4 }, size: 2 } ] } ]); resolve(); }, 500); }); }, uploadPDFTemplates({ state, commit }, files) { return new Promise((resolve, reject) => { setTimeout(() => { const reader = new FileReader(); reader.onload = event => { let templates = state.pdfTemplates; templates.push(JSON.parse(event.target.result)); commit("pdfTemplates", templates); // TODO: send template to server }; reader.onerror = error => reject(error); reader.readAsText(files[0]); resolve(); }, 1000); }); }, removePDFTemplate({ state, commit }, template) { let templates = state.pdfTemplates; let removeIndex = templates.findIndex(t => t.name === template.name); if (removeIndex !== -1) { templates.splice(removeIndex, 1); commit("pdfTemplates", templates); } } } };