Repository: incubator-ignite Updated Branches: refs/heads/ignite-843 576c87d2f -> 2030dfb8f
IGNITE-843 Added check for group item name. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2030dfb8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2030dfb8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2030dfb8 Branch: refs/heads/ignite-843 Commit: 2030dfb8fea41ae8efc38561f6c3bd961dcaa823 Parents: 576c87d Author: AKuznetsov <akuznet...@gridgain.com> Authored: Tue Jul 21 13:33:37 2015 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Tue Jul 21 13:33:37 2015 +0700 ---------------------------------------------------------------------- .../nodejs/controllers/metadata-controller.js | 55 ++++++++++++++------ 1 file changed, 40 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2030dfb8/modules/web-control-center/nodejs/controllers/metadata-controller.js ---------------------------------------------------------------------- diff --git a/modules/web-control-center/nodejs/controllers/metadata-controller.js b/modules/web-control-center/nodejs/controllers/metadata-controller.js index f577dea..bf08194 100644 --- a/modules/web-control-center/nodejs/controllers/metadata-controller.js +++ b/modules/web-control-center/nodejs/controllers/metadata-controller.js @@ -506,7 +506,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo if ($common.isDefined(groups)) { var idx = _.findIndex(groups, function (group) { - return group.name == groupName + return group.name == groupName; }); // Found itself. @@ -576,25 +576,50 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo return $common.isNonEmpty(fieldName) && $common.isNonEmpty(className); }; - $scope.tableGroupItemSave = function (fieldName, className, direction, groupIndex, index) { - $table.tableReset(); + function tableGroupItemValid(fieldName, groupIndex, index) { + var groupItems = $scope.backupItem.groups[groupIndex].fields; - var group = $scope.backupItem.groups[groupIndex]; + if ($common.isDefined(groupItems)) { + var idx = _.findIndex(groupItems, function (groupItem) { + return groupItem.name == fieldName; + }); - if (index < 0) { - var newGroupItem = {name: fieldName, className: className, direction: direction}; + // Found itself. + if (index >= 0 && index == idx) + return true; - if (group.fields) - group.fields.push(newGroupItem); - else - group.fields = [newGroupItem]; + // Found duplicate. + if (idx >= 0) { + $common.showError('Field with such name already exists in group!'); + + return false; + } } - else { - var groupItem = group.fields[index]; - groupItem.name = fieldName; - groupItem.className = className; - groupItem.direction = direction; + return true; + } + + $scope.tableGroupItemSave = function (fieldName, className, direction, groupIndex, index) { + if (tableGroupItemValid(fieldName, groupIndex, index)) { + $table.tableReset(); + + var group = $scope.backupItem.groups[groupIndex]; + + if (index < 0) { + var newGroupItem = {name: fieldName, className: className, direction: direction}; + + if (group.fields) + group.fields.push(newGroupItem); + else + group.fields = [newGroupItem]; + } + else { + var groupItem = group.fields[index]; + + groupItem.name = fieldName; + groupItem.className = className; + groupItem.direction = direction; + } } };