1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

Merge pull request #2109 from anoek/858

Fixed/enhanced scan job type selection process
This commit is contained in:
Akita Noek 2016-06-01 09:22:48 -04:00
commit 0948375763
7 changed files with 108 additions and 64 deletions

View File

@ -433,6 +433,10 @@ input[type='radio']:checked:before {
outline:none;
}
.Form-inputLabelContainer {
width: 100%;
display: block !important;
}
.Form-inputLabel{
text-transform: uppercase;
color: @default-interface-txt;
@ -443,6 +447,16 @@ input[type='radio']:checked:before {
.noselect;
}
.Form-labelAction {
text-transform: uppercase;
font-weight: normal;
font-size: 0.8em;
padding-left:5px;
float: right;
margin-top: 3px;
.noselect;
}
.Form-buttons{
height: 30px;
display: flex;

View File

@ -81,6 +81,11 @@ export default
},
project: {
label: 'Project',
labelAction: {
label: 'RESET',
ngClick: 'resetProjectToDefault()',
'class': "{{!(job_type.value === 'scan' && project_name !== 'Default') ? 'hidden' : ''}}",
},
type: 'lookup',
sourceModel: 'project',
sourceField: 'name',
@ -99,6 +104,7 @@ export default
label: 'Playbook',
type:'select',
ngOptions: 'book for book in playbook_options track by book',
ngDisabled: "job_type.value === 'scan' && project_name === 'Default'",
id: 'playbook-select',
awRequiredWhen: {
reqExpression: "playbookrequired",
@ -110,12 +116,6 @@ export default
dataPlacement: 'right',
dataContainer: "body",
},
default_scan: {
type: 'custom',
column: 1,
ngShow: 'job_type.value === "scan" && project_name !== "Default"',
control: '<a href="" ng-click="toggleScanInfo()">Reset to default project and playbook</a>'
},
credential: {
label: 'Machine Credential',
type: 'lookup',

View File

@ -177,7 +177,7 @@ angular.module('JobTemplatesHelper', ['Utilities'])
});
if(scope.project === "" && scope.playbook === ""){
if (scope.project === "" && scope.playbook === "") {
scope.toggleScanInfo();
}

View File

@ -197,12 +197,20 @@
});
});
function sync_playbook_select2() {
CreateSelect2({
element:'#playbook-select',
multiple: false
});
}
// Update playbook select whenever project value changes
selectPlaybook = function (oldValue, newValue) {
var url;
if($scope.job_type.value === 'scan' && $scope.project_name === "Default"){
$scope.playbook_options = ['Default'];
$scope.playbook = 'Default';
sync_playbook_select2();
Wait('stop');
}
else if (oldValue !== newValue) {
@ -217,6 +225,7 @@
opts.push(data[i]);
}
$scope.playbook_options = opts;
sync_playbook_select2();
Wait('stop');
})
.error(function (data, status) {
@ -227,32 +236,37 @@
}
};
$scope.jobTypeChange = function(){
if($scope.job_type){
if($scope.job_type.value === 'scan'){
let last_non_scan_project_name = null;
let last_non_scan_playbook = "";
let last_non_scan_playbook_options = [];
$scope.jobTypeChange = function() {
if ($scope.job_type) {
if ($scope.job_type.value === 'scan') {
if ($scope.project_name !== "Default") {
last_non_scan_project_name = $scope.project_name;
last_non_scan_playbook = $scope.playbook;
last_non_scan_playbook_options = $scope.playbook_options;
}
// If the job_type is 'scan' then we don't want the user to be
// able to prompt for job type or inventory
$scope.ask_job_type_on_launch = false;
$scope.ask_inventory_on_launch = false;
$scope.toggleScanInfo();
$scope.resetProjectToDefault();
}
else if($scope.project_name === "Default"){
$scope.project_name = null;
$scope.playbook_options = [];
// $scope.playbook = 'null';
else if ($scope.project_name === "Default") {
$scope.project_name = last_non_scan_project_name;
$scope.playbook_options = last_non_scan_playbook_options;
$scope.playbook = last_non_scan_playbook;
$scope.job_templates_form.playbook.$setPristine();
}
}
sync_playbook_select2();
};
$scope.toggleScanInfo = function() {
$scope.resetProjectToDefault = function() {
$scope.project_name = 'Default';
if($scope.project === null){
selectPlaybook();
}
else {
$scope.project = null;
}
selectPlaybook('force_load');
};
// Detect and alert user to potential SCM status issues

View File

@ -76,6 +76,13 @@ export default
$scope.playbook = null;
generator.reset();
function sync_playbook_select2() {
CreateSelect2({
element:'#playbook-select',
multiple: false
});
}
getPlaybooks = function (project) {
var url;
if ($scope.playbook) {
@ -85,6 +92,7 @@ export default
if($scope.job_type.value === 'scan' && $scope.project_name === "Default"){
$scope.playbook_options = ['Default'];
$scope.playbook = 'Default';
sync_playbook_select2();
Wait('stop');
}
else if (!Empty(project)) {
@ -93,14 +101,14 @@ export default
Rest.setUrl(url);
Rest.get()
.success(function (data) {
var i;
$scope.playbook_options = [];
for (i = 0; i < data.length; i++) {
for (var i = 0; i < data.length; i++) {
$scope.playbook_options.push(data[i]);
if (data[i] === $scope.playbook) {
$scope.job_templates_form.playbook.$setValidity('required', true);
}
}
sync_playbook_select2();
if ($scope.playbook) {
$scope.$emit('jobTemplateLoadFinished');
} else {
@ -122,23 +130,31 @@ export default
}
};
$scope.jobTypeChange = function(){
if($scope.job_type){
if($scope.job_type.value === 'scan'){
let last_non_scan_project_name = null;
let last_non_scan_playbook = "";
let last_non_scan_playbook_options = [];
$scope.jobTypeChange = function() {
if ($scope.job_type) {
if ($scope.job_type.value === 'scan') {
if ($scope.project_name !== "Default") {
last_non_scan_project_name = $scope.project_name;
last_non_scan_playbook = $scope.playbook;
last_non_scan_playbook_options = $scope.playbook_options;
}
// If the job_type is 'scan' then we don't want the user to be
// able to prompt for job type or inventory
$scope.ask_job_type_on_launch = false;
$scope.ask_inventory_on_launch = false;
$scope.toggleScanInfo();
$scope.resetProjectToDefault();
}
else if($scope.project_name === "Default"){
$scope.project_name = null;
$scope.playbook_options = [];
// $scope.playbook = 'null';
else if ($scope.project_name === "Default") {
$scope.project_name = last_non_scan_project_name;
$scope.playbook_options = last_non_scan_playbook_options;
$scope.playbook = last_non_scan_playbook;
$scope.job_templates_form.playbook.$setPristine();
}
}
sync_playbook_select2();
};
$scope.toggleNotification = function(event, notifier_id, column) {
@ -159,14 +175,10 @@ export default
});
};
$scope.toggleScanInfo = function() {
$scope.resetProjectToDefault = function() {
$scope.project_name = 'Default';
if($scope.project === null){
getPlaybooks();
}
else {
$scope.project = null;
}
getPlaybooks();
};
// Detect and alert user to potential SCM status issues

View File

@ -714,13 +714,10 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
function label() {
var html = '';
if (field.label || field.labelBind) {
html += "<label ";
if (horizontal || field.labelClass) {
html += "class=\"";
html += "<label class=\"";
html += (field.labelClass) ? field.labelClass : "";
html += (horizontal) ? " " + getLabelWidth() : "";
html += (horizontal) ? " " + getLabelWidth() : "Form-inputLabelContainer ";
html += "\" ";
}
html += (field.labelNGClass) ? "ng-class=\"" + field.labelNGClass + "\" " : "";
html += "for=\"" + fld + '">\n';
html += (field.icon) ? Icon(field.icon) : "";
@ -742,6 +739,14 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += "\" value=\"json\" ng-change=\"parseTypeChange()\"> <span class=\"parse-label\">JSON</span>\n";
html += "</div>\n";
}
if (field.labelAction) {
let action = field.labelAction;
let href = action.href || "";
let ngClick = action.ngClick || "";
let cls = action["class"] || "";
html += `<a class="Form-labelAction ${cls}" href="${href}" ng-click="${ngClick}">${action.label}</a>`;
}
html += "\n\t</label>\n";
}
return html;

View File

@ -8,7 +8,6 @@ export default ['$log', '$rootScope', '$scope', '$state', '$stateParams', 'Proce
function ($log, $rootScope, $scope, $state, $stateParams, ProcessErrors, Rest, Wait) {
var api_complete = false,
stdout_url,
current_range,
loaded_sections = [],
event_queue = 0,