mirror of
https://github.com/mmumshad/ansible-playable.git
synced 2025-03-09 23:38:54 +00:00
Initial Commit
This commit is contained in:
commit
c92f737237
273 changed files with 16964 additions and 0 deletions
280
client/app/custom_modules/new_module/new_module.controller.js
Normal file
280
client/app/custom_modules/new_module/new_module.controller.js
Normal file
|
@ -0,0 +1,280 @@
|
|||
'use strict';
|
||||
const angular = require('angular');
|
||||
|
||||
/*@ngInject*/
|
||||
export function newModuleController($scope,$filter,customModules,ansible,YAML) {
|
||||
|
||||
$scope.optionTypes = ['str','list','dict','bool','int','float','path','raw','jsonarg','json','bytes','bits'];
|
||||
|
||||
var defaultModule = {
|
||||
module:null,
|
||||
short_description:"",
|
||||
description:"",
|
||||
version_added:"",
|
||||
author:"",
|
||||
notes: "",
|
||||
requirements: "",
|
||||
options:[
|
||||
{
|
||||
name:"parameter1",
|
||||
description: 'Description of parameter 1',
|
||||
required: true,
|
||||
default: null,
|
||||
choices: '"choice1", "choice2"',
|
||||
aliases: '"option1", "argument1"',
|
||||
type: ""
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
$scope.loadDefaultTemplate = function(){
|
||||
$scope.newModule = angular.copy(defaultModule);
|
||||
$scope.selectedModule.module_code = "Loading Template..";
|
||||
|
||||
customModules.show('template.py',function(response) {
|
||||
$scope.selectedModule.module_code = response.data.split("Stream :: close")[0];
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$watch('newModule',function(newValue,oldValue){
|
||||
|
||||
updateDocumentation(newValue);
|
||||
updateParameters(newValue);
|
||||
updateExamples(newValue);
|
||||
|
||||
},true);
|
||||
|
||||
var updateParameters = function(newValue){
|
||||
newValue = angular.copy(newValue);
|
||||
|
||||
var parameters_definition_lines = [];
|
||||
var parameters_retreive_lines = [];
|
||||
angular.forEach(newValue.options,function(option){
|
||||
if(option.name) {
|
||||
var line = option.name + "=dict(";
|
||||
|
||||
var line_arguments = [];
|
||||
if (option.required)line_arguments.push("required=True");
|
||||
if (!option.required && option.default)line_arguments.push("default='" + option.default + "'");
|
||||
if (option.type)line_arguments.push("type='" + option.type + "'");
|
||||
if (option.choices)line_arguments.push("choices=[" + option.choices + "]");
|
||||
if (option.aliases)line_arguments.push("aliases=[" + option.aliases + "]");
|
||||
|
||||
line += line_arguments.join(",");
|
||||
line += ")";
|
||||
|
||||
parameters_definition_lines.push(line);
|
||||
parameters_retreive_lines.push(option.name + ' = module.params[\'' + option.name + '\']')
|
||||
}
|
||||
});
|
||||
|
||||
var parameters_definition_string = parameters_definition_lines.join(",\n ");
|
||||
var parameters_retreive_string = parameters_retreive_lines.join("\n ");
|
||||
|
||||
var re = /(# <--Begin Parameter Definition -->\s+ )([^]+)(\s+ # <--END Parameter Definition -->)/;
|
||||
$scope.selectedModule.module_code = $scope.selectedModule.module_code.replace(re,"$1" + parameters_definition_string + "$3");
|
||||
|
||||
var supports_check_mode_string = '\n';
|
||||
if(newValue.supports_check_mode){
|
||||
supports_check_mode_string = '\n supports_check_mode=True\n'
|
||||
}
|
||||
|
||||
var re2 = /(# <--Begin Supports Check Mode -->)([^]+)( # <--End Supports Check Mode -->)/;
|
||||
$scope.selectedModule.module_code = $scope.selectedModule.module_code.replace(re2,"$1" + supports_check_mode_string + "$3");
|
||||
|
||||
var re3 = /(# <--Begin Retreiving Parameters -->\s+ )([^]+)(\s+ # <--End Retreiving Parameters -->)/;
|
||||
$scope.selectedModule.module_code = $scope.selectedModule.module_code.replace(re3,"$1" + parameters_retreive_string + "$3");
|
||||
|
||||
};
|
||||
|
||||
var updateDocumentation = function(newValue){
|
||||
newValue = angular.copy(newValue);
|
||||
newValue.options = convertOptionsToObject(newValue.options);
|
||||
|
||||
delete newValue['supports_check_mode'];
|
||||
|
||||
if(newValue.description)
|
||||
newValue.description = newValue.description.split(";");
|
||||
|
||||
if(newValue.notes)
|
||||
newValue.notes = newValue.notes.split(";");
|
||||
|
||||
if(newValue.requirements)
|
||||
newValue.requirements = newValue.requirements.split(";");
|
||||
|
||||
$scope.documentation_yaml = '---\n' + $filter('json2yaml')(angular.toJson(newValue)).toString().replace(/__dot__/g,".");
|
||||
|
||||
//var re = /(.*DOCUMENTATION = '''\n)([^]+?)(\n'''.*)/;
|
||||
var re = /([^]+DOCUMENTATION = '''\s+)([^]+?)(\s+'''[^]+)/;
|
||||
$scope.selectedModule.module_code = $scope.selectedModule.module_code.replace(re,'$1' + $scope.documentation_yaml + '$3');
|
||||
};
|
||||
|
||||
var updateExamples = function(newValue){
|
||||
newValue = angular.copy(newValue);
|
||||
|
||||
var moduleCopy = {
|
||||
|
||||
};
|
||||
|
||||
moduleCopy[newValue.module] = convertOptionsToExampleObject(newValue.options);
|
||||
|
||||
$scope.example_yaml = YAML.stringify(moduleCopy,4);
|
||||
|
||||
//var re = /(.*DOCUMENTATION = '''\n)([^]+?)(\n'''.*)/;
|
||||
var re = /([^]+EXAMPLES = '''[^]+# <-- -->\s+)([^]+?)(\s+# <-- \/ -->\s+'''[^]+)/;
|
||||
$scope.selectedModule.module_code = $scope.selectedModule.module_code.replace(re,'$1' + $scope.example_yaml + '$3');
|
||||
};
|
||||
|
||||
var convertOptionsToObject = function(options){
|
||||
|
||||
var result = {};
|
||||
|
||||
angular.forEach(options,function(option){
|
||||
if(option.name){
|
||||
result[option.name] = {
|
||||
description: option.description
|
||||
};
|
||||
|
||||
if(option.required)
|
||||
result[option.name]['required'] = "True";
|
||||
else
|
||||
delete result[option.name]['required'];
|
||||
|
||||
if(!option.required && option.default)
|
||||
result[option.name]['default'] = option.default;
|
||||
|
||||
if(option.choices){
|
||||
result[option.name]['choices'] = "[" + option.choices + "]"
|
||||
}
|
||||
|
||||
if(option.aliases){
|
||||
result[option.name]['aliases'] = "[" + option.aliases + "]"
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return result
|
||||
|
||||
};
|
||||
|
||||
var convertOptionsToExampleObject = function(options){
|
||||
|
||||
var result = {};
|
||||
|
||||
angular.forEach(options,function(option){
|
||||
if(option.name){
|
||||
result[option.name] = "value";
|
||||
}
|
||||
});
|
||||
|
||||
return result
|
||||
|
||||
};
|
||||
|
||||
var convertOptionsToArrays = function(options){
|
||||
|
||||
var result = [];
|
||||
|
||||
angular.forEach(options,function(value,key){
|
||||
var option = {
|
||||
name: key,
|
||||
description: value.description,
|
||||
required: value.required,
|
||||
default:value.default
|
||||
};
|
||||
|
||||
if(value.choices && value.choices.length)
|
||||
option['choices'] = value.choices.map(function(item){return ('"' + item + '"')}).join(",")
|
||||
|
||||
if(value.aliases && value.aliases.length)
|
||||
option['aliases'] = value.aliases.map(function(item){return ('"' + item + '"')}).join(",")
|
||||
|
||||
result.push(option)
|
||||
});
|
||||
|
||||
return result
|
||||
|
||||
};
|
||||
|
||||
$scope.saveNewModule = function(){
|
||||
$scope.saving = true;
|
||||
customModules.save($scope.newModule.module + '.py',$scope.selectedModule.module_code,function(response){
|
||||
$scope.saving = false;
|
||||
$scope.getCustomModules();
|
||||
|
||||
ansible.getAnsibleModules(function(response){
|
||||
|
||||
}, function(response){
|
||||
|
||||
},null,true);
|
||||
$scope.cancelNewModule();
|
||||
},function(response){
|
||||
$scope.saving = false;
|
||||
console.error(response.data)
|
||||
})
|
||||
};
|
||||
|
||||
$scope.cancelNewModule = function(){
|
||||
$scope.showNewModuleForm.value = false;
|
||||
$scope.$parent.showModuleCode($scope.selectedModule.module.name)
|
||||
};
|
||||
|
||||
var getPropertiesFromCode = function(module_code){
|
||||
|
||||
//var re = /([^]+DOCUMENTATION = '''\n)([^]+?)(\n'''[^]+)/;
|
||||
var re = /([^]+DOCUMENTATION = '''\s+)([^]+?)(\s+'''[^]+)/;
|
||||
var module_string = $scope.selectedModule.module_code.replace(re,'$2');
|
||||
|
||||
$scope.newModule = YAML.parse(module_string);
|
||||
$scope.newModule.options = convertOptionsToArrays($scope.newModule.options);
|
||||
|
||||
if($scope.newModule.description && $scope.newModule.description.length)
|
||||
$scope.newModule.description = $scope.newModule.description.join(";");
|
||||
|
||||
if($scope.newModule.notes && $scope.newModule.notes.length)
|
||||
$scope.newModule.notes = $scope.newModule.notes.join(";");
|
||||
|
||||
if($scope.newModule.requirements && $scope.newModule.requirements.length)
|
||||
$scope.newModule.requirements = $scope.newModule.requirements.join(";");
|
||||
|
||||
|
||||
re = /([^]+# <--Begin Parameter Definition -->\s+ )([^]+)(\s+ # <--END Parameter Definition -->[^]+)/;
|
||||
var parameter_string = $scope.selectedModule.module_code.replace(re,"$2");
|
||||
|
||||
// Read property type form parameter definition
|
||||
re = /\s+(.*?)=.*type=(.*?)[,\)].*/g;
|
||||
var m;
|
||||
|
||||
while ((m = re.exec(parameter_string)) !== null) {
|
||||
if (m.index === re.lastIndex) {
|
||||
re.lastIndex++;
|
||||
}
|
||||
// View your result using the m-variable.
|
||||
// eg m[0] etc.
|
||||
if(m[1]){
|
||||
angular.forEach($scope.newModule.options,function(option){
|
||||
if(option.name === m[1]){
|
||||
option.type = m[2].replace(/'/g,'')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
$scope.$on('editModule', function(e) {
|
||||
getPropertiesFromCode($scope.selected_module_code)
|
||||
});
|
||||
|
||||
$scope.$on('newModule', function(e) {
|
||||
$scope.loadDefaultTemplate();
|
||||
});
|
||||
}
|
||||
|
||||
export default angular.module('webAppApp.new_module', [])
|
||||
.controller('NewModuleController', newModuleController)
|
||||
.name;
|
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
describe('Controller: NewModuleCtrl', function() {
|
||||
// load the controller's module
|
||||
beforeEach(module('webAppApp.new_module'));
|
||||
|
||||
var NewModuleCtrl;
|
||||
|
||||
// Initialize the controller and a mock scope
|
||||
beforeEach(inject(function($controller) {
|
||||
NewModuleCtrl = $controller('NewModuleCtrl', {});
|
||||
}));
|
||||
|
||||
it('should ...', function() {
|
||||
expect(1).to.equal(1);
|
||||
});
|
||||
});
|
144
client/app/custom_modules/new_module/new_module.html
Normal file
144
client/app/custom_modules/new_module/new_module.html
Normal file
|
@ -0,0 +1,144 @@
|
|||
<div class="row" ng-controller="NewModuleController">
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">New Module</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<p class="form-group">
|
||||
<label>Module Name</label>
|
||||
<input type="text" ng-model="newModule.module" class="form-control" ng-required="true" placeholder="modulename">
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<p class="form-group">
|
||||
<label>Version Added</label>
|
||||
<input type="text" ng-model="newModule.version_added" class="form-control" ng-required="true" placeholder="X.Y">
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<p class="form-group">
|
||||
<label>Check Mode</label>
|
||||
<label class="checkbox-inline"><input ng-model="newModule.supports_check_mode" type="checkbox"></label>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<p class="form-group">
|
||||
<label>Author</label>
|
||||
<input type="text" ng-model="newModule.author" class="form-control" ng-required="true" placeholder="Your AWESOME name, @awesome-github-id">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<p class="form-group">
|
||||
<label>Short Description</label>
|
||||
<input type="text" ng-model="newModule.short_description" class="form-control" ng-required="true" placeholder="This is a sentence describing the module">
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<p class="form-group">
|
||||
<label>Description</label>
|
||||
<input type="text" ng-model="newModule.description" class="form-control" ng-required="true" placeholder="Longer description of the module; You might include instructions">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p class="form-group">
|
||||
<label>Notes</label>
|
||||
<input type="text" ng-model="newModule.notes" class="form-control" ng-required="true" placeholder="Other things consumers of your module should know">
|
||||
</p>
|
||||
|
||||
<p class="form-group">
|
||||
<label>Requirements</label>
|
||||
<input type="text" ng-model="newModule.requirements" class="form-control" ng-required="true" placeholder="List of required things separated by semicolon; like the factor package; or a specific platform">
|
||||
</p>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Options</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-md-2" style="text-align: center">
|
||||
<label>Name</label>
|
||||
</div>
|
||||
<div class="col-md-2" style="text-align: center">
|
||||
<label>Description</label>
|
||||
</div>
|
||||
<div class="col-md-1" style="text-align: center">
|
||||
<label>Type</label>
|
||||
</div>
|
||||
<div class="col-md-1" style="text-align: center">
|
||||
<label>Required</label>
|
||||
</div>
|
||||
<div class="col-md-1" style="text-align: center">
|
||||
<label>Default</label>
|
||||
</div>
|
||||
<div class="col-md-2" style="text-align: center">
|
||||
<label>Aliases</label>
|
||||
</div>
|
||||
<div class="col-md-2" style="text-align: center">
|
||||
<label>Choices</label>
|
||||
</div>
|
||||
<div class="col-md-1" style="text-align: center">
|
||||
<label>Actions</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-repeat="option in newModule.options">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-2" style="padding:2px;">
|
||||
<input type="text" ng-model="option.name" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-2" style="padding:2px;">
|
||||
<!--<input type="text" ng-model="member.value">-->
|
||||
<input type="text" ng-model="option.description" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="col-md-1" style="padding:2px;">
|
||||
<select class="form-control" ng-model="option.type" ng-options="optionType for optionType in optionTypes">
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-1" style="padding:2px;text-align: center">
|
||||
<label class="checkbox-inline"><input ng-model="option.required" type="checkbox" value=""></label>
|
||||
</div>
|
||||
<div class="col-md-1" style="padding:2px;">
|
||||
<input type="text" ng-disabled="option.required" ng-model="option.default" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-2" style="padding:2px;">
|
||||
<input type="text" ng-model="option.aliases" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-2" style="padding:2px;">
|
||||
<input type="text" ng-model="option.choices" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-1" style="padding:2px;text-align: center;">
|
||||
<div class="btn-group">
|
||||
<label class="btn btn-default" uib-tooltip="Insert new row after" ng-click="newModule.options.splice($index+1,0,{})" style="padding-top: 3px;padding-bottom: 3px;padding-left:5px;padding-right:5px;"><span class="fa fa-plus"></span></label>
|
||||
<label class="btn btn-danger" uib-tooltip="Delete row" ng-click="newModule.options.splice($index,1)" style="padding-top: 3px;padding-bottom: 3px; padding-left:5px; padding-right:5px;"><span class="fa fa-minus"></span></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--<input type="text" ng-model="member.value" uib-typeahead="('"\{\{' + var.name + '\}\}"') as (var.name + ' = ' + var.value) for var in hostvars | filter: $viewValue" class="form-control">-->
|
||||
</div>
|
||||
<!--<button class="btn btn-danger" ng-click="deleteProject()" confirm="Are you sure you want to delete?">Delete <span ng-if="!deleteProjectLoading" class="fa fa-trash"></span> <span ng-if="deleteProjectLoading" class="fa fa-spinner fa-spin"></span></button>-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<button class="btn btn-primary" ng-disabled="!newModule.module" ng-click="saveNewModule()"> Save <span ng-if="!saving" class="fa fa-save"></span> <span ng-if="saving" class="fa fa-spin fa-spinner"></span> </button>
|
||||
<button class="btn btn-default" confirm="Are you sure you want to discard the changes?" ng-click="cancelNewModule()"> Cancel <span class="fa fa-times"></span> </button>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue