mirror of
https://github.com/ansible/awx.git
synced 2026-02-15 02:00:01 -03:30
Directives integer, min, max, and awlookup now working. Lookups now allow user to enter a value, the name is validated, and capitalization is corrected.
This commit is contained in:
@@ -42,7 +42,8 @@ angular.module('ansible', [
|
||||
'CredentialFormDefinition',
|
||||
'LookUpHelper',
|
||||
'JobTemplatesListDefinition',
|
||||
'JobTemplateFormDefinition'
|
||||
'JobTemplateFormDefinition',
|
||||
'ProjectsListDefinition'
|
||||
])
|
||||
.config(['$routeProvider', function($routeProvider) {
|
||||
$routeProvider.
|
||||
@@ -55,6 +56,9 @@ angular.module('ansible', [
|
||||
// when('/job_templates/:id', { templateUrl: urlPrefix + 'partials/job_templates.html',
|
||||
// controller: JobTemplatesEdit }).
|
||||
|
||||
when('/projects', { templateUrl: urlPrefix + 'partials/projects.html',
|
||||
controller: ProjectsList }).
|
||||
|
||||
when('/inventories', { templateUrl: urlPrefix + 'partials/inventories.html',
|
||||
controller: InventoriesList }).
|
||||
|
||||
@@ -180,7 +184,6 @@ angular.module('ansible', [
|
||||
Authorization.restoreUserInfo(); //user must have hit browser refresh
|
||||
}
|
||||
}
|
||||
console.log($rootScope.breadcrumbs)
|
||||
});
|
||||
|
||||
if (! Authorization.isTokenValid() ) {
|
||||
|
||||
@@ -132,7 +132,7 @@ JobTemplatesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$rout
|
||||
|
||||
function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
|
||||
GetBasePath, InventoryList, CredentialList, LookUpInit)
|
||||
GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
@@ -161,6 +161,38 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
field: 'credential'
|
||||
});
|
||||
|
||||
// Update playbook select whenever project value changes
|
||||
var selectPlaybook = function(oldValue, newValue) {
|
||||
$('#playbook-select option').each( function(index) {
|
||||
if (index > 0) {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
if (scope.project) {
|
||||
var url = GetBasePath('projects') + scope.project + '/playbooks/';
|
||||
Rest.setUrl(url);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
for (var i=0; i < data.length; i++) {
|
||||
$('#playbook-select').append('<option value="' + data[i] + '">' + data[i] + '</option>');
|
||||
}
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to get playbook list for ' + url +'. GET returned status: ' + status });
|
||||
});
|
||||
}
|
||||
};
|
||||
scope.$watch('project_name', selectPlaybook);
|
||||
|
||||
LookUpInit({
|
||||
scope: scope,
|
||||
form: form,
|
||||
current_item: null,
|
||||
list: ProjectList,
|
||||
field: 'project'
|
||||
});
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl);
|
||||
@@ -170,15 +202,40 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
}
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
ReturnToCaller(1);
|
||||
// Template saved. Now post job
|
||||
Rest.setUrl(data.related.jobs);
|
||||
Rest.post({
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
job_template: data.job_template,
|
||||
job_type: data.job_type,
|
||||
inventory: data.inventory,
|
||||
project: data.project,
|
||||
playbook: data.playbook,
|
||||
credential: data.credential,
|
||||
forks: data.forks,
|
||||
limit: data.limit,
|
||||
verbosity: data.verbosity,
|
||||
extra_vars: data.extra_vars})
|
||||
.success( function(data, status, headers, config) {
|
||||
// <--- We'll need something to prompt for passwords and then actually start
|
||||
// the job
|
||||
console.log('Job posted!');
|
||||
console.log(data);
|
||||
// Do we need to cancel the watch on playbook select????
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to post job. POST returned status: ' + status });
|
||||
});
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to add new user. Post returned status: ' + status });
|
||||
{ hdr: 'Error!', msg: 'Failed to add new project. POST returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Cancel
|
||||
// Reset
|
||||
scope.formReset = function() {
|
||||
// Defaults
|
||||
generator.reset();
|
||||
@@ -188,5 +245,5 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
|
||||
JobTemplatesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope',
|
||||
'GetBasePath', 'InventoryList', 'CredentialList', 'LookUpInit' ];
|
||||
'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit' ];
|
||||
|
||||
|
||||
131
lib/ui/static/js/controllers/Projects.js
Normal file
131
lib/ui/static/js/controllers/Projects.js
Normal file
@@ -0,0 +1,131 @@
|
||||
/************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* Projects.js
|
||||
*
|
||||
* Controller functions for the Projects model.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, ProjectList,
|
||||
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
|
||||
ClearScope, ProcessErrors, GetBasePath)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
var list = ProjectList;
|
||||
var defaultUrl = GetBasePath('projects');
|
||||
var view = GenerateList;
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
var mode = (base == 'projects') ? 'edit' : 'select'; // if base path 'credentials', we're here to add/edit
|
||||
var scope = view.inject(list, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SearchInit({ scope: scope, set: 'projects', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.addCredential = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
|
||||
scope.editCredential = function(id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
}
|
||||
|
||||
scope.deleteCredential = function(id, name) {
|
||||
|
||||
var action = function() {
|
||||
var url = defaultUrl + id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.delete()
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl(GetBasePath('projects'));
|
||||
scope.queue = [];
|
||||
|
||||
if (scope.callFinishedRemove) {
|
||||
scope.callFinishedRemove();
|
||||
}
|
||||
scope.callFinishedRemoved = scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
scope.selected = [];
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
Alert('Error', 'There was an error while adding one or more of the selected Pojects.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var project = null;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
for (var j=0; j < scope.projects.length; j++) {
|
||||
if (scope.projects[j].id == scope.selected[i]) {
|
||||
project = scope.credentials[j];
|
||||
}
|
||||
}
|
||||
if (project !== null) {
|
||||
Rest.post(project)
|
||||
.success( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'success', data: data, status: status });
|
||||
scope.$emit('callFinished');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'error', data: data, status: status, headers: headers });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_project = function(idx) {
|
||||
if (scope.selected.indexOf(idx) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(idx),1);
|
||||
}
|
||||
else {
|
||||
scope.selected.push(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProjectsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'ProjectList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors',
|
||||
'GetBasePath' ];
|
||||
@@ -33,16 +33,16 @@ angular.module('JobTemplateFormDefinition', [])
|
||||
type: 'select',
|
||||
options: [{ value: 'run', label: 'Run' }, { value: 'check', label: 'Check' }],
|
||||
default: 'run',
|
||||
addRequired: false,
|
||||
editRequired: false
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
inventory: {
|
||||
label: 'Inventory',
|
||||
type: 'lookup',
|
||||
sourceModel: 'inventory',
|
||||
sourceField: 'name',
|
||||
addRequired: false,
|
||||
editRequired: false,
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
ngClick: 'lookUpInventory()'
|
||||
},
|
||||
project: {
|
||||
@@ -50,51 +50,49 @@ angular.module('JobTemplateFormDefinition', [])
|
||||
type: 'lookup',
|
||||
sourceModel: 'project',
|
||||
sourceField: 'name',
|
||||
addRequired: false,
|
||||
editRequired: false,
|
||||
ngClick: 'lookUpProject()'
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
ngClick: 'lookUpProject()',
|
||||
},
|
||||
playbook: {
|
||||
label: 'Playbook',
|
||||
type:'text',
|
||||
addRequired: false,
|
||||
editRequired: false
|
||||
type:'select',
|
||||
id: 'playbook-select',
|
||||
addRequired: true,
|
||||
editRequired: true
|
||||
},
|
||||
credential: {
|
||||
label: 'Credential',
|
||||
type: 'lookup',
|
||||
sourceModel: 'credential',
|
||||
sourceField: 'name',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
ngClick: 'lookUpCredential()',
|
||||
addRequired: false,
|
||||
editRequired: false
|
||||
},
|
||||
forks: {
|
||||
label: 'Forks',
|
||||
type: 'integer',
|
||||
default: 0,
|
||||
type: 'number',
|
||||
integer: true,
|
||||
min: 0,
|
||||
max: 10,
|
||||
max: 100,
|
||||
default: 0,
|
||||
addRequired: false,
|
||||
editRequired: false
|
||||
},
|
||||
limit: {
|
||||
label: 'Limit',
|
||||
type: 'integer',
|
||||
default: 0,
|
||||
min: 0,
|
||||
max: 10,
|
||||
type: 'text',
|
||||
addRequired: false,
|
||||
editRequired: false
|
||||
},
|
||||
verbosity: {
|
||||
label: 'Verbosity',
|
||||
type: 'integer',
|
||||
type: 'number',
|
||||
integer: true,
|
||||
default: 0,
|
||||
min: 0,
|
||||
max: 5,
|
||||
max: 3,
|
||||
addRequired: false,
|
||||
editRequired: false
|
||||
},
|
||||
@@ -125,7 +123,33 @@ angular.module('JobTemplateFormDefinition', [])
|
||||
},
|
||||
|
||||
related: { //related colletions (and maybe items?)
|
||||
|
||||
|
||||
jobs: {
|
||||
type: 'collection',
|
||||
title: 'Jobs',
|
||||
iterator: 'job',
|
||||
open: false,
|
||||
|
||||
actions: {
|
||||
},
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Description'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "edit('jobs', \{\{ job.id \}\}, '\{\{ job.name \}\}')",
|
||||
icon: 'icon-edit'
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
}); //InventoryForm
|
||||
|
||||
@@ -24,15 +24,19 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P
|
||||
var current_item = params.current_item; //id of the item that should be selected on open
|
||||
var list = params.list; // list object
|
||||
var field = params.field; // form field
|
||||
var postAction = params.postAction //action to perform post user selection
|
||||
|
||||
// Show pop-up to select user
|
||||
var name = list.iterator.charAt(0).toUpperCase() + list.iterator.substring(1);
|
||||
var defaultUrl = (list.name == 'inventories') ? GetBasePath('inventory') : GetBasePath(list.name);
|
||||
|
||||
$('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-url',defaultUrl +
|
||||
'?' + form.fields[field].sourceField + '__' + 'iexact=:value');
|
||||
$('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-source',field);
|
||||
|
||||
scope['lookUp' + name] = function() {
|
||||
var listGenerator = GenerateList;
|
||||
var listScope = listGenerator.inject(list, { mode: 'lookup', hdr: 'Select ' + name });
|
||||
var defaultUrl = (list.name == 'inventories') ? GetBasePath('inventory') : GetBasePath(list.name);
|
||||
|
||||
listScope.selectAction = function() {
|
||||
var found = false;
|
||||
var name;
|
||||
@@ -43,6 +47,8 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P
|
||||
if (form.fields[field] && form.fields[field].sourceModel) {
|
||||
scope[form.fields[field].sourceModel + '_' + form.fields[field].sourceField] =
|
||||
listScope[list.name][i][form.fields[field].sourceField];
|
||||
scope[form.name + '_form'][form.fields[field].sourceModel + '_' + form.fields[field].sourceField]
|
||||
.$setValidity('awlookup',true);
|
||||
}
|
||||
if (scope[form.name + '_form']) {
|
||||
scope[form.name + '_form'].$setDirty();
|
||||
@@ -54,6 +60,11 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P
|
||||
Alert('Missing Selection', 'Oops, you failed to make a selection. Click on a row to make your selection, ' +
|
||||
'and then click the Select button.');
|
||||
}
|
||||
else {
|
||||
if (postAction) {
|
||||
postAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listScope['toggle_' + list.iterator] = function(id) {
|
||||
|
||||
53
lib/ui/static/js/lists/Projects.js
Normal file
53
lib/ui/static/js/lists/Projects.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Projects.js
|
||||
* List view object for Project data model.
|
||||
*
|
||||
*
|
||||
*/
|
||||
angular.module('ProjectsListDefinition', [])
|
||||
.value(
|
||||
'ProjectList', {
|
||||
|
||||
name: 'projects',
|
||||
iterator: 'project',
|
||||
selectTitle: 'Add Project',
|
||||
editTitle: '{{ name }}',
|
||||
selectInstructions: 'Check the Select checkbox next to each project to be added, and click Finished when done. Use the green <i class=\"icon-plus\"></i> button to create a new project.',
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
key: true,
|
||||
label: 'Name'
|
||||
},
|
||||
description: {
|
||||
label: 'Descriptions'
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
add: {
|
||||
icon: 'icon-plus',
|
||||
mode: 'all', // One of: edit, select, all
|
||||
ngClick: 'addProject()',
|
||||
class: 'btn btn-mini btn-success',
|
||||
awToolTip: 'Create a new project'
|
||||
}
|
||||
},
|
||||
|
||||
fieldActions: {
|
||||
edit: {
|
||||
ngClick: "editProject(\{\{ project.id \}\})",
|
||||
icon: 'icon-edit',
|
||||
awToolTip: 'Edit project'
|
||||
},
|
||||
|
||||
delete: {
|
||||
ngClick: "deleteProject(\{\{ project.id \}\},'\{\{ project.name \}\}')",
|
||||
icon: 'icon-remove',
|
||||
class: 'btn-danger',
|
||||
awToolTip: 'Delete project'
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user