Mercurial > gemma
comparison client/src/usermanagement/Usermanagement.vue @ 585:ef307bd6b5d8
refac: restructured client application
To make the application more accessible for developers, the structure was reorganized.
Instead of sticking to technical terminology, the application terminology is according to the domain:
I.e. "map" contains everything regarding map (including store).
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Fri, 07 Sep 2018 11:13:56 +0200 |
parents | |
children | 8278b2fb0c33 |
comparison
equal
deleted
inserted
replaced
584:8b66a10aaf8a | 585:ef307bd6b5d8 |
---|---|
1 <template> | |
2 <div class="main d-flex flex-column"> | |
3 <div class="d-flex content flex-column"> | |
4 <div class="d-flex flex-row"> | |
5 <div :class="userlistStyle"> | |
6 <div class="card"> | |
7 <div class="card-header shadow-sm text-white bg-info mb-3"> | |
8 Users | |
9 </div> | |
10 <div class="card-body"> | |
11 <table id="datatable" :class="tableStyle"> | |
12 <thead> | |
13 <tr> | |
14 <th scope="col" @click="sortBy('user')"> | |
15 <span>Username | |
16 <i v-if="sortCriterion=='user'" class="fa fa-angle-down"></i> | |
17 </span> | |
18 </th> | |
19 <th scope="col" @click="sortBy('country')"> | |
20 <span>Country | |
21 <i v-if="sortCriterion=='country'" class="fa fa-angle-down"></i> | |
22 </span> | |
23 </th> | |
24 <th scope="col" @click="sortBy('email')"> | |
25 <span>Email | |
26 <i v-if="sortCriterion=='email'" class="fa fa-angle-down"></i> | |
27 </span> | |
28 </th> | |
29 <th scope="col" @click="sortBy('role')"> | |
30 <span>Role | |
31 <i v-if="sortCriterion=='role'" class="fa fa-angle-down"></i> | |
32 </span> | |
33 </th> | |
34 <th scope="col"></th> | |
35 </tr> | |
36 </thead> | |
37 <tbody> | |
38 <tr v-for="user in users" :key="user.user" @click="selectUser(user.user)"> | |
39 <td>{{ user.user }}</td> | |
40 <td>{{ user.country }}</td> | |
41 <td>{{ user.email}}</td> | |
42 <td> | |
43 <i v-tooltip="user.roleLabel" :class="{ | |
44 fa:true, | |
45 icon:true, | |
46 'fa-user':user.role==='waterway_user', | |
47 'fa-star':user.role=='sys_admin', | |
48 'fa-adn':user.role==='waterway_admin'}"></i> | |
49 </td> | |
50 <td> | |
51 <i @click="deleteUser(user.user)" class="icon fa fa-trash-o"></i> | |
52 </td> | |
53 </tr> | |
54 </tbody> | |
55 </table> | |
56 </div> | |
57 <div class="d-flex flex-row pagination"> | |
58 <i @click=" prevPage " v-if="this.currentPage!=1 " class="backwards btn btn-sm btn-light align-self-center pages fa fa-caret-left "></i> {{this.currentPage}} / {{this.pages}} | |
59 <i @click="nextPage " class="forwards btn btn-sm btn-light align-self-center pages fa fa-caret-right "></i> | |
60 </div> | |
61 <div class="adduser "> | |
62 <button @click="addUser " class="btn btn-info pull-right shadow-sm ">Add User</button> | |
63 </div> | |
64 </div> | |
65 </div> | |
66 <Userdetail v-if="isUserDetailsVisible "></Userdetail> | |
67 </div> | |
68 </div> | |
69 </div> | |
70 </template> | |
71 | |
72 <style lang="scss"> | |
73 @import "../application/assets/application.scss"; | |
74 @import "../application/assets/tooltip.scss"; | |
75 | |
76 .main { | |
77 height: 100vh; | |
78 } | |
79 | |
80 .backwards { | |
81 margin-right: 0.5rem; | |
82 } | |
83 | |
84 .forwards { | |
85 margin-left: 0.5rem; | |
86 } | |
87 | |
88 .content { | |
89 margin-top: $large-offset; | |
90 margin-left: auto; | |
91 margin-right: auto; | |
92 } | |
93 | |
94 .adduser { | |
95 margin-right: $offset; | |
96 padding-bottom: $offset; | |
97 } | |
98 | |
99 .icon { | |
100 font-size: large; | |
101 } | |
102 | |
103 .userlist { | |
104 margin-top: $topbarheight; | |
105 margin-right: $offset; | |
106 min-width: 520px; | |
107 height: 100%; | |
108 } | |
109 | |
110 .pagination { | |
111 margin-left: auto; | |
112 margin-right: auto; | |
113 } | |
114 .userlistsmall { | |
115 width: 30vw; | |
116 } | |
117 | |
118 .userlistextended { | |
119 width: 70vw; | |
120 } | |
121 | |
122 .table { | |
123 width: 90% !important; | |
124 margin: auto; | |
125 } | |
126 | |
127 .table th, | |
128 .pages { | |
129 cursor: pointer; | |
130 } | |
131 | |
132 .table th, | |
133 td { | |
134 font-size: 0.9rem; | |
135 border-top: 0px !important; | |
136 text-align: left; | |
137 padding: 0.5rem !important; | |
138 } | |
139 | |
140 .table td { | |
141 font-size: 0.9rem; | |
142 cursor: pointer; | |
143 } | |
144 | |
145 tr span { | |
146 display: flex; | |
147 } | |
148 </style> | |
149 | |
150 <script> | |
151 import Userdetail from "./Userdetail"; | |
152 import store from "../store"; | |
153 import { mapGetters } from "vuex"; | |
154 import { displayError } from "../application/lib/errors.js"; | |
155 | |
156 export default { | |
157 name: "userview", | |
158 data() { | |
159 return { | |
160 sortCriterion: "user", | |
161 pageSize: 10, | |
162 currentPage: 1 | |
163 }; | |
164 }, | |
165 components: { | |
166 Userdetail | |
167 }, | |
168 computed: { | |
169 ...mapGetters("usermanagement", ["isUserDetailsVisible"]), | |
170 ...mapGetters("application", ["sidebarCollapsed"]), | |
171 users() { | |
172 let users = [...this.$store.getters["usermanagement/users"]]; | |
173 users.sort((a, b) => { | |
174 if ( | |
175 a[this.sortCriterion].toLowerCase() < | |
176 b[this.sortCriterion].toLowerCase() | |
177 ) | |
178 return -1; | |
179 if ( | |
180 a[this.sortCriterion].toLowerCase() > | |
181 b[this.sortCriterion].toLowerCase() | |
182 ) | |
183 return 1; | |
184 return 0; | |
185 }); | |
186 const start = (this.currentPage - 1) * this.pageSize; | |
187 return users.slice(start, start + this.pageSize); | |
188 }, | |
189 pages() { | |
190 let users = [...this.$store.getters["usermanagement/users"]]; | |
191 return Math.ceil(users.length / this.pageSize); | |
192 }, | |
193 tableStyle() { | |
194 return { | |
195 table: true, | |
196 "table-hover": true, | |
197 "table-sm": this.isUserDetailsVisible, | |
198 fadeIn: true, | |
199 animated: true | |
200 }; | |
201 }, | |
202 userlistStyle() { | |
203 return { | |
204 userlist: true, | |
205 shadow: true, | |
206 userlistsmall: this.isUserDetailsVisible, | |
207 userlistextended: !this.isUserDetailsVisible | |
208 }; | |
209 } | |
210 }, | |
211 methods: { | |
212 tween() {}, | |
213 nextPage() { | |
214 if (this.currentPage < this.pages) { | |
215 document.querySelector("#datatable").classList.add("fadeOut"); | |
216 setTimeout(() => { | |
217 document.querySelector("#datatable").classList.remove("fadeOut"); | |
218 this.currentPage += 1; | |
219 }, 10); | |
220 } | |
221 return; | |
222 }, | |
223 prevPage() { | |
224 if (this.currentPage > 0) { | |
225 document.querySelector("#datatable").classList.add("fadeOut"); | |
226 setTimeout(() => { | |
227 document.querySelector("#datatable").classList.remove("fadeOut"); | |
228 this.currentPage -= 1; | |
229 }, 10); | |
230 } | |
231 return; | |
232 }, | |
233 sortBy(criterion) { | |
234 this.sortCriterion = criterion; | |
235 }, | |
236 deleteUser(name) { | |
237 this.$store | |
238 .dispatch("usermanagement/deleteUser", { name: name }) | |
239 .then(() => { | |
240 this.submitted = false; | |
241 this.$store.dispatch("usermanagement/loadUsers").catch(error => { | |
242 const { status, data } = error.response; | |
243 displayError({ | |
244 title: "Backend Error", | |
245 message: `${status}: ${data.message || data}` | |
246 }); | |
247 }); | |
248 }) | |
249 .catch(error => { | |
250 const { status, data } = error.response; | |
251 displayError({ | |
252 title: "Backend Error", | |
253 message: `${status}: ${data.message || data}` | |
254 }); | |
255 }); | |
256 }, | |
257 addUser() { | |
258 this.$store.commit("usermanagement/clearCurrentUser"); | |
259 this.$store.commit("usermanagement/setUserDetailsVisible"); | |
260 }, | |
261 selectUser(name) { | |
262 const user = this.$store.getters["usermanagement/getUserByName"](name); | |
263 this.$store.commit("usermanagement/setCurrentUser", user); | |
264 } | |
265 }, | |
266 beforeRouteEnter(to, from, next) { | |
267 store | |
268 .dispatch("usermanagement/loadUsers") | |
269 .then(next) | |
270 .catch(error => { | |
271 const { status, data } = error.response; | |
272 displayError({ | |
273 title: "Backend Error", | |
274 message: `${status}: ${data}` | |
275 }); | |
276 }); | |
277 }, | |
278 beforeRouteLeave(to, from, next) { | |
279 store.commit("usermanagement/clearCurrentUser"); | |
280 store.commit("usermanagement/setUserDetailsInvisible"); | |
281 next(); | |
282 } | |
283 }; | |
284 </script> |