From 29d54f46aa79a5f3fe067717fa418092e150eb47 Mon Sep 17 00:00:00 2001 From: Thuan Pham Quoc Date: Tue, 7 Nov 2017 14:01:27 +0700 Subject: Added people list in admin panel , just raw data right now, will add more features soon --- client/components/settings/peopleBody.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 client/components/settings/peopleBody.js (limited to 'client/components/settings/peopleBody.js') diff --git a/client/components/settings/peopleBody.js b/client/components/settings/peopleBody.js new file mode 100644 index 00000000..058cb8d5 --- /dev/null +++ b/client/components/settings/peopleBody.js @@ -0,0 +1,26 @@ +Meteor.subscribe('people'); + +BlazeComponent.extendComponent({ + onCreated() { + this.error = new ReactiveVar(''); + this.loading = new ReactiveVar(false); + this.people = new ReactiveVar(true); + }, + + setError(error) { + this.error.set(error); + }, + + setLoading(w) { + this.loading.set(w); + }, + + peopleList() { + this.users = Users.find({}); + + this.users.forEach((user) => { + console.log(JSON.stringify(user)); + }); + return this.users; + }, +}).register('people'); -- cgit v1.2.3-1-g7c22 From 1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a Mon Sep 17 00:00:00 2001 From: Thuan Pham Quoc Date: Tue, 7 Nov 2017 22:26:21 +0700 Subject: Added edit user from admin panel --- client/components/settings/peopleBody.js | 101 ++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 8 deletions(-) (limited to 'client/components/settings/peopleBody.js') diff --git a/client/components/settings/peopleBody.js b/client/components/settings/peopleBody.js index 058cb8d5..85376ebb 100644 --- a/client/components/settings/peopleBody.js +++ b/client/components/settings/peopleBody.js @@ -6,21 +6,106 @@ BlazeComponent.extendComponent({ this.loading = new ReactiveVar(false); this.people = new ReactiveVar(true); }, - setError(error) { this.error.set(error); }, - setLoading(w) { this.loading.set(w); }, - peopleList() { - this.users = Users.find({}); - - this.users.forEach((user) => { - console.log(JSON.stringify(user)); + return Users.find({}, { + fields: {_id: true}, }); - return this.users; }, }).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 email = tpl.find('.js-profile-email').value.trim(); + console.log('isAdmin', isAdmin); + let isChangeUserName = false; + let isChangeEmail = false; + Users.update(this.userId, { + $set: { + 'profile.fullname': fullname, + 'profile.initials': initials, + 'isAdmin': true, + }, + }); + + isChangeUserName = username !== user.username; + isChangeEmail = email.toLowerCase() !== user.emails[0].address.toLowerCase(); + if (isChangeUserName && isChangeEmail) { + Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), 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.back(); + } + }); + } else if (isChangeUserName) { + Meteor.call('setUsername', username, function (error) { + const messageElement = tpl.$('.username-taken'); + if (error) { + messageElement.show(); + } else { + messageElement.hide(); + Popup.back(); + } + }); + } else if (isChangeEmail) { + Meteor.call('setEmail', email.toLowerCase(), function (error) { + const messageElement = tpl.$('.email-taken'); + if (error) { + messageElement.show(); + } else { + messageElement.hide(); + Popup.back(); + } + }); + } else Popup.back(); + }, +}); -- cgit v1.2.3-1-g7c22 From 3bead1bf78758e81a97150053c5df8e6be2d6fe1 Mon Sep 17 00:00:00 2001 From: Thuan Pham Quoc Date: Wed, 8 Nov 2017 11:27:59 +0700 Subject: Added pagination to people management in admin panel --- client/components/settings/peopleBody.js | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'client/components/settings/peopleBody.js') diff --git a/client/components/settings/peopleBody.js b/client/components/settings/peopleBody.js index 85376ebb..d59dc38b 100644 --- a/client/components/settings/peopleBody.js +++ b/client/components/settings/peopleBody.js @@ -1,10 +1,46 @@ -Meteor.subscribe('people'); +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); -- cgit v1.2.3-1-g7c22 From fa1d8cd5ef0834f882e6d34d356d5fea55eb6ea1 Mon Sep 17 00:00:00 2001 From: Thuan Pham Quoc Date: Wed, 8 Nov 2017 11:34:37 +0700 Subject: Added update all user profile from admin panel --- client/components/settings/peopleBody.js | 39 ++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'client/components/settings/peopleBody.js') diff --git a/client/components/settings/peopleBody.js b/client/components/settings/peopleBody.js index d59dc38b..d0da60d0 100644 --- a/client/components/settings/peopleBody.js +++ b/client/components/settings/peopleBody.js @@ -89,22 +89,25 @@ Template.editUserPopup.events({ 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(); - console.log('isAdmin', isAdmin); let isChangeUserName = false; let isChangeEmail = false; + Users.update(this.userId, { $set: { 'profile.fullname': fullname, 'profile.initials': initials, - 'isAdmin': true, + '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(), function (error) { + Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), this.userId, function (error) { const usernameMessageElement = tpl.$('.username-taken'); const emailMessageElement = tpl.$('.email-taken'); if (error) { @@ -119,29 +122,35 @@ Template.editUserPopup.events({ } else { usernameMessageElement.hide(); emailMessageElement.hide(); - Popup.back(); + Popup.close(); } }); } else if (isChangeUserName) { - Meteor.call('setUsername', username, function (error) { - const messageElement = tpl.$('.username-taken'); + Meteor.call('setUsername', username, this.userId, function (error) { + const usernameMessageElement = tpl.$('.username-taken'); if (error) { - messageElement.show(); + const errorElement = error.error; + if (errorElement === 'username-already-taken') { + usernameMessageElement.show(); + } } else { - messageElement.hide(); - Popup.back(); + usernameMessageElement.hide(); + Popup.close(); } }); } else if (isChangeEmail) { - Meteor.call('setEmail', email.toLowerCase(), function (error) { - const messageElement = tpl.$('.email-taken'); + Meteor.call('setEmail', email.toLowerCase(), this.userId, function (error) { + const emailMessageElement = tpl.$('.email-taken'); if (error) { - messageElement.show(); + const errorElement = error.error; + if (errorElement === 'email-already-taken') { + emailMessageElement.show(); + } } else { - messageElement.hide(); - Popup.back(); + emailMessageElement.hide(); + Popup.close(); } }); - } else Popup.back(); + } else Popup.close(); }, }); -- cgit v1.2.3-1-g7c22