From 0818e6ab3d48ec1ad92d9445daf13b014fcc89eb Mon Sep 17 00:00:00 2001 From: chouseknecht Date: Tue, 14 May 2013 13:50:45 -0400 Subject: [PATCH] Latest UI changes -working on Job Templates --- lib/ui/static/js/app.js | 10 +- lib/ui/static/js/controllers/JobTemplates.js | 68 +++++++++- lib/ui/static/js/forms/Credentials.js | 2 +- lib/ui/static/js/forms/JobTemplates.js | 132 +++++++++++++++++++ lib/ui/static/js/helpers/Lookup.js | 2 +- lib/ui/static/lib/ansible/filters.js | 2 +- lib/ui/static/lib/ansible/form-generator.js | 64 ++++++++- lib/ui/templates/ui/index.html | 1 + 8 files changed, 272 insertions(+), 9 deletions(-) create mode 100644 lib/ui/static/js/forms/JobTemplates.js diff --git a/lib/ui/static/js/app.js b/lib/ui/static/js/app.js index 31c46efa45..52390b099b 100644 --- a/lib/ui/static/js/app.js +++ b/lib/ui/static/js/app.js @@ -41,12 +41,19 @@ angular.module('ansible', [ 'CredentialsListDefinition', 'CredentialFormDefinition', 'LookUpHelper', - 'JobTemplatesListDefinition' + 'JobTemplatesListDefinition', + 'JobTemplateFormDefinition' ]) .config(['$routeProvider', function($routeProvider) { $routeProvider. when('/job_templates', { templateUrl: urlPrefix + 'partials/job_templates.html', controller: JobTemplatesList }). + + when('/job_templates/add', { templateUrl: urlPrefix + 'partials/job_templates.html', + controller: JobTemplatesAdd }). + + // when('/job_templates/:id', { templateUrl: urlPrefix + 'partials/job_templates.html', + // controller: JobTemplatesEdit }). when('/inventories', { templateUrl: urlPrefix + 'partials/inventories.html', controller: InventoriesList }). @@ -173,6 +180,7 @@ angular.module('ansible', [ Authorization.restoreUserInfo(); //user must have hit browser refresh } } + console.log($rootScope.breadcrumbs) }); if (! Authorization.isTokenValid() ) { diff --git a/lib/ui/static/js/controllers/JobTemplates.js b/lib/ui/static/js/controllers/JobTemplates.js index 1174ecc0f9..cc78aebf79 100644 --- a/lib/ui/static/js/controllers/JobTemplates.js +++ b/lib/ui/static/js/controllers/JobTemplates.js @@ -21,7 +21,6 @@ function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Re var view = GenerateList; var base = $location.path().replace(/^\//,'').split('/')[0]; var mode = (base == 'job_templates') ? 'edit' : 'select'; // if base path 'credentials', we're here to add/edit - console.log(base); var scope = view.inject(list, { mode: mode }); // Inject our view scope.selected = []; @@ -31,15 +30,15 @@ function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Re LoadBreadCrumbs(); - scope.addCredential = function() { + scope.addJobTemplate = function() { $location.path($location.path() + '/add'); } - scope.editCredential = function(id) { + scope.editJobTemplate = function(id) { $location.path($location.path() + '/' + id); } - scope.deleteCredential = function(id, name) { + scope.deleteJobTemplate = function(id, name) { var action = function() { var url = defaultUrl + id + '/'; @@ -130,3 +129,64 @@ function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Re JobTemplatesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'JobTemplateList', 'GenerateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors','GetBasePath' ]; + +function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, + GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, + GetBasePath, InventoryList, CredentialList, LookUpInit) +{ + ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior + //scope. + + // Inject dynamic view + var defaultUrl = GetBasePath('job_templates'); + var form = JobTemplateForm; + var generator = GenerateForm; + var scope = generator.inject(form, {mode: 'add', related: false}); + generator.reset(); + LoadBreadCrumbs(); + + LookUpInit({ + scope: scope, + form: form, + current_item: null, + list: InventoryList, + field: 'inventory' + }); + + LookUpInit({ + scope: scope, + form: form, + current_item: null, + list: CredentialList, + field: 'credential' + }); + + // Save + scope.formSave = function() { + Rest.setUrl(defaultUrl); + var data = {} + for (var fld in form.fields) { + data[fld] = scope[fld]; + } + Rest.post(data) + .success( function(data, status, headers, config) { + ReturnToCaller(1); + }) + .error( function(data, status, headers, config) { + ProcessErrors(scope, data, status, form, + { hdr: 'Error!', msg: 'Failed to add new user. Post returned status: ' + status }); + }); + }; + + // Cancel + scope.formReset = function() { + // Defaults + generator.reset(); + }; + +} + +JobTemplatesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm', + 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', + 'GetBasePath', 'InventoryList', 'CredentialList', 'LookUpInit' ]; + diff --git a/lib/ui/static/js/forms/Credentials.js b/lib/ui/static/js/forms/Credentials.js index e0bd2f3a7d..41971ff7da 100644 --- a/lib/ui/static/js/forms/Credentials.js +++ b/lib/ui/static/js/forms/Credentials.js @@ -12,7 +12,7 @@ angular.module('CredentialFormDefinition', []) addTitle: 'Create Credential', //Legend in add mode editTitle: '{{ name }}', //Legend in edit mode - name: 'team', + name: 'credential', well: true, fields: { diff --git a/lib/ui/static/js/forms/JobTemplates.js b/lib/ui/static/js/forms/JobTemplates.js new file mode 100644 index 0000000000..be6e61806f --- /dev/null +++ b/lib/ui/static/js/forms/JobTemplates.js @@ -0,0 +1,132 @@ +/********************************************* + * Copyright (c) 2013 AnsibleWorks, Inc. + * + * JobTemplates.js + * Form definition for Credential model + * + * + */ +angular.module('JobTemplateFormDefinition', []) + .value( + 'JobTemplateForm', { + + addTitle: 'Create Job Templates', //Legend in add mode + editTitle: '{{ name }}', //Legend in edit mode + name: 'job_templates', + well: true, + + fields: { + name: { + label: 'Name', + type: 'text', + addRequired: true, + editRequired: true + }, + description: { + label: 'Description', + type: 'text', + addRequired: false, + editRequired: false + }, + job_type: { + label: 'Job Type', + type: 'select', + options: [{ value: 'run', label: 'Run' }, { value: 'check', label: 'Check' }], + default: 'run', + addRequired: false, + editRequired: false + }, + inventory: { + label: 'Inventory', + type: 'lookup', + sourceModel: 'inventory', + sourceField: 'name', + addRequired: false, + editRequired: false, + ngClick: 'lookUpInventory()' + }, + project: { + label: 'Project', + type: 'lookup', + sourceModel: 'project', + sourceField: 'name', + addRequired: false, + editRequired: false, + ngClick: 'lookUpProject()' + }, + playbook: { + label: 'Playbook', + type:'text', + addRequired: false, + editRequired: false + }, + 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, + min: 0, + max: 10, + addRequired: false, + editRequired: false + }, + limit: { + label: 'Limit', + type: 'integer', + default: 0, + min: 0, + max: 10, + addRequired: false, + editRequired: false + }, + verbosity: { + label: 'Verbosity', + type: 'integer', + default: 0, + min: 0, + max: 5, + addRequired: false, + editRequired: false + }, + extra_vars: { + label: 'Extra Variables', + type: 'textarea', + rows: 10, + addRequired: false, + editRequired: false + } + }, + + buttons: { //for now always generates