Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playbook automate method changes #2114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a23f61d
Added support for "playbook" type Automate method
h-kataria Aug 30, 2017
efd1a35
Further changes to use Anugularized Input Parameters table.
h-kataria Sep 5, 2017
272f465
Added changes to show playbook data on method summary screen.
h-kataria Sep 6, 2017
3f39230
Addressed rubocop comments
h-kataria Sep 6, 2017
52b70b1
Made some minor changes to new ipnut parameter table styling
h-kataria Sep 7, 2017
3b18893
Addressed some of the code climate warnings.
h-kataria Sep 10, 2017
1f82622
Added "Escalate Privilege" switch to playbook method form
h-kataria Sep 17, 2017
a3aabac
Fixed code to get method editor working when clicking on items from list
h-kataria Sep 18, 2017
0c94382
split input form table into a separate view, can be reused if needed.
h-kataria Sep 18, 2017
4129ba3
Fixed nil.id error when trying to add playbook type method.
h-kataria Sep 19, 2017
16cf97b
Changed playbook data keys to be saved/read as symbols
h-kataria Sep 20, 2017
3865ee3
Store API.get promises and resolve them together.
h-kataria Sep 21, 2017
98035d9
Removed "Hosts" field from playbook method screens
h-kataria Sep 25, 2017
d939cf6
Addressed PR comments.
h-kataria Sep 25, 2017
7c2369a
Made a minor fix to validate unique input parameter name.
h-kataria Sep 26, 2017
634324e
Attempt to address code climate warning.
h-kataria Sep 28, 2017
b824f19
Replaced YAML.load with YAML.safe_load to address Hakiri warning.
h-kataria Oct 2, 2017
b24d48d
Addressed other rubocop/pr review comments
h-kataria Oct 2, 2017
d24f423
Added helper method to use while display data in view.
h-kataria Oct 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
ManageIQ.angular.app.controller('aeMethodFormController', aeMethodFormController);
aeMethodFormController.$inject = ['$http', '$scope', 'aeMethodFormId', 'currentRegion', 'miqService', 'playbookReusableCodeMixin'];

function aeMethodFormController($http, $scope, aeMethodFormId, currentRegion, miqService, playbookReusableCodeMixin) {
var vm = this;
var init = function() {
vm.aeMethodModel = {
name: '',
display_name: '',
location: '',
namespace_path: '',
class_id: '',
language: '',
scope: '',
key: '',
key_value: '',
key_type: 'string',
available_datatypes: '',
provisioning_repository_id: '',
provisioning_playbook_id: '',
provisioning_machine_credential_id: '',
provisioning_network_credential_id: '',
provisioning_cloud_credential_id: '',
provisioning_key: '',
provisioning_value: '',
provisioning_type: 'string',
provisioning_inputs: [],
provisioning_verbosity: '0',
provisioning_editMode: false,
provisioning_become_enabled: false,
};
vm.verbosity_types = playbookReusableCodeMixin.getVerbosityTypes();
vm.provisioning_cloud_type = '';
vm.currentRegion = currentRegion;
vm.formId = aeMethodFormId;
vm.afterGet = false;
vm.model = "aeMethodModel";

ManageIQ.angular.scope = $scope;

$http.get('method_form_fields/' + aeMethodFormId)
.then(getMethodFormData)
.catch(miqService.handleFailure);
vm.saveable = miqService.saveable;
vm.newRecord = aeMethodFormId === 'new';
if (aeMethodFormId === 'new') {
playbookReusableCodeMixin.formOptions(vm);
}
};

function getMethodFormData(response) {
var data = response.data;
vm.aeMethodModel.name = data.name;
vm.aeMethodModel.display_name = data.display_name;
vm.aeMethodModel.namespace_path = data.namespace_path;
vm.aeMethodModel.location = data.location;
vm.aeMethodModel.class_id = data.class_id;
vm.aeMethodModel.language = data.language;
vm.aeMethodModel.scope = data.scope;
vm.aeMethodModel.available_datatypes = data.available_datatypes;
playbookReusableCodeMixin.formOptions(vm);
playbookReusableCodeMixin.formCloudCredentials(vm, data.config_info.cloud_credential_id, null);
getConfigInfo(data.config_info);
vm.modelCopy = angular.copy(vm.aeMethodModel);
}

var getConfigInfo = function(configData) {
vm.aeMethodModel.provisioning_repository_id = configData.repository_id;
vm.aeMethodModel.provisioning_playbook_id = configData.playbook_id;
vm.aeMethodModel.provisioning_machine_credential_id = configData.credential_id;
vm.aeMethodModel.provisioning_network_credential_id = configData.network_credential_id;
vm.aeMethodModel.provisioning_cloud_credential_id = playbookReusableCodeMixin.setIfDefined(configData.cloud_credential_id);
vm.aeMethodModel.provisioning_become_enabled = configData.become_enabled === 'true';
vm.aeMethodModel.provisioning_key = '';
vm.aeMethodModel.provisioning_value = '';

if (configData.verbosity === undefined || configData.verbosity === '') {
vm.aeMethodModel.provisioning_verbosity = '0';
} else {
vm.aeMethodModel.provisioning_verbosity = configData.verbosity;
}
setExtraVars('provisioning_inputs', configData.extra_vars);
};

var setExtraVars = function(variableName, extraVars) {
if (extraVars !== 'undefined') {
vm.aeMethodModel[variableName] = [];
extraVars.forEach(function(arrayItem) {
var inputVars = [arrayItem.name, arrayItem.default_value, arrayItem.datatype, arrayItem.id];
vm.aeMethodModel[variableName].push(inputVars);
});
}
playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm);
};

vm.resetClicked = function() {
vm.aeMethodModel = angular.copy(vm.modelCopy);
playbookReusableCodeMixin.formOptions(vm);
playbookReusableCodeMixin.cloudCredentialsList(vm, vm.aeMethodModel.provisioning_cloud_credential_id);
$scope.angularForm.$setUntouched(true);
$scope.angularForm.$setPristine(true);
miqService.miqFlash("warn", __("All changes have been reset"));
};

var methodEditButtonClicked = function(buttonName) {
miqService.sparkleOn();
var url = '/miq_ae_class/add_update_method/' + aeMethodFormId + '?button=' + buttonName;
miqService.miqAjaxButton(url, setConfigInfo(vm.aeMethodModel, vm.modelCopy));
};

vm.cancelClicked = function() {
methodEditButtonClicked('cancel');
$scope.angularForm.$setPristine(true);
};

vm.saveClicked = function() {
methodEditButtonClicked('save');
$scope.angularForm.$setPristine(true);
};

vm.addClicked = function() {
methodEditButtonClicked('add');
$scope.angularForm.$setPristine(true);
};

var setConfigInfo = function(configData) {
var method = {
name: configData.name,
display_name: configData.display_name,
class_id: configData.class_id,
language: configData.language,
scope: configData.scope,
location: "playbook",
repository_id: configData.provisioning_repository_id,
playbook_id: configData.provisioning_playbook_id,
credential_id: configData.provisioning_machine_credential_id,
verbosity: configData.provisioning_verbosity,
become_enabled: configData.provisioning_become_enabled,
extra_vars: configData.provisioning_inputs,
};
if (configData.provisioning_network_credential_id !== '') {
method.network_credential_id = configData.provisioning_network_credential_id;
}

if (configData.provisioning_cloud_credential_id !== '') {
method.cloud_credential_id = configData.provisioning_cloud_credential_id;
}
return method;
};

$scope.$watch('vm._provisioning_repository', function(value) {
if (value) {
playbookReusableCodeMixin.repositoryChanged(vm, 'provisioning', value.id);
} else {
vm.aeMethodModel.provisioning_repository_id = '';
}
playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm);
});

$scope.$watch('vm.aeMethodModel.key_type', function(value) {
if (value && vm.aeMethodModel.key_type === vm.aeMethodModel.original_key_type) {
vm.aeMethodModel.key_value = '';
}
playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm);
});

$scope.$watch('vm.aeMethodModel.provisioning_type', function(value) {
if (value) {
vm.aeMethodModel.provisioning_value = '';
}
playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm);
});

vm.fieldsRequired = function(prefix) {
return prefix === 'provisioning';
};

$scope.$watch('vm._provisioning_cloud_type', function(value) {
playbookReusableCodeMixin.cloudTypeChanged(vm, 'provisioning', value);
playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm);
});

vm.addKeyValue = function() {
var valid = validateInputName(vm.aeMethodModel.provisioning_key, 0, "add");
if (! valid) {
return miqService.miqFlash("error", __("Inputs name must be unique"));
}
vm.aeMethodModel.provisioning_inputs.push(
[vm.aeMethodModel.provisioning_key, vm.aeMethodModel.provisioning_value, vm.aeMethodModel.provisioning_type]);
vm.aeMethodModel.provisioning_key = '';
vm.aeMethodModel.provisioning_value = '';
vm.aeMethodModel.provisioning_type = 'string';
return true;
};

vm.provisioning_repository_selected = function() {
return vm.aeMethodModel.provisioning_repository_id !== '';
};

vm.removeKeyValue = function(index) {
vm.aeMethodModel.provisioning_inputs.splice(index, 1);
playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm);
};

vm.editKeyValue = function(key, keyValue, keyType, index) {
vm.aeMethodModel.provisioning_editMode = true;
vm.aeMethodModel.s_index = index;
vm.aeMethodModel.key = key;
vm.aeMethodModel.key_value = keyValue;
vm.aeMethodModel.key_type = keyType;
vm.aeMethodModel.original_key = key;
vm.aeMethodModel.original_key_value = keyValue;
vm.aeMethodModel.original_key_type = keyType;
};

vm.cancelKeyValue = function(index) {
vm.aeMethodModel.provisioning_editMode = false;
vm.aeMethodModel.s_index = '';
vm.aeMethodModel.provisioning_inputs[index][0] = vm.aeMethodModel.original_key;
vm.aeMethodModel.provisioning_inputs[index][1] = vm.aeMethodModel.original_key_value;
vm.aeMethodModel.provisioning_inputs[index][2] = vm.aeMethodModel.original_key_type;
};

vm.saveKeyValue = function(index) {
var valid = validateInputName(vm.aeMethodModel.key, index, "edit");
if (! valid) {
return miqService.miqFlash("error", __("Input Name must be unique"));
}
vm.aeMethodModel.provisioning_editMode = false;
vm.aeMethodModel.s_index = '';
vm.aeMethodModel.provisioning_inputs[index][0] = vm.aeMethodModel.key;
vm.aeMethodModel.provisioning_inputs[index][1] = vm.aeMethodModel.key_value;
vm.aeMethodModel.provisioning_inputs[index][2] = vm.aeMethodModel.key_type;
return true;
};

var validateInputName = function(inputName, index, type) {
var valid = true;
vm.aeMethodModel.provisioning_inputs.forEach(function(input, i) {
// validate input name if input name is changed for current input parameter
// or when new one is being added
if ((type === "add" && input[0] === inputName) || (type === "edit" && index !== i && input[0] === inputName)) {
valid = false;
}
});
return valid;
};

// watch for all the drop downs on screen
"provisioning_playbook provisioning_machine_credential provisioning_network_credential provisioning_cloud_credential".split(" ").forEach(idWatch);

function idWatch(name) {
var fieldName = "vm._" + name;
$scope.$watch(fieldName, function(value) {
if (value) {
vm.aeMethodModel[name + '_id'] = value.id;
}
playbookReusableCodeMixin.checkFormPristine(vm.aeMethodModel, vm.modelCopy, $scope.angularForm);
});
}

init();
}
Loading