Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'thuanpq-devel' into devel
User Admin to Admin Panel: List users. Change: is user admin, name, fullname, email address, is user active. Not changing password yet. Thanks to thuanpq and xet7 ! Related #802
- Loading branch information
Showing
46 changed files
with
831 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
template(name="people") | ||
.setting-content | ||
unless currentUser.isAdmin | ||
| {{_ 'error-notAuthorized'}} | ||
else | ||
.content-title | ||
span {{_ 'people'}} | ||
.content-body | ||
.side-menu | ||
ul | ||
li.active | ||
a.js-setting-menu(data-id="people-setting") {{_ 'people'}} | ||
.main-body | ||
if loading.get | ||
+spinner | ||
else if people.get | ||
+peopleGeneral | ||
|
||
template(name="peopleGeneral") | ||
table | ||
tbody | ||
tr | ||
th {{_ 'username'}} | ||
th {{_ 'fullname'}} | ||
th {{_ 'admin'}} | ||
th {{_ 'email'}} | ||
th {{_ 'verified'}} | ||
th {{_ 'createdAt'}} | ||
th {{_ 'active'}} | ||
th | ||
each user in peopleList | ||
+peopleRow(userId=user._id) | ||
|
||
template(name="peopleRow") | ||
tr | ||
td.username {{ userData.username }} | ||
td {{ userData.profile.fullname }} | ||
td | ||
if userData.isAdmin | ||
| {{_ 'yes'}} | ||
else | ||
| {{_ 'no'}} | ||
td {{ userData.emails.[0].address }} | ||
td | ||
if userData.emails.[0].verified | ||
| {{_ 'yes'}} | ||
else | ||
| {{_ 'no'}} | ||
td {{ moment userData.createdAt 'LLL' }} | ||
td | ||
if userData.loginDisabled | ||
| {{_ 'no'}} | ||
else | ||
| {{_ 'yes'}} | ||
td | ||
a.edit-user | ||
| {{_ 'edit'}} | ||
|
||
template(name="editUserPopup") | ||
form | ||
label.hide.userId(type="text" value=user._id) | ||
label | ||
| {{_ 'fullname'}} | ||
input.js-profile-fullname(type="text" value=user.profile.fullname autofocus) | ||
label | ||
| {{_ 'username'}} | ||
span.error.hide.username-taken | ||
| {{_ 'error-username-taken'}} | ||
input.js-profile-username(type="text" value=user.username) | ||
label | ||
| {{_ 'initials'}} | ||
input.js-profile-initials(type="text" value=user.profile.initials) | ||
label | ||
| {{_ 'email'}} | ||
span.error.hide.email-taken | ||
| {{_ 'error-email-taken'}} | ||
input.js-profile-email(type="email" value="{{user.emails.[0].address}}") | ||
label | ||
| {{_ 'admin'}} | ||
select.select-role.js-profile-isadmin | ||
option(value="false") {{_ 'no'}} | ||
option(value="true" selected="{{user.isAdmin}}") {{_ 'yes'}} | ||
label | ||
| {{_ 'active'}} | ||
select.select-active.js-profile-isactive | ||
option(value="false") {{_ 'yes'}} | ||
option(value="true" selected="{{user.loginDisabled}}") {{_ 'no'}} | ||
|
||
input.primary.wide(type="submit" value="{{_ 'save'}}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
const usersPerPage = 25; | ||
|
||
BlazeComponent.extendComponent({ | ||
mixins() { | ||
return [Mixins.InfiniteScrolling]; | ||
}, | ||
onCreated() { | ||
this.error = new ReactiveVar(''); | ||
this.loading = new ReactiveVar(false); | ||
this.people = new ReactiveVar(true); | ||
|
||
this.page = new ReactiveVar(1); | ||
this.loadNextPageLocked = false; | ||
this.callFirstWith(null, 'resetNextPeak'); | ||
this.autorun(() => { | ||
const limit = this.page.get() * usersPerPage; | ||
|
||
this.subscribe('people', limit, () => { | ||
this.loadNextPageLocked = false; | ||
const nextPeakBefore = this.callFirstWith(null, 'getNextPeak'); | ||
this.calculateNextPeak(); | ||
const nextPeakAfter = this.callFirstWith(null, 'getNextPeak'); | ||
if (nextPeakBefore === nextPeakAfter) { | ||
this.callFirstWith(null, 'resetNextPeak'); | ||
} | ||
}); | ||
}); | ||
}, | ||
loadNextPage() { | ||
if (this.loadNextPageLocked === false) { | ||
this.page.set(this.page.get() + 1); | ||
this.loadNextPageLocked = true; | ||
} | ||
}, | ||
calculateNextPeak() { | ||
const element = this.find('.main-body'); | ||
if (element) { | ||
const altitude = element.scrollHeight; | ||
this.callFirstWith(this, 'setNextPeak', altitude); | ||
} | ||
}, | ||
reachNextPeak() { | ||
this.loadNextPage(); | ||
}, | ||
setError(error) { | ||
this.error.set(error); | ||
}, | ||
setLoading(w) { | ||
this.loading.set(w); | ||
}, | ||
peopleList() { | ||
return Users.find({}, { | ||
fields: {_id: true}, | ||
}); | ||
}, | ||
}).register('people'); | ||
|
||
Template.peopleRow.helpers({ | ||
userData() { | ||
const userCollection = this.esSearch ? ESSearchResults : Users; | ||
return userCollection.findOne(this.userId); | ||
}, | ||
}); | ||
|
||
Template.editUserPopup.helpers({ | ||
user() { | ||
return Users.findOne(this.userId); | ||
}, | ||
}); | ||
|
||
BlazeComponent.extendComponent({ | ||
onCreated() { | ||
}, | ||
user() { | ||
return Users.findOne(this.userId); | ||
}, | ||
events() { | ||
return [{ | ||
'click a.edit-user': Popup.open('editUser'), | ||
}]; | ||
}, | ||
}).register('peopleRow'); | ||
|
||
Template.editUserPopup.events({ | ||
submit(evt, tpl) { | ||
evt.preventDefault(); | ||
const user = Users.findOne(this.userId); | ||
const fullname = tpl.find('.js-profile-fullname').value.trim(); | ||
const username = tpl.find('.js-profile-username').value.trim(); | ||
const initials = tpl.find('.js-profile-initials').value.trim(); | ||
const isAdmin = tpl.find('.js-profile-isadmin').value.trim(); | ||
const isActive = tpl.find('.js-profile-isactive').value.trim(); | ||
const email = tpl.find('.js-profile-email').value.trim(); | ||
let isChangeUserName = false; | ||
let isChangeEmail = false; | ||
|
||
Users.update(this.userId, { | ||
$set: { | ||
'profile.fullname': fullname, | ||
'profile.initials': initials, | ||
'isAdmin': isAdmin === 'true', | ||
'loginDisabled': isActive === 'true', | ||
}, | ||
}); | ||
|
||
isChangeUserName = username !== user.username; | ||
isChangeEmail = email.toLowerCase() !== user.emails[0].address.toLowerCase(); | ||
|
||
if (isChangeUserName && isChangeEmail) { | ||
Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), this.userId, function (error) { | ||
const usernameMessageElement = tpl.$('.username-taken'); | ||
const emailMessageElement = tpl.$('.email-taken'); | ||
if (error) { | ||
const errorElement = error.error; | ||
if (errorElement === 'username-already-taken') { | ||
usernameMessageElement.show(); | ||
emailMessageElement.hide(); | ||
} else if (errorElement === 'email-already-taken') { | ||
usernameMessageElement.hide(); | ||
emailMessageElement.show(); | ||
} | ||
} else { | ||
usernameMessageElement.hide(); | ||
emailMessageElement.hide(); | ||
Popup.close(); | ||
} | ||
}); | ||
} else if (isChangeUserName) { | ||
Meteor.call('setUsername', username, this.userId, function (error) { | ||
const usernameMessageElement = tpl.$('.username-taken'); | ||
if (error) { | ||
const errorElement = error.error; | ||
if (errorElement === 'username-already-taken') { | ||
usernameMessageElement.show(); | ||
} | ||
} else { | ||
usernameMessageElement.hide(); | ||
Popup.close(); | ||
} | ||
}); | ||
} else if (isChangeEmail) { | ||
Meteor.call('setEmail', email.toLowerCase(), this.userId, function (error) { | ||
const emailMessageElement = tpl.$('.email-taken'); | ||
if (error) { | ||
const errorElement = error.error; | ||
if (errorElement === 'email-already-taken') { | ||
emailMessageElement.show(); | ||
} | ||
} else { | ||
emailMessageElement.hide(); | ||
Popup.close(); | ||
} | ||
}); | ||
} else Popup.close(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.main-body | ||
overflow: scroll; | ||
|
||
table | ||
font-family: arial, sans-serif; | ||
border-collapse: collapse; | ||
width: 100%; | ||
|
||
td, th | ||
border: 1px solid #d2d0d0; | ||
text-align: left; | ||
padding: 8px; | ||
|
||
tr:nth-child(even) | ||
background-color: #dddddd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.