Commit 33c05b32 authored by NGPixel's avatar NGPixel

refactor: admin-edit-user -> vue + fixes

parent d590c67d
...@@ -74,6 +74,7 @@ import pageLoaderComponent from './components/page-loader.vue' ...@@ -74,6 +74,7 @@ import pageLoaderComponent from './components/page-loader.vue'
import searchComponent from './components/search.vue' import searchComponent from './components/search.vue'
import treeComponent from './components/tree.vue' import treeComponent from './components/tree.vue'
import adminEditUserComponent from './pages/admin-edit-user.component.js'
import adminProfileComponent from './pages/admin-profile.component.js' import adminProfileComponent from './pages/admin-profile.component.js'
import adminSettingsComponent from './pages/admin-settings.component.js' import adminSettingsComponent from './pages/admin-settings.component.js'
import contentViewComponent from './pages/content-view.component.js' import contentViewComponent from './pages/content-view.component.js'
...@@ -163,6 +164,7 @@ $(() => { ...@@ -163,6 +164,7 @@ $(() => {
mixins: [helpers], mixins: [helpers],
components: { components: {
alert: alertComponent, alert: alertComponent,
adminEditUser: adminEditUserComponent,
adminProfile: adminProfileComponent, adminProfile: adminProfileComponent,
adminSettings: adminSettingsComponent, adminSettings: adminSettingsComponent,
anchor: anchorComponent, anchor: anchorComponent,
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
.modal-content(v-show='isShown') .modal-content(v-show='isShown')
header.is-blue header.is-blue
span {{ $t('modal.createusertitle') }} span {{ $t('modal.createusertitle') }}
p.modal-notify(v-bind:class='{ "is-active": isLoading }'): i p.modal-notify(:class='{ "is-active": isLoading }'): i
section section
label.label {{ $t('modal.createuseremail') }} label.label {{ $t('modal.createuseremail') }}
p.control.is-fullwidth p.control.is-fullwidth
input.input(type='text', v-bind:placeholder='$t("modal.createuseremailplaceholder")', v-model='email', ref='createUserEmailInput') input.input(type='text', :placeholder='$t("modal.createuseremailplaceholder")', v-model='email', ref='createUserEmailInput')
section section
label.label {{ $t('modal.createuserprovider') }} label.label {{ $t('modal.createuserprovider') }}
p.control.is-fullwidth p.control.is-fullwidth
...@@ -30,17 +30,17 @@ ...@@ -30,17 +30,17 @@
section(v-if='provider=="local"') section(v-if='provider=="local"')
label.label {{ $t('modal.createuserfullname') }} label.label {{ $t('modal.createuserfullname') }}
p.control.is-fullwidth p.control.is-fullwidth
input.input(type='text', v-bind:placeholder='$t("modal.createusernameplaceholder")', v-model='name') input.input(type='text', :placeholder='$t("modal.createusernameplaceholder")', v-model='name')
footer footer
a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('modal.discard') }} a.button.is-grey.is-outlined(@click='cancel') {{ $t('modal.discard') }}
a.button(v-on:click='create', v-if='provider=="local"', v-bind:disabled='isLoading', v-bind:class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuser') }} a.button(@click='create', v-if='provider=="local"', :disabled='isLoading', :class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuser') }}
a.button(v-on:click='create', v-if='provider!="local"', v-bind:disabled='isLoading', v-bind:class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuserauthorize') }} a.button(@click='create', v-if='provider!="local"', :disabled='isLoading', :class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuserauthorize') }}
</template> </template>
<script> <script>
export default { export default {
name: 'modal-create-user', name: 'modal-create-user',
data () { data() {
return { return {
email: '', email: '',
provider: 'local', provider: 'local',
...@@ -50,23 +50,23 @@ ...@@ -50,23 +50,23 @@
} }
}, },
computed: { computed: {
isShown () { isShown() {
return this.$store.state.modalCreateUser.shown return this.$store.state.modalCreateUser.shown
} }
}, },
methods: { methods: {
init () { init() {
let self = this let self = this
self._.delay(() => { self._.delay(() => {
self.$refs.createUserEmailInput.focus() self.$refs.createUserEmailInput.focus()
}, 100) }, 100)
}, },
cancel () { cancel() {
this.$store.dispatch('modalCreateUser/close') this.$store.dispatch('modalCreateUser/close')
this.email = '' this.email = ''
this.provider = 'local' this.provider = 'local'
}, },
create () { create() {
let self = this let self = this
this.isLoading = true this.isLoading = true
this.$http.post('/admin/users/create', { this.$http.post('/admin/users/create', {
...@@ -96,10 +96,10 @@ ...@@ -96,10 +96,10 @@
msg: 'Error: ' + err.body.msg msg: 'Error: ' + err.body.msg
}) })
}) })
}
}, },
mounted () { mounted() {
this.$root.$on('modalCreateUser/init', this.init) this.$root.$on('modalCreateUser/init', this.init)
} }
} }
}
</script> </script>
...@@ -12,21 +12,21 @@ ...@@ -12,21 +12,21 @@
section section
span {{ $t('modal.deleteuserwarning') }} span {{ $t('modal.deleteuserwarning') }}
footer footer
a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('modal.abort') }} a.button.is-grey.is-outlined(@click='cancel') {{ $t('modal.abort') }}
a.button.is-red(v-on:click='deleteUser') {{ $t('modal.delete') }} a.button.is-red(@click='deleteUser') {{ $t('modal.delete') }}
</template> </template>
<script> <script>
export default { export default {
name: 'modal-delete-user', name: 'modal-delete-user',
props: ['currentUser'], props: ['currentUser'],
data () { data() {
return { return {
isLoading: false isLoading: false
} }
}, },
computed: { computed: {
isShown () { isShown() {
return this.$store.state.modalDeleteUser.shown return this.$store.state.modalDeleteUser.shown
} }
}, },
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
this.isLoading = false this.isLoading = false
this.$store.dispatch('modalDeleteUser/close') this.$store.dispatch('modalDeleteUser/close')
}, },
discard: function () { deleteUser: function () {
let self = this let self = this
this.isLoading = true this.isLoading = true
this.$http.delete('/admin/users/' + this.currentUser).then(resp => { this.$http.delete('/admin/users/' + this.currentUser).then(resp => {
...@@ -61,5 +61,5 @@ ...@@ -61,5 +61,5 @@
}) })
} }
} }
} }
</script> </script>
'use strict' 'use strict'
/* global usrData */ export default {
name: 'admin-edit-user',
import $ from 'jquery' props: ['usrdata'],
import _ from 'lodash' data() {
import Vue from 'vue' return {
module.exports = (alerts) => {
if ($('#page-type-admin-users-edit').length) {
let vueEditUser = new Vue({
el: '#page-type-admin-users-edit',
data: {
id: '', id: '',
email: '', email: '',
password: '********', password: '********',
name: '', name: '',
rights: [], rights: [],
roleoverride: 'none' roleoverride: 'none'
}
}, },
methods: { methods: {
addRightsRow: (ev) => { addRightsRow() {
vueEditUser.rights.push({ this.rights.push({
role: 'write', role: 'write',
path: '/', path: '/',
exact: false, exact: false,
deny: false deny: false
}) })
}, },
removeRightsRow: (idx) => { removeRightsRow(idx) {
_.pullAt(vueEditUser.rights, idx) this._.pullAt(this.rights, idx)
vueEditUser.$forceUpdate() this.$forceUpdate()
}, },
saveUser: (ev) => { saveUser() {
let formattedRights = _.cloneDeep(vueEditUser.rights) let self = this
switch (vueEditUser.roleoverride) { let formattedRights = this._.cloneDeep(this.rights)
switch (this.roleoverride) {
case 'admin': case 'admin':
formattedRights.push({ formattedRights.push({
role: 'admin', role: 'admin',
...@@ -43,30 +39,36 @@ module.exports = (alerts) => { ...@@ -43,30 +39,36 @@ module.exports = (alerts) => {
}) })
break break
} }
$.post(window.location.href, { this.$http.post(window.location.href, {
password: vueEditUser.password, password: this.password,
name: vueEditUser.name, name: this.name,
rights: JSON.stringify(formattedRights) rights: JSON.stringify(formattedRights)
}).done((resp) => { }).then(resp => {
alerts.pushSuccess('Saved successfully', 'Changes have been applied.') self.$store.dispatch('alert', {
}).fail((jqXHR, txtStatus, resp) => { style: 'green',
alerts.pushError('Error', resp) icon: 'check',
msg: 'Changes have been applied successfully.'
})
}).catch(err => {
self.$store.dispatch('alert', {
style: 'red',
icon: 'square-cross',
msg: 'Error: ' + err.body.msg
})
}) })
} }
}, },
created: function () { mounted() {
this.id = usrData._id let usr = JSON.parse(this.usrdata)
this.email = usrData.email this.id = usr._id
this.name = usrData.name this.email = usr.email
this.name = usr.name
if (_.find(usrData.rights, { role: 'admin' })) { if (this._.find(usr.rights, { role: 'admin' })) {
this.rights = _.reject(usrData.rights, ['role', 'admin']) this.rights = this._.reject(usr.rights, ['role', 'admin'])
this.roleoverride = 'admin' this.roleoverride = 'admin'
} else { } else {
this.rights = usrData.rights this.rights = usr.rights
}
} }
})
require('../modals/admin-users-delete.js')(alerts)
} }
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"discard": "Discard", "discard": "Discard",
"edit": "Edit", "edit": "Edit",
"history": "History", "history": "History",
"home": "Home",
"login": "Login", "login": "Login",
"logout": "Logout", "logout": "Logout",
"move": "Move", "move": "Move",
......
extends ../../layout.pug extends ../../layout.pug
block rootNavCenter block rootNavCenter
h2.nav-item= t('nav.account') h2.nav-item= t('nav.settings')
block rootNavRight block rootNavRight
loading-spinner loading-spinner
...@@ -48,7 +48,7 @@ block content ...@@ -48,7 +48,7 @@ block content
a(href='/admin/settings') a(href='/admin/settings')
i.icon-cog i.icon-cog
span= t('nav.syssettings') span= t('nav.syssettings')
li //-li
a(href='/admin/theme') a(href='/admin/theme')
i.icon-drop i.icon-drop
span= t('nav.theme') span= t('nav.theme')
......
...@@ -8,9 +8,10 @@ block rootNavRight ...@@ -8,9 +8,10 @@ block rootNavRight
span= t('admin:users.returntousers') span= t('admin:users.returntousers')
block adminContent block adminContent
#page-type-admin-users-edit admin-edit-user(inline-template, usrdata=JSON.stringify(usr))
div
.hero .hero
h1.title#title= t('admin:users.edituser') h1.title= t('admin:users.edituser')
h2.subtitle= usr.email h2.subtitle= usr.email
table.table table.table
thead thead
...@@ -118,6 +119,3 @@ block adminContent ...@@ -118,6 +119,3 @@ block adminContent
span Delete Account span Delete Account
modal-delete-user(current-user=usr._id) modal-delete-user(current-user=usr._id)
script(type='text/javascript').
var usrData = !{JSON.stringify(usr)};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment