ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [33/50] [abbrv] ignite git commit: IGNITE-2676 Refactoring IGFS screen to Angular directives and JADE mixins.
Date Mon, 28 Mar 2016 08:48:13 GMT
http://git-wip-us.apache.org/repos/asf/ignite/blob/6cd972a1/modules/control-center-web/src/main/js/controllers/igfs-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/igfs-controller.js b/modules/control-center-web/src/main/js/controllers/igfs-controller.js
index b32b606..553fd4c 100644
--- a/modules/control-center-web/src/main/js/controllers/igfs-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/igfs-controller.js
@@ -17,102 +17,38 @@
 
 // Controller for IGFS screen.
 consoleModule.controller('igfsController', [
-    '$scope', '$http', '$state', '$filter', '$timeout', '$common', '$focus', '$confirm',
'$clone', '$table', '$preview', '$loading', '$unsavedChangesGuard',
-    function ($scope, $http, $state, $filter, $timeout, $common, $focus, $confirm, $clone,
$table, $preview, $loading, $unsavedChangesGuard) {
+    '$scope', '$http', '$state', '$filter', '$timeout', '$common', '$confirm', '$clone',
'$loading', '$cleanup', '$unsavedChangesGuard',
+    function ($scope, $http, $state, $filter, $timeout, $common, $confirm, $clone, $loading,
$cleanup, $unsavedChangesGuard) {
         $unsavedChangesGuard.install($scope);
 
+        var emptyIgfs = {empty: true};
+
+        var __original_value;
+
+        var blank = {
+            ipcEndpointConfiguration: {},
+            secondaryFileSystem: {}
+        };
+
+        // We need to initialize backupItem with empty object in order to properly used from
angular directives.
+        $scope.backupItem = emptyIgfs;
+
         $scope.ui = $common.formUI();
+        $scope.ui.angularWay = true; // TODO We need to distinguish refactored UI from legacy
UI.
         $scope.ui.activePanels = [0];
         $scope.ui.topPanels = [0];
 
-        $scope.joinTip = $common.joinTip;
-        $scope.getModel = $common.getModel;
-        $scope.javaBuiltInClasses = $common.javaBuiltInClasses;
         $scope.compactJavaName = $common.compactJavaName;
         $scope.widthIsSufficient = $common.widthIsSufficient;
         $scope.saveBtnTipText = $common.saveBtnTipText;
-        $scope.panelExpanded = $common.panelExpanded;
-
-        $scope.tableVisibleRow = $table.tableVisibleRow;
-
-        $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);
-
-                    break;
-            }
-
-            return true;
-        };
-
-        $scope.tableReset = function (save) {
-            var field = $table.tableField();
-
-            if (!save || !$common.isDefined(field) || $scope.tableSave(field, $table.tableEditedRowIndex(),
true)) {
-                $table.tableReset();
-
-                return true;
-            }
-
-            return false;
-        };
-
-        $scope.tableNewItem = function (field) {
-            if ($scope.tableReset(true))
-                $table.tableNewItem(field);
-        };
-
-        $scope.tableNewItemActive = $table.tableNewItemActive;
-
-        $scope.tableStartEdit = function (item, field, index) {
-            if ($scope.tableReset(true))
-                $table.tableStartEdit(item, field, index);
-        };
-
-        $scope.tableEditing = $table.tableEditing;
-
-        $scope.tableRemove = function (item, field, index) {
-            if ($scope.tableReset(true))
-                $table.tableRemove(item, field, index);
-        };
-
-        $scope.tableSimpleSave = $table.tableSimpleSave;
-        $scope.tableSimpleSaveVisible = $table.tableSimpleSaveVisible;
-
-        $scope.tableSimpleUp = function (item, field, index) {
-            if ($scope.tableReset(true))
-                $table.tableSimpleUp(item, field, index);
-        };
-
-        $scope.tableSimpleDown = function (item, field, index) {
-            if ($scope.tableReset(true))
-                $table.tableSimpleDown(item, field, index);
-        };
-
-        $scope.tableSimpleDownVisible = $table.tableSimpleDownVisible;
-
-        $scope.tablePairSave = $table.tablePairSave;
-        $scope.tablePairSaveVisible = $table.tablePairSaveVisible;
-
-        var previews = [];
-
-        $scope.previewInit = function (preview) {
-            previews.push(preview);
-
-            $preview.previewInit(preview);
-        };
-
-        $scope.previewChanged = $preview.previewChanged;
-
-        $scope.hidePopover = $common.hidePopover;
 
         var showPopoverMessage = $common.showPopoverMessage;
 
-        $scope.igfsModes = $common.mkOptions(['PRIMARY', 'PROXY', 'DUAL_SYNC', 'DUAL_ASYNC']);
+        $scope.contentVisible = function () {
+            var item = $scope.backupItem;
 
-        $scope.ipcTypes = $common.mkOptions(['SHMEM', 'TCP']);
+            return !item.empty && (!item._id || _.find($scope.displayedRows, {_id:
item._id}));
+        };
 
         $scope.toggleExpanded = function () {
             $scope.ui.expanded = !$scope.ui.expanded;
@@ -120,38 +56,9 @@ consoleModule.controller('igfsController', [
             $common.hidePopover();
         };
 
-        $scope.general = [];
-        $scope.advanced = [];
         $scope.igfss = [];
         $scope.clusters = [];
 
-        $scope.preview = {
-            general: {xml: '', java: '', allDefaults: true},
-            ipc: {xml: '', java: '', allDefaults: true},
-            fragmentizer: {xml: '', java: '', allDefaults: true},
-            dualMode: {xml: '', java: '', allDefaults: true},
-            secondaryFileSystem: {xml: '', java: '', allDefaults: true},
-            misc: {xml: '', java: '', allDefaults: true}
-        };
-
-        $scope.tablePairValid = function (item, field, index) {
-            var pairValue = $table.tablePairValue(field, index);
-
-            var model = item[field.model];
-
-            if ($common.isDefined(model)) {
-                var idx = _.findIndex(model, function (pair) {
-                    return pair.path === pairValue.key;
-                });
-
-                // Found duplicate.
-                if (idx >= 0 && idx !== index)
-                    return showPopoverMessage($scope.ui, 'misc', $table.tableFieldId(index,
'KeyPathMode'), 'Such path already exists!');
-            }
-
-            return true;
-        };
-
         function selectFirstItem() {
             if ($scope.igfss.length > 0)
                 $scope.selectItem($scope.igfss[0]);
@@ -171,113 +78,82 @@ consoleModule.controller('igfsController', [
                     };
                 });
 
-                // Load page descriptor.
-                $http.get('/models/igfs.json')
-                    .success(function (data) {
-                        $scope.general = data.general;
-                        $scope.advanced = data.advanced;
+                if ($state.params.id)
+                    $scope.createItem($state.params.id);
+                else {
+                    var lastSelectedIgfs = angular.fromJson(sessionStorage.lastSelectedIgfs);
 
-                        $scope.ui.addGroups(data.general, data.advanced);
+                    if (lastSelectedIgfs) {
+                        var idx = _.findIndex($scope.igfss, function (igfs) {
+                            return igfs._id === lastSelectedIgfs;
+                        });
 
-                        if ($state.params.id)
-                            $scope.createItem($state.params.id);
+                        if (idx >= 0)
+                            $scope.selectItem($scope.igfss[idx]);
                         else {
-                            var lastSelectedIgfs = angular.fromJson(sessionStorage.lastSelectedIgfs);
-
-                            if (lastSelectedIgfs) {
-                                var idx = _.findIndex($scope.igfss, function (igfs) {
-                                    return igfs._id === lastSelectedIgfs;
-                                });
+                            sessionStorage.removeItem('lastSelectedIgfs');
 
-                                if (idx >= 0)
-                                    $scope.selectItem($scope.igfss[idx]);
-                                else {
-                                    sessionStorage.removeItem('lastSelectedIgfs');
-
-                                    selectFirstItem();
-                                }
-
-                            }
-                            else
-                                selectFirstItem();
+                            selectFirstItem();
                         }
+                    }
+                    else
+                        selectFirstItem();
+                }
 
-                        $scope.$watch('backupItem', function (val) {
-                            if (val) {
-                                var srcItem = $scope.selectedItem ? $scope.selectedItem :
prepareNewItem();
-
-                                $scope.ui.checkDirty(val, srcItem);
-
-                                var varName = $commonUtils.toJavaName('igfs', val.name);
-
-                                $scope.preview.general.xml = $generatorXml.igfsGeneral(val).asString();
-                                $scope.preview.general.java = $generatorJava.igfsGeneral(val,
varName).asString();
-                                $scope.preview.general.allDefaults = $common.isEmptyString($scope.preview.general.xml);
-
-                                $scope.preview.ipc.xml = $generatorXml.igfsIPC(val).asString();
-                                $scope.preview.ipc.java = $generatorJava.igfsIPC(val, varName).asString();
-                                $scope.preview.ipc.allDefaults = $common.isEmptyString($scope.preview.ipc.xml);
-
-                                $scope.preview.fragmentizer.xml = $generatorXml.igfsFragmentizer(val).asString();
-                                $scope.preview.fragmentizer.java = $generatorJava.igfsFragmentizer(val,
varName).asString();
-                                $scope.preview.fragmentizer.allDefaults = $common.isEmptyString($scope.preview.fragmentizer.xml);
-
-                                $scope.preview.dualMode.xml = $generatorXml.igfsDualMode(val).asString();
-                                $scope.preview.dualMode.java = $generatorJava.igfsDualMode(val,
varName).asString();
-                                $scope.preview.dualMode.allDefaults = $common.isEmptyString($scope.preview.dualMode.xml);
+                $scope.$watch('ui.inputForm.$valid', function(valid) {
+                    if (valid && __original_value === JSON.stringify($cleanup($scope.backupItem)))
{
+                        $scope.ui.inputForm.$dirty = false;
+                    }
+                });
 
-                                $scope.preview.secondaryFileSystem.xml = $generatorXml.igfsSecondFS(val).asString();
-                                $scope.preview.secondaryFileSystem.java = $generatorJava.igfsSecondFS(val,
varName).asString();
-                                $scope.preview.secondaryFileSystem.allDefaults = $common.isEmptyString($scope.preview.secondaryFileSystem.xml);
+                $scope.$watch('backupItem', function (val) {
+                    var form = $scope.ui.inputForm;
 
-                                $scope.preview.misc.xml = $generatorXml.igfsMisc(val).asString();
-                                $scope.preview.misc.java = $generatorJava.igfsMisc(val, varName).asString();
-                                $scope.preview.misc.allDefaults = $common.isEmptyString($scope.preview.misc.xml);
-                            }
-                        }, true);
-                    })
-                    .error(function (errMsg) {
-                        $common.showError(errMsg);
-                    });
+                    if (form.$pristine || (form.$valid && __original_value === JSON.stringify($cleanup(val))))
+                        form.$setPristine();
+                    else
+                        form.$setDirty();
+                }, true);
             })
-            .error(function (errMsg) {
+            .catch(function (errMsg) {
                 $common.showError(errMsg);
             })
             .finally(function () {
                 $scope.ui.ready = true;
+                $scope.ui.inputForm.$setPristine();
                 $loading.finish('loadingIgfsScreen');
             });
 
         $scope.selectItem = function (item, backup) {
             function selectItem() {
-                $table.tableReset();
-
-                $scope.selectedItem = angular.copy(item);
+                $scope.selectedItem = item;
 
                 try {
-                    if (item)
+                    if (item && item._id)
                         sessionStorage.lastSelectedIgfs = angular.toJson(item._id);
                     else
                         sessionStorage.removeItem('lastSelectedIgfs');
                 }
-                catch (error) { }
-
-                _.forEach(previews, function(preview) {
-                    preview.attractAttention = false;
-                });
+                catch (ignored) {
+                    // No-op.
+                }
 
                 if (backup)
                     $scope.backupItem = backup;
                 else if (item)
                     $scope.backupItem = angular.copy(item);
                 else
-                    $scope.backupItem = undefined;
+                    $scope.backupItem = emptyIgfs;
+
+                $scope.backupItem = angular.merge({}, blank, $scope.backupItem);
+
+                __original_value = JSON.stringify($cleanup($scope.backupItem));
 
                 if ($common.getQueryVariable('new'))
                     $state.go('base.configuration.igfs');
             }
 
-            $common.confirmUnsavedChanges($scope.ui.isDirty(), selectItem);
+            $common.confirmUnsavedChanges($scope.backupItem && $scope.ui.inputForm.$dirty,
selectItem);
         };
 
         function prepareNewItem(id) {
@@ -290,51 +166,90 @@ consoleModule.controller('igfsController', [
             };
         }
 
+        $scope.zzz = function () {
+            console.log("TEST on enter!")
+        };
+
         // Add new IGFS.
         $scope.createItem = function (id) {
-            if ($scope.tableReset(true)) {
-                $timeout(function () {
-                    $common.ensureActivePanel($scope.ui, 'general', 'igfsName');
-                });
+            $timeout(function () {
+                $common.ensureActivePanel($scope.ui, 'general', 'igfsName');
+            });
 
-                $scope.selectItem(undefined, prepareNewItem(id));
-            }
+            $scope.selectItem(undefined, prepareNewItem(id));
         };
 
         // Check IGFS logical consistency.
         function validate(item) {
+            $common.hidePopover();
+
             if ($common.isEmptyString(item.name))
-                return showPopoverMessage($scope.ui, 'general', 'igfsName', 'Name should
not be empty');
+                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.endsWith('JavaClass'))
+                    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.isEmptyString(item.dualModePutExecutorService) &&
                 !$common.isValidJavaClass('Put executor service', item.dualModePutExecutorService,
false, 'dualModePutExecutorService', false, $scope.ui, 'dualMode'))
                 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');
+                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++) {
                     if (!item.secondaryFileSystemEnabled && item.pathModes[pathIx].mode
=== 'PROXY')
-                        return showPopoverMessage($scope.ui, 'misc', 'secondaryFileSystem-title',
'Secondary file system should be configured for "PROXY" path mode');
+                        return showPopoverMessage($scope.ui, 'misc', 'secondaryFileSystem-title',
'Secondary file system should be configured for "PROXY" path mode!');
                 }
             }
 
             return true;
         }
 
-        // Save IGFS into database.
+        // Save IGFS in database.
         function save(item) {
             $http.post('/api/v1/configuration/igfs/save', item)
                 .success(function (_id) {
-                    $scope.ui.markPristine();
+                    $scope.ui.inputForm.$setPristine();
 
                     var idx = _.findIndex($scope.igfss, function (igfs) {
                         return igfs._id === _id;
                     });
 
                     if (idx >= 0)
-                        angular.extend($scope.igfss[idx], item);
+                        angular.merge($scope.igfss[idx], item);
                     else {
                         item._id = _id;
                         $scope.igfss.push(item);
@@ -351,12 +266,10 @@ consoleModule.controller('igfsController', [
 
         // Save IGFS.
         $scope.saveItem = function () {
-            if ($scope.tableReset(true)) {
-                var item = $scope.backupItem;
+            var item = $scope.backupItem;
 
-                if (validate(item))
-                    save(item);
-            }
+            if (validate(item))
+                save(item);
         };
 
         function _igfsNames() {
@@ -365,13 +278,14 @@ consoleModule.controller('igfsController', [
             });
         }
 
-        // Save IGFS with new name.
+        // Clone IGFS with new name.
         $scope.cloneItem = function () {
-            if ($scope.tableReset(true) && validate($scope.backupItem)) {
+            if (validate($scope.backupItem)) {
                 $clone.confirm($scope.backupItem.name, _igfsNames()).then(function (newName)
{
                     var item = angular.copy($scope.backupItem);
 
                     delete item._id;
+
                     item.name = newName;
 
                     save(item);
@@ -381,8 +295,6 @@ consoleModule.controller('igfsController', [
 
         // Remove IGFS from db.
         $scope.removeItem = function () {
-            $table.tableReset();
-
             var selectedItem = $scope.selectedItem;
 
             $confirm.confirm('Are you sure you want to remove IGFS: "' + selectedItem.name
+ '"?')
@@ -405,7 +317,7 @@ consoleModule.controller('igfsController', [
                                 if (igfss.length > 0)
                                     $scope.selectItem(igfss[0]);
                                 else
-                                    $scope.selectItem(undefined, undefined);
+                                    $scope.backupItem = emptyIgfs;
                             }
                         })
                         .error(function (errMsg) {
@@ -414,10 +326,8 @@ consoleModule.controller('igfsController', [
                 });
         };
 
-        // Remove all igfss from db.
+        // Remove all IGFS from db.
         $scope.removeAllItems = function () {
-            $table.tableReset();
-
             $confirm.confirm('Are you sure you want to remove all IGFS?')
                 .then(function () {
                     $http.post('/api/v1/configuration/igfs/remove/all')
@@ -425,8 +335,8 @@ consoleModule.controller('igfsController', [
                             $common.showInfo('All IGFS have been removed');
 
                             $scope.igfss = [];
-                            $scope.ui.markPristine();
-                            $scope.selectItem(undefined, undefined);
+                            $scope.backupItem = emptyIgfs;
+                            $scope.ui.inputForm.$setPristine();
                         })
                         .error(function (errMsg) {
                             $common.showError(errMsg);
@@ -434,23 +344,11 @@ consoleModule.controller('igfsController', [
                 });
         };
 
-        $scope.resetItem = function (group) {
-            var resetTo = $scope.selectedItem;
-
-            if (!$common.isDefined(resetTo))
-                resetTo = prepareNewItem();
-
-            $common.resetItem($scope.backupItem, resetTo, $scope.general, group);
-            $common.resetItem($scope.backupItem, resetTo, $scope.advanced, group);
-        };
-
         $scope.resetAll = function () {
-            $table.tableReset();
-
             $confirm.confirm('Are you sure you want to undo all changes for current IGFS?')
                 .then(function () {
                     $scope.backupItem = $scope.selectedItem ? angular.copy($scope.selectedItem)
: prepareNewItem();
-                    $scope.ui.markPristine();
+                    $scope.ui.inputForm.$setPristine();
                 });
         };
     }]

http://git-wip-us.apache.org/repos/asf/ignite/blob/6cd972a1/modules/control-center-web/src/main/js/views/configuration/igfs.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/configuration/igfs.jade b/modules/control-center-web/src/main/js/views/configuration/igfs.jade
index 1a9d262..947cebe 100644
--- a/modules/control-center-web/src/main/js/views/configuration/igfs.jade
+++ b/modules/control-center-web/src/main/js/views/configuration/igfs.jade
@@ -28,13 +28,21 @@ include ../includes/infos
             .padding-top-dflt(bs-affix)
                 .panel-tip-container(data-placement='bottom' bs-tooltip='' data-title='Create
new IGFS')
                     button.btn.btn-primary(id='new-item' ng-click='createItem()') Add IGFS
-                +save-remove-buttons('IGFS')
+                +save-remove-buttons-new('IGFS')
                 hr
             .bs-affix-fix
-            form.form-horizontal(name='ui.inputForm' ng-show='backupItem && tableVisibleRow(displayedRows,
selectedItem)' novalidate)
-                .panel-group(bs-collapse ng-model='ui.activePanels' data-allow-multiple='true'
ng-click='triggerDigest = true')
-                    +groups('general', 'backupItem')
-                    div(ng-show='ui.expanded')
-                        +advanced-options
-                        +groups('advanced', 'backupItem')
-                +advanced-options
+            div(bs-collapse='' data-allow-multiple='true' ng-model='ui.activePanels')
+                form.form-horizontal(name='ui.inputForm' ng-show='contentVisible()' novalidate)
+                    .panel-group
+                        ignite-configuration-igfs-general
+
+                        ignite-advanced-options-toggle
+
+                        div(ng-show='ui.expanded')
+                            ignite-configuration-igfs-ipc
+                            ignite-configuration-igfs-fragmentizer
+                            ignite-configuration-igfs-dual
+                            ignite-configuration-igfs-secondary
+                            ignite-configuration-igfs-misc
+
+                            ignite-advanced-options-toggle


Mime
View raw message