From 3dd54b58b98b6da5080d3dd0c3caea34b47bab1d Mon Sep 17 00:00:00 2001 From: Mae Isabelle Turiana Date: Mon, 25 Apr 2016 21:04:41 +0800 Subject: [PATCH 1/3] - Fixed issue in saving options and loading of previous options - Also added validation for missing input file path --- .../static/app/mlcp/mlcp.controller.js | 72 ++++++++++++------- .../resources/static/app/mlcp/mlcp.groups.js | 14 +++- .../main/resources/static/app/mlcp/mlcp.html | 7 ++ 3 files changed, 66 insertions(+), 27 deletions(-) diff --git a/quick-start/src/main/resources/static/app/mlcp/mlcp.controller.js b/quick-start/src/main/resources/static/app/mlcp/mlcp.controller.js index bf7c61bdb6..23b7847fff 100644 --- a/quick-start/src/main/resources/static/app/mlcp/mlcp.controller.js +++ b/quick-start/src/main/resources/static/app/mlcp/mlcp.controller.js @@ -20,7 +20,7 @@ hideFileTree: hideFileTree, isText: isText, dataForTheTree: [], - groups: mlcpGroups.groups(entityName, flowName), + groups: mlcpGroups.groups(entityName, flowName, mlcpOptions), treeOptions: { nodeChildren: 'children', dirSelectable: false, @@ -29,12 +29,29 @@ } }); + $scope.errorMessage = null; + $scope.hasError = false; + $scope.mlcp = angular.extend({ input_file_type: 'documents', }, mlcpOptions); - + + function ok() { - $uibModalInstance.close($scope.mlcp); + if(isValidInputFilePath) { + $uibModalInstance.close($scope.mlcp); + } + } + + function isValidInputFilePath() { + if($scope.mlcp.input_file_path) { + $scope.hasError = false; + $scope.errorMessage = null; + return true; + } else { + $scope.hasError = true; + $scope.errorMessage = 'The Location of Files to Load is required.'; + } } function cancel() { @@ -109,25 +126,19 @@ function buildMlcpOptions() { var options = []; - options.push('import'); - options.push('-mode'); - options.push('local'); - options.push('-host'); - options.push(DataHub.status.mlHost); - options.push('-port'); - options.push(DataHub.status.mlStagingPort); - options.push('-username'); - options.push(DataHub.status.mlUsername); - options.push('-password'); - options.push(DataHub.status.mlPassword); - - options.push('-input_file_path'); - options.push($scope.mlcp.input_file_path); - options.push('-input_file_type'); - options.push($scope.mlcp.input_file_type); - options.push('-output_uri_replace'); - options.push('"' + $scope.mlcp.input_file_path + ',\'\'"'); - + var inputFilePath = $scope.mlcp.input_file_path; + var input_file_type = $scope.mlcp.input_file_type; + $scope.mlcp = {}; + addMlcpOption(options, 'import', null, false); + addMlcpOption(options, 'mode', 'local', false); + addMlcpOption(options, 'host', DataHub.status.mlHost, false); + addMlcpOption(options, 'port', DataHub.status.mlStagingPort, false); + addMlcpOption(options, 'username', DataHub.status.mlUsername, false); + addMlcpOption(options, 'password', DataHub.status.mlPassword, false); + addMlcpOption(options, 'input_file_path', inputFilePath, true); + addMlcpOption(options, 'input_file_type', input_file_type, true); + addMlcpOption(options, 'output_uri_replace', '"' + inputFilePath + ',\'\'"', true); + angular.forEach(self.groups, function(group) { if (isGroupVisible(group.category)) { $.each(group.settings, function(i, setting) { @@ -137,14 +148,23 @@ if (setting.type !== 'boolean') { value = '"' + setting.value + '"'; } - options.push('-' + key); - options.push(value); + addMlcpOption(options, key, value, true); } }); } }); return options; } + + function addMlcpOption(options, key, value, isOtherOption) { + options.push('-' + key); + if(value) { + options.push(value); + if(isOtherOption) { + $scope.mlcp[key] = value; + } + } + } function updateMlcpCommand() { var mlcpCommand = 'mlcp'; @@ -157,7 +177,9 @@ } $scope.$watch('mlcp.input_file_path', function(value) { - searchPath(value); + if(isValidInputFilePath(value)) { + searchPath(value); + } }); $scope.$watch('mlcp', function(value) { diff --git a/quick-start/src/main/resources/static/app/mlcp/mlcp.groups.js b/quick-start/src/main/resources/static/app/mlcp/mlcp.groups.js index 0e8fedd580..0767435cb7 100644 --- a/quick-start/src/main/resources/static/app/mlcp/mlcp.groups.js +++ b/quick-start/src/main/resources/static/app/mlcp/mlcp.groups.js @@ -8,8 +8,8 @@ function MlcpGroupsFactory() { return { - groups: function(entityName, flowName) { - return [ + groups: function(entityName, flowName, previousOptions) { + var groups = [ { category: 'General Options', settings: [ @@ -237,6 +237,16 @@ ] } ]; + angular.forEach(previousOptions, function(value, key) { + $.each(groups, function(i, group) { + $.each(group.settings, function(i, setting) { + if (setting.field === key) { + setting.value = value.replace(/"/g, ''); + } + }); + }); + }); + return groups; } }; } diff --git a/quick-start/src/main/resources/static/app/mlcp/mlcp.html b/quick-start/src/main/resources/static/app/mlcp/mlcp.html index b161df798b..e051d83cf6 100644 --- a/quick-start/src/main/resources/static/app/mlcp/mlcp.html +++ b/quick-start/src/main/resources/static/app/mlcp/mlcp.html @@ -4,6 +4,13 @@