comparison client/src/store/application.js @ 1096:aa1f5daf6fc9

refac: centralized stores
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 30 Oct 2018 16:55:29 +0100
parents client/src/application/stores/application.js@7ec2133c6404
children 8d12056d602a
comparison
equal deleted inserted replaced
1095:2d6d8b676e3f 1096:aa1f5daf6fc9
1 /* This is Free Software under GNU Affero General Public License v >= 3.0
2 * without warranty, see README.md and license for details.
3 *
4 * SPDX-License-Identifier: AGPL-3.0-or-later
5 * License-Filename: LICENSES/AGPL-3.0.txt
6 *
7 * Copyright (C) 2018 by via donau
8 * – Österreichische Wasserstraßen-Gesellschaft mbH
9 * Software engineering by Intevation GmbH
10 *
11 * Author(s):
12 * Thomas Junk <thomas.junk@intevation.de>
13 * Markus Kottländer <markus.kottlaender@intevation.de>
14 * Bernhard E. Reiter <bernhard.reiter@intevation.de>
15 */
16
17 import { version } from "../../package.json";
18
19 const defaultCollapseState = true;
20
21 const initializeSplitScreen = () => {
22 return {
23 active: false,
24 mode: "v"
25 };
26 };
27
28 const Application = {
29 namespaced: true,
30 state: {
31 appTitle: process.env.VUE_APP_TITLE,
32 secondaryLogo: process.env.VUE_APP_SECONDARY_LOGO_URL,
33 sidebar: {
34 iscollapsed: defaultCollapseState
35 },
36 bottlenecksCollapsed: true,
37 splitsceen: initializeSplitScreen(),
38 usermenu: {
39 iscollapsed: defaultCollapseState
40 },
41 countries: ["AT", "SK", "HU", "HR", "RS", "BiH", "BG", "RO", "UA"],
42 // there are three states of drawMode: null, "LineString", "Polygon"
43 drawMode: null,
44 version
45 },
46 getters: {
47 countries: state => {
48 return state.countries;
49 },
50 sidebarCollapsed: state => {
51 return state.sidebar.iscollapsed;
52 },
53 isUsermenuCollapsed: state => {
54 return state.usermenu.iscollapsed;
55 },
56 appTitle: state => {
57 return state.appTitle;
58 },
59 secondaryLogo: state => {
60 return state.secondaryLogo;
61 },
62 isSplitscreen: state => {
63 return state.splitsceen.active;
64 },
65 splitMode: state => {
66 return state.splitsceen.mode;
67 },
68 versionStr: state => {
69 // version number from package.json
70 let versionStr = "v" + state.version;
71
72 // hg revision
73 if (
74 process.env.VUE_APP_HGREV &&
75 (state.version.includes("dev") ||
76 state.version.includes("beta") ||
77 state.version.includes("alpha"))
78 )
79 versionStr += " " + process.env.VUE_APP_HGREV;
80
81 return versionStr;
82 }
83 },
84 mutations: {
85 toggleSidebar: state => {
86 state.sidebar.iscollapsed = !state.sidebar.iscollapsed;
87 },
88 toggleBottlenecks: state => {
89 state.bottlenecksCollapsed = !state.bottlenecksCollapsed;
90 },
91 toggleUserMenu: state => {
92 state.usermenu.iscollapsed = !state.usermenu.iscollapsed;
93 },
94 toggleSplitScreen: state => {
95 state.splitsceen.active = !state.splitsceen.active;
96 },
97 openSplitScreen: state => {
98 state.splitsceen.active = true;
99 },
100 closeSplitScreen: state => {
101 state.splitsceen.active = false;
102 },
103 resetSidebar: state => {
104 state.sidebar.iscollapsed = defaultCollapseState;
105 },
106 collapseSidebar: state => {
107 state.sidebar.iscollapsed = true;
108 },
109 resetUserMenu: state => {
110 state.usermenu.iscollapsed = defaultCollapseState;
111 },
112 collapseUserMenu: state => {
113 state.usermenu.iscollapsed = true;
114 },
115 resetSplitScreen: state => {
116 state.splitsceen = initializeSplitScreen();
117 },
118 toggleDrawModeLine: state => {
119 if (state.drawMode) {
120 state.drawMode = null;
121 } else {
122 state.drawMode = "LineString";
123 }
124 },
125 activateDrawModePolygon: state => {
126 state.drawMode = "Polygon";
127 }
128 },
129 actions: {}
130 };
131
132 export default Application;