ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [14/22] ignite git commit: Ignite Web Console beta2.
Date Mon, 27 Jun 2016 03:22:58 GMT
http://git-wip-us.apache.org/repos/asf/ignite/blob/541e17d0/modules/web-console/src/main/js/controllers/igfs-controller.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/controllers/igfs-controller.js b/modules/web-console/src/main/js/controllers/igfs-controller.js
index 3a0e093..c37d08f 100644
--- a/modules/web-console/src/main/js/controllers/igfs-controller.js
+++ b/modules/web-console/src/main/js/controllers/igfs-controller.js
@@ -20,14 +20,14 @@ import consoleModule from 'controllers/common-module';
 
 consoleModule.controller('igfsController', [
     '$scope', '$http', '$state', '$filter', '$timeout', '$common', '$confirm', '$clone',
'$loading', '$cleanup', '$unsavedChangesGuard', '$table',
-    function ($scope, $http, $state, $filter, $timeout, $common, $confirm, $clone, $loading,
$cleanup, $unsavedChangesGuard, $table) {
+    function($scope, $http, $state, $filter, $timeout, $common, $confirm, $clone, $loading,
$cleanup, $unsavedChangesGuard, $table) {
         $unsavedChangesGuard.install($scope);
 
-        var emptyIgfs = {empty: true};
+        const emptyIgfs = {empty: true};
 
-        var __original_value;
+        let __original_value;
 
-        var blank = {
+        const blank = {
             ipcEndpointConfiguration: {},
             secondaryFileSystem: {}
         };
@@ -43,60 +43,55 @@ consoleModule.controller('igfsController', [
         $scope.widthIsSufficient = $common.widthIsSufficient;
         $scope.saveBtnTipText = $common.saveBtnTipText;
 
-        // TODO LEGACY start
-        $scope.tableSave = function (field, index, stopEdit) {
-            switch (field.type) {
-                case 'pathModes':
-                    if ($table.tablePairSaveVisible(field, index))
-                        return $table.tablePairSave($scope.tablePairValid, $scope.backupItem,
field, index, stopEdit);
+        const showPopoverMessage = $common.showPopoverMessage;
 
-                    break;
-            }
+        // TODO LEGACY start
+        $scope.tableSave = function(field, index, stopEdit) {
+            if (field.type === 'pathModes' && $table.tablePairSaveVisible(field,
index))
+                return $table.tablePairSave($scope.tablePairValid, $scope.backupItem, field,
index, stopEdit);
 
             return true;
         };
 
-        $scope.tableReset = function (save) {
-            var field = $table.tableField();
+        $scope.tableReset = (trySave) => {
+            const field = $table.tableField();
 
-            if (!save || !$common.isDefined(field) || $scope.tableSave(field, $table.tableEditedRowIndex(),
true)) {
-                $table.tableReset();
+            if (trySave && $common.isDefined(field) && !$scope.tableSave(field,
$table.tableEditedRowIndex(), true))
+                return false;
 
-                return true;
-            }
+            $table.tableReset();
 
-            return false;
+            return true;
         };
 
-        $scope.tableNewItem = function (field) {
+        $scope.tableNewItem = function(field) {
             if ($scope.tableReset(true))
                 $table.tableNewItem(field);
         };
 
         $scope.tableNewItemActive = $table.tableNewItemActive;
 
-        $scope.tableStartEdit = function (item, field, index) {
+        $scope.tableStartEdit = function(item, field, index) {
             if ($scope.tableReset(true))
                 $table.tableStartEdit(item, field, index, $scope.tableSave);
         };
 
         $scope.tableEditing = $table.tableEditing;
-
         $scope.tablePairSave = $table.tablePairSave;
         $scope.tablePairSaveVisible = $table.tablePairSaveVisible;
 
-        $scope.tableRemove = function (item, field, index) {
+        $scope.tableRemove = function(item, field, index) {
             if ($scope.tableReset(true))
                 $table.tableRemove(item, field, index);
         };
 
-        $scope.tablePairValid = function (item, field, index) {
-            var pairValue = $table.tablePairValue(field, index);
+        $scope.tablePairValid = function(item, field, index) {
+            const pairValue = $table.tablePairValue(field, index);
 
-            var model = item[field.model];
+            const model = item[field.model];
 
             if ($common.isDefined(model)) {
-                var idx = _.findIndex(model, function (pair) {
+                const idx = _.findIndex(model, function(pair) {
                     return pair.path === pairValue.key;
                 });
 
@@ -108,18 +103,26 @@ consoleModule.controller('igfsController', [
             return true;
         };
 
+        $scope.tblPathModes = {
+            type: 'pathModes',
+            model: 'pathModes',
+            focusId: 'PathMode',
+            ui: 'table-pair',
+            keyName: 'path',
+            valueName: 'mode',
+            save: $scope.tableSave
+        };
+
         $scope.igfsModes = $common.mkOptions(['PRIMARY', 'PROXY', 'DUAL_SYNC', 'DUAL_ASYNC']);
         // TODO LEGACY start - end
 
-        var showPopoverMessage = $common.showPopoverMessage;
-
-        $scope.contentVisible = function () {
-            var item = $scope.backupItem;
+        $scope.contentVisible = function() {
+            const item = $scope.backupItem;
 
             return !item.empty && (!item._id || _.find($scope.displayedRows, {_id:
item._id}));
         };
 
-        $scope.toggleExpanded = function () {
+        $scope.toggleExpanded = function() {
             $scope.ui.expanded = !$scope.ui.expanded;
 
             $common.hidePopover();
@@ -137,34 +140,34 @@ consoleModule.controller('igfsController', [
 
         // When landing on the page, get IGFSs and show them.
         $http.post('/api/v1/configuration/igfs/list')
-            .success(function (data) {
+            .success(function(data) {
                 $scope.spaces = data.spaces;
 
                 $scope.igfss = data.igfss || [];
 
                 // For backward compatibility set colocateMetadata and relaxedConsistency
default values.
-                _.forEach($scope.igfss, function (igfs) {
-                   if (_.isUndefined(igfs.colocateMetadata))
-                       igfs.colocateMetadata = true;
+                _.forEach($scope.igfss, (igfs) => {
+                    if (_.isUndefined(igfs.colocateMetadata))
+                        igfs.colocateMetadata = true;
 
-                   if (_.isUndefined(igfs.relaxedConsistency))
-                       igfs.relaxedConsistency = true;
+                    if (_.isUndefined(igfs.relaxedConsistency))
+                        igfs.relaxedConsistency = true;
                 });
 
-                $scope.clusters = _.map(data.clusters  || [], function (cluster) {
+                $scope.clusters = _.map(data.clusters || [], function(cluster) {
                     return {
                         value: cluster._id,
                         label: cluster.name
                     };
                 });
 
-                if ($state.params.id)
-                    $scope.createItem($state.params.id);
+                if ($state.params.linkId)
+                    $scope.createItem($state.params.linkId);
                 else {
-                    var lastSelectedIgfs = angular.fromJson(sessionStorage.lastSelectedIgfs);
+                    const lastSelectedIgfs = angular.fromJson(sessionStorage.lastSelectedIgfs);
 
                     if (lastSelectedIgfs) {
-                        var idx = _.findIndex($scope.igfss, function (igfs) {
+                        const idx = _.findIndex($scope.igfss, function(igfs) {
                             return igfs._id === lastSelectedIgfs;
                         });
 
@@ -181,30 +184,29 @@ consoleModule.controller('igfsController', [
                 }
 
                 $scope.$watch('ui.inputForm.$valid', function(valid) {
-                    if (valid && __original_value === JSON.stringify($cleanup($scope.backupItem)))
{
+                    if (valid && _.isEqual(__original_value, $cleanup($scope.backupItem)))
                         $scope.ui.inputForm.$dirty = false;
-                    }
                 });
 
-                $scope.$watch('backupItem', function (val) {
-                    var form = $scope.ui.inputForm;
+                $scope.$watch('backupItem', function(val) {
+                    const form = $scope.ui.inputForm;
 
-                    if (form.$pristine || (form.$valid && __original_value === JSON.stringify($cleanup(val))))
+                    if (form.$pristine || (form.$valid && _.isEqual(__original_value,
$cleanup(val))))
                         form.$setPristine();
                     else
                         form.$setDirty();
                 }, true);
             })
-            .catch(function (errMsg) {
+            .catch(function(errMsg) {
                 $common.showError(errMsg);
             })
-            .finally(function () {
+            .finally(function() {
                 $scope.ui.ready = true;
                 $scope.ui.inputForm.$setPristine();
                 $loading.finish('loadingIgfsScreen');
             });
 
-        $scope.selectItem = function (item, backup) {
+        $scope.selectItem = function(item, backup) {
             function selectItem() {
                 $table.tableReset(); // TODO LEGACY
 
@@ -229,7 +231,7 @@ consoleModule.controller('igfsController', [
 
                 $scope.backupItem = angular.merge({}, blank, $scope.backupItem);
 
-                __original_value = JSON.stringify($cleanup($scope.backupItem));
+                __original_value = $cleanup($scope.backupItem);
 
                 if ($common.getQueryVariable('new'))
                     $state.go('base.configuration.igfs');
@@ -238,26 +240,26 @@ consoleModule.controller('igfsController', [
             $common.confirmUnsavedChanges($scope.backupItem && $scope.ui.inputForm.$dirty,
selectItem);
         };
 
-        function prepareNewItem(id) {
+        $scope.linkId = () => $scope.backupItem._id ? $scope.backupItem._id : 'create';
+
+        function prepareNewItem(linkId) {
             return {
                 space: $scope.spaces[0]._id,
                 ipcEndpointEnabled: true,
                 fragmentizerEnabled: true,
                 colocateMetadata: true,
                 relaxedConsistency: true,
-                clusters: id && _.find($scope.clusters, {value: id}) ? [id] :
-                    (!_.isEmpty($scope.clusters) ? [$scope.clusters[0].value] : [])
+                clusters: linkId && _.find($scope.clusters, {value: linkId}) ? [linkId]
:
+                    (_.isEmpty($scope.clusters) ? [] : [$scope.clusters[0].value])
             };
         }
 
         // Add new IGFS.
-        $scope.createItem = function (id) {
+        $scope.createItem = function(linkId) {
             if ($scope.tableReset(true)) { // TODO LEGACY
-                $timeout(function () {
-                    $common.ensureActivePanel($scope.ui, 'general', 'igfsName');
-                });
+                $timeout(() => $common.ensureActivePanel($scope.ui, 'general', 'igfsName'));
 
-                $scope.selectItem(undefined, prepareNewItem(id));
+                $scope.selectItem(null, prepareNewItem(linkId));
             }
         };
 
@@ -268,46 +270,14 @@ consoleModule.controller('igfsController', [
             if ($common.isEmptyString(item.name))
                 return showPopoverMessage($scope.ui, 'general', 'igfsName', 'IGFS name should
not be empty!');
 
-            var form = $scope.ui.inputForm;
-            var errors = form.$error;
-            var errKeys = Object.keys(errors);
-
-            if (errKeys && errKeys.length > 0) {
-                var firstErrorKey = errKeys[0];
-
-                var firstError = errors[firstErrorKey][0];
-                var actualError = firstError.$error[firstErrorKey][0];
-
-                var errNameFull = actualError.$name;
-                var errNameShort = errNameFull;
-
-                if (errNameShort.endsWith('TextInput'))
-                    errNameShort = errNameShort.substring(0, errNameShort.length - 9);
-
-                var extractErrorMessage = function (errName) {
-                    try {
-                        return errors[firstErrorKey][0].$errorMessages[errName][firstErrorKey];
-                    }
-                    catch(ignored) {
-                        try {
-                            msg = form[firstError.$name].$errorMessages[errName][firstErrorKey];
-                        }
-                        catch(ignited) {
-                            return false;
-                        }
-                    }
-                };
-
-                var msg = extractErrorMessage(errNameFull) || extractErrorMessage(errNameShort)
|| 'Invalid value!';
-
-                return showPopoverMessage($scope.ui, firstError.$name, errNameFull, msg);
-            }
+            if (!$common.checkFieldValidators($scope.ui))
+                return false;
 
             if (!item.secondaryFileSystemEnabled && (item.defaultMode === 'PROXY'))
                 return showPopoverMessage($scope.ui, 'secondaryFileSystem', 'secondaryFileSystem-title',
'Secondary file system should be configured for "PROXY" IGFS mode!');
 
             if (item.pathModes) {
-                for (var pathIx = 0; pathIx < item.pathModes.length; pathIx++) {
+                for (let pathIx = 0; pathIx < item.pathModes.length; pathIx++) {
                     if (!item.secondaryFileSystemEnabled && item.pathModes[pathIx].mode
=== 'PROXY')
                         return showPopoverMessage($scope.ui, 'secondaryFileSystem', 'secondaryFileSystem-title',
'Secondary file system should be configured for "PROXY" path mode!');
                 }
@@ -319,10 +289,10 @@ consoleModule.controller('igfsController', [
         // Save IGFS in database.
         function save(item) {
             $http.post('/api/v1/configuration/igfs/save', item)
-                .success(function (_id) {
+                .success(function(_id) {
                     $scope.ui.inputForm.$setPristine();
 
-                    var idx = _.findIndex($scope.igfss, function (igfs) {
+                    const idx = _.findIndex($scope.igfss, function(igfs) {
                         return igfs._id === _id;
                     });
 
@@ -337,15 +307,15 @@ consoleModule.controller('igfsController', [
 
                     $common.showInfo('IGFS "' + item.name + '" saved.');
                 })
-                .error(function (errMsg) {
+                .error(function(errMsg) {
                     $common.showError(errMsg);
                 });
         }
 
         // Save IGFS.
-        $scope.saveItem = function () {
+        $scope.saveItem = function() {
             if ($scope.tableReset(true)) { // TODO LEGACY
-                var item = $scope.backupItem;
+                const item = $scope.backupItem;
 
                 if (validate(item))
                     save(item);
@@ -353,16 +323,16 @@ consoleModule.controller('igfsController', [
         };
 
         function _igfsNames() {
-            return _.map($scope.igfss, function (igfs) {
+            return _.map($scope.igfss, function(igfs) {
                 return igfs.name;
             });
         }
 
         // Clone IGFS with new name.
-        $scope.cloneItem = function () {
+        $scope.cloneItem = function() {
             if ($scope.tableReset(true) && validate($scope.backupItem)) { // TODO
LEGACY
-                $clone.confirm($scope.backupItem.name, _igfsNames()).then(function (newName)
{
-                    var item = angular.copy($scope.backupItem);
+                $clone.confirm($scope.backupItem.name, _igfsNames()).then(function(newName)
{
+                    const item = angular.copy($scope.backupItem);
 
                     delete item._id;
 
@@ -374,22 +344,22 @@ consoleModule.controller('igfsController', [
         };
 
         // Remove IGFS from db.
-        $scope.removeItem = function () {
+        $scope.removeItem = function() {
             $table.tableReset(); // TODO LEGACY
 
-            var selectedItem = $scope.selectedItem;
+            const selectedItem = $scope.selectedItem;
 
             $confirm.confirm('Are you sure you want to remove IGFS: "' + selectedItem.name
+ '"?')
-                .then(function () {
-                    var _id = selectedItem._id;
+                .then(function() {
+                    const _id = selectedItem._id;
 
-                    $http.post('/api/v1/configuration/igfs/remove', {_id: _id})
-                        .success(function () {
+                    $http.post('/api/v1/configuration/igfs/remove', {_id})
+                        .success(function() {
                             $common.showInfo('IGFS has been removed: ' + selectedItem.name);
 
-                            var igfss = $scope.igfss;
+                            const igfss = $scope.igfss;
 
-                            var idx = _.findIndex(igfss, function (igfs) {
+                            const idx = _.findIndex(igfss, function(igfs) {
                                 return igfs._id === _id;
                             });
 
@@ -398,41 +368,43 @@ consoleModule.controller('igfsController', [
 
                                 if (igfss.length > 0)
                                     $scope.selectItem(igfss[0]);
-                                else
+                                else {
                                     $scope.backupItem = emptyIgfs;
+                                    $scope.ui.inputForm.$setPristine();
+                                }
                             }
                         })
-                        .error(function (errMsg) {
+                        .error(function(errMsg) {
                             $common.showError(errMsg);
                         });
                 });
         };
 
         // Remove all IGFS from db.
-        $scope.removeAllItems = function () {
+        $scope.removeAllItems = function() {
             $table.tableReset(); // TODO LEGACY
 
             $confirm.confirm('Are you sure you want to remove all IGFS?')
-                .then(function () {
+                .then(function() {
                     $http.post('/api/v1/configuration/igfs/remove/all')
-                        .success(function () {
+                        .success(function() {
                             $common.showInfo('All IGFS have been removed');
 
                             $scope.igfss = [];
                             $scope.backupItem = emptyIgfs;
                             $scope.ui.inputForm.$setPristine();
                         })
-                        .error(function (errMsg) {
+                        .error(function(errMsg) {
                             $common.showError(errMsg);
                         });
                 });
         };
 
-        $scope.resetAll = function () {
+        $scope.resetAll = function() {
             $table.tableReset(); // TODO LEGACY
 
             $confirm.confirm('Are you sure you want to undo all changes for current IGFS?')
-                .then(function () {
+                .then(function() {
                     $scope.backupItem = $scope.selectedItem ? angular.copy($scope.selectedItem)
: prepareNewItem();
                     $scope.ui.inputForm.$setPristine();
                 });

http://git-wip-us.apache.org/repos/asf/ignite/blob/541e17d0/modules/web-console/src/main/js/controllers/profile-controller.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/controllers/profile-controller.js b/modules/web-console/src/main/js/controllers/profile-controller.js
index ffeffd4..39457af 100644
--- a/modules/web-console/src/main/js/controllers/profile-controller.js
+++ b/modules/web-console/src/main/js/controllers/profile-controller.js
@@ -19,66 +19,74 @@
 import consoleModule from 'controllers/common-module';
 
 consoleModule.controller('profileController', [
-    '$rootScope', '$scope', '$http', '$common', '$focus', '$confirm', 'IgniteCountries',
-    function ($root, $scope, $http, $common, $focus, $confirm, Countries) {
+    '$rootScope', '$scope', '$http', '$common', '$focus', '$confirm', 'IgniteCountries',
'User',
+    function($root, $scope, $http, $common, $focus, $confirm, Countries, User) {
         $scope.user = angular.copy($root.user);
 
         $scope.countries = Countries.getAll();
 
         $scope.generateToken = () => {
             $confirm.confirm('Are you sure you want to change security token?')
-                .then(() => $scope.user.token = $common.randomString(20))
+                .then(() => $scope.user.token = $common.randomString(20));
         };
 
-        const _cleanup = () => {
-            const _user = $scope.user;
-
-            if (!$scope.expandedToken)
-                _user.token = $root.user.token;
-
-            if (!$scope.expandedPassword) {
-                delete _user.password;
+        const _passwordValid = () => {
+            const cur = $scope.user;
 
-                delete _user.confirm;
-            }
+            return !$scope.expandedPassword || (cur.password && cur.confirm &&
cur.password === cur.confirm);
         };
 
         const _profileChanged = () => {
-            _cleanup();
-
             const old = $root.user;
             const cur = $scope.user;
 
             return !_.isEqual(old, cur);
         };
 
-        $scope.profileCouldBeSaved = () => _profileChanged() && $scope.profileForm
&& $scope.profileForm.$valid;
+        $scope.toggleToken = () => {
+            $scope.expandedToken = !$scope.expandedToken;
+
+            if (!$scope.expandedToken)
+                $scope.user.token = $root.user.token;
+        };
+
+        $scope.togglePassword = () => {
+            $scope.expandedPassword = !$scope.expandedPassword;
+
+            if (!$scope.expandedPassword) {
+                delete $scope.user.password;
+
+                delete $scope.user.confirm;
+            }
+        };
+
+        $scope.profileCouldBeSaved = () => _profileChanged() && $scope.profileForm
&& $scope.profileForm.$valid && _passwordValid();
 
         $scope.saveBtnTipText = () => {
             if (!_profileChanged())
                 return 'Nothing to save';
 
+            if (!_passwordValid())
+                return 'Invalid password';
+
             return $scope.profileForm && $scope.profileForm.$valid ? 'Save profile'
: 'Invalid profile settings';
         };
 
         $scope.saveUser = () => {
-            _cleanup();
-
             $http.post('/api/v1/profile/save', $scope.user)
-                .success(() => {
-                    $scope.expandedPassword = false;
-
-                    _cleanup();
-
-                    $scope.expandedToken = false;
+                .then(User.read)
+                .then(() => {
+                    if ($scope.expandedPassword)
+                        $scope.togglePassword();
 
-                    $root.user = angular.copy($scope.user);
+                    if ($scope.expandedToken)
+                        $scope.toggleToken();
 
                     $common.showInfo('Profile saved.');
 
                     $focus('profile-username');
                 })
-                .error((err) => $common.showError('Failed to save profile: ' + $common.errorMessage(err)));
+                .catch((err) => $common.showError('Failed to save profile: ' + $common.errorMessage(err)));
         };
     }]
 );


Mime
View raw message