Adding scheduler for inventory syncs

which can be found in the groups panel on the left side of hte inventory manage page in the row for each group.
This commit is contained in:
Jared Tabor
2016-04-25 09:36:31 -07:00
parent 72b80457eb
commit f1545860f0
7 changed files with 153 additions and 39 deletions

View File

@@ -207,24 +207,47 @@ export default
}; };
}]) }])
.factory('AddSchedule', ['$location', '$stateParams', 'SchedulerInit', 'ShowSchedulerModal', 'Wait', 'GetBasePath', 'Empty', .factory('AddSchedule', ['$location', '$stateParams', 'SchedulerInit',
'SchedulePost', '$state', 'ShowSchedulerModal', 'Wait', 'GetBasePath', 'Empty',
function($location, $stateParams, SchedulerInit, ShowSchedulerModal, Wait, GetBasePath, Empty, SchedulePost, $state) { 'SchedulePost', '$state', 'Rest', 'ProcessErrors',
function($location, $stateParams, SchedulerInit, ShowSchedulerModal,
Wait, GetBasePath, Empty, SchedulePost, $state, Rest,
ProcessErrors) {
return function(params) { return function(params) {
var scope = params.scope, var scope = params.scope,
callback= params.callback, callback= params.callback,
base = params.base || $location.path().replace(/^\//, '').split('/')[0], base = params.base || $location.path().replace(/^\//, '').split('/')[0],
url = GetBasePath(base), url,
scheduler; scheduler;
if (!Empty($stateParams.template_id)) { if (!Empty($stateParams.template_id)) {
url += $stateParams.template_id + '/schedules/'; url = GetBasePath(base) + $stateParams.template_id + '/schedules/';
} }
else if (!Empty($stateParams.id) && base !== 'system_job_templates') { else if (!Empty($stateParams.id) && base !== 'system_job_templates' && base !== 'inventory') {
url += $stateParams.id + '/schedules/'; url = GetBasePath(base) + $stateParams.id + '/schedules/';
} }
else if (base === 'system_job_templates') { else if(base === "inventory"){
url += $stateParams.id + '/schedules/'; if (!params.url){
if($stateParams.id === 4){ url = GetBasePath('groups') + $stateParams.id + '/';
Rest.setUrl(url);
Rest.get().
then(function (data) {
url = data.data.related.inventory_source + 'schedules/';
}).catch(function (response) {
ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!',
msg: 'Failed to get inventory group info. GET returned status: ' +
response.status
});
});
}
else {
url = params.url;
}
}
else if (base == 'system_job_templates') {
url = GetBasePath(base) + $stateParams.id + '/schedules/';
if($stateParams.id == 4){
scope.isFactCleanup = true; scope.isFactCleanup = true;
scope.keep_unit_choices = [{ scope.keep_unit_choices = [{
"label" : "Days", "label" : "Days",
@@ -528,10 +551,10 @@ export default
}; };
}]) }])
.factory('SchedulesControllerInit', ['$state', '$location',
.factory('SchedulesControllerInit', ['$state', '$location', 'ToggleSchedule', 'ToggleSchedule', 'DeleteSchedule', 'ParamPass',
'DeleteSchedule', function($state, $location, ToggleSchedule, DeleteSchedule,
function($state, $location, ToggleSchedule, DeleteSchedule) { ParamPass) {
return function(params) { return function(params) {
var scope = params.scope, var scope = params.scope,
parent_scope = params.parent_scope, parent_scope = params.parent_scope,
@@ -567,7 +590,8 @@ export default
scope.addSchedule = function() { scope.addSchedule = function() {
var base = $state.current.name.split(".")[0]; var base = $state.current.name.split(".")[0];
$state.go(base + ".add", {passedScope: scope}); ParamPass.set(scope.schedule_url);
$state.go(base + ".add");
}; };
scope.refreshSchedules = function() { scope.refreshSchedules = function() {

View File

@@ -400,6 +400,12 @@ function InventoriesManage($log, $scope, $rootScope, $location,
}); });
}; };
$scope.scheduleGroup = function(id) {
$state.go('inventoryManageSchedules', {
inventory_id: $scope.inventory.id, id: id
});
};
$scope.copyGroup = function(id) { $scope.copyGroup = function(id) {
PreviousSearchParams = Store('group_current_search_params'); PreviousSearchParams = Store('group_current_search_params');
var params = { var params = {

View File

@@ -214,6 +214,7 @@ function manageGroupsDirectiveController($filter, $location, $log,
master.source_regions = opts; master.source_regions = opts;
CreateSelect2({ CreateSelect2({
element: "group_source_regions", element: "group_source_regions",
multiple: true,
opts: opts opts: opts
}); });
@@ -241,7 +242,8 @@ function manageGroupsDirectiveController($filter, $location, $log,
} }
master.group_by = opts; master.group_by = opts;
CreateSelect2({ CreateSelect2({
element: "#source_group_by", element: "#group_group_by",
multiple: true,
opts: opts opts: opts
}); });
} }
@@ -407,7 +409,7 @@ function manageGroupsDirectiveController($filter, $location, $log,
if ($scope.source && ($scope.source.value === 'ec2')) { if ($scope.source && ($scope.source.value === 'ec2')) {
data.instance_filters = $scope.instance_filters; data.instance_filters = $scope.instance_filters;
// Create a string out of selected list of regions // Create a string out of selected list of regions
group_by = $('#source_group_by').select2("data"); group_by = $('#group_group_by').select2("data");
r = []; r = [];
for (i = 0; i < group_by.length; i++) { for (i = 0; i < group_by.length; i++) {
r.push(group_by[i].id); r.push(group_by[i].id);

View File

@@ -161,6 +161,14 @@ export default
ngShow: "group.id > 0", ngShow: "group.id > 0",
dataPlacement: "top" dataPlacement: "top"
}, },
schedule: {
mode: 'all',
ngClick: "scheduleGroup(group.id)",
awToolTip: "{{ group.group_schedule_tooltip }}",
ngClass: "group.scm_type_class",
dataPlacement: 'top',
ngHide: "group.summary_fields.inventory_source.source === ''"
},
edit: { edit: {
//label: 'Edit', //label: 'Edit',
mode: 'all', mode: 'all',

View File

@@ -81,4 +81,37 @@ export default
}] }]
} }
}); });
$stateExtender.addState({
name: 'inventoryManageSchedules',
route: '/inventory/:inventory_id/manage/:id/schedules',
templateUrl: templateUrl("scheduler/scheduler"),
controller: 'schedulerController',
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
});
$stateExtender.addState({
name: 'inventoryManageSchedules.add',
route: '/add',
templateUrl: templateUrl("scheduler/schedulerForm"),
controller: 'schedulerAddController',
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
});
$stateExtender.addState({
name: 'inventoryManageSchedules.edit',
route: '/:schedule_id',
templateUrl: templateUrl("scheduler/schedulerForm"),
controller: 'schedulerEditController',
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
});
}]); }]);

View File

@@ -12,15 +12,18 @@
export default [ export default [
'$scope', '$compile', '$location', '$stateParams', 'SchedulesList', 'Rest', 'ProcessErrors', 'ReturnToCaller', 'ClearScope', '$scope', '$compile', '$location', '$stateParams', 'SchedulesList', 'Rest',
'GetBasePath', 'Wait', 'Find', 'LoadDialogPartial', 'LoadSchedulesScope', 'GetChoices', 'ProcessErrors', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Wait',
'Find', 'LoadDialogPartial', 'LoadSchedulesScope', 'GetChoices', '$q',
function ($scope, $compile, $location, $stateParams, function ($scope, $compile, $location, $stateParams,
SchedulesList, Rest, ProcessErrors, ReturnToCaller, ClearScope, SchedulesList, Rest, ProcessErrors, ReturnToCaller, ClearScope,
GetBasePath, Wait, Find, LoadDialogPartial, LoadSchedulesScope, GetChoices) { GetBasePath, Wait, Find, LoadDialogPartial, LoadSchedulesScope, GetChoices,
$q) {
ClearScope(); ClearScope();
var base, id, url, parentObject; var base, id, url,parentObject, title;
base = $location.path().replace(/^\//, '').split('/')[0]; base = $location.path().replace(/^\//, '').split('/')[0];
if (base === 'management_jobs') { if (base === 'management_jobs') {
$scope.base = base = 'system_job_templates'; $scope.base = base = 'system_job_templates';
@@ -28,6 +31,7 @@ export default [
if ($stateParams.job_type){ if ($stateParams.job_type){
$scope.job_type = $stateParams.job_type; $scope.job_type = $stateParams.job_type;
} }
if ($scope.removePostRefresh) { if ($scope.removePostRefresh) {
$scope.removePostRefresh(); $scope.removePostRefresh();
} }
@@ -46,7 +50,8 @@ export default [
SchedulesList.well = true; SchedulesList.well = true;
// include name of item in listTitle // include name of item in listTitle
SchedulesList.listTitle = parentObject.name + "<div class='List-titleLockup'></div>Schedules"; SchedulesList.listTitle = title ? title : parentObject.name;
SchedulesList.listTitle = `${SchedulesList.listTitle}<div class='List-titleLockup'></div>Schedules`;
LoadSchedulesScope({ LoadSchedulesScope({
parent_scope: $scope, parent_scope: $scope,
@@ -58,6 +63,28 @@ export default [
}); });
}); });
function getUrl(){
if($stateParams.inventory_id){
url = GetBasePath('groups') + $stateParams.id + '/';
Rest.setUrl(url);
var promise;
promise = Rest.get();
return promise.then(function (data) {
url = data.data.related.inventory_source;
title = data.data.name;
}).catch(function (response) {
ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!',
msg: 'Failed to get inventory group info. GET returned status: ' +
response.status
});
});
}
else{
url = GetBasePath(base) + id + '/';
return $q.when(url);
}
}
if ($scope.removeChoicesReady) { if ($scope.removeChoicesReady) {
$scope.removeChocesReady(); $scope.removeChocesReady();
@@ -65,17 +92,18 @@ export default [
$scope.removeChoicesReady = $scope.$on('choicesReady', function() { $scope.removeChoicesReady = $scope.$on('choicesReady', function() {
// Load the parent object // Load the parent object
id = $stateParams.id; id = $stateParams.id;
url = GetBasePath(base) + id + '/'; getUrl().then(function(){
Rest.setUrl(url); Rest.setUrl(url);
Rest.get() Rest.get()
.success(function(data) { .success(function(data) {
parentObject = data; parentObject = data;
$scope.$emit('ParentLoaded'); $scope.$emit('ParentLoaded');
}) })
.error(function(data, status) { .error(function(data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', ProcessErrors($scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET returned: ' + status }); msg: 'Call to ' + url + ' failed. GET returned: ' + status });
}); });
});
}); });
$scope.refreshJobs = function() { $scope.refreshJobs = function() {

View File

@@ -1,4 +1,15 @@
export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', 'GetBasePath', 'Rest', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange, GetBasePath, Rest) { /*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait',
'$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', 'GetBasePath',
'Rest', 'ParamPass',
function($compile, $state, $stateParams, AddSchedule, Wait, $scope,
$rootScope, CreateSelect2, ParseTypeChange, GetBasePath, Rest, ParamPass) {
$scope.$on("ScheduleFormCreated", function(e, scope) { $scope.$on("ScheduleFormCreated", function(e, scope) {
$scope.hideForm = false; $scope.hideForm = false;
$scope = angular.extend($scope, scope); $scope = angular.extend($scope, scope);
@@ -40,6 +51,7 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
$scope.hideForm = true; $scope.hideForm = true;
var schedule_url = ParamPass.get();
$scope.formCancel = function() { $scope.formCancel = function() {
$state.go("^"); $state.go("^");
@@ -90,7 +102,8 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
AddSchedule({ AddSchedule({
scope: $scope, scope: $scope,
callback: 'SchedulesRefresh', callback: 'SchedulesRefresh',
base: $scope.base ? $scope.base : null base: $scope.base ? $scope.base : null,
url: schedule_url
}); });
var callSelect2 = function() { var callSelect2 = function() {