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

Fixed/enhanced scan job type selection process

* Appropriately set project and playbook to default when job type is set
  to 'scan' - #1273
* Add 'RESET' link on the Project label line to reset to Default
  project/playbook #858
* Fixed dropdown option clearing problem #1489
* Remember what project/playbook was set when switching from run/check
  to scan, so if you change back, those options will be auto-selected
  again
This commit is contained in:
Akita Noek 2016-05-31 16:03:01 -04:00
parent cad3ab6fd3
commit d8dac662a1
6 changed files with 110 additions and 63 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,17 @@ input[type='radio']:checked:before {
.noselect;
}
.Form-labelAction {
text-transform: uppercase;
//color: @default-interface-txt;
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

@ -196,12 +196,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) {
@ -216,6 +224,7 @@
opts.push(data[i]);
}
$scope.playbook_options = opts;
sync_playbook_select2();
Wait('stop');
})
.error(function (data, status) {
@ -226,32 +235,37 @@
}
};
$scope.jobTypeChange = function(){
if($scope.job_type){
if($scope.job_type.value === 'scan'){
// 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();
}
else if($scope.project_name === "Default"){
$scope.project_name = null;
$scope.playbook_options = [];
// $scope.playbook = 'null';
$scope.job_templates_form.playbook.$setPristine();
}
}
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.resetProjectToDefault();
}
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;
}
$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,32 @@ export default
}
};
$scope.jobTypeChange = function(){
if($scope.job_type){
if($scope.job_type.value === 'scan'){
// 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();
}
else if($scope.project_name === "Default"){
$scope.project_name = null;
$scope.playbook_options = [];
// $scope.playbook = 'null';
$scope.job_templates_form.playbook.$setPristine();
}
}
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.resetProjectToDefault();
}
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();
//setTimeout(() => $("#playbook-select").trigger('change'), 1) // sync select2
};
$scope.toggleNotification = function(event, notifier_id, column) {
@ -159,14 +176,10 @@ export default
});
};
$scope.toggleScanInfo = function() {
$scope.resetProjectToDefault = function() {
$scope.project_name = 'Default';
if($scope.project === null){
getPlaybooks();
}
else {
$scope.project = null;
}
$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 += (field.labelClass) ? field.labelClass : "";
html += (horizontal) ? " " + getLabelWidth() : "";
html += "\" ";
}
html += "<label class=\"";
html += (field.labelClass) ? field.labelClass : "";
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;