Skip to content

Commit eae5cdf

Browse files
committed
Add group display to admin panel
1 parent 7be880d commit eae5cdf

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

webapp/src/components/AdminDisplay.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<template>
22
<div class="admin-display">
33
<template v-if="selectedItem === 'Users'"> <UserTable /> </template>
4+
<template v-else-if="selectedItem === 'Groups'"> <GroupTable /> </template>
45
</div>
56
</template>
67

78
<script>
89
import UserTable from "./UserTable.vue";
10+
import GroupTable from "./GroupTable.vue";
911
1012
export default {
1113
name: "AdminDisplay",
12-
components: { UserTable },
14+
components: { UserTable, GroupTable },
1315
props: {
1416
selectedItem: {
1517
type: String,

webapp/src/components/GroupTable.vue

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<template>
2+
<table class="table table-hover table-sm" data-testid="user-table">
3+
<thead>
4+
<tr>
5+
<th scope="col">Group ID</th>
6+
<th scope="col">Name</th>
7+
<th scope="col">Description</th>
8+
<th></th>
9+
</tr>
10+
</thead>
11+
<tbody>
12+
<tr v-for="group in groups" :key="group.group_id">
13+
<td align="left">
14+
<span class="badge badge-light table-group-id">{{ group.group_id }}</span>
15+
</td>
16+
<td align="left">{{ group.display_name }}</td>
17+
<td align="left">{{ group.description }}</td>
18+
<td align="right"><font-awesome-icon :icon="['far', 'plus-square']" /></td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
</template>
23+
24+
<script>
25+
import { getGroupsList } from "@/server_fetch_utils.js";
26+
27+
export default {
28+
data() {
29+
return {
30+
groups: null,
31+
original_groups: null,
32+
};
33+
},
34+
created() {
35+
this.getGroups();
36+
},
37+
methods: {
38+
async getGroups() {
39+
let data = await getGroupsList();
40+
if (data != null) {
41+
this.groups = JSON.parse(JSON.stringify(data));
42+
this.original_groups = JSON.parse(JSON.stringify(data));
43+
}
44+
},
45+
},
46+
};
47+
</script>
48+
49+
<style scoped>
50+
td {
51+
vertical-align: middle;
52+
}
53+
54+
.table-group-id {
55+
border: 2px solid #ccc;
56+
}
57+
58+
select {
59+
border: 1px solid #ccc;
60+
border-radius: 0.25rem;
61+
}
62+
63+
.badge {
64+
margin-left: 1em;
65+
font-family: "Andalé Mono", monospace;
66+
}
67+
</style>

webapp/src/components/UserTable.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</tr>
1010
</thead>
1111
<tbody>
12-
<tr v-for="user in users" :key="user._id">
12+
<tr v-for="user in users" :key="user.immutable_id">
1313
<td align="left">
1414
{{ user.display_name }}
1515
<span v-if="user.account_status === 'active'" class="badge badge-success text-uppercase">

webapp/src/server_fetch_utils.js

+13
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ export function getUsersList() {
269269
});
270270
}
271271

272+
export function getGroupsList() {
273+
return fetch_get(`${API_URL}/groups`)
274+
.then(function (response_json) {
275+
const groups = response_json.data;
276+
return groups;
277+
})
278+
.catch((error) => {
279+
console.error("Error when fetching groups list");
280+
console.error(error);
281+
throw error;
282+
});
283+
}
284+
272285
export function getStartingMaterialList() {
273286
return fetch_get(`${API_URL}/starting-materials/`)
274287
.then(function (response_json) {

webapp/src/views/Admin.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default {
2323
},
2424
data() {
2525
return {
26-
items: ["Users"],
26+
items: ["Users", "Groups"],
2727
selectedItem: "Users",
2828
user: null,
2929
};

0 commit comments

Comments
 (0)