Edit User client logic + Delete User UI
This commit is contained in:
parent
0809946914
commit
ec6f32d29c
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@
|
|||||||
// Vue Create User instance
|
// Vue Create User instance
|
||||||
|
|
||||||
let vueCreateUser = new Vue({
|
let vueCreateUser = new Vue({
|
||||||
el: '#modal-admin-createuser',
|
el: '#modal-admin-users-create',
|
||||||
data: {
|
data: {
|
||||||
email: '',
|
email: '',
|
||||||
provider: 'local',
|
provider: 'local',
|
||||||
@ -11,11 +11,11 @@ let vueCreateUser = new Vue({
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
open: (ev) => {
|
open: (ev) => {
|
||||||
$('#modal-admin-createuser').addClass('is-active');
|
$('#modal-admin-users-create').addClass('is-active');
|
||||||
$('#modal-admin-createuser input').first().focus();
|
$('#modal-admin-users-create input').first().focus();
|
||||||
},
|
},
|
||||||
cancel: (ev) => {
|
cancel: (ev) => {
|
||||||
$('#modal-admin-createuser').removeClass('is-active');
|
$('#modal-admin-users-create').removeClass('is-active');
|
||||||
vueCreateUser.email = '';
|
vueCreateUser.email = '';
|
||||||
vueCreateUser.provider = 'local';
|
vueCreateUser.provider = 'local';
|
||||||
},
|
},
|
22
client/js/modals/admin-users-delete.js
Normal file
22
client/js/modals/admin-users-delete.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
// Vue Delete User instance
|
||||||
|
|
||||||
|
let vueDeleteUser = new Vue({
|
||||||
|
el: '#modal-admin-users-delete',
|
||||||
|
data: {
|
||||||
|
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
open: (ev) => {
|
||||||
|
$('#modal-admin-users-delete').addClass('is-active');
|
||||||
|
},
|
||||||
|
cancel: (ev) => {
|
||||||
|
$('#modal-admin-users-delete').removeClass('is-active');
|
||||||
|
},
|
||||||
|
deleteUser: (ev) => {
|
||||||
|
vueDeleteUser.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.btn-deluser-prompt').on('click', vueDeleteUser.open);
|
@ -1,6 +1,50 @@
|
|||||||
|
|
||||||
if($('#page-type-admin').length) {
|
if($('#page-type-admin-users').length) {
|
||||||
|
|
||||||
//=include ../modals/admin-createuser.js
|
//=include ../modals/admin-users-create.js
|
||||||
|
|
||||||
|
} else if($('#page-type-admin-users-edit').length) {
|
||||||
|
|
||||||
|
let vueEditUser = new Vue({
|
||||||
|
el: '#page-type-admin-users-edit',
|
||||||
|
data: {
|
||||||
|
id: '',
|
||||||
|
email: '',
|
||||||
|
password: '********',
|
||||||
|
name: '',
|
||||||
|
rights: [],
|
||||||
|
roleoverride: 'none'
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
addRightsRow: (ev) => {
|
||||||
|
vueEditUser.rights.push({});
|
||||||
|
},
|
||||||
|
removeRightsRow: (ev) => {
|
||||||
|
|
||||||
|
},
|
||||||
|
saveUser: (ev) => {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created: function() {
|
||||||
|
|
||||||
|
this.id = usrData._id;
|
||||||
|
this.email = usrData.email;
|
||||||
|
this.name = usrData.name;
|
||||||
|
|
||||||
|
console.log(_.find(usrData.rights, { role: 'admin' }));
|
||||||
|
|
||||||
|
if(_.find(usrData.rights, { role: 'admin' })) {
|
||||||
|
this.rights = _.reject(usrData.rights, ['role', 'admin']);
|
||||||
|
this.roleoverride = 'admin';
|
||||||
|
} else {
|
||||||
|
this.rights = usrData.rights;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//=include ../modals/admin-users-delete.js
|
||||||
|
|
||||||
}
|
}
|
@ -69,9 +69,18 @@ router.get('/users/:id', (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db.User.findById(req.params.id)
|
db.User.findById(req.params.id)
|
||||||
.select('-password')
|
.select('-password -providerId')
|
||||||
.exec().then((usr) => {
|
.exec().then((usr) => {
|
||||||
res.render('pages/admin/users-edit', { adminTab: 'users', usr });
|
|
||||||
|
let usrOpts = {
|
||||||
|
canChangeEmail: (usr.email !== 'guest' && usr.provider === 'local' && usr.email !== req.app.locals.appconfig.admin),
|
||||||
|
canChangeName: (usr.email !== 'guest'),
|
||||||
|
canChangePassword: (usr.email !== 'guest' && usr.provider === 'local'),
|
||||||
|
canChangeRole: (usr.email !== 'guest' && !(usr.provider === 'local' && usr.email === req.app.locals.appconfig.admin)),
|
||||||
|
canBeDeleted: (usr.email !== 'guest' && !(usr.provider === 'local' && usr.email === req.app.locals.appconfig.admin))
|
||||||
|
};
|
||||||
|
|
||||||
|
res.render('pages/admin/users-edit', { adminTab: 'users', usr, usrOpts });
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
.modal#modal-admin-createuser
|
.modal#modal-admin-users-create
|
||||||
.modal-background
|
.modal-background
|
||||||
.modal-container
|
.modal-container
|
||||||
.modal-content
|
.modal-content
|
||||||
|
10
views/modals/admin-deleteuser.pug
Normal file
10
views/modals/admin-deleteuser.pug
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.modal#modal-admin-users-delete
|
||||||
|
.modal-background
|
||||||
|
.modal-container
|
||||||
|
.modal-content
|
||||||
|
header.is-red Delete User Account?
|
||||||
|
section
|
||||||
|
span Are you sure you want to delete this user account? This action cannot be undone!
|
||||||
|
footer
|
||||||
|
a.button.is-grey.is-outlined(v-on:click="cancel") Abort
|
||||||
|
a.button.is-red(v-on:click="deleteUser") Delete
|
@ -8,7 +8,7 @@ block rootNavRight
|
|||||||
span Return to Users
|
span Return to Users
|
||||||
|
|
||||||
block adminContent
|
block adminContent
|
||||||
#page-type-admin
|
#page-type-admin-users-edit
|
||||||
.hero
|
.hero
|
||||||
h1.title#title Edit User
|
h1.title#title Edit User
|
||||||
h2.subtitle= usr.email
|
h2.subtitle= usr.email
|
||||||
@ -16,14 +16,12 @@ block adminContent
|
|||||||
thead
|
thead
|
||||||
tr
|
tr
|
||||||
th Unique ID
|
th Unique ID
|
||||||
th Email
|
|
||||||
th Provider
|
th Provider
|
||||||
th Created On
|
th Created On
|
||||||
th Updated On
|
th Updated On
|
||||||
tbody
|
tbody
|
||||||
tr
|
tr
|
||||||
td.is-centered= usr._id
|
td.is-centered= usr._id
|
||||||
td.is-centered= usr.email
|
|
||||||
td.is-centered.has-icons
|
td.is-centered.has-icons
|
||||||
case usr.provider
|
case usr.provider
|
||||||
when 'local'
|
when 'local'
|
||||||
@ -42,15 +40,19 @@ block adminContent
|
|||||||
td.is-centered= userMoment(usr.createdAt).format('lll')
|
td.is-centered= userMoment(usr.createdAt).format('lll')
|
||||||
td.is-centered= userMoment(usr.updatedAt).format('lll')
|
td.is-centered= userMoment(usr.updatedAt).format('lll')
|
||||||
.form-sections
|
.form-sections
|
||||||
|
section
|
||||||
|
label.label Email Address
|
||||||
|
p.control.is-fullwidth
|
||||||
|
input.input(type='text', placeholder='john.smith@example.com', v-model='email', disabled=!usrOpts.canChangeEmail)
|
||||||
section
|
section
|
||||||
label.label Display Name
|
label.label Display Name
|
||||||
p.control.is-fullwidth
|
p.control.is-fullwidth
|
||||||
input.input(type='text', placeholder='John Smith', value=usr.name)
|
input.input(type='text', placeholder='John Smith', v-model='name', disabled=!usrOpts.canChangeName)
|
||||||
if usr.provider == 'local'
|
if usrOpts.canChangePassword
|
||||||
section
|
section
|
||||||
label.label Password
|
label.label Password
|
||||||
p.control.is-fullwidth
|
p.control.is-fullwidth
|
||||||
input.input(type='password', placeholder='Password', value='********')
|
input.input(type='password', placeholder='Password', v-model='password', value='********')
|
||||||
section
|
section
|
||||||
label.label Access Rights
|
label.label Access Rights
|
||||||
table.table
|
table.table
|
||||||
@ -62,7 +64,7 @@ block adminContent
|
|||||||
th(style={width: '150px'}) Access
|
th(style={width: '150px'}) Access
|
||||||
th(style={width: '50px'})
|
th(style={width: '50px'})
|
||||||
tbody
|
tbody
|
||||||
tr(v-for='right in rights')
|
tr(v-for='right in rights', v-cloak)
|
||||||
td.is-icon
|
td.is-icon
|
||||||
i.icon-marquee-plus.is-green(v-if='!right.deny')
|
i.icon-marquee-plus.is-green(v-if='!right.deny')
|
||||||
i.icon-marquee-minus.is-red(v-if='right.deny')
|
i.icon-marquee-minus.is-red(v-if='right.deny')
|
||||||
@ -87,28 +89,38 @@ block adminContent
|
|||||||
option(value='false') Allow
|
option(value='false') Allow
|
||||||
option(value='true') Deny
|
option(value='true') Deny
|
||||||
td.is-centered.has-action-icons
|
td.is-centered.has-action-icons
|
||||||
i.icon-delete.is-red
|
i.icon-delete.is-red(v-on:click='removeRightsRow(right._id)')
|
||||||
|
tr(v-if='rights.length < 1', v-cloak)
|
||||||
|
td.is-icon
|
||||||
|
td.is-centered(colspan='3'): em No additional access rights
|
||||||
|
td.is-centered.has-action-icons
|
||||||
.table-actions
|
.table-actions
|
||||||
button.button.is-blue
|
button.button.is-blue(v-on:click='addRightsRow')
|
||||||
i.icon-plus
|
i.icon-plus
|
||||||
span Add New Row
|
span Add New Row
|
||||||
section
|
section
|
||||||
label.label Role Override
|
label.label Role Override
|
||||||
p.control.is-fullwidth
|
p.control.is-fullwidth
|
||||||
select(v-model='roleoverride')
|
select(v-model='roleoverride', disabled=!usrOpts.canChangeRole)
|
||||||
option(value='none') None
|
option(value='none') None
|
||||||
option(value='admin') Global Administrator
|
option(value='admin') Global Administrator
|
||||||
.columns.is-gapless
|
.columns.is-gapless
|
||||||
.column
|
.column
|
||||||
section
|
section
|
||||||
button.button.is-green
|
button.button.is-green(v-on:click='saveUser')
|
||||||
i.icon-check
|
i.icon-check
|
||||||
span Save Changes
|
span Save Changes
|
||||||
button.button.is-grey.is-outlined
|
a.button.button.is-grey.is-outlined(href='/admin/users')
|
||||||
i.icon-cancel
|
i.icon-cancel
|
||||||
span Discard
|
span Discard
|
||||||
.column.is-narrow
|
.column.is-narrow
|
||||||
section
|
section
|
||||||
button.button.is-red
|
if usrOpts.canBeDeleted
|
||||||
i.icon-trash2
|
button.button.is-red.btn-deluser-prompt
|
||||||
span Delete Account
|
i.icon-trash2
|
||||||
|
span Delete Account
|
||||||
|
|
||||||
|
include ../../modals/admin-deleteuser.pug
|
||||||
|
|
||||||
|
script(type='text/javascript').
|
||||||
|
var usrData = !{JSON.stringify(usr)};
|
@ -8,7 +8,7 @@ block rootNavRight
|
|||||||
span Create / Authorize User
|
span Create / Authorize User
|
||||||
|
|
||||||
block adminContent
|
block adminContent
|
||||||
#page-type-admin
|
#page-type-admin-users
|
||||||
.hero
|
.hero
|
||||||
h1.title#title Users
|
h1.title#title Users
|
||||||
h2.subtitle Manage users and access rights
|
h2.subtitle Manage users and access rights
|
||||||
|
Loading…
Reference in New Issue
Block a user