From 02ab635fe76c092c3730058a562932bc8b71a3e2 Mon Sep 17 00:00:00 2001 From: Mumshad Mannambeth Date: Mon, 12 Jun 2017 23:49:17 -0400 Subject: [PATCH] Identify task module names from modules list --- client/app/app.js | 8 +- client/app/designer/designer.component.js | 2 + client/app/designer/designer.html | 53 +-- .../tasks/new_task/new_task.controller.js | 111 +++--- client/app/designer/tasks/tasks.directive.js | 13 +- client/app/designer/tasks/tasks.html | 7 +- .../app/services/ansible/ansible.service.js | 354 ++++++++++++------ helpers/AnsibleAPI.py | 2 +- package.json | 3 + server/components/ansible/ansible_tool.js | 2 +- 10 files changed, 361 insertions(+), 194 deletions(-) diff --git a/client/app/app.js b/client/app/app.js index f4434a7..d5db67a 100644 --- a/client/app/app.js +++ b/client/app/app.js @@ -20,11 +20,17 @@ import 'ansi-to-html'; import 'angular-markdown-directive'; +import 'ng-tags-input'; + +import 'angular-loading-bar'; + import treecontrol from 'angular-tree-control'; import 'angular-tree-control/css/tree-control-attribute.css'; import 'angular-tree-control/css/tree-control.css'; +import 'ng-tags-input/build/ng-tags-input.min.css'; + import { routeConfig } from './app.config'; @@ -102,7 +108,7 @@ angular.module('app2App', [ngCookies, ngResource, ngSanitize, uiRouter, uiBootst // Filters dictToKeyValueArray, dictToKeyValueArraySimple, keyValueArrayToDict, keyValueArrayToArray, addDotInKey, removeDotInKey, json2yaml, // Directives - complexVar, tasks, treecontrol, 'btford.markdown' + complexVar, tasks, treecontrol, 'btford.markdown', 'ngTagsInput', 'angular-loading-bar' ]) .config(routeConfig) diff --git a/client/app/designer/designer.component.js b/client/app/designer/designer.component.js index 0c2a381..d8dfc2f 100644 --- a/client/app/designer/designer.component.js +++ b/client/app/designer/designer.component.js @@ -35,6 +35,8 @@ export class DesignerComponent { Projects.selectedProject = $scope.selectedProject; $scope.listOfInventoryFiles(); $scope.$broadcast('projectLoaded'); + // Refresh modules list on project load + ansible.getAnsibleModules(); }) }; diff --git a/client/app/designer/designer.html b/client/app/designer/designer.html index 70def7a..7d0b36f 100644 --- a/client/app/designer/designer.html +++ b/client/app/designer/designer.html @@ -1,47 +1,56 @@
-
+ +
+ Ansible Version:{{selectedProject.ansibleVersion}} +
+ +
+ +
+ An inventory file to work with +
+ + +
+
+ + + + +
+ + + -
+
{{err_msg}}
diff --git a/client/app/designer/tasks/new_task/new_task.controller.js b/client/app/designer/tasks/new_task/new_task.controller.js index 153328c..413b34b 100644 --- a/client/app/designer/tasks/new_task/new_task.controller.js +++ b/client/app/designer/tasks/new_task/new_task.controller.js @@ -55,8 +55,9 @@ export function newTaskController($window, $scope, $sce, $uibModal, ansi2html, a selectedTask = angular.copy(selectedTask); $scope.newTask = selectedTask; if(selectedTask.tags)$scope.newTask.tags = $scope.newTask.tags.join(','); - var module = $scope.getModuleFromTask(selectedTask); - $scope.getModuleDescription(module,true) + $scope.getModuleFromTask(selectedTask, module => { + $scope.getModuleDescription(module,true) + }); } }, function(response){ @@ -180,66 +181,68 @@ export function newTaskController($window, $scope, $sce, $uibModal, ansi2html, a * @param task - Single task object containing task properties * @returns {{}} */ - $scope.getModuleFromTask = function(task){ + $scope.getModuleFromTask = function(task, successCallback){ var moduleObject = {}; $scope.local_action = false; var task_properties = null; - var module = ansible.getModuleFromTask(task); - - if(module === 'include'){ - module = null; - task.tags = task.include.replace(/.*tags=(.*)/,"$1") - return; - }else if(module === 'local_action'){ - $scope.local_action = true; - module = task.local_action.module; - task_properties = task.local_action; - delete task_properties.module; - }else{ - task_properties = task[module]; - } - - angular.forEach($scope.modules, function(item,index) { - if(item.name == module){ - moduleObject = item; - $scope.newTask.module = item; + ansible.getModuleFromTask(task, module => { + if(module === 'include'){ + module = null; + task.tags = task.include.replace(/.*tags=(.*)/,"$1") + return; + }else if(module === 'local_action'){ + $scope.local_action = true; + module = task.local_action.module; + task_properties = task.local_action; + delete task_properties.module; + }else{ + task_properties = task[module]; } + + angular.forEach($scope.modules, function(item,index) { + if(item.name == module){ + moduleObject = item; + $scope.newTask.module = item; + } + }); + + + if(!(moduleObject && moduleObject.name)){ + $scope.err_msg = "Unable to find module " + module + " in Ansible controller"; + return + } + + //moduleObject.name = module; + moduleObject.variables = []; + if(typeof task_properties == "string"){ + moduleObject.variables.push({'name':'free_form','value':task_properties}); + + var re = /\b(\w+)=\s*([^=]*\S)\b\s*(?=\w+=|$)/g; + var m; + + while ((m = re.exec(task_properties)) !== null) { + if (m.index === re.lastIndex) { + re.lastIndex++; + } + // View your result using the m-variable. + // eg m[0] etc. + var k=m[1]; + var v=m[2]; + moduleObject.variables.push({'name':k,'value':v}) + } + + }else if(typeof task_properties == "object"){ + + angular.forEach(task_properties,function(value,key){ + this.push({'name':key,'value':value,'complexValue':value}) + },moduleObject.variables) + + } + successCallback(moduleObject); }); - if(!(moduleObject && moduleObject.name)){ - $scope.err_msg = "Unable to find module " + module + " in Ansible controller"; - return - } - - //moduleObject.name = module; - moduleObject.variables = []; - if(typeof task_properties == "string"){ - moduleObject.variables.push({'name':'free_form','value':task_properties}); - - var re = /\b(\w+)=\s*([^=]*\S)\b\s*(?=\w+=|$)/g; - var m; - - while ((m = re.exec(task_properties)) !== null) { - if (m.index === re.lastIndex) { - re.lastIndex++; - } - // View your result using the m-variable. - // eg m[0] etc. - var k=m[1]; - var v=m[2]; - moduleObject.variables.push({'name':k,'value':v}) - } - - }else if(typeof task_properties == "object"){ - - angular.forEach(task_properties,function(value,key){ - this.push({'name':key,'value':value,'complexValue':value}) - },moduleObject.variables) - - } - return moduleObject }; diff --git a/client/app/designer/tasks/tasks.directive.js b/client/app/designer/tasks/tasks.directive.js index 0d1921e..939b009 100644 --- a/client/app/designer/tasks/tasks.directive.js +++ b/client/app/designer/tasks/tasks.directive.js @@ -27,14 +27,15 @@ export default angular.module('webAppApp.tasks', []) scope.tasksMetaData = []; angular.forEach(scope.tasksList,function(task){ - var taskModule = ansible.getModuleFromTask(task); - var taskName = task.name; + ansible.getModuleFromTask(task, taskModule => { + var taskName = task.name; - if(taskModule === 'include'){ - taskName = task[taskModule].replace(/(.*yml) .*/,"$1") - } + if(taskModule === 'include'){ + taskName = task[taskModule].replace(/(.*yml) .*/,"$1") + } - scope.tasksMetaData.push({taskModule:taskModule,taskName:taskName,selected:false}) + scope.tasksMetaData.push({taskModule:taskModule,taskName:taskName,selected:false}) + }); }) },true); diff --git a/client/app/designer/tasks/tasks.html b/client/app/designer/tasks/tasks.html index f05d002..2c65f1c 100644 --- a/client/app/designer/tasks/tasks.html +++ b/client/app/designer/tasks/tasks.html @@ -13,7 +13,12 @@ {{tasksMetaData[$index].taskName}} - {{tasksMetaData[$index].taskModule}} + + {{tasksMetaData[$index].taskModule}} + + + Unidentified +