ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject ignite git commit: IGNITE-2481 Refactor profile.
Date Mon, 01 Feb 2016 09:44:37 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843-rc2 7e3cc27ae -> 439fb31e2


IGNITE-2481 Refactor profile.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/439fb31e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/439fb31e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/439fb31e

Branch: refs/heads/ignite-843-rc2
Commit: 439fb31e2d78595573ac9ca88f4f28d3f8a77830
Parents: 7e3cc27
Author: Andrey <anovikov@gridgain.com>
Authored: Mon Feb 1 16:44:28 2016 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Mon Feb 1 16:44:28 2016 +0700

----------------------------------------------------------------------
 .../main/js/controllers/profile-controller.js   | 98 +++++++-------------
 .../src/main/js/routes/profile.js               | 56 +++++------
 .../src/main/js/views/settings/profile.jade     | 52 ++++++-----
 3 files changed, 83 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/439fb31e/modules/control-center-web/src/main/js/controllers/profile-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/profile-controller.js b/modules/control-center-web/src/main/js/controllers/profile-controller.js
index b7ea353..3232897 100644
--- a/modules/control-center-web/src/main/js/controllers/profile-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/profile-controller.js
@@ -17,93 +17,61 @@
 
 // Controller for Profile screen.
 consoleModule.controller('profileController',
-    ['$scope', '$http', '$common', '$focus', '$confirm', 'igniteCountries', function ($scope,
$http, $common, $focus, $confirm, countries) {
-    $scope.profileUser = angular.copy($scope.$root.user);
+    ['$rootScope', '$scope', '$http', '$common', '$focus', '$confirm', 'igniteCountries',
function ($rootScope, $scope, $http, $common, $focus, $confirm, countries) {
+    $scope.user = angular.copy($scope.$root.user);
 
     $scope.countries = countries;
 
-    if ($scope.profileUser && !$scope.profileUser.token)
-        $scope.profileUser.token = 'No security token. Regenerate please.';
+    if ($scope.user && !$scope.user.token)
+        $scope.user.token = 'No security token. Regenerate please.';
 
     $scope.generateToken = function () {
         $confirm.confirm('Are you sure you want to change security token?')
             .then(function () {
-                $scope.profileUser.token = $commonUtils.randomString(20);
+                $scope.user.token = $commonUtils.randomString(20);
             })
     };
 
-    $scope.profileChanged = function () {
-        var old = $scope.$root.user;
-        var cur = $scope.profileUser;
+    function _profileChanged() {
+        var old = $rootScope.user;
+        var cur = $scope.user;
 
-        return old && (old.username != cur.username || old.email != cur.email ||
-            old.company != cur.company || old.country != cur.country
-            || old.token != cur.token || (cur.changePassword && !$common.isEmptyString(cur.newPassword)));
+        return !_.isEqual(old, cur) || ($scope.expandedPassword && !$common.isEmptyString($scope.newPassword));
     };
 
     $scope.profileCouldBeSaved = function () {
-        return $scope.profileForm.$valid && $scope.profileChanged();
+        return $scope.profileForm.$valid && _profileChanged();
     };
 
     $scope.saveBtnTipText = function () {
         if (!$scope.profileForm.$valid)
             return 'Invalid profile settings';
 
-        return $scope.profileChanged() ? 'Save profile' : 'Nothing to save';
+        return _profileChanged() ? 'Save profile' : 'Nothing to save';
     };
 
     $scope.saveUser = function () {
-        var profile = $scope.profileUser;
-
-        if (profile) {
-            var userName = profile.username;
-            var changeUsername = userName != $scope.$root.user.username;
-
-            var email = profile.email;
-            var changeEmail = email != $scope.$root.user.email;
-
-            var company = profile.company;
-            var changeCompany = company != $scope.$root.user.company;
-
-            var country = profile.country;
-            var changeCountry = country != $scope.$root.user.country;
-
-            var token = profile.token;
-            var changeToken = token != $scope.$root.user.token;
-
-            if (changeUsername || changeEmail || changeCompany || changeCountry || changeToken
|| profile.changePassword) {
-                $http.post('/api/v1/profile/save', {
-                    _id: profile._id,
-                    userName: changeUsername ? userName : undefined,
-                    email: changeEmail ? email : undefined,
-                    company: changeCompany ? company : undefined,
-                    country: changeCountry ? country : undefined,
-                    token: changeToken ? token : undefined,
-                    newPassword: profile.changePassword ? profile.newPassword : undefined
-                }).success(function (user) {
-                    $common.showInfo('Profile saved.');
-
-                    profile.changePassword = false;
-                    profile.newPassword = null;
-                    profile.confirmPassword = null;
-
-                    if (changeUsername)
-                        $scope.$root.user.username = userName;
-
-                    if (changeEmail)
-                        $scope.$root.user.email = email;
-
-                    if (changeCompany)
-                        $scope.$root.user.company = company;
-
-                    if (changeCountry)
-                        $scope.$root.user.country = country;
-
-                    $focus('profile-username');
-                }).error(function (err) {
-                    $common.showError('Failed to save profile: ' + $common.errorMessage(err));
-                });
-            }
-        }
+        var _user = angular.copy($scope.user);
+
+        if ($scope.expandedPassword)
+            _user.password = $scope.newPassword;
+
+        $http.post('/api/v1/profile/save', _user)
+            .success(function () {
+                $scope.expandedToken = false;
+
+                $scope.expandedToken = false;
+                $scope.newPassword = '';
+                $scope.confirmPassword = '';
+
+                $rootScope.user = angular.copy($scope.user);
+
+                $common.showInfo('Profile saved.');
+
+                $focus('profile-username');
+            })
+            .error(function (err) {
+                $common.showError('Failed to save profile: ' + $common.errorMessage(err));
+            });
     };
 }]);

http://git-wip-us.apache.org/repos/asf/ignite/blob/439fb31e/modules/control-center-web/src/main/js/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/profile.js b/modules/control-center-web/src/main/js/routes/profile.js
index 4fa154d..ae262cc 100644
--- a/modules/control-center-web/src/main/js/routes/profile.js
+++ b/modules/control-center-web/src/main/js/routes/profile.js
@@ -15,38 +15,25 @@
  * limitations under the License.
  */
 
+var _ = require('lodash');
+
 var router = require('express').Router();
 var db = require('../db');
 
-function _updateUser(res, user, params) {
-    if (params.userName)
-        user.username = params.userName;
+function _updateUser(res, params) {
+    db.Account.update({_id: params._id}, params, {upsert: true}, function (err, user) {
+        // TODO IGNITE-843 Send error to admin.
+        if (err)
+            return res.status(500).send('Failed to update profile!');
 
     if (params.email)
         user.email = params.email;
 
-    if (params.company)
-        user.company = params.company;
-
-    if (params.country)
-        user.country = params.country;
-
-    if (params.token)
-        user.token = params.token;
-
-    if (params.userName || params.email || params.company || params.country || params.token
|| params.newPassword)
-        user.save(function (err) {
-            if (err)
-                // TODO IGNITE-843 Send error to admin.
-                return res.status(500).send('Failed to update profile!');
-
-            res.json(user);
-        });
-    else
-        res.status(200);
+        res.sendStatus(200);
+    });
 }
 
-function _checkUserEmailAndUpdate(res, user, params) {
+function _checkEmail(res, user, params) {
     if (params.email && user.email != params.email) {
         db.Account.findOne({email: params.email}, function(err, userForEmail) {
             // TODO send error to admin
@@ -56,11 +43,11 @@ function _checkUserEmailAndUpdate(res, user, params) {
             if (userForEmail && userForEmail._id != user._id)
                 return res.status(500).send('User with this e-mail already registered!');
 
-            _updateUser(res, user, params);
+            _updateUser(res, params);
         });
     }
     else
-        _updateUser(res, user, params);
+        _updateUser(res, params);
 }
 
 /**
@@ -70,25 +57,28 @@ router.post('/save', function (req, res) {
     var params = req.body;
 
     db.Account.findById(params._id, function (err, user) {
-        if (err)
         // TODO IGNITE-843 Send error to admin
+        if (err)
             return res.status(500).send('Failed to find user!');
 
-        if (params.newPassword) {
-            var newPassword = params.newPassword;
-
-            if (!newPassword || newPassword.length == 0)
+        if (params.password) {
+            if (_.isEmpty(params.password))
                 return res.status(500).send('Wrong value for new password!');
 
-            user.setPassword(newPassword, function (err, user) {
+            user.setPassword(params.password, function (err, user) {
                 if (err)
                     return res.status(500).send(err.message);
 
-                _checkUserEmailAndUpdate(res, user, params);
+                user.save(function(err) {
+                    if (err)
+                        return res.status(500).send("Failed to change password!");
+
+                    _checkEmail(res, user, params);
+                });
             });
         }
         else
-            _checkUserEmailAndUpdate(res, user, params);
+            _checkEmail(res, user, params);
     });
 });
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/439fb31e/modules/control-center-web/src/main/js/views/settings/profile.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/settings/profile.jade b/modules/control-center-web/src/main/js/views/settings/profile.jade
index 048115e..a31824d 100644
--- a/modules/control-center-web/src/main/js/views/settings/profile.jade
+++ b/modules/control-center-web/src/main/js/views/settings/profile.jade
@@ -28,43 +28,45 @@ mixin lbl(txt)
                     .details-row
                         +lbl('User name:')
                         .col-xs-5.col-sm-4
-                            input#profile-username.form-control(type='text' ng-model='profileUser.username'
placeholder='Input name' required auto-focus)
+                            input#profile-username.form-control(type='text' ng-model='user.username'
placeholder='Input name' required auto-focus)
                     .details-row
                         +lbl('Email:')
                         .col-xs-5.col-sm-4
-                            input#profile-email.form-control(type='email' ng-model='profileUser.email'
placeholder='you@domain.com' required)
+                            input#profile-email.form-control(type='email' ng-model='user.email'
placeholder='you@domain.com' required)
                     .details-row
                         label.col-sm-2.labelFormField Company:
                         .col-xs-5.col-sm-4
-                            input#profile-company.form-control(type='text' ng-model='profileUser.company'
placeholder='You company name')
+                            input#profile-company.form-control(type='text' ng-model='user.company'
placeholder='You company name')
                     .details-row
                         label.col-sm-2.labelFormField Country:
                         .col-xs-5.col-sm-4
-                            button#profile-country.select-toggle.form-control(bs-select bs-options='item
for item in countries' type='text' ng-model='profileUser.country' placeholder='Choose you
country')
+                            button#profile-country.select-toggle.form-control(bs-select bs-options='item
for item in countries' type='text' ng-model='user.country' placeholder='Choose you country')
                     .details-row
                         .advanced-options
-                            i.fa.fa-chevron-circle-down(ng-show='profileUser.showToken' ng-click='profileUser.showToken
= ! profileUser.showToken')
-                            i.fa.fa-chevron-circle-right(ng-show='!profileUser.showToken'
ng-click='profileUser.showToken = ! profileUser.showToken')
-                            a(ng-click='profileUser.showToken = ! profileUser.showToken')
{{profileUser.showToken ? 'Hide security token...' : 'Show security token...'}}
-                    .details-row(ng-show='profileUser.showToken')
-                        +lbl('Security token:')
-                        label {{profileUser.token}}
-                        i.tipLabel.fa.fa-refresh(ng-click='generateToken()' bs-tooltip=''
data-title='Generate random security token')
-                        i.tipLabel.fa.fa-clipboard(ng-click-copy='{{profileUser.token}}'
bs-tooltip='' data-title='Copy security token to clipboard')
-                        i.tipLabel.fa.fa-question-circle(ng-if=lines bs-tooltip='' data-title='The
security token is used for authorization of web agent')
+                            i.fa(
+                            ng-click='expandedToken = !expandedToken'
+                            ng-class='expandedToken ? "fa-chevron-circle-down" : "fa-chevron-circle-right"')
+                            a(ng-click='expandedToken = !expandedToken') {{expandedToken
? 'Hide security token...' : 'Show security token...'}}
+                        div(ng-show='expandedToken')
+                            +lbl('Security token:')
+                            label {{user.token}}
+                            i.tipLabel.fa.fa-refresh(ng-click='generateToken()' bs-tooltip=''
data-title='Generate random security token')
+                            i.tipLabel.fa.fa-clipboard(ng-click-copy='{{user.token}}' bs-tooltip=''
data-title='Copy security token to clipboard')
+                            i.tipLabel.fa.fa-question-circle(ng-if=lines bs-tooltip='' data-title='The
security token is used for authorization of web agent')
                     .details-row
                         .advanced-options
-                            i.fa.fa-chevron-circle-down(ng-show='profileUser.changePassword'
ng-click='profileUser.changePassword = ! profileUser.changePassword')
-                            i.fa.fa-chevron-circle-right(ng-show='!profileUser.changePassword'
ng-click='profileUser.changePassword = ! profileUser.changePassword')
-                            a(ng-click='profileUser.changePassword = ! profileUser.changePassword')
{{profileUser.changePassword ? 'Cancel password changing...' : 'Change password...'}}
-                    div(ng-if='profileUser.changePassword')
-                        .details-row
-                            +lbl('New password:')
-                            .col-xs-5.col-sm-4
-                                input.form-control(type='password' ng-model='profileUser.newPassword'
placeholder='New password' ng-required='profileUser.changePassword')
-                        .details-row
-                            +lbl('Confirm:')
-                            .col-xs-5.col-sm-4
-                                input.form-control(type='password' ng-model='profileUser.confirmPassword'
match='profileUser.newPassword' placeholder='Confirm new password' ng-required='profileUser.changePassword')
+                            i.fa(
+                            ng-click='expandedPassword = !expandedPassword'
+                            ng-class='expandedPassword ? "fa-chevron-circle-down" : "fa-chevron-circle-right"')
+                            a(ng-click='expandedPassword = !expandedPassword') {{expandedPassword
? 'Cancel password changing...' : 'Change password...'}}
+                        div(ng-show='expandedPassword')
+                            .details-row
+                                +lbl('New password:')
+                                .col-xs-5.col-sm-4
+                                    input.form-control(type='password' ng-model='newPassword'
placeholder='New password')
+                            .details-row
+                                +lbl('Confirm:')
+                                .col-xs-5.col-sm-4
+                                    input.form-control(type='password' ng-model='confirmPassword'
match='newPassword' placeholder='Confirm new password')
                 .col-xs-12.col-sm-12.details-row
                     a.btn.btn-primary(ng-disabled='!profileCouldBeSaved()' ng-click='profileCouldBeSaved()
&& saveUser()' bs-tooltip='' data-title='{{saveBtnTipText()}}' data-placement='bottom'
data-trigger='hover') Save


Mime
View raw message