Mercurial > gemma
comparison client/src/components/admin/usermanagement/Usermanagement.vue @ 1272:bc55ffaeb639
cleaned up client/src directory
better organization of files and directories, better naming, separation of admin and map context
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Thu, 22 Nov 2018 07:07:12 +0100 |
parents | |
children | 2738a6ae9ad8 |
comparison
equal
deleted
inserted
replaced
1268:aca692e73028 | 1272:bc55ffaeb639 |
---|---|
1 <template> | |
2 <div class="main d-flex flex-row"> | |
3 <div :class="spacerStyle"></div> | |
4 <div class="d-flex content flex-column"> | |
5 <div class="d-flex flex-row"> | |
6 <div :class="userlistStyle"> | |
7 <div class="card"> | |
8 <div class="card-header shadow-sm text-white bg-info mb-3"> | |
9 Users | |
10 </div> | |
11 <div class="card-body"> | |
12 <table id="datatable" :class="tableStyle"> | |
13 <thead> | |
14 <tr> | |
15 <th scope="col" @click="sortBy('user')"> | |
16 <span>Username | |
17 <i v-if="sortCriterion=='user'" class="fa fa-angle-down"></i> | |
18 </span> | |
19 </th> | |
20 <th scope="col" @click="sortBy('country')"> | |
21 <span>Country | |
22 <i v-if="sortCriterion=='country'" class="fa fa-angle-down"></i> | |
23 </span> | |
24 </th> | |
25 <th scope="col" @click="sortBy('email')"> | |
26 <span>Email | |
27 <i v-if="sortCriterion=='email'" class="fa fa-angle-down"></i> | |
28 </span> | |
29 </th> | |
30 <th scope="col" @click="sortBy('role')"> | |
31 <span>Role | |
32 <i v-if="sortCriterion=='role'" class="fa fa-angle-down"></i> | |
33 </span> | |
34 </th> | |
35 <th scope="col"></th> | |
36 </tr> | |
37 </thead> | |
38 <tbody> | |
39 <tr v-for="user in users" :key="user.user" @click="selectUser(user.user)"> | |
40 <td>{{ user.user }}</td> | |
41 <td>{{ user.country }}</td> | |
42 <td>{{ user.email}}</td> | |
43 <td> | |
44 <i v-tooltip="user.roleLabel" :class="{ | |
45 fa:true, | |
46 icon:true, | |
47 'fa-user':user.role==='waterway_user', | |
48 'fa-star':user.role=='sys_admin', | |
49 'fa-adn':user.role==='waterway_admin'}"></i> | |
50 </td> | |
51 <td> | |
52 <i @click="deleteUser(user.user)" class="icon fa fa-trash-o"></i> | |
53 </td> | |
54 </tr> | |
55 </tbody> | |
56 </table> | |
57 </div> | |
58 <div class="d-flex flex-row pagination"> | |
59 <i @click=" prevPage " v-if="this.currentPage!=1 " class="mr-2 btn btn-sm btn-light align-self-center pages fa fa-caret-left "></i> {{this.currentPage}} / {{this.pages}} | |
60 <i @click="nextPage " class="ml-2 btn btn-sm btn-light align-self-center pages fa fa-caret-right "></i> | |
61 </div> | |
62 <div class="mr-3 pb-3"> | |
63 <button @click="addUser " class="btn btn-info pull-right shadow-sm ">Add User</button> | |
64 </div> | |
65 </div> | |
66 </div> | |
67 <Userdetail v-if="isUserDetailsVisible "></Userdetail> | |
68 </div> | |
69 </div> | |
70 </div> | |
71 </template> | |
72 | |
73 <style scoped lang="sass"> | |
74 @import "../../../assets/tooltip.sass" | |
75 | |
76 .spacer | |
77 height: 100vh | |
78 | |
79 .spacer-collapsed | |
80 min-width: $icon-width + $offset | |
81 transition: $transition-fast | |
82 | |
83 @media screen and (min-width: 600px) | |
84 .spacer-expanded | |
85 min-width: $icon-width + $offset | |
86 | |
87 @media screen and (max-width: 1650px) | |
88 .spacer-expanded | |
89 min-width: $sidebar-width + $offset | |
90 | |
91 .main | |
92 height: 100vh | |
93 | |
94 @media screen and (min-width: 600px) | |
95 .content | |
96 margin-left: $sidebar-width | |
97 margin-right: auto | |
98 | |
99 @media screen and (min-width: 1650px) | |
100 .content | |
101 margin-left: $sidebar-width | |
102 margin-right: auto | |
103 | |
104 .icon | |
105 font-size: large | |
106 | |
107 .userlist | |
108 min-width: 520px | |
109 height: 100% | |
110 | |
111 .pagination | |
112 margin-left: auto | |
113 margin-right: auto | |
114 | |
115 .userlistsmall | |
116 width: 30vw | |
117 | |
118 .userlistextended | |
119 width: 70vw | |
120 | |
121 .table | |
122 width: 90% !important | |
123 margin: auto | |
124 | |
125 .table th, | |
126 .pages | |
127 cursor: pointer | |
128 | |
129 .table th, | |
130 td | |
131 font-size: $smaller | |
132 border-top: 0px !important | |
133 text-align: left | |
134 padding: $small-offset !important | |
135 | |
136 .table td | |
137 font-size: $smaller | |
138 cursor: pointer | |
139 | |
140 tr span | |
141 display: flex | |
142 </style> | |
143 | |
144 <script> | |
145 /* | |
146 * This is Free Software under GNU Affero General Public License v >= 3.0 | |
147 * without warranty, see README.md and license for details. | |
148 * | |
149 * SPDX-License-Identifier: AGPL-3.0-or-later | |
150 * License-Filename: LICENSES/AGPL-3.0.txt | |
151 * | |
152 * Copyright (C) 2018 by via donau | |
153 * – Österreichische Wasserstraßen-Gesellschaft mbH | |
154 * Software engineering by Intevation GmbH | |
155 * | |
156 * Author(s): | |
157 * Thomas Junk <thomas.junk@intevation.de> | |
158 */ | |
159 import Userdetail from "./Userdetail"; | |
160 import store from "../../../store"; | |
161 import { mapGetters, mapState } from "vuex"; | |
162 import { displayError } from "../../../lib/errors.js"; | |
163 | |
164 export default { | |
165 name: "userview", | |
166 data() { | |
167 return { | |
168 sortCriterion: "user", | |
169 pageSize: 10, | |
170 currentPage: 1 | |
171 }; | |
172 }, | |
173 components: { | |
174 Userdetail | |
175 }, | |
176 computed: { | |
177 ...mapGetters("usermanagement", ["isUserDetailsVisible"]), | |
178 ...mapState("application", ["showSidebar", "showUsermenu"]), | |
179 spacerStyle() { | |
180 return [ | |
181 "spacer ml-3", | |
182 { | |
183 "spacer-expanded": this.showUsermenu && this.showSidebar, | |
184 "spacer-collapsed": !this.showUsermenu && this.showSidebar | |
185 } | |
186 ]; | |
187 }, | |
188 users() { | |
189 let users = [...this.$store.getters["usermanagement/users"]]; | |
190 users.sort((a, b) => { | |
191 if ( | |
192 a[this.sortCriterion].toLowerCase() < | |
193 b[this.sortCriterion].toLowerCase() | |
194 ) | |
195 return -1; | |
196 if ( | |
197 a[this.sortCriterion].toLowerCase() > | |
198 b[this.sortCriterion].toLowerCase() | |
199 ) | |
200 return 1; | |
201 return 0; | |
202 }); | |
203 const start = (this.currentPage - 1) * this.pageSize; | |
204 return users.slice(start, start + this.pageSize); | |
205 }, | |
206 pages() { | |
207 let users = [...this.$store.getters["usermanagement/users"]]; | |
208 return Math.ceil(users.length / this.pageSize); | |
209 }, | |
210 tableStyle() { | |
211 return { | |
212 table: true, | |
213 "table-hover": true, | |
214 "table-sm": this.isUserDetailsVisible, | |
215 fadeIn: true, | |
216 animated: true | |
217 }; | |
218 }, | |
219 userlistStyle() { | |
220 return [ | |
221 "userlist mt-3 mr-3 shadow", | |
222 { | |
223 userlistsmall: this.isUserDetailsVisible, | |
224 userlistextended: !this.isUserDetailsVisible | |
225 } | |
226 ]; | |
227 } | |
228 }, | |
229 methods: { | |
230 tween() {}, | |
231 nextPage() { | |
232 if (this.currentPage < this.pages) { | |
233 document.querySelector("#datatable").classList.add("fadeOut"); | |
234 setTimeout(() => { | |
235 document.querySelector("#datatable").classList.remove("fadeOut"); | |
236 this.currentPage += 1; | |
237 }, 10); | |
238 } | |
239 return; | |
240 }, | |
241 prevPage() { | |
242 if (this.currentPage > 0) { | |
243 document.querySelector("#datatable").classList.add("fadeOut"); | |
244 setTimeout(() => { | |
245 document.querySelector("#datatable").classList.remove("fadeOut"); | |
246 this.currentPage -= 1; | |
247 }, 10); | |
248 } | |
249 return; | |
250 }, | |
251 sortBy(criterion) { | |
252 this.sortCriterion = criterion; | |
253 }, | |
254 deleteUser(name) { | |
255 this.$store | |
256 .dispatch("usermanagement/deleteUser", { name: name }) | |
257 .then(() => { | |
258 this.submitted = false; | |
259 this.$store.dispatch("usermanagement/loadUsers").catch(error => { | |
260 const { status, data } = error.response; | |
261 displayError({ | |
262 title: "Backend Error", | |
263 message: `${status}: ${data.message || data}` | |
264 }); | |
265 }); | |
266 }) | |
267 .catch(error => { | |
268 const { status, data } = error.response; | |
269 displayError({ | |
270 title: "Backend Error", | |
271 message: `${status}: ${data.message || data}` | |
272 }); | |
273 }); | |
274 }, | |
275 addUser() { | |
276 this.$store.commit("usermanagement/clearCurrentUser"); | |
277 this.$store.commit("usermanagement/setUserDetailsVisible"); | |
278 }, | |
279 selectUser(name) { | |
280 const user = this.$store.getters["usermanagement/getUserByName"](name); | |
281 this.$store.commit("usermanagement/setCurrentUser", user); | |
282 } | |
283 }, | |
284 beforeRouteEnter(to, from, next) { | |
285 store | |
286 .dispatch("usermanagement/loadUsers") | |
287 .then(next) | |
288 .catch(error => { | |
289 const { status, data } = error.response; | |
290 displayError({ | |
291 title: "Backend Error", | |
292 message: `${status}: ${data}` | |
293 }); | |
294 }); | |
295 }, | |
296 beforeRouteLeave(to, from, next) { | |
297 store.commit("usermanagement/clearCurrentUser"); | |
298 store.commit("usermanagement/setUserDetailsInvisible"); | |
299 next(); | |
300 } | |
301 }; | |
302 </script> |