Merge pull request #1703 from jaredevantabor/inv_sync_schedules

Adding scheduler for inventory syncs
This commit is contained in:
Jared Tabor 2016-04-29 09:25:24 -07:00
commit b27e84e805
7 changed files with 173 additions and 43 deletions

View File

@ -207,23 +207,46 @@ export default
};
}])
.factory('AddSchedule', ['$location', '$stateParams', 'SchedulerInit', 'ShowSchedulerModal', 'Wait', 'GetBasePath', 'Empty',
'SchedulePost', '$state',
function($location, $stateParams, SchedulerInit, ShowSchedulerModal, Wait, GetBasePath, Empty, SchedulePost, $state) {
.factory('AddSchedule', ['$location', '$stateParams', 'SchedulerInit',
'ShowSchedulerModal', 'Wait', 'GetBasePath', 'Empty',
'SchedulePost', '$state', 'Rest', 'ProcessErrors',
function($location, $stateParams, SchedulerInit, ShowSchedulerModal,
Wait, GetBasePath, Empty, SchedulePost, $state, Rest,
ProcessErrors) {
return function(params) {
var scope = params.scope,
callback= params.callback,
base = params.base || $location.path().replace(/^\//, '').split('/')[0],
url = GetBasePath(base),
url,
scheduler;
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') {
url += $stateParams.id + '/schedules/';
else if (!Empty($stateParams.id) && base !== 'system_job_templates' && base !== 'inventory') {
url = GetBasePath(base) + $stateParams.id + '/schedules/';
}
else if(base === "inventory"){
if (!params.url){
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 += $stateParams.id + '/schedules/';
url = GetBasePath(base) + $stateParams.id + '/schedules/';
if($stateParams.id === 4){
scope.isFactCleanup = true;
scope.keep_unit_choices = [{
@ -302,7 +325,9 @@ export default
};
}])
.factory('SchedulePost', ['Rest', 'ProcessErrors', 'RRuleToAPI', 'Wait', function(Rest, ProcessErrors, RRuleToAPI, Wait) {
.factory('SchedulePost', ['Rest', 'ProcessErrors', 'RRuleToAPI', 'Wait',
'ToJSON',
function(Rest, ProcessErrors, RRuleToAPI, Wait, ToJSON) {
return function(params) {
var scope = params.scope,
url = params.url,
@ -334,6 +359,10 @@ export default
else if (scope.serializedExtraVars){
schedule.extra_data = scope.serializedExtraVars;
}
else if(scope.extraVars){
schedule.extra_data = ToJSON(scope.parseType,
scope.extraVars, false);
}
Rest.setUrl(url);
if (mode === 'add') {
Rest.post(schedule)
@ -528,10 +557,10 @@ export default
};
}])
.factory('SchedulesControllerInit', ['$state', '$location', 'ToggleSchedule',
'DeleteSchedule',
function($state, $location, ToggleSchedule, DeleteSchedule) {
.factory('SchedulesControllerInit', ['$state', '$location',
'ToggleSchedule', 'DeleteSchedule', 'ParamPass',
function($state, $location, ToggleSchedule, DeleteSchedule,
ParamPass) {
return function(params) {
var scope = params.scope,
parent_scope = params.parent_scope,
@ -567,7 +596,8 @@ export default
scope.addSchedule = function() {
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() {

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) {
PreviousSearchParams = Store('group_current_search_params');
var params = {

View File

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

View File

@ -161,6 +161,14 @@ export default
ngShow: "group.id > 0",
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: {
//label: 'Edit',
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 [
'$scope', '$compile', '$location', '$stateParams', 'SchedulesList', 'Rest', 'ProcessErrors', 'ReturnToCaller', 'ClearScope',
'GetBasePath', 'Wait', 'Find', 'LoadDialogPartial', 'LoadSchedulesScope', 'GetChoices',
'$scope', '$compile', '$location', '$stateParams', 'SchedulesList', 'Rest',
'ProcessErrors', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'Wait',
'Find', 'LoadDialogPartial', 'LoadSchedulesScope', 'GetChoices', '$q',
function ($scope, $compile, $location, $stateParams,
SchedulesList, Rest, ProcessErrors, ReturnToCaller, ClearScope,
GetBasePath, Wait, Find, LoadDialogPartial, LoadSchedulesScope, GetChoices) {
GetBasePath, Wait, Find, LoadDialogPartial, LoadSchedulesScope, GetChoices,
$q) {
ClearScope();
var base, id, url, parentObject;
var base, id, url,parentObject, title;
base = $location.path().replace(/^\//, '').split('/')[0];
if (base === 'management_jobs') {
$scope.base = base = 'system_job_templates';
@ -28,6 +31,7 @@ export default [
if ($stateParams.job_type){
$scope.job_type = $stateParams.job_type;
}
if ($scope.removePostRefresh) {
$scope.removePostRefresh();
}
@ -46,7 +50,8 @@ export default [
SchedulesList.well = true;
// 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({
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) {
$scope.removeChocesReady();
@ -65,17 +92,18 @@ export default [
$scope.removeChoicesReady = $scope.$on('choicesReady', function() {
// Load the parent object
id = $stateParams.id;
url = GetBasePath(base) + id + '/';
Rest.setUrl(url);
Rest.get()
.success(function(data) {
parentObject = data;
$scope.$emit('ParentLoaded');
})
.error(function(data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET returned: ' + status });
});
getUrl().then(function(){
Rest.setUrl(url);
Rest.get()
.success(function(data) {
parentObject = data;
$scope.$emit('ParentLoaded');
})
.error(function(data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET returned: ' + status });
});
});
});
$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.hideForm = false;
$scope = angular.extend($scope, scope);
@ -40,6 +51,7 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
$scope.hideForm = true;
var schedule_url = ParamPass.get();
$scope.formCancel = function() {
$state.go("^");
@ -50,15 +62,15 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
$scope.parseType = 'yaml';
var defaultUrl = GetBasePath('job_templates') + $stateParams.id + '/';
Rest.setUrl(defaultUrl);
Rest.get().then(function(res){
Rest.get().then(function(res){
// sanitize
var data = JSON.parse(JSON.stringify(res.data.extra_vars));
$scope.extraVars = data === '' ? '---' : data;
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
parse_variable: 'parseType',
field_id: 'SchedulerForm-extraVars'
field_id: 'SchedulerForm-extraVars'
});
});
$scope.$watch('extraVars', function(){
@ -79,18 +91,29 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
else if ($state.current.name === 'projectSchedules.add'){
$scope.extraVars = '---';
$scope.parseType = 'yaml';
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
parse_variable: 'parseType',
field_id: 'SchedulerForm-extraVars'
field_id: 'SchedulerForm-extraVars'
});
}
else if ($state.current.name === 'inventoryManageSchedules.add'){
$scope.extraVars = '---';
$scope.parseType = 'yaml';
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
parse_variable: 'parseType',
field_id: 'SchedulerForm-extraVars'
});
}
AddSchedule({
scope: $scope,
callback: 'SchedulesRefresh',
base: $scope.base ? $scope.base : null
base: $scope.base ? $scope.base : null,
url: schedule_url
});
var callSelect2 = function() {