comparison client/src/views/Usermanagement.vue @ 583:a27c405ec1a8

added missing vue files
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 07 Sep 2018 08:40:21 +0200
parents
children
comparison
equal deleted inserted replaced
582:93e90f6be2ad 583:a27c405ec1a8
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&nbsp;
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&nbsp;
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&nbsp;
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&nbsp;
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 "../assets/application.scss";
74 @import "../assets/tooltip.scss";
75 .main {
76 height: 100vh;
77 }
78
79 .backwards {
80 margin-right: 0.5rem;
81 }
82
83 .forwards {
84 margin-left: 0.5rem;
85 }
86
87 .content {
88 margin-top: $large-offset;
89 margin-left: auto;
90 margin-right: auto;
91 }
92
93 .adduser {
94 margin-right: $offset;
95 padding-bottom: $offset;
96 }
97
98 .icon {
99 font-size: large;
100 }
101
102 .userlist {
103 margin-top: $topbarheight;
104 margin-right: $offset;
105 min-width: 520px;
106 height: 100%;
107 }
108
109 .pagination {
110 margin-left: auto;
111 margin-right: auto;
112 }
113 .userlistsmall {
114 width: 30vw;
115 }
116
117 .userlistextended {
118 width: 70vw;
119 }
120
121 .table {
122 width: 90% !important;
123 margin: auto;
124 }
125
126 .table th,
127 .pages {
128 cursor: pointer;
129 }
130
131 .table th,
132 td {
133 font-size: 0.9rem;
134 border-top: 0px !important;
135 text-align: left;
136 padding: 0.5rem !important;
137 }
138
139 .table td {
140 font-size: 0.9rem;
141 cursor: pointer;
142 }
143
144 tr span {
145 display: flex;
146 }
147 </style>
148
149 <script>
150 import Userdetail from "../components/Userdetail";
151 import store from "../store";
152 import { mapGetters } from "vuex";
153 import { displayError } from "../lib/errors.js";
154
155 export default {
156 name: "userview",
157 data() {
158 return {
159 sortCriterion: "user",
160 pageSize: 10,
161 currentPage: 1
162 };
163 },
164 components: {
165 Userdetail
166 },
167 computed: {
168 ...mapGetters("usermanagement", ["isUserDetailsVisible"]),
169 ...mapGetters("application", ["sidebarCollapsed"]),
170 users() {
171 let users = [...this.$store.getters["usermanagement/users"]];
172 users.sort((a, b) => {
173 if (
174 a[this.sortCriterion].toLowerCase() <
175 b[this.sortCriterion].toLowerCase()
176 )
177 return -1;
178 if (
179 a[this.sortCriterion].toLowerCase() >
180 b[this.sortCriterion].toLowerCase()
181 )
182 return 1;
183 return 0;
184 });
185 const start = (this.currentPage - 1) * this.pageSize;
186 return users.slice(start, start + this.pageSize);
187 },
188 pages() {
189 let users = [...this.$store.getters["usermanagement/users"]];
190 return Math.ceil(users.length / this.pageSize);
191 },
192 tableStyle() {
193 return {
194 table: true,
195 "table-hover": true,
196 "table-sm": this.isUserDetailsVisible,
197 fadeIn: true,
198 animated: true
199 };
200 },
201 userlistStyle() {
202 return {
203 userlist: true,
204 shadow: true,
205 userlistsmall: this.isUserDetailsVisible,
206 userlistextended: !this.isUserDetailsVisible
207 };
208 }
209 },
210 methods: {
211 tween() {},
212 nextPage() {
213 if (this.currentPage < this.pages) {
214 document.querySelector("#datatable").classList.add("fadeOut");
215 setTimeout(() => {
216 document.querySelector("#datatable").classList.remove("fadeOut");
217 this.currentPage += 1;
218 }, 10);
219 }
220 return;
221 },
222 prevPage() {
223 if (this.currentPage > 0) {
224 document.querySelector("#datatable").classList.add("fadeOut");
225 setTimeout(() => {
226 document.querySelector("#datatable").classList.remove("fadeOut");
227 this.currentPage -= 1;
228 }, 10);
229 }
230 return;
231 },
232 sortBy(criterion) {
233 this.sortCriterion = criterion;
234 },
235 deleteUser(name) {
236 this.$store
237 .dispatch("usermanagement/deleteUser", { name: name })
238 .then(() => {
239 this.submitted = false;
240 this.$store.dispatch("usermanagement/loadUsers").catch(error => {
241 const { status, data } = error.response;
242 displayError({
243 title: "Backend Error",
244 message: `${status}: ${data.message || data}`
245 });
246 });
247 })
248 .catch(error => {
249 const { status, data } = error.response;
250 displayError({
251 title: "Backend Error",
252 message: `${status}: ${data.message || data}`
253 });
254 });
255 },
256 addUser() {
257 this.$store.commit("usermanagement/clearCurrentUser");
258 this.$store.commit("usermanagement/setUserDetailsVisible");
259 },
260 selectUser(name) {
261 const user = this.$store.getters["usermanagement/getUserByName"](name);
262 this.$store.commit("usermanagement/setCurrentUser", user);
263 }
264 },
265 beforeRouteEnter(to, from, next) {
266 store
267 .dispatch("usermanagement/loadUsers")
268 .then(next)
269 .catch(error => {
270 const { status, data } = error.response;
271 displayError({
272 title: "Backend Error",
273 message: `${status}: ${data}`
274 });
275 });
276 },
277 beforeRouteLeave(to, from, next) {
278 store.commit("usermanagement/clearCurrentUser");
279 store.commit("usermanagement/setUserDetailsInvisible");
280 next();
281 }
282 };
283 </script>