mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
add users data call/storing
This commit is contained in:
parent
b5898d41aa
commit
687d93882a
2 changed files with 18 additions and 16 deletions
|
@ -2,17 +2,23 @@ import api from './api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
domains: undefined
|
domains: undefined,
|
||||||
|
users: undefined
|
||||||
}),
|
}),
|
||||||
mutations: {
|
mutations: {
|
||||||
'SET_DATA' (state, { key, data }) {
|
'SET_DOMAINS' (state, domains) {
|
||||||
state[key] = data
|
state.domains = domains
|
||||||
|
},
|
||||||
|
'SET_USERS' (state, users) {
|
||||||
|
console.log(users)
|
||||||
|
state.users = Object.keys(users).length === 0 ? null : Object.values(users)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async 'FETCH' ({ commit }, uri) {
|
async 'FETCH' ({ commit }, uri) {
|
||||||
return api.get('/' + uri).then(data => {
|
return api.get(uri).then(responseData => {
|
||||||
commit('SET_DATA', { data: data[uri], key: uri })
|
const data = responseData[uri] ? responseData[uri] : responseData
|
||||||
|
commit('SET_' + uri.toUpperCase(), data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -54,30 +54,26 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import api from '@/helpers/api'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'UserList',
|
name: 'UserList',
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
search: '',
|
search: ''
|
||||||
users: undefined
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
users () {
|
||||||
|
return this.$store.state.data.users
|
||||||
|
},
|
||||||
filteredUser () {
|
filteredUser () {
|
||||||
|
const search = this.search.toLowerCase()
|
||||||
return this.users.filter(user => {
|
return this.users.filter(user => {
|
||||||
return user.username.toLowerCase().includes(this.search.toLowerCase())
|
return user.username.toLowerCase().includes(search)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async created () {
|
async created () {
|
||||||
const data = await api.get('users')
|
this.$store.dispatch('FETCH', 'users')
|
||||||
if (!data || Object.keys(data.users).length === 0) {
|
|
||||||
this.users = null
|
|
||||||
} else {
|
|
||||||
this.users = Object.values(data.users)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue