Move everything to models and services #17
|
@ -77,7 +77,7 @@
|
|||
Admin
|
||||
</template>
|
||||
</button>
|
||||
<button @click="user.user_id = u.id; showUserDeleteModal = true" class="button is-danger" v-if="u.id !== currentUser.id">
|
||||
<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>
|
||||
|
@ -110,6 +110,7 @@
|
|||
import UserListModel from '../../models/userList'
|
||||
import UserListService from '../../services/userList'
|
||||
import UserNamespaceService from '../../services/userNamespace'
|
||||
import UserModel from "../../models/user";
|
||||
|
||||
export default {
|
||||
name: 'user',
|
||||
|
@ -121,8 +122,9 @@
|
|||
data() {
|
||||
return {
|
||||
userService: UserService, // To search for users
|
||||
user: UserModel,
|
||||
userStuff: Object, // This will be either UserNamespaceModel or UserListModel
|
||||
userStuffService: Object, // This will be either UserListService or UserNamespaceService
|
||||
user: Object, // This will be either UserNamespaceModel or UserListModel
|
||||
|
||||
loading: false,
|
||||
currentUser: auth.user.infos,
|
||||
|
@ -138,14 +140,16 @@
|
|||
},
|
||||
created() {
|
||||
this.userService = new UserService()
|
||||
this.user = new UserModel()
|
||||
|
||||
if (this.type === 'list') {
|
||||
this.typeString = `list`
|
||||
this.userStuffService = new UserListService()
|
||||
this.user = new UserListModel({listID: this.id})
|
||||
this.userStuff = new UserListModel({listID: this.id})
|
||||
} else if (this.type === 'namespace') {
|
||||
this.typeString = `namespace`
|
||||
this.userStuffService = new UserNamespaceService()
|
||||
this.user = new UserNamespaceModel({namespaceID: this.id})
|
||||
this.userStuff = new UserNamespaceModel({namespaceID: this.id})
|
||||
} else {
|
||||
throw new Error('Unknown type: ' + this.type)
|
||||
}
|
||||
|
@ -154,7 +158,7 @@
|
|||
},
|
||||
methods: {
|
||||
loadUsers() {
|
||||
this.userStuffService.getAll()
|
||||
this.userStuffService.getAll(this.userStuff)
|
||||
.then(response => {
|
||||
this.$set(this, 'users', response)
|
||||
})
|
||||
|
@ -163,7 +167,11 @@
|
|||
})
|
||||
},
|
||||
deleteUser() {
|
||||
this.userStuffService.delete(this.user)
|
||||
// The api wants the user id as userID
|
||||
let usr = this.user
|
||||
this.userStuff.userID = usr.id
|
||||
|
||||
this.userStuffService.delete(this.userStuff)
|
||||
.then(() => {
|
||||
this.showUserDeleteModal = false;
|
||||
this.handleSuccess({message: 'The user was successfully deleted from the ' + this.typeString + '.'})
|
||||
|
@ -174,20 +182,16 @@
|
|||
})
|
||||
},
|
||||
addUser(admin = false) {
|
||||
this.user.right = 0
|
||||
this.userStuff.right = 0
|
||||
if (admin) {
|
||||
this.user.right = 2
|
||||
this.userStuff.right = 2
|
||||
}
|
||||
|
||||
// The api wants the user id as user_id
|
||||
this.user.userID = this.user.id
|
||||
|
||||
// TODO
|
||||
// let newUserShare = new UserShareModel({user_id: this.newUser.id, listID: lorem.
|
||||
|
||||
// The api wants the user id as userID
|
||||
this.userStuff.userID = this.user.id
|
||||
this.$set(this, 'foundUsers', [])
|
||||
|
||||
this.userStuffService.create(this.user)
|
||||
this.userStuffService.create(this.userStuff)
|
||||
.then(() => {
|
||||
this.loadUsers()
|
||||
this.handleSuccess({message: 'The user was successfully added.'})
|
||||
|
@ -197,13 +201,13 @@
|
|||
})
|
||||
},
|
||||
toggleUserType(userid, current) {
|
||||
this.user.userID = userid
|
||||
this.user.right = 0
|
||||
this.userStuff.userID = userid
|
||||
this.userStuff.right = 0
|
||||
if (!current) {
|
||||
this.user.right = 2
|
||||
this.userStuff.right = 2
|
||||
}
|
||||
|
||||
this.userStuffService.update(this.user)
|
||||
this.userStuffService.update(this.userStuff)
|
||||
.then(() => {
|
||||
this.loadUsers()
|
||||
this.handleSuccess({message: 'The user right was successfully updated.'})
|
||||
|
|
Reference in New Issue
Block a user