From 6b3d5da5003da73e06ce227f49dea1b631aae99f Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Tue, 1 Apr 2014 12:47:12 -0400 Subject: [PATCH] Fixed schedules list on Projects page and Job Templates page. --- awx/ui/static/js/controllers/JobTemplates.js | 10 ++- awx/ui/static/js/controllers/Projects.js | 30 ++++---- awx/ui/static/js/controllers/Schedules.js | 7 +- awx/ui/static/js/forms/Projects.js | 81 ++++++++------------ awx/ui/static/js/helpers/Schedules.js | 28 +++++-- awx/ui/static/js/helpers/search.js | 6 +- awx/ui/static/lib/ansible/list-generator.js | 6 +- awx/ui/static/partials/job_templates.html | 1 + awx/ui/static/partials/projects.html | 1 + 9 files changed, 85 insertions(+), 85 deletions(-) diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index e8ff6012e4..6df28e2ce3 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -337,7 +337,7 @@ JobTemplatesAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$lo function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList, ProjectList, LookUpInit, GetBasePath, md5Setup, ParseTypeChange, JobStatusToolTip, FormatDate, - Wait, Stream, Empty, Prompt, ParseVariableString, ToJSON) { + Wait, Stream, Empty, Prompt, ParseVariableString, ToJSON, SchedulesControllerInit) { ClearScope(); @@ -466,7 +466,11 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP for (var set in relatedSets) { $scope.search(relatedSets[set].iterator); } - + SchedulesControllerInit({ + scope: $scope, + parent_scope: $scope, + iterator: 'schedule' + }); } }); @@ -753,5 +757,5 @@ JobTemplatesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$l 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', 'GetBasePath', 'md5Setup', 'ParseTypeChange', 'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream', 'Empty', 'Prompt', - 'ParseVariableString', 'ToJSON' + 'ParseVariableString', 'ToJSON', 'SchedulesControllerInit' ]; \ No newline at end of file diff --git a/awx/ui/static/js/controllers/Projects.js b/awx/ui/static/js/controllers/Projects.js index ce21665f74..6c58166da3 100644 --- a/awx/ui/static/js/controllers/Projects.js +++ b/awx/ui/static/js/controllers/Projects.js @@ -373,7 +373,7 @@ function ProjectsAdd($scope, $rootScope, $compile, $location, $log, $routeParams ClearScope(); // Inject dynamic view - var form = ProjectsForm, + var form = ProjectsForm(), generator = GenerateForm, base = $location.path().replace(/^\//, '').split('/')[0], defaultUrl = GetBasePath('projects'), @@ -510,12 +510,12 @@ ProjectsAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, ProjectsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, Prompt, ClearScope, GetBasePath, ReturnToCaller, GetProjectPath, Authorization, CredentialList, LookUpInit, GetChoices, - Empty, DebugForm, Wait, Stream) { + Empty, DebugForm, Wait, Stream, SchedulesControllerInit) { ClearScope('htmlTemplate'); // Inject dynamic view - var form = ProjectsForm, + var form = ProjectsForm(), generator = GenerateForm, defaultUrl = GetBasePath('projects') + $routeParams.id + '/', base = $location.path().replace(/^\//, '').split('/')[0], @@ -540,6 +540,12 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam $scope.search(relatedSets[set].iterator); } + SchedulesControllerInit({ + scope: $scope, + parent_scope: $scope, + iterator: 'schedule' + }); + if (Authorization.getUserInfo('is_superuser') === true) { GetProjectPath({ scope: $scope, master: master }); } else { @@ -574,7 +580,7 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam Rest.setUrl(defaultUrl); Rest.get({ params: { id: id } }) .success(function (data) { - var related, set, fld, i; + var fld, i; LoadBreadCrumbs({ path: '/projects/' + id, title: data.name }); for (fld in form.fields) { if (form.fields[fld].type === 'checkbox_group') { @@ -596,15 +602,8 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; } } - related = data.related; - for (set in form.related) { - if (related[set]) { - relatedSets[set] = { - url: related[set], - iterator: form.related[set].iterator - }; - } - } + + relatedSets = form.relatedSets(data.related); data.scm_type = (Empty(data.scm_type)) ? '' : data.scm_type; @@ -639,8 +638,7 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam $scope.$emit('projectLoaded'); }) .error(function (data, status) { - ProcessErrors($scope, data, status, form, { - hdr: 'Error!', + ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to retrieve project: ' + id + '. GET status: ' + status }); }); @@ -756,5 +754,5 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam ProjectsEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'ProjectsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'Prompt', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'GetProjectPath', 'Authorization', 'CredentialList', 'LookUpInit', 'GetChoices', 'Empty', - 'DebugForm', 'Wait', 'Stream' + 'DebugForm', 'Wait', 'Stream', 'SchedulesControllerInit' ]; \ No newline at end of file diff --git a/awx/ui/static/js/controllers/Schedules.js b/awx/ui/static/js/controllers/Schedules.js index d1f576ed11..0e253e0d71 100644 --- a/awx/ui/static/js/controllers/Schedules.js +++ b/awx/ui/static/js/controllers/Schedules.js @@ -15,8 +15,7 @@ GetBasePath, Wait, Breadcrumbs, Find, LoadDialogPartial, LoadSchedulesScope, Get ClearScope(); - var base, e, id, url, parentObject, - schedules_scope = $scope.$new(); + var base, e, id, url, parentObject; base = $location.path().replace(/^\//, '').split('/')[0]; @@ -47,7 +46,7 @@ GetBasePath, Wait, Breadcrumbs, Find, LoadDialogPartial, LoadSchedulesScope, Get LoadSchedulesScope({ parent_scope: $scope, - scope: schedules_scope, + scope: $scope, list: SchedulesList, id: 'schedule-list-target', url: url @@ -75,7 +74,7 @@ GetBasePath, Wait, Breadcrumbs, Find, LoadDialogPartial, LoadSchedulesScope, Get }); $scope.refreshJobs = function() { - schedules_scope.search(SchedulesList.iterator); + $scope.search(SchedulesList.iterator); }; Wait('start'); diff --git a/awx/ui/static/js/forms/Projects.js b/awx/ui/static/js/forms/Projects.js index 462526ec64..30a61fab4c 100644 --- a/awx/ui/static/js/forms/Projects.js +++ b/awx/ui/static/js/forms/Projects.js @@ -7,8 +7,8 @@ * * */ -angular.module('ProjectFormDefinition', []) - .value('ProjectsForm', { +angular.module('ProjectFormDefinition', ['SchedulesListDefinition']) + .value('ProjectsFormObject', { addTitle: 'Create Project', editTitle: '{{ name }}', @@ -282,53 +282,36 @@ angular.module('ProjectFormDefinition', []) } }, - schedules: { - type: 'collection', - title: 'Schedules', - iterator: 'schedule', - index: true, - open: false, - - fields: { - name: { - key: true, - label: 'Name' - }, - dtstart: { - label: 'Start' - }, - dtend: { - label: 'End' - } - }, - - actions: { - add: { - mode: 'all', - ngClick: 'addSchedule()', - awToolTip: 'Add a new schedule' - } - }, - - fieldActions: { - edit: { - label: 'Edit', - ngClick: "editSchedule(schedule.id)", - icon: 'icon-edit', - awToolTip: 'Edit schedule', - dataPlacement: 'top' - }, - - "delete": { - label: 'Delete', - ngClick: "deleteSchedule(schedule.id)", - icon: 'icon-trash', - awToolTip: 'Delete schedule', - dataPlacement: 'top' - } - } - + schedules: { + include: "SchedulesList" } + + }, + + relatedSets: function(urls) { + return { + organizations: { + iterator: 'organization', + url: urls.organizations + }, + schedules: { + iterator: 'schedule', + url: urls.schedules + } + }; } - }); // Form \ No newline at end of file + }) + + .factory('ProjectsForm', ['ProjectsFormObject', 'SchedulesList', function(ProjectsFormObject, ScheduleList) { + return function() { + var itm; + for (itm in ProjectsFormObject.related) { + if (ProjectsFormObject.related[itm].include === "SchedulesList") { + ProjectsFormObject.related[itm] = ScheduleList; + ProjectsFormObject.related[itm].generateList = true; // tell form generator to call list generator and inject a list + } + } + return ProjectsFormObject; + }; + }]); \ No newline at end of file diff --git a/awx/ui/static/js/helpers/Schedules.js b/awx/ui/static/js/helpers/Schedules.js index c2a77f626f..3222e9a1c3 100644 --- a/awx/ui/static/js/helpers/Schedules.js +++ b/awx/ui/static/js/helpers/Schedules.js @@ -69,6 +69,7 @@ angular.module('SchedulesHelper', [ 'Utilities', 'RestServices', 'SchedulesHelpe return function(params) { var scope = params.scope, id = params.id, + callback = params.callback, schedule, scheduler, url = GetBasePath('schedules') + id + '/'; @@ -118,8 +119,13 @@ angular.module('SchedulesHelper', [ 'Utilities', 'RestServices', 'SchedulesHelpe Rest.setUrl(url); Rest.put(schedule) .success(function(){ - Wait('stop'); $('#scheduler-modal-dialog').dialog('close'); + if (callback) { + scope.$emit(callback); + } + else { + Wait('stop'); + } }) .error(function(data, status){ ProcessErrors(scope, data, status, null, { hdr: 'Error!', @@ -368,11 +374,13 @@ angular.module('SchedulesHelper', [ 'Utilities', 'RestServices', 'SchedulesHelpe }]) - .factory('SchedulesControllerInit', ['ToggleSchedule', 'DeleteSchedule', 'EditSchedule', 'AddSchedule', - function(ToggleSchedule, DeleteSchedule, EditSchedule, AddSchedule) { + .factory('SchedulesControllerInit', ['$location', 'ToggleSchedule', 'DeleteSchedule', 'EditSchedule', 'AddSchedule', + function($location, ToggleSchedule, DeleteSchedule, EditSchedule, AddSchedule) { return function(params) { var scope = params.scope, - parent_scope = params.parent_scope; + parent_scope = params.parent_scope, + iterator = (params.iterator) ? params.iterator : scope.iterator, + base = $location.path().replace(/^\//, '').split('/')[0]; scope.toggleSchedule = function(event, id) { try { @@ -412,11 +420,19 @@ angular.module('SchedulesHelper', [ 'Utilities', 'RestServices', 'SchedulesHelpe }; scope.refreshJobs = function() { - parent_scope.refreshJobs(); + if (base === 'jobs') { + parent_scope.refreshJobs(); + } + else { + scope.search(iterator); + } }; + if (scope.removeSchedulesRefresh) { + scope.removeSchedulesRefresh(); + } scope.$on('SchedulesRefresh', function() { - parent_scope.refreshJobs(); + scope.refreshJobs(); }); }; }]) diff --git a/awx/ui/static/js/helpers/search.js b/awx/ui/static/js/helpers/search.js index 086aad308e..ec04ac9d19 100644 --- a/awx/ui/static/js/helpers/search.js +++ b/awx/ui/static/js/helpers/search.js @@ -446,11 +446,11 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper']) }; - scope.sort = function (fld) { + scope.sort = function (iterator, fld) { // Reset sort icons back to 'icon-sort' on all columns // except the one clicked. $('.list-header').each(function () { - if ($(this).attr('id') !== fld + '-header') { + if ($(this).attr('id') !== iterator + '-' + fld + '-header') { var icon = $(this).find('i'); icon.attr('class', 'fa fa-sort'); } @@ -458,7 +458,7 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper']) // Toggle the icon for the clicked column // and set the sort direction - var icon = $('#' + fld + '-header i'), + var icon = $('#' + iterator + '-' + fld + '-header i'), direction = ''; if (icon.hasClass('fa-sort')) { icon.removeClass('fa-sort'); diff --git a/awx/ui/static/lib/ansible/list-generator.js b/awx/ui/static/lib/ansible/list-generator.js index bef9b98a66..e4a9e6e982 100644 --- a/awx/ui/static/lib/ansible/list-generator.js +++ b/awx/ui/static/lib/ansible/list-generator.js @@ -300,11 +300,9 @@ angular.module('ListGenerator', ['GeneratorHelpers']) !(options.mode === 'lookup' && list.fields[fld].excludeModal !== undefined && list.fields[fld].excludeModal === true)) { html += "
+
\ No newline at end of file diff --git a/awx/ui/static/partials/projects.html b/awx/ui/static/partials/projects.html index 59059d79f9..b8f1781cf7 100644 --- a/awx/ui/static/partials/projects.html +++ b/awx/ui/static/partials/projects.html @@ -1,4 +1,5 @@
+
\ No newline at end of file