mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 20:05:03 -02:30
promise-ify createselect2 and use that instead for deferring launch button enabling
This commit is contained in:
@@ -579,8 +579,8 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
|||||||
* ]
|
* ]
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
.factory('CreateSelect2', ['$filter',
|
.factory('CreateSelect2', ['$filter', '$q',
|
||||||
function($filter) {
|
function($filter, $q) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var element = params.element,
|
var element = params.element,
|
||||||
@@ -591,10 +591,10 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
|||||||
addNew = params.addNew,
|
addNew = params.addNew,
|
||||||
scope = params.scope,
|
scope = params.scope,
|
||||||
selectOptions = params.options,
|
selectOptions = params.options,
|
||||||
callback = params.callback,
|
|
||||||
model = params.model,
|
model = params.model,
|
||||||
original_options,
|
original_options,
|
||||||
minimumResultsForSearch = params.minimumResultsForSearch ? params.minimumResultsForSearch : Infinity;
|
minimumResultsForSearch = params.minimumResultsForSearch ? params.minimumResultsForSearch : Infinity,
|
||||||
|
defer = $q.defer();
|
||||||
|
|
||||||
if (scope && selectOptions) {
|
if (scope && selectOptions) {
|
||||||
original_options = _.get(scope, selectOptions);
|
original_options = _.get(scope, selectOptions);
|
||||||
@@ -704,12 +704,10 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
|||||||
|
|
||||||
$(element).trigger('change');
|
$(element).trigger('change');
|
||||||
}
|
}
|
||||||
|
defer.resolve("select2 loaded");
|
||||||
if (callback) {
|
|
||||||
scope.$emit(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return defer.promise;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ export default
|
|||||||
callback,
|
callback,
|
||||||
choicesCount = 0,
|
choicesCount = 0,
|
||||||
select2Count = 0,
|
select2Count = 0,
|
||||||
instance_group_url = defaultUrl + id + '/instance_groups';
|
instance_group_url = defaultUrl + id + '/instance_groups',
|
||||||
|
select2LoadDefer = [],
|
||||||
|
launchHasBeenEnabled = false;
|
||||||
|
|
||||||
init();
|
init();
|
||||||
function init() {
|
function init() {
|
||||||
@@ -169,86 +171,71 @@ export default
|
|||||||
};
|
};
|
||||||
|
|
||||||
function sync_playbook_select2() {
|
function sync_playbook_select2() {
|
||||||
CreateSelect2({
|
select2LoadDefer.push(CreateSelect2({
|
||||||
element:'#playbook-select',
|
element:'#playbook-select',
|
||||||
multiple: false
|
multiple: false
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function sync_verbosity_select2() {
|
function sync_verbosity_select2() {
|
||||||
CreateSelect2({
|
select2LoadDefer.push(CreateSelect2({
|
||||||
element:'#job_template_verbosity',
|
element:'#job_template_verbosity',
|
||||||
multiple: false
|
multiple: false
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function jobTemplateLoadFinished(){
|
function jobTemplateLoadFinished(){
|
||||||
CreateSelect2({
|
select2LoadDefer.push(CreateSelect2({
|
||||||
element:'#job_template_job_type',
|
element:'#job_template_job_type',
|
||||||
multiple: false,
|
multiple: false
|
||||||
callback: 'select2Loaded',
|
}));
|
||||||
scope: $scope
|
|
||||||
});
|
|
||||||
|
|
||||||
CreateSelect2({
|
select2LoadDefer.push(CreateSelect2({
|
||||||
element:'#playbook-select',
|
element:'#playbook-select',
|
||||||
multiple: false,
|
multiple: false
|
||||||
callback: 'select2Loaded',
|
}));
|
||||||
scope: $scope
|
|
||||||
});
|
|
||||||
|
|
||||||
CreateSelect2({
|
select2LoadDefer.push(CreateSelect2({
|
||||||
element:'#job_template_job_tags',
|
element:'#job_template_job_tags',
|
||||||
multiple: true,
|
multiple: true,
|
||||||
addNew: true,
|
addNew: true
|
||||||
callback: 'select2Loaded',
|
}));
|
||||||
scope: $scope
|
|
||||||
});
|
|
||||||
|
|
||||||
CreateSelect2({
|
select2LoadDefer.push(CreateSelect2({
|
||||||
element:'#job_template_skip_tags',
|
element:'#job_template_skip_tags',
|
||||||
multiple: true,
|
multiple: true,
|
||||||
addNew: true,
|
addNew: true
|
||||||
callback: 'select2Loaded',
|
}));
|
||||||
scope: $scope
|
|
||||||
});
|
|
||||||
|
|
||||||
CreateSelect2({
|
select2LoadDefer.push(CreateSelect2({
|
||||||
element: '#job_template_custom_virtualenv',
|
element: '#job_template_custom_virtualenv',
|
||||||
multiple: false,
|
multiple: false,
|
||||||
opts: $scope.custom_virtualenvs_options,
|
opts: $scope.custom_virtualenvs_options
|
||||||
callback: 'select2Loaded',
|
}));
|
||||||
scope: $scope
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.$on('select2Loaded', () => {
|
if (!launchHasBeenEnabled) {
|
||||||
select2Count++;
|
$q.all(select2LoadDefer).then(() => {
|
||||||
if (select2Count === 10) {
|
// updates based on lookups will initially set the form as dirty.
|
||||||
$scope.$emit('select2LoadFinished');
|
// we need to set it as pristine when it contains the values given by the api
|
||||||
|
// so that we can enable launching when the two are the same
|
||||||
|
$scope.job_template_form.$setPristine();
|
||||||
|
// this is used to set the overall form as dirty for the values
|
||||||
|
// that don't actually set this internally (lookups, toggles and code mirrors).
|
||||||
|
$scope.$watchGroup([
|
||||||
|
'inventory',
|
||||||
|
'project',
|
||||||
|
'multiCredential.selectedCredentials',
|
||||||
|
'extra_vars',
|
||||||
|
'diff_mode',
|
||||||
|
'instance_groups'
|
||||||
|
], (val, prevVal) => {
|
||||||
|
if (!_.isEqual(val, prevVal)) {
|
||||||
|
$scope.job_template_form.$setDirty();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
$scope.$on('select2LoadFinished', () => {
|
|
||||||
// updates based on lookups will initially set the form as dirty.
|
|
||||||
// we need to set it as pristine when it contains the values given by the api
|
|
||||||
// so that we can enable launching when the two are the same
|
|
||||||
$scope.job_template_form.$setPristine();
|
|
||||||
// this is used to set the overall form as dirty for the values
|
|
||||||
// that don't actually set this internally (lookups, toggles and code mirrors).
|
|
||||||
$scope.$watchGroup([
|
|
||||||
'inventory',
|
|
||||||
'project',
|
|
||||||
'multiCredential.selectedCredentials',
|
|
||||||
'extra_vars',
|
|
||||||
'diff_mode',
|
|
||||||
'instance_groups'
|
|
||||||
], (val, prevVal) => {
|
|
||||||
if (!_.isEqual(val, prevVal)) {
|
|
||||||
$scope.job_template_form.$setDirty();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.toggleForm = function(key) {
|
$scope.toggleForm = function(key) {
|
||||||
$scope[key] = !$scope[key];
|
$scope[key] = !$scope[key];
|
||||||
@@ -298,8 +285,8 @@ export default
|
|||||||
variable: 'extra_vars',
|
variable: 'extra_vars',
|
||||||
onChange: callback
|
onChange: callback
|
||||||
});
|
});
|
||||||
|
|
||||||
jobTemplateLoadFinished();
|
jobTemplateLoadFinished();
|
||||||
|
launchHasBeenEnabled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
Wait('start');
|
Wait('start');
|
||||||
@@ -497,12 +484,12 @@ export default
|
|||||||
.map(i => ({id: i.id + "",
|
.map(i => ({id: i.id + "",
|
||||||
test: i.name}));
|
test: i.name}));
|
||||||
|
|
||||||
CreateSelect2({
|
select2LoadDefer.push(CreateSelect2({
|
||||||
element:'#job_template_labels',
|
element:'#job_template_labels',
|
||||||
multiple: true,
|
multiple: true,
|
||||||
addNew: true,
|
addNew: true,
|
||||||
opts: opts
|
opts: opts
|
||||||
});
|
}));
|
||||||
|
|
||||||
$scope.$emit("choicesReady");
|
$scope.$emit("choicesReady");
|
||||||
|
|
||||||
|
|||||||
@@ -257,22 +257,11 @@ export default [
|
|||||||
|
|
||||||
// Select2-ify the lables input
|
// Select2-ify the lables input
|
||||||
CreateSelect2({
|
CreateSelect2({
|
||||||
scope: $scope,
|
|
||||||
element:'#workflow_job_template_labels',
|
element:'#workflow_job_template_labels',
|
||||||
multiple: true,
|
multiple: true,
|
||||||
addNew: true,
|
addNew: true,
|
||||||
opts,
|
opts
|
||||||
callback: 'select2Loaded'
|
}).then(() => {
|
||||||
});
|
|
||||||
|
|
||||||
$scope.$on('select2Loaded', () => {
|
|
||||||
select2Count++;
|
|
||||||
if (select2Count === 1) {
|
|
||||||
$scope.$emit('select2LoadFinished');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.$on('select2LoadFinished', () => {
|
|
||||||
// updates based on lookups will initially set the form as dirty.
|
// updates based on lookups will initially set the form as dirty.
|
||||||
// we need to set it as pristine when it contains the values given by the api
|
// we need to set it as pristine when it contains the values given by the api
|
||||||
// so that we can enable launching when the two are the same
|
// so that we can enable launching when the two are the same
|
||||||
|
|||||||
Reference in New Issue
Block a user