mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
add FETCH args for custom keyStore and param, separate users and precise user data storing
This commit is contained in:
parent
04fa1ecf01
commit
474e70fa92
4 changed files with 43 additions and 23 deletions
|
@ -1,26 +1,36 @@
|
||||||
|
import Vue from 'vue'
|
||||||
import api from './api'
|
import api from './api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
domains: undefined,
|
domains: undefined, // Array
|
||||||
users: undefined
|
users: undefined, // basic user data: Object {username: {data}}
|
||||||
|
users_details: {} // precise user data: Object {username: {data}}
|
||||||
}),
|
}),
|
||||||
mutations: {
|
mutations: {
|
||||||
'SET_DOMAINS' (state, domains) {
|
'SET_DOMAINS' (state, domains) {
|
||||||
state.domains = domains
|
state.domains = domains
|
||||||
},
|
},
|
||||||
'SET_USERS' (state, users) {
|
'SET_USERS' (state, users) {
|
||||||
console.log(users)
|
state.users = Object.keys(users).length === 0 ? null : users
|
||||||
state.users = Object.keys(users).length === 0 ? null : Object.values(users)
|
},
|
||||||
|
'SET_USERS_PARAM' (state, [username, userData]) {
|
||||||
|
Vue.set(state.users_details, username, userData)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async 'FETCH' ({ state, commit }, { uri, force = false }) {
|
'FETCH' ({ state, commit, dispatch }, { uri, param, storeKey = uri, force = false }) {
|
||||||
|
const currentState = param ? state[storeKey][param] : state[storeKey]
|
||||||
// if data has already been queried, simply return
|
// if data has already been queried, simply return
|
||||||
if (state[uri] !== undefined && !force) return
|
if (currentState !== undefined && !force) return
|
||||||
return api.get(uri).then(responseData => {
|
console.log(`will query: "/${param ? `${uri}/${param}` : uri}" and will store in "${storeKey || uri}"`)
|
||||||
|
return api.get(param ? `${uri}/${param}` : uri).then(responseData => {
|
||||||
const data = responseData[uri] ? responseData[uri] : responseData
|
const data = responseData[uri] ? responseData[uri] : responseData
|
||||||
commit('SET_' + uri.toUpperCase(), data)
|
if (param) {
|
||||||
|
commit(`SET_${uri.toUpperCase()}_PARAM`, [param, data])
|
||||||
|
} else {
|
||||||
|
commit('SET_' + uri.toUpperCase(), data)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,52 +1,63 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="user">
|
<div class="user">
|
||||||
<breadcrumb />
|
<breadcrumb />
|
||||||
|
|
||||||
<b-card :class="{skeleton: !user}">
|
<b-card :class="{skeleton: !user}">
|
||||||
<template v-slot:header>
|
<template v-slot:header>
|
||||||
<h2>{{ user ? user.fullname : '' }}</h2>
|
<h2>{{ user ? user.fullname : '' }}</h2>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<icon iname="user" class="fa-fw" />
|
<icon iname="user" class="fa-fw" />
|
||||||
|
|
||||||
<div class="w-100">
|
<div class="w-100">
|
||||||
<template v-if="user">
|
<template v-if="user">
|
||||||
<b-row>
|
<b-row>
|
||||||
<b-col><strong>{{ $t('user_username') }}</strong></b-col>
|
<b-col><strong>{{ $t('user_username') }}</strong></b-col>
|
||||||
<b-col>{{ user.username }}</b-col>
|
<b-col>{{ user.username }}</b-col>
|
||||||
</b-row>
|
</b-row>
|
||||||
|
|
||||||
<b-row>
|
<b-row>
|
||||||
<b-col><strong>{{ $t('user_email') }}</strong></b-col>
|
<b-col><strong>{{ $t('user_email') }}</strong></b-col>
|
||||||
<b-col class="font-italic">
|
<b-col class="font-italic">
|
||||||
{{ user.mail }}
|
{{ user.mail }}
|
||||||
</b-col>
|
</b-col>
|
||||||
</b-row>
|
</b-row>
|
||||||
|
|
||||||
<b-row>
|
<b-row>
|
||||||
<b-col><strong>{{ $t('user_mailbox_quota') }}</strong></b-col>
|
<b-col><strong>{{ $t('user_mailbox_quota') }}</strong></b-col>
|
||||||
<b-col>{{ user['mailbox-quota'].limit }}</b-col>
|
<b-col>{{ user['mailbox-quota'].limit }}</b-col>
|
||||||
</b-row>
|
</b-row>
|
||||||
|
|
||||||
<b-row>
|
<b-row>
|
||||||
<b-col><strong>{{ $t('user_mailbox_use') }}</strong></b-col>
|
<b-col><strong>{{ $t('user_mailbox_use') }}</strong></b-col>
|
||||||
<b-col>{{ user['mailbox-quota'].use }}</b-col>
|
<b-col>{{ user['mailbox-quota'].use }}</b-col>
|
||||||
</b-row>
|
</b-row>
|
||||||
|
|
||||||
<b-row v-for="(trad, mailType) in {'mail-aliases': 'user_emailaliases', 'mail-forward': 'user_emailforward'}" :key="mailType">
|
<b-row v-for="(trad, mailType) in {'mail-aliases': 'user_emailaliases', 'mail-forward': 'user_emailforward'}" :key="mailType">
|
||||||
<b-col><strong>{{ $t(trad) }}</strong></b-col>
|
<b-col><strong>{{ $t(trad) }}</strong></b-col>
|
||||||
<b-col>
|
|
||||||
<ul v-if="user[mailType] && user[mailType].length > 1">
|
<b-col v-if="user[mailType]">
|
||||||
|
<ul v-if="user[mailType].length > 1">
|
||||||
<li v-for="(alias, index) in user[mailType]" :key="index">
|
<li v-for="(alias, index) in user[mailType]" :key="index">
|
||||||
{{ alias }}
|
{{ alias }}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<template v-else-if="user[mailType][0]">
|
<template v-else-if="user[mailType][0]">
|
||||||
{{ user[mailType][0] }}
|
{{ user[mailType][0] }}
|
||||||
</template>
|
</template>
|
||||||
</b-col>
|
</b-col>
|
||||||
</b-row>
|
</b-row>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- skeleton -->
|
<!-- skeleton -->
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<b-row v-for="(n, index) in 6" :key="index">
|
<b-row v-for="(n, index) in 6" :key="index">
|
||||||
<b-col>
|
<b-col>
|
||||||
<strong class="rounded" />
|
<strong class="rounded" />
|
||||||
</b-col>
|
</b-col>
|
||||||
|
|
||||||
<b-col>
|
<b-col>
|
||||||
<span v-if="n <= 4" class="rounded" />
|
<span v-if="n <= 4" class="rounded" />
|
||||||
</b-col>
|
</b-col>
|
||||||
|
@ -61,6 +72,7 @@
|
||||||
>
|
>
|
||||||
{{ user ? $t('user_username_edit', {name: user.username}) : '' }}
|
{{ user ? $t('user_username_edit', {name: user.username}) : '' }}
|
||||||
</b-button>
|
</b-button>
|
||||||
|
|
||||||
<b-button :variant="user ? 'danger' : 'dark'" class="ml-2">
|
<b-button :variant="user ? 'danger' : 'dark'" class="ml-2">
|
||||||
{{ user ? $t('delete') : '' }}
|
{{ user ? $t('delete') : '' }}
|
||||||
</b-button>
|
</b-button>
|
||||||
|
@ -71,8 +83,6 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import api from '@/helpers/api'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'User',
|
name: 'User',
|
||||||
props: {
|
props: {
|
||||||
|
@ -81,15 +91,15 @@ export default {
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data: function () {
|
computed: {
|
||||||
return {
|
user () {
|
||||||
user: undefined
|
return this.$store.state.data.users_details[this.name]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async created () {
|
created () {
|
||||||
const data = await api.get('users/' + this.name)
|
this.$store.dispatch('FETCH',
|
||||||
if (!data) return
|
{ uri: 'users', param: this.name, storeKey: 'users_details' }
|
||||||
this.user = data
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -152,13 +152,11 @@ export default {
|
||||||
onSubmit () {
|
onSubmit () {
|
||||||
const data = this.form
|
const data = this.form
|
||||||
for (const key in this.validation) {
|
for (const key in this.validation) {
|
||||||
console.log(this.validation[key] === false, this.validation[key])
|
|
||||||
if (this.validation[key] === false) return
|
if (this.validation[key] === false) return
|
||||||
}
|
}
|
||||||
const quota = data.mailbox_quota
|
const quota = data.mailbox_quota
|
||||||
data.mailbox_quota = parseInt(quota) ? quota + 'M' : 0
|
data.mailbox_quota = parseInt(quota) ? quota + 'M' : 0
|
||||||
data.mail = `${data.email}@${data.domain}`
|
data.mail = `${data.email}@${data.domain}`
|
||||||
console.log('go')
|
|
||||||
// TODO post data
|
// TODO post data
|
||||||
},
|
},
|
||||||
validatePassword () {
|
validatePassword () {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
<icon iname="key-modern" />
|
<icon iname="key-modern" />
|
||||||
{{ $t('groups_and_permissions_manage') }}
|
{{ $t('groups_and_permissions_manage') }}
|
||||||
</b-button>
|
</b-button>
|
||||||
|
|
||||||
<b-button variant="success" :to="{name: 'user-create'}">
|
<b-button variant="success" :to="{name: 'user-create'}">
|
||||||
<icon iname="plus" />
|
<icon iname="plus" />
|
||||||
{{ $t('users_new') }}
|
{{ $t('users_new') }}
|
||||||
|
@ -63,7 +64,8 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
users () {
|
users () {
|
||||||
return this.$store.state.data.users
|
const users = this.$store.state.data.users
|
||||||
|
return users ? Object.values(users) : users
|
||||||
},
|
},
|
||||||
filteredUser () {
|
filteredUser () {
|
||||||
const search = this.search.toLowerCase()
|
const search = this.search.toLowerCase()
|
||||||
|
@ -72,7 +74,7 @@ export default {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async created () {
|
created () {
|
||||||
this.$store.dispatch('FETCH', { uri: 'users' })
|
this.$store.dispatch('FETCH', { uri: 'users' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue