Started moving user sharing to models
All checks were successful
the build was successful

This commit is contained in:
kolaente 2019-02-25 08:57:29 +01:00
parent d670fb7e17
commit c4b24bc9b8
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 28 additions and 16 deletions

View File

@ -20,7 +20,7 @@
@search-change="findUsers"
placeholder="Type to search a user"
label="username"
track-by="user_id">
track-by="id">
<template slot="clear" slot-scope="props">
<div class="multiselect__clear" v-if="newUser.id !== 0" @mousedown.prevent.stop="clearAll(props.search)"></div>
@ -105,6 +105,8 @@
import message from '../../message'
import multiselect from 'vue-multiselect'
import 'vue-multiselect/dist/vue-multiselect.min.css'
import UserService from '../../services/user'
import UserModel from '../../models/user'
export default {
name: 'user',
@ -115,12 +117,14 @@
},
data() {
return {
userService: UserService,
loading: false,
currentUser: auth.user.infos,
typeString: '',
showUserDeleteModal: false,
users: [],
newUser: {username: '', user_id: 0},
newUser: UserModel,
userToDelete: 0,
newUserid: 0,
foundUsers: [],
@ -130,6 +134,7 @@
multiselect
},
created() {
this.userService = new UserService()
if (this.type === 'list') {
this.typeString = `list`
} else if (this.type === 'namespace') {
@ -178,6 +183,9 @@
this.newUser.right = 2
}
// TODO
// let newUserShare = new UserShareModel({user_id: this.newUser.id, listID: lorem.
this.$set(this, 'foundUsers', [])
HTTP.put(this.typeString + `s/` + this.id + `/users`, this.newUser, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
@ -218,24 +226,14 @@
return
}
this.$set(this, 'newUser', {username: '', user_id: 0})
this.$set(this, 'newUser', new UserModel)
HTTP.get(`users?s=` + query, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
this.userService.getAll({}, {s: query})
.then(response => {
this.$set(this, 'foundUsers', [])
for (const u in response.data) {
this.foundUsers.push({
username: response.data[u].username,
user_id: response.data[u].id,
})
}
cancel()
this.$set(this, 'foundUsers', response)
})
.catch(e => {
cancel()
this.handleError(e)
message.error(e, this)
})
},
clearAll () {

14
src/services/user.js Normal file
View File

@ -0,0 +1,14 @@
import AbstractService from './abstractService'
import UserModel from '../models/user'
export default class UserService extends AbstractService {
constructor() {
super({
getAll: '/users'
})
}
modelFactory(data) {
return new UserModel(data)
}
}