more ui work for branch and refspec on project/jt

- add refspec field to project
- update refspec and branch help text on project form
- add refspec field to job detail
- adjust form gen and ProcessErrors to show api errors for checkbox_groups correctly
- consolidate showPromptButton conditionals and fix the add/edit workflow node one for showing prompt when only branch is promptable
This commit is contained in:
John Mitchell
2019-08-05 12:22:32 -04:00
committed by AlanCoding
parent 13751e73f9
commit 139e8cde70
10 changed files with 112 additions and 119 deletions

View File

@@ -354,6 +354,17 @@ function getSCMBranchDetails (scmBranch) {
return { label, value }; return { label, value };
} }
function getSCMRefspecDetails (scmRefspec) {
const label = strings.get('labels.SCM_REFSPEC');
const value = scmRefspec || resource.model.get('scm_refspec');
if (!value) {
return null;
}
return { label, value };
}
function getInventoryScmDetails (updateId, updateStatus) { function getInventoryScmDetails (updateId, updateStatus) {
const projectId = resource.model.get('summary_fields.source_project.id'); const projectId = resource.model.get('summary_fields.source_project.id');
const projectName = resource.model.get('summary_fields.source_project.name'); const projectName = resource.model.get('summary_fields.source_project.name');
@@ -812,6 +823,7 @@ function JobDetailsController (
vm.projectUpdate = getProjectUpdateDetails(); vm.projectUpdate = getProjectUpdateDetails();
vm.projectStatus = getProjectStatusDetails(); vm.projectStatus = getProjectStatusDetails();
vm.scmBranch = getSCMBranchDetails(); vm.scmBranch = getSCMBranchDetails();
vm.scmRefspec = getSCMRefspecDetails();
vm.scmRevision = getSCMRevisionDetails(); vm.scmRevision = getSCMRevisionDetails();
vm.inventoryScm = getInventoryScmDetails(); vm.inventoryScm = getInventoryScmDetails();
vm.playbook = getPlaybookDetails(); vm.playbook = getPlaybookDetails();
@@ -853,6 +865,7 @@ function JobDetailsController (
finished, finished,
scm, scm,
scmBranch, scmBranch,
scmRefspec,
inventoryScm, inventoryScm,
scmRevision, scmRevision,
instanceGroup, instanceGroup,
@@ -865,6 +878,7 @@ function JobDetailsController (
vm.projectUpdate = getProjectUpdateDetails(scm.id); vm.projectUpdate = getProjectUpdateDetails(scm.id);
vm.projectStatus = getProjectStatusDetails(scm.status); vm.projectStatus = getProjectStatusDetails(scm.status);
vm.scmBranch = getSCMBranchDetails(scmBranch); vm.scmBranch = getSCMBranchDetails(scmBranch);
vm.scmRefspec = getSCMRefspecDetails(scmRefspec);
vm.environment = getEnvironmentDetails(environment); vm.environment = getEnvironmentDetails(environment);
vm.artifacts = getArtifactsDetails(artifacts); vm.artifacts = getArtifactsDetails(artifacts);
vm.executionNode = getExecutionNodeDetails(executionNode); vm.executionNode = getExecutionNodeDetails(executionNode);

View File

@@ -222,7 +222,13 @@
<div class="JobResults-resultRow" ng-if="vm.scmBranch"> <div class="JobResults-resultRow" ng-if="vm.scmBranch">
<label class="JobResults-resultRowLabel">{{ vm.scmBranch.label }}</label> <label class="JobResults-resultRowLabel">{{ vm.scmBranch.label }}</label>
<div class="JobResults-resultRowText">{{ vm.scmBranch.value }}</div> <div class="JobResults-resultRowText">{{ vm.scmBranch.value }}</div>
</div> </div>
<!-- REFSPEC DETAIL -->
<div class="JobResults-resultRow" ng-if="vm.scmRefspec">
<label class="JobResults-resultRowLabel">{{ vm.scmRefspec.label }}</label>
<div class="JobResults-resultRowText">{{ vm.scmRefspec.value }}</div>
</div>
<!-- INVENTORY SCM DETAIL --> <!-- INVENTORY SCM DETAIL -->
<div class="JobResults-resultRow" ng-if="!vm.project && vm.inventoryScm"> <div class="JobResults-resultRow" ng-if="!vm.project && vm.inventoryScm">

View File

@@ -79,6 +79,7 @@ function OutputStrings (BaseString) {
PLAYBOOK: t.s('Playbook'), PLAYBOOK: t.s('Playbook'),
PROJECT: t.s('Project'), PROJECT: t.s('Project'),
SCM_BRANCH: t.s('Branch'), SCM_BRANCH: t.s('Branch'),
SCM_REFSPEC: t.s('Refspec'),
RESULT_TRACEBACK: t.s('Error Details'), RESULT_TRACEBACK: t.s('Error Details'),
SCM_REVISION: t.s('Revision'), SCM_REVISION: t.s('Revision'),
SKIP_TAGS: t.s('Skip Tags'), SKIP_TAGS: t.s('Skip Tags'),

View File

@@ -46,6 +46,7 @@ function JobStatusService (moment, message) {
status: model.get('summary_fields.project_update.status') status: model.get('summary_fields.project_update.status')
}, },
scmBranch: model.get('scm_branch'), scmBranch: model.get('scm_branch'),
scmRefspec: model.get('scm_refspec'),
inventoryScm: { inventoryScm: {
id: model.get('source_project_update'), id: model.get('source_project_update'),
status: model.get('summary_fields.inventory_source.status') status: model.get('summary_fields.inventory_source.status')

View File

@@ -125,7 +125,7 @@ export default ['i18n', 'NotificationsList', 'TemplateList',
type: 'text', type: 'text',
ngShow: "scm_type && scm_type.value !== 'manual' && scm_type.value !== 'insights'", ngShow: "scm_type && scm_type.value !== 'manual' && scm_type.value !== 'insights'",
ngDisabled: '!(project_obj.summary_fields.user_capabilities.edit || canAdd)', ngDisabled: '!(project_obj.summary_fields.user_capabilities.edit || canAdd)',
awPopOver: '<p>' + i18n._("Branch to checkout. You can input other refs like tags and commit hashes as well. You can set a custom refspec, to allow for other refs to be input.") + '</p>', awPopOver: '<p>' + i18n._("Branch to checkout. In addition to branches, you can input tags, commit hashes, and arbitrary refs. Some commit hashes and refs may not be availble unless you also provide a custom refspec.") + '</p>',
dataTitle: i18n._('SCM Branch'), dataTitle: i18n._('SCM Branch'),
subForm: 'sourceSubForm', subForm: 'sourceSubForm',
}, },
@@ -140,7 +140,8 @@ export default ['i18n', 'NotificationsList', 'TemplateList',
'</p><ul class=\"no-bullets\"><li>refs/*:refs/remotes/origin/*</li>' + '</p><ul class=\"no-bullets\"><li>refs/*:refs/remotes/origin/*</li>' +
'<li>refs/pull/62/head:refs/remotes/origin/pull/62/head</li></ul>' + '<li>refs/pull/62/head:refs/remotes/origin/pull/62/head</li></ul>' +
'<p>' + i18n._('The first fetches all references. The second fetches only the Github pull request number 62, in this example the branch needs to be `refs/pull/62/head`.') + '<p>' + i18n._('The first fetches all references. The second fetches only the Github pull request number 62, in this example the branch needs to be `refs/pull/62/head`.') +
'</p>', '</p>' +
'<p>' + i18n._('For more information, refer to the') + '<a target="_blank" href="https://docs.ansible.com/ansible-tower/latest/html/userguide/projects.html#manage-playbooks-using-source-control"> ' + i18n._('Ansible Tower Documentation') + '</a>.</p>',
dataTitle: i18n._('SCM Refspec'), dataTitle: i18n._('SCM Refspec'),
subForm: 'sourceSubForm', subForm: 'sourceSubForm',
}, },

View File

@@ -20,6 +20,20 @@ export default ['$filter', '$state', '$stateParams', '$http', 'Wait',
scheduler, scheduler,
job_type; job_type;
const shouldShowPromptButton = (launchConf) => launchConf.survey_enabled ||
launchConf.ask_inventory_on_launch ||
launchConf.ask_credential_on_launch ||
launchConf.ask_verbosity_on_launch ||
launchConf.ask_job_type_on_launch ||
launchConf.ask_limit_on_launch ||
launchConf.ask_tags_on_launch ||
launchConf.ask_skip_tags_on_launch ||
launchConf.ask_diff_mode_on_launch ||
launchConf.credential_needed_to_start ||
launchConf.ask_variables_on_launch ||
launchConf.ask_scm_branch_on_launch ||
launchConf.variables_needed_to_start.length !== 0;
var schedule_url = ParentObject.related.schedules || `${ParentObject.related.inventory_source}schedules`; var schedule_url = ParentObject.related.schedules || `${ParentObject.related.inventory_source}schedules`;
if (ParentObject){ if (ParentObject){
$scope.parentObject = ParentObject; $scope.parentObject = ParentObject;
@@ -152,20 +166,7 @@ export default ['$filter', '$state', '$stateParams', '$http', 'Wait',
$scope.noVars = true; $scope.noVars = true;
} }
if (!launchConf.survey_enabled && if (!shouldShowPromptButton(launchConf)) {
!launchConf.ask_inventory_on_launch &&
!launchConf.ask_credential_on_launch &&
!launchConf.ask_verbosity_on_launch &&
!launchConf.ask_job_type_on_launch &&
!launchConf.ask_limit_on_launch &&
!launchConf.ask_tags_on_launch &&
!launchConf.ask_skip_tags_on_launch &&
!launchConf.ask_diff_mode_on_launch &&
!launchConf.ask_scm_branch_on_launch &&
!launchConf.survey_enabled &&
!launchConf.credential_needed_to_start &&
!launchConf.inventory_needed_to_start &&
launchConf.variables_needed_to_start.length === 0) {
$scope.showPromptButton = false; $scope.showPromptButton = false;
} else { } else {
$scope.showPromptButton = true; $scope.showPromptButton = true;
@@ -240,21 +241,8 @@ export default ['$filter', '$state', '$stateParams', '$http', 'Wait',
}); });
}; };
if (!launchConf.survey_enabled && if (!shouldShowPromptButton(launchConf)) {
!launchConf.ask_inventory_on_launch && $scope.showPromptButton = false;
!launchConf.ask_credential_on_launch &&
!launchConf.ask_verbosity_on_launch &&
!launchConf.ask_job_type_on_launch &&
!launchConf.ask_limit_on_launch &&
!launchConf.ask_tags_on_launch &&
!launchConf.ask_skip_tags_on_launch &&
!launchConf.ask_diff_mode_on_launch &&
!launchConf.ask_scm_branch_on_launch &&
!launchConf.survey_enabled &&
!launchConf.credential_needed_to_start &&
!launchConf.inventory_needed_to_start &&
launchConf.variables_needed_to_start.length === 0) {
$scope.showPromptButton = false;
} else { } else {
$scope.showPromptButton = true; $scope.showPromptButton = true;

View File

@@ -10,6 +10,21 @@ function($filter, $state, $stateParams, Wait, $scope, moment,
let schedule, scheduler, scheduleCredentials = []; let schedule, scheduler, scheduleCredentials = [];
const shouldShowPromptButton = (launchConf) => launchConf.survey_enabled ||
launchConf.ask_inventory_on_launch ||
launchConf.ask_credential_on_launch ||
launchConf.ask_verbosity_on_launch ||
launchConf.ask_job_type_on_launch ||
launchConf.ask_limit_on_launch ||
launchConf.ask_tags_on_launch ||
launchConf.ask_skip_tags_on_launch ||
launchConf.ask_diff_mode_on_launch ||
launchConf.credential_needed_to_start ||
launchConf.ask_variables_on_launch ||
launchConf.ask_scm_branch_on_launch ||
launchConf.passwords_needed_to_start.length !== 0 ||
launchConf.variables_needed_to_start.length !== 0;
$scope.preventCredsWithPasswords = true; $scope.preventCredsWithPasswords = true;
// initial end @ midnight values // initial end @ midnight values
@@ -326,21 +341,7 @@ function($filter, $state, $stateParams, Wait, $scope, moment,
// ask_variables_on_launch = true // ask_variables_on_launch = true
$scope.noVars = !launchConf.ask_variables_on_launch; $scope.noVars = !launchConf.ask_variables_on_launch;
if (!launchConf.survey_enabled && if (!shouldShowPromptButton(launchConf)) {
!launchConf.ask_inventory_on_launch &&
!launchConf.ask_credential_on_launch &&
!launchConf.ask_verbosity_on_launch &&
!launchConf.ask_job_type_on_launch &&
!launchConf.ask_limit_on_launch &&
!launchConf.ask_tags_on_launch &&
!launchConf.ask_skip_tags_on_launch &&
!launchConf.ask_diff_mode_on_launch &&
!launchConf.ask_scm_branch_on_launch &&
!launchConf.survey_enabled &&
!launchConf.credential_needed_to_start &&
!launchConf.inventory_needed_to_start &&
launchConf.passwords_needed_to_start.length === 0 &&
launchConf.variables_needed_to_start.length === 0) {
$scope.showPromptButton = false; $scope.showPromptButton = false;
if (launchConf.ask_variables_on_launch) { if (launchConf.ask_variables_on_launch) {
@@ -425,21 +426,7 @@ function($filter, $state, $stateParams, Wait, $scope, moment,
currentValues: scheduleResolve currentValues: scheduleResolve
}); });
if (!launchConf.survey_enabled && if (!shouldShowPromptButton(launchConf)) {
!launchConf.ask_inventory_on_launch &&
!launchConf.ask_credential_on_launch &&
!launchConf.ask_verbosity_on_launch &&
!launchConf.ask_job_type_on_launch &&
!launchConf.ask_limit_on_launch &&
!launchConf.ask_tags_on_launch &&
!launchConf.ask_skip_tags_on_launch &&
!launchConf.ask_diff_mode_on_launch &&
!launchConf.ask_scm_branch_on_launch &&
!launchConf.survey_enabled &&
!launchConf.credential_needed_to_start &&
!launchConf.inventory_needed_to_start &&
launchConf.passwords_needed_to_start.length === 0 &&
launchConf.variables_needed_to_start.length === 0) {
$scope.showPromptButton = false; $scope.showPromptButton = false;
} else { } else {
$scope.showPromptButton = true; $scope.showPromptButton = true;

View File

@@ -182,41 +182,52 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
} }
} else if (form) { //if no error code is detected it begins to loop through to see where the api threw an error } else if (form) { //if no error code is detected it begins to loop through to see where the api threw an error
fieldErrors = false; fieldErrors = false;
for (field in form.fields) {
if (data[field] && form.fields[field].tab) { const addApiErrors = (data, field, fld) => {
if (data && field.tab) {
// If the form is part of a tab group, activate the tab // If the form is part of a tab group, activate the tab
$('#' + form.name + "_tabs a[href=\"#" + form.fields[field].tab + '"]').tab('show'); $('#' + form.name + "_tabs a[href=\"#" + field.tab + '"]').tab('show');
} }
if (form.fields[field].realName) { if (field.realName) {
if (data[form.fields[field].realName]) { if (field.realName) {
scope[field + '_api_error'] = data[form.fields[field].realName][0]; scope[fld + '_api_error'] = data[field.realName][0];
//scope[form.name + '_form'][form.fields[field].realName].$setValidity('apiError', false); //scope[form.name + '_form'][form.fields[field].realName].$setValidity('apiError', false);
$('[name="' + form.fields[field].realName + '"]').addClass('ng-invalid'); $('[name="' + field.realName + '"]').addClass('ng-invalid');
$('html, body').animate({scrollTop: $('[name="' + form.fields[field].realName + '"]').offset().top}, 0); $('html, body').animate({scrollTop: $('[name="' + field.realName + '"]').offset().top}, 0);
fieldErrors = true; fieldErrors = true;
} }
} }
if (form.fields[field].sourceModel) { if (field.sourceModel) {
if (data[field]) { if (data) {
scope[form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '_api_error'] = scope[field.sourceModel + '_' + field.sourceField + '_api_error'] =
data[field][0]; data[0];
//scope[form.name + '_form'][form.fields[field].sourceModel + '_' + form.fields[field].sourceField].$setValidity('apiError', false); //scope[form.name + '_form'][form.fields[field].sourceModel + '_' + form.fields[field].sourceField].$setValidity('apiError', false);
$('[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').addClass('ng-invalid'); $('[name="' + field.sourceModel + '_' + field.sourceField + '"]').addClass('ng-invalid');
$('[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').ScrollTo({ "onlyIfOutside": true, "offsetTop": 100 }); $('[name="' + field.sourceModel + '_' + field.sourceField + '"]').ScrollTo({ "onlyIfOutside": true, "offsetTop": 100 });
fieldErrors = true; fieldErrors = true;
} }
} else { } else {
if (data[field]) { if (data) {
scope[field + '_api_error'] = data[field][0]; scope[fld + '_api_error'] = data[0];
$('[name="' + field + '"]').addClass('ng-invalid'); $('[name="' + fld + '"]').addClass('ng-invalid');
$('label[for="' + field + '"] span').addClass('error-color'); $('label[for="' + fld + '"] span').addClass('error-color');
$('html, body').animate({scrollTop: $('[name="' + field + '"]').offset().top}, 0); $('html, body').animate({scrollTop: $('[name="' + fld + '"]').offset().top}, 0);
fieldErrors = true; fieldErrors = true;
if(form.fields[field].codeMirror){ if(field.codeMirror){
$(`#cm-${field}-container .CodeMirror`).addClass('error-border'); $(`#cm-${fld}-container .CodeMirror`).addClass('error-border');
} }
} }
} }
};
for (field in form.fields) {
if (form.fields[field].type === "checkbox_group") {
form.fields[field].fields.forEach(fld => {
addApiErrors(data[fld.name], fld, fld.name)
});
} else {
addApiErrors(data[field], form.fields[field], field);
}
} }
if (defaultMsg) { if (defaultMsg) {
Alert(defaultMsg.hdr, defaultMsg.msg); Alert(defaultMsg.hdr, defaultMsg.msg);

View File

@@ -1156,6 +1156,9 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
field.max + "</div>\n"; field.max + "</div>\n";
} }
html += "<div class=\"error api-error\" id=\"" + this.form.name + "-" + fld + "-api-error\" ng-bind=\"" + fld + "_api_error\"></div>\n"; html += "<div class=\"error api-error\" id=\"" + this.form.name + "-" + fld + "-api-error\" ng-bind=\"" + fld + "_api_error\"></div>\n";
for (i = 0; i < field.fields.length; i++) {
html += "<div class=\"error api-error\" id=\"" + this.form.name + "-" + field.fields[i].name + "-api-error\" ng-bind=\"" + field.fields[i].name + "_api_error\"></div>\n";
}
html += "</div><!-- checkbox-group -->\n"; html += "</div><!-- checkbox-group -->\n";
html += "</div>\n"; html += "</div>\n";
} }

View File

@@ -16,6 +16,20 @@ export default ['$scope', 'TemplatesService', 'JobTemplateModel', 'PromptService
let promptWatcher, credentialsWatcher, surveyQuestionWatcher, listPromises = []; let promptWatcher, credentialsWatcher, surveyQuestionWatcher, listPromises = [];
const shouldShowPromptButton = (launchConf) => launchConf.survey_enabled ||
launchConf.ask_inventory_on_launch ||
launchConf.ask_credential_on_launch ||
launchConf.ask_verbosity_on_launch ||
launchConf.ask_job_type_on_launch ||
launchConf.ask_limit_on_launch ||
launchConf.ask_tags_on_launch ||
launchConf.ask_skip_tags_on_launch ||
launchConf.ask_diff_mode_on_launch ||
launchConf.credential_needed_to_start ||
launchConf.ask_variables_on_launch ||
launchConf.ask_scm_branch_on_launch ||
launchConf.variables_needed_to_start.length !== 0;
$scope.strings = TemplatesStrings; $scope.strings = TemplatesStrings;
$scope.editNodeHelpMessage = null; $scope.editNodeHelpMessage = null;
@@ -198,18 +212,7 @@ export default ['$scope', 'TemplatesService', 'JobTemplateModel', 'PromptService
$scope.promptData = _.cloneDeep($scope.nodeConfig.node.promptData); $scope.promptData = _.cloneDeep($scope.nodeConfig.node.promptData);
const launchConf = $scope.promptData.launchConf; const launchConf = $scope.promptData.launchConf;
if (!launchConf.survey_enabled && if (!shouldShowPromptButton(launchConf)) {
!launchConf.ask_inventory_on_launch &&
!launchConf.ask_credential_on_launch &&
!launchConf.ask_verbosity_on_launch &&
!launchConf.ask_job_type_on_launch &&
!launchConf.ask_limit_on_launch &&
!launchConf.ask_tags_on_launch &&
!launchConf.ask_skip_tags_on_launch &&
!launchConf.ask_diff_mode_on_launch &&
!launchConf.credential_needed_to_start &&
!launchConf.ask_variables_on_launch &&
launchConf.variables_needed_to_start.length === 0) {
$scope.showPromptButton = false; $scope.showPromptButton = false;
$scope.promptModalMissingReqFields = false; $scope.promptModalMissingReqFields = false;
} else { } else {
@@ -305,18 +308,7 @@ export default ['$scope', 'TemplatesService', 'JobTemplateModel', 'PromptService
$scope.credentialRequiresPassword = credentialRequiresPassword; $scope.credentialRequiresPassword = credentialRequiresPassword;
if (!launchConf.survey_enabled && if (!shouldShowPromptButton(launchConf)) {
!launchConf.ask_inventory_on_launch &&
!launchConf.ask_credential_on_launch &&
!launchConf.ask_verbosity_on_launch &&
!launchConf.ask_job_type_on_launch &&
!launchConf.ask_limit_on_launch &&
!launchConf.ask_tags_on_launch &&
!launchConf.ask_skip_tags_on_launch &&
!launchConf.ask_diff_mode_on_launch &&
!launchConf.credential_needed_to_start &&
!launchConf.ask_variables_on_launch &&
launchConf.variables_needed_to_start.length === 0) {
$scope.showPromptButton = false; $scope.showPromptButton = false;
$scope.promptModalMissingReqFields = false; $scope.promptModalMissingReqFields = false;
$scope.nodeFormDataLoaded = true; $scope.nodeFormDataLoaded = true;
@@ -491,18 +483,7 @@ export default ['$scope', 'TemplatesService', 'JobTemplateModel', 'PromptService
$scope.selectedTemplateInvalid = selectedTemplateInvalid; $scope.selectedTemplateInvalid = selectedTemplateInvalid;
$scope.selectedTemplate = angular.copy(selectedTemplate); $scope.selectedTemplate = angular.copy(selectedTemplate);
if (!launchConf.survey_enabled && if (!shouldShowPromptButton(launchConf)) {
!launchConf.ask_inventory_on_launch &&
!launchConf.ask_credential_on_launch &&
!launchConf.ask_verbosity_on_launch &&
!launchConf.ask_job_type_on_launch &&
!launchConf.ask_limit_on_launch &&
!launchConf.ask_tags_on_launch &&
!launchConf.ask_skip_tags_on_launch &&
!launchConf.ask_diff_mode_on_launch &&
!launchConf.credential_needed_to_start &&
!launchConf.ask_variables_on_launch &&
launchConf.variables_needed_to_start.length === 0) {
$scope.showPromptButton = false; $scope.showPromptButton = false;
$scope.promptModalMissingReqFields = false; $scope.promptModalMissingReqFields = false;
} else { } else {