Improved team search and team managing #18
|
@ -9,13 +9,13 @@
|
|||
<div class="card-content content teams-list">
|
||||
<form @submit.prevent="addTeam()" class="add-team-form" v-if="userIsAdmin">
|
||||
<div class="field is-grouped">
|
||||
<p class="control is-expanded" v-bind:class="{ 'is-loading': this.teamService.loading}">
|
||||
<p class="control is-expanded" v-bind:class="{ 'is-loading': teamService.loading}">
|
||||
<multiselect
|
||||
v-model="team"
|
||||
:options="foundTeams"
|
||||
:multiple="false"
|
||||
:searchable="true"
|
||||
:loading="teamStuffService.loading"
|
||||
:loading="teamService.loading"
|
||||
:internal-search="true"
|
||||
@search-change="findTeams"
|
||||
placeholder="Type to search a team"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<header class="card-header">
|
||||
<p class="card-header-title">
|
||||
Users with access to this {{type}}
|
||||
Users with access to this {{typeString}}
|
||||
</p>
|
||||
</header>
|
||||
<div class="card-content content users-list">
|
||||
|
@ -28,7 +28,7 @@
|
|||
</multiselect>
|
||||
</p>
|
||||
<p class="control">
|
||||
<button type="submit" class="button is-success" style="margin-top: 3px;">
|
||||
<button type="submit" class="button is-success">
|
||||
<span class="icon is-small">
|
||||
<icon icon="plus"/>
|
||||
</span>
|
||||
|
@ -47,13 +47,13 @@
|
|||
</template>
|
||||
</td>
|
||||
<td class="type">
|
||||
<template v-if="u.right === 2">
|
||||
<template v-if="u.right === rights.ADMIN">
|
||||
<span class="icon is-small">
|
||||
<icon icon="lock"/>
|
||||
</span>
|
||||
Admin
|
||||
</template>
|
||||
<template v-else-if="u.right === 1">
|
||||
<template v-else-if="u.right === rights.READ_WRITE">
|
||||
<span class="icon is-small">
|
||||
<icon icon="pen"/>
|
||||
</span>
|
||||
|
@ -67,19 +67,17 @@
|
|||
</template>
|
||||
</td>
|
||||
<td class="actions" v-if="userIsAdmin">
|
||||
<button @click="toggleUserType(u.id, (u.right === 2))" class="button buttonright is-primary" v-if="u.id !== currentUser.id">
|
||||
Make
|
||||
<template v-if="u.right === 2">
|
||||
Member
|
||||
</template>
|
||||
<template v-else>
|
||||
Admin
|
||||
</template>
|
||||
</button>
|
||||
<button @click="user = u; showUserDeleteModal = true" class="button is-danger" v-if="u.id !== currentUser.id">
|
||||
<span class="icon is-small">
|
||||
<icon icon="trash-alt"/>
|
||||
</span>
|
||||
<div class="select">
|
||||
<select @change="userStuffModel.userID = u.id;toggleUserType()" v-model="selectedRight" class="button buttonright">
|
||||
<option :value="rights.READ" :selected="u.right === rights.READ">Read only</option>
|
||||
<option :value="rights.READ_WRITE" :selected="u.right === rights.READ_WRITE">Read & write</option>
|
||||
<option :value="rights.ADMIN" :selected="u.right === rights.ADMIN">Admin</option>
|
||||
</select>
|
||||
</div>
|
||||
<button @click="userStuffModel.userID = u.id; showUserDeleteModal = true" class="button is-danger icon-only">
|
||||
<span class="icon is-small">
|
||||
<icon icon="trash-alt"/>
|
||||
</span>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -103,14 +101,15 @@
|
|||
import message from '../../message'
|
||||
import multiselect from 'vue-multiselect'
|
||||
import 'vue-multiselect/dist/vue-multiselect.min.css'
|
||||
|
||||
import UserService from '../../services/user'
|
||||
|
||||
import UserNamespaceService from '../../services/userNamespace'
|
||||
import UserNamespaceModel from '../../models/userNamespace'
|
||||
import UserListModel from '../../models/userList'
|
||||
import UserListService from '../../services/userList'
|
||||
import UserNamespaceService from '../../services/userNamespace'
|
||||
import UserService from '../../services/user'
|
||||
import UserModel from '../../models/user'
|
||||
|
||||
import rights from '../../models/rights'
|
||||
|
||||
export default {
|
||||
name: 'user',
|
||||
props: {
|
||||
|
@ -120,16 +119,19 @@
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
userService: UserService, // To search for users
|
||||
userStuffService: Object, // This user service is either a userNamespaceService or a userListService, depending on the type we are using
|
||||
userStuffModel: Object,
|
||||
userService: UserService,
|
||||
|
||||
user: UserModel,
|
||||
userStuff: Object, // This will be either UserNamespaceModel or UserListModel
|
||||
userStuffService: Object, // This will be either UserListService or UserNamespaceService
|
||||
|
||||
foundUsers: [],
|
||||
rights: rights,
|
||||
selectedRight: rights.READ,
|
||||
|
||||
currentUser: auth.user.infos,
|
||||
typeString: '',
|
||||
showUserDeleteModal: false,
|
||||
users: [],
|
||||
foundUsers: [],
|
||||
showUserDeleteModal: false,
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
@ -138,75 +140,82 @@
|
|||
created() {
|
||||
this.userService = new UserService()
|
||||
this.user = new UserModel()
|
||||
|
||||
|
||||
if (this.type === 'list') {
|
||||
this.typeString = `list`
|
||||
this.userStuffService = new UserListService()
|
||||
this.userStuff = new UserListModel({listID: this.id})
|
||||
this.userStuffModel = new UserListModel({listID: this.id})
|
||||
} else if (this.type === 'namespace') {
|
||||
this.typeString = `namespace`
|
||||
this.userStuffService = new UserNamespaceService()
|
||||
this.userStuff = new UserNamespaceModel({namespaceID: this.id})
|
||||
this.userStuffModel = new UserNamespaceModel({namespaceID: this.id})
|
||||
} else {
|
||||
throw new Error('Unknown type: ' + this.type)
|
||||
}
|
||||
|
||||
|
||||
this.loadUsers()
|
||||
},
|
||||
methods: {
|
||||
loadUsers() {
|
||||
this.userStuffService.getAll(this.userStuff)
|
||||
.then(response => {
|
||||
this.$set(this, 'users', response)
|
||||
this.userStuffService.getAll(this.userStuffModel)
|
||||
.then(r => {
|
||||
this.$set(this, 'users', r)
|
||||
})
|
||||
.catch(e => {
|
||||
message.error(e, this)
|
||||
})
|
||||
},
|
||||
deleteUser() {
|
||||
// The api wants the user id as userID
|
||||
let usr = this.user
|
||||
this.userStuff.userID = usr.id
|
||||
|
||||
this.userStuffService.delete(this.userStuff)
|
||||
this.userStuffService.delete(this.userStuffModel)
|
||||
.then(() => {
|
||||
this.showUserDeleteModal = false;
|
||||
this.showUserDeleteModal = false
|
||||
for (const i in this.users) {
|
||||
if (this.users[i].id === this.userStuffModel.userID) {
|
||||
this.users.splice(i, 1)
|
||||
}
|
||||
}
|
||||
message.success({message: 'The user was successfully deleted from the ' + this.typeString + '.'}, this)
|
||||
this.loadUsers()
|
||||
})
|
||||
.catch(e => {
|
||||
message.error(e, this)
|
||||
})
|
||||
},
|
||||
addUser(admin = false) {
|
||||
this.userStuff.right = 0
|
||||
addUser(admin) {
|
||||
if(admin === null) {
|
||||
admin = false
|
||||
}
|
||||
this.userStuffModel.right = rights.READ
|
||||
if (admin) {
|
||||
this.userStuff.right = 2
|
||||
this.userStuffModel.right = rights.ADMIN
|
||||
}
|
||||
|
||||
// The api wants the user id as userID
|
||||
this.userStuff.userID = this.user.id
|
||||
this.$set(this, 'foundUsers', [])
|
||||
|
||||
this.userStuffService.create(this.userStuff)
|
||||
|
||||
this.userStuffModel.userID = this.user.id
|
||||
|
||||
this.userStuffService.create(this.userStuffModel)
|
||||
.then(() => {
|
||||
this.loadUsers()
|
||||
message.success({message: 'The user was successfully added.'}, this)
|
||||
this.loadUsers()
|
||||
})
|
||||
.catch(e => {
|
||||
message.error(e, this)
|
||||
})
|
||||
},
|
||||
toggleUserType(userid, current) {
|
||||
this.userStuff.userID = userid
|
||||
this.userStuff.right = 0
|
||||
if (!current) {
|
||||
this.userStuff.right = 2
|
||||
toggleUserType() {
|
||||
if (this.selectedRight !== rights.ADMIN &&
|
||||
this.selectedRight !== rights.READ &&
|
||||
this.selectedRight !== rights.READ_WRITE
|
||||
) {
|
||||
this.selectedRight = rights.READ
|
||||
}
|
||||
|
||||
this.userStuffService.update(this.userStuff)
|
||||
.then(() => {
|
||||
this.loadUsers()
|
||||
this.userStuffModel.right = this.selectedRight
|
||||
|
||||
this.userStuffService.update(this.userStuffModel)
|
||||
.then(r => {
|
||||
for (const i in this.users) {
|
||||
if (this.users[i].id === this.userStuffModel.userID) {
|
||||
this.$set(this.users[i], 'right', r.right)
|
||||
}
|
||||
}
|
||||
message.success({message: 'The user right was successfully updated.'}, this)
|
||||
})
|
||||
.catch(e => {
|
||||
|
@ -218,7 +227,7 @@
|
|||
this.$set(this, 'foundUsers', [])
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
this.userService.getAll({}, {s: query})
|
||||
.then(response => {
|
||||
this.$set(this, 'foundUsers', response)
|
||||
|
@ -237,7 +246,7 @@
|
|||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
.card{
|
||||
margin-bottom: 1rem;
|
||||
|
||||
|
@ -253,7 +262,7 @@
|
|||
}
|
||||
|
||||
td.type, td.actions{
|
||||
width: 200px;
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
td.actions{
|
||||
|
@ -265,27 +274,4 @@
|
|||
.users-list, .users-namespace{
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
ul.multiselect__content{
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
.multiselect{
|
||||
background-color: white;
|
||||
border: 1px solid #dbdbdb;
|
||||
color: #363636;
|
||||
-webkit-box-shadow: inset 0 1px 2px rgba(10, 10, 10, 0.1);
|
||||
box-shadow: inset 0 1px 2px rgba(10, 10, 10, 0.1);
|
||||
|
||||
border-radius: 4px;
|
||||
font-size: 1rem;
|
||||
height: 2.25em;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.multiselect--active{
|
||||
-webkit-box-shadow: inset 0 0.125em 0 rgba(10, 10, 10, 0.075), 0 0 0 0.125em rgba(91, 183, 219, 0.25);
|
||||
box-shadow: inset 0 0.125em 0 rgba(10, 10, 10, 0.075), 0 0 0 0.125em rgba(91, 183, 219, 0.25);
|
||||
border: 1px solid #5bb7db;
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user