annotate client/src/store/imports.js @ 1350:58d41573e530

staging: now with real data from backend
author Thomas Junk <thomas.junk@intevation.de>
date Mon, 26 Nov 2018 14:42:48 +0100
parents eda98694e678
children da7ee82ad5d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
1 /*
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
2 * This is Free Software under GNU Affero General Public License v >= 3.0
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
3 * without warranty, see README.md and license for details.
1173
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
4 *
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
5 * SPDX-License-Identifier: AGPL-3.0-or-later
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
6 * License-Filename: LICENSES/AGPL-3.0.txt
1173
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
7 *
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
8 * Copyright (C) 2018 by via donau
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
9 * – Österreichische Wasserstraßen-Gesellschaft mbH
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
10 * Software engineering by Intevation GmbH
1173
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
11 *
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
12 * Author(s):
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
13 * Thomas Junk <thomas.junk@intevation.de>
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
14 */
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
15
1272
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents: 1173
diff changeset
16 import { HTTP } from "../lib/http";
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
17
1311
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
18 /* eslint-disable no-unused-vars */
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
19 /* eslint-disable no-unreachable */
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
20 const STATES = {
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
21 NEEDSAPPROVAL: "NEEDSAPPROVAL",
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
22 APPROVED: "APPROVED",
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
23 REJECTED: "REJECTED"
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
24 };
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
25
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
26 // initial state
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
27 const init = () => {
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
28 return {
1310
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
29 imports: [],
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
30 staging: []
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
31 };
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
32 };
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
33
1344
eda98694e678 staging: retrieve real data instead of displaying demodata
Thomas Junk <thomas.junk@intevation.de>
parents: 1311
diff changeset
34 const imports = {
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
35 init,
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
36 namespaced: true,
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
37 state: init(),
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
38 mutations: {
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
39 setImports: (state, imports) => {
1173
3035ddd3d1a8 feat: importqueue
Thomas Junk <thomas.junk@intevation.de>
parents: 1142
diff changeset
40 state.imports = imports;
1310
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
41 },
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
42 setStaging: (state, staging) => {
1350
58d41573e530 staging: now with real data from backend
Thomas Junk <thomas.junk@intevation.de>
parents: 1344
diff changeset
43 const enriched = staging.map(x => {
58d41573e530 staging: now with real data from backend
Thomas Junk <thomas.junk@intevation.de>
parents: 1344
diff changeset
44 return { ...x, status: STATES.NEEDSAPPROVAL };
58d41573e530 staging: now with real data from backend
Thomas Junk <thomas.junk@intevation.de>
parents: 1344
diff changeset
45 });
58d41573e530 staging: now with real data from backend
Thomas Junk <thomas.junk@intevation.de>
parents: 1344
diff changeset
46 state.staging = enriched;
1311
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
47 },
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
48
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
49 toggleApproval: (state, change) => {
1344
eda98694e678 staging: retrieve real data instead of displaying demodata
Thomas Junk <thomas.junk@intevation.de>
parents: 1311
diff changeset
50 const { id, newStatus } = change;
1350
58d41573e530 staging: now with real data from backend
Thomas Junk <thomas.junk@intevation.de>
parents: 1344
diff changeset
51 const stagedResult = state.staging.find(e => {
1311
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
52 return e.id === id;
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
53 });
1344
eda98694e678 staging: retrieve real data instead of displaying demodata
Thomas Junk <thomas.junk@intevation.de>
parents: 1311
diff changeset
54 if (stagedResult.status === newStatus) {
eda98694e678 staging: retrieve real data instead of displaying demodata
Thomas Junk <thomas.junk@intevation.de>
parents: 1311
diff changeset
55 stagedResult.status = STATES.NEEDSAPPROVAL;
1311
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
56 } else {
1344
eda98694e678 staging: retrieve real data instead of displaying demodata
Thomas Junk <thomas.junk@intevation.de>
parents: 1311
diff changeset
57 stagedResult.status = newStatus;
1311
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
58 }
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
59 }
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
60 },
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
61 actions: {
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
62 getImports({ commit }) {
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
63 return new Promise((resolve, reject) => {
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
64 HTTP.get("/imports", {
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
65 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
66 })
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
67 .then(response => {
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
68 commit("setImports", response.data.imports);
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
69 resolve(response);
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
70 })
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
71 .catch(error => {
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
72 reject(error);
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
73 });
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
74 });
1310
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
75 },
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
76 getStaging({ commit }) {
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
77 return new Promise((resolve, reject) => {
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
78 HTTP.get("/imports?states=pending", {
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
79 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
80 })
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
81 .then(response => {
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
82 commit("setStaging", response.data.imports);
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
83 resolve(response);
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
84 })
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
85 .catch(error => {
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
86 reject(error);
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
87 });
d675e6439aa5 staging view: prepare retrieving list of pending imports for staging
Thomas Junk <thomas.junk@intevation.de>
parents: 1296
diff changeset
88 });
1311
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
89 },
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
90 setStaging({ commit }, results) {
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
91 return new Promise((resolve, reject) => {
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
92 throw "Not implemented!";
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
93 HTTP.get("/imports?states=pending", {
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
94 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
95 })
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
96 .then(response => {
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
97 commit("setStaging", response.data.imports);
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
98 resolve(response);
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
99 })
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
100 .catch(error => {
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
101 reject(error);
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
102 });
d5eda9f79610 staging: display visual feedback for now due missing backendcall
Thomas Junk <thomas.junk@intevation.de>
parents: 1310
diff changeset
103 });
1142
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
104 }
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
105 }
dc3f0277628a feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
106 };
1344
eda98694e678 staging: retrieve real data instead of displaying demodata
Thomas Junk <thomas.junk@intevation.de>
parents: 1311
diff changeset
107
eda98694e678 staging: retrieve real data instead of displaying demodata
Thomas Junk <thomas.junk@intevation.de>
parents: 1311
diff changeset
108 export { imports, STATES };