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