demodalizing inventory scripts

and refactoring to use es6 modules
This commit is contained in:
Jared Tabor 2015-07-14 16:18:14 -04:00
parent ee6bc5dbfd
commit 4e6c97aa56
27 changed files with 578 additions and 502 deletions

View File

@ -29,6 +29,7 @@ import {CredentialsAdd, CredentialsEdit, CredentialsList} from './controllers/Cr
import {JobsListController} from './controllers/Jobs';
import {PortalController} from './controllers/Portal';
import systemTracking from './system-tracking/main';
import inventoryScripts from './inventory-scripts/main';
import routeExtensions from './shared/route-extensions/main';
import breadcrumbs from './shared/breadcrumbs/main';
@ -67,6 +68,7 @@ import './shared/Socket';
import './job-templates/main';
import './shared/features/main';
/*#if DEBUG#*/
import {__deferLoadIfEnabled} from './debug';
__deferLoadIfEnabled();
@ -81,6 +83,7 @@ var tower = angular.module('Tower', [
browserData.name,
breadcrumbs.name,
systemTracking.name,
inventoryScripts.name,
setupMenu.name,
mainMenu.name,
dashboard.name,
@ -104,7 +107,6 @@ var tower = angular.module('Tower', [
'PaginationHelpers',
'RefreshHelper',
'AdminListDefinition',
'CustomInventoryListDefinition',
'AWDirectives',
'AdhocFormDefinition',
'InventoriesListDefinition',
@ -183,8 +185,6 @@ var tower = angular.module('Tower', [
'PortalJobsListDefinition',
'ConfigureTowerHelper',
'ConfigureTowerJobsListDefinition',
'CreateCustomInventoryHelper',
'CustomInventoryListDefinition',
'AdhocHelper',
'features',
'longDateFilter'
@ -896,6 +896,17 @@ var tower = angular.module('Tower', [
}
}).
// when('/inventory_scripts', {
// name: 'inventoryScriptsList',
// templateUrl: urlPrefix + 'partials/inventory_scripts.html',
// controller: InventoryScriptsList,
// resolve: {
// features: ['FeaturesService', function(FeaturesService) {
// return FeaturesService.get();
// }]
// }
// }).
when('/license', {
name: 'license',
templateUrl: urlPrefix + 'partials/license.html',
@ -933,9 +944,9 @@ var tower = angular.module('Tower', [
}])
.run(['$compile', '$cookieStore', '$rootScope', '$log', 'CheckLicense', '$location', 'Authorization', 'LoadBasePaths', 'Timer', 'ClearScope', 'HideStream', 'Socket',
'LoadConfig', 'Store', 'ShowSocketHelp', 'AboutAnsibleHelp', 'ConfigureTower', 'CreateCustomInventory',
'LoadConfig', 'Store', 'ShowSocketHelp', 'AboutAnsibleHelp', 'ConfigureTower',
function ($compile, $cookieStore, $rootScope, $log, CheckLicense, $location, Authorization, LoadBasePaths, Timer, ClearScope, HideStream, Socket,
LoadConfig, Store, ShowSocketHelp, AboutAnsibleHelp, ConfigureTower, CreateCustomInventory) {
LoadConfig, Store, ShowSocketHelp, AboutAnsibleHelp, ConfigureTower) {
var sock;
@ -1150,12 +1161,6 @@ var tower = angular.module('Tower', [
});
};
$rootScope.createCustomInv = function(){
CreateCustomInventory({
parent_scope: $rootScope
});
};
}); // end of 'ConfigReady'

View File

@ -7,7 +7,6 @@
import ActivityDetail from "./forms/ActivityDetail";
import Credentials from "./forms/Credentials";
import Adhoc from "./forms/Adhoc";
import CustomInventory from "./forms/CustomInventory";
import EventsViewer from "./forms/EventsViewer";
import Groups from "./forms/Groups";
import HostGroups from "./forms/HostGroups";
@ -37,7 +36,6 @@ export
{ ActivityDetail,
Credentials,
Adhoc,
CustomInventory,
EventsViewer,
Groups,
HostGroups,

View File

@ -1,78 +0,0 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
/**
* @ngdoc function
* @name forms.function:CustomInventory
* @description This form is for adding/editing an organization
*/
export default
angular.module('CustomInventoryFormDefinition', [])
.value('CustomInventoryForm', {
addTitle: 'Create Custom Inventory', //Title in add mode
editTitle: '{{ name }}', //Title in edit mode
name: 'custom_inventory', //entity or model name in singular form
well: false,
showActions: false,
fields: {
name: {
label: 'Name',
type: 'text',
addRequired: true,
editRequired: true,
capitalize: false
},
description: {
label: 'Description',
type: 'text',
addRequired: false,
editRequired: false
},
organization: {
label: 'Organization',
type: 'lookup',
awRequiredWhen: {
variable: "orgrequired",
init: true
},
sourceModel: 'organization',
sourceField: 'name',
ngClick: 'lookUpOrganization()'
},
script: {
label: 'Custom Script',
type: 'textarea',
hintText: "Drag and drop an inventory script on the field below",
addRequired: true,
editRequired: true,
awDropFile: true,
'class': 'ssh-key-field',
rows: 10,
awPopOver: "<p>Drag and drop your custom inventory script file here or create one in the field to import your custom inventory. " +
"<br><br> Script must begin with a hashbang sequence: i.e.... #!/usr/bin/env python</p>",
dataTitle: 'Custom Script',
dataPlacement: 'right',
dataContainer: "body"
},
},
buttons: { //for now always generates <button> tags
save: {
ngClick: 'formSave()', //$scope.function to call on click, optional
ngDisabled: true //Disable when $pristine or $invalid, optional
},
reset: {
ngClick: 'formReset()',
ngDisabled: true //Disabled when $pristine
}
},
}); //OrganizationForm

View File

@ -10,9 +10,7 @@ import './lists';
import AboutAnsible from "./helpers/AboutAnsible";
import Access from "./helpers/Access";
import Children from "./helpers/Children";
import ConfigureTower from "./helpers/ConfigureTower";
import Credentials from "./helpers/Credentials";
import CustomInventory from "./helpers/CustomInventory";
import EventViewer from "./helpers/EventViewer";
import Events from "./helpers/Events";
import Groups from "./helpers/Groups";
@ -51,9 +49,7 @@ export
{ AboutAnsible,
Access,
Children,
ConfigureTower,
Credentials,
CustomInventory,
EventViewer,
Events,
Groups,

View File

@ -1,362 +0,0 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
/**
* @ngdoc function
* @name helpers.function:CustomInventory
* @description
* Schedules Helper
*
* Display the scheduler widget in a dialog
*
*/
import listGenerator from '../shared/list-generator/main';
export default
angular.module('CreateCustomInventoryHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', 'SearchHelper', 'PaginationHelpers', listGenerator.name, 'ModalDialog',
'GeneratorHelpers', 'CustomInventoryFormDefinition'])
.factory('CreateCustomInventory', ['Wait', 'CreateDialog', 'CustomInventoryList', 'generateList', 'GetBasePath' , 'SearchInit' , 'PaginateInit', 'PlaybookRun', 'CustomInventoryAdd',
'SchedulesList', 'CustomInventoryEdit', 'Rest' , 'ProcessErrors', 'CustomInventoryForm', 'GenerateForm', 'Prompt',
function(Wait, CreateDialog, CustomInventoryList, GenerateList, GetBasePath, SearchInit, PaginateInit, PlaybookRun, CustomInventoryAdd,
SchedulesList, CustomInventoryEdit, Rest, ProcessErrors, CustomInventoryForm, GenerateForm, Prompt) {
return function(params) {
// Set modal dimensions based on viewport width
var scope = params.parent_scope.$new(),
callback = 'OpenConfig',
defaultUrl = GetBasePath('inventory_scripts'),
list = CustomInventoryList,
view = GenerateList,
buttons = [
{
"label": "Close",
"onClick": function() {
// $(this).dialog('close');
scope.cancelConfigure();
},
"icon": "fa-times",
"class": "btn btn-default",
"id": "script-close-button"
}
];
scope.cleanupJob = true;
if(scope.removeOpenConfig) {
scope.removeOpenConfig();
}
scope.removeOpenConfig = scope.$on('OpenConfig', function() {
$('#custom-script-dialog').dialog('open');
$('#script-close-button').focus();
$('#script-close-button').blur();
});
view.inject( list, {
id : 'custom-script-dialog',
mode: 'edit',
scope: scope,
breadCrumbs: false,
activityStream: false,
showSearch: true
});
SearchInit({
scope: scope,
set: 'source_scripts' , // 'custom_inventories',
list: list,
url: defaultUrl
});
PaginateInit({
scope: scope,
list: list,
url: defaultUrl
});
scope.search(list.iterator);
// SchedulesControllerInit({
// scope: scope,
// parent_scope: parent_scope,
// // list: list
// });
CreateDialog({
id: 'custom-script-dialog',
title: 'Inventory Scripts',
target: 'custom-script-dialog',
scope: scope,
buttons: buttons,
width: 700,
height: 800,
minWidth: 400,
callback: callback,
onClose: function () {
// Destroy on close
$('.tooltip').each(function () {
// Remove any lingering tooltip <div> elements
$(this).remove();
});
$('.popover').each(function () {
// remove lingering popover <div> elements
$(this).remove();
});
// $("#configure-jobs").show();
// $("#configure-schedules-form-container").hide();
// $('#configure-schedules-list').empty();
// $('#configure-schedules-form').empty();
// $('#configure-schedules-detail').empty();
// $('#configure-tower-dialog').hide();
$(this).dialog('destroy');
scope.cancelConfigure();
},
});
// Cancel
scope.cancelConfigure = function () {
try {
$('#custom-script-dialog').dialog('close');
}
catch(e) {
//ignore
}
if (scope.searchCleanup) {
scope.searchCleanup();
}
// if (!Empty(parent_scope) && parent_scope.restoreSearch) {
// parent_scope.restoreSearch();
// }
else {
Wait('stop');
}
};
scope.editCustomInv = function(id){
CustomInventoryEdit({
scope: scope,
id: id
});
};
scope.deleteCustomInv = function(id, name){
var action = function () {
$('#prompt-modal').modal('hide');
Wait('start');
var url = defaultUrl + id + '/';
Rest.setUrl(url);
Rest.destroy()
.success(function () {
scope.search(list.iterator);
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
});
};
var bodyHtml = "<div class=\"alert alert-info\">Are you sure you want to delete " + name + "?</div>";
Prompt({
hdr: 'Delete',
body: bodyHtml,
action: action
});
};
scope.addCustomInv = function(){
CustomInventoryAdd({
scope: scope
});
};
};
}])
.factory('CustomInventoryAdd', ['$compile','SchedulerInit', 'Rest', 'Wait', 'CustomInventoryList', 'CustomInventoryForm', 'ProcessErrors', 'GetBasePath', 'Empty', 'GenerateForm',
'SearchInit' , 'PaginateInit', 'generateList', 'LookUpInit', 'OrganizationList',
function($compile, SchedulerInit, Rest, Wait, CustomInventoryList, CustomInventoryForm, ProcessErrors, GetBasePath, Empty, GenerateForm,
SearchInit, PaginateInit, GenerateList, LookUpInit, OrganizationList) {
return function(params) {
var scope = params.scope,
generator = GenerateForm,
form = CustomInventoryForm,
view = GenerateList,
list = CustomInventoryList,
url = GetBasePath('inventory_scripts');
generator.inject(form, { id:'custom-script-dialog', mode: 'add' , scope:scope, related: false, breadCrumbs: false});
generator.reset();
LookUpInit({
url: GetBasePath('organization'),
scope: scope,
form: form,
// hdr: "Select Custom Inventory",
list: OrganizationList,
field: 'organization',
input_type: 'radio'
});
// Save
scope.formSave = function () {
generator.clearApiErrors();
Wait('start');
Rest.setUrl(url);
Rest.post({ name: scope.name, description: scope.description, organization: scope.organization, script: scope.script })
.success(function () {
view.inject( list, {
id : 'custom-script-dialog',
mode: 'edit',
scope: scope,
breadCrumbs: false,
activityStream: false,
showSearch: true
});
SearchInit({
scope: scope,
set: 'source_scripts', //'custom_inventories',
list: list,
url: url
});
PaginateInit({
scope: scope,
list: list,
url: url
});
scope.search(list.iterator);
Wait('stop');
Wait('stop');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to add new inventory script. POST returned status: ' + status });
});
};
// Cancel
scope.formReset = function () {
generator.reset();
};
};
}])
.factory('CustomInventoryEdit', ['$compile','CustomInventoryList', 'Rest', 'Wait', 'generateList', 'CustomInventoryForm', 'ProcessErrors', 'GetBasePath', 'Empty', 'GenerateForm',
'SearchInit', 'PaginateInit', '$routeParams', 'OrganizationList', 'LookUpInit',
function($compile, CustomInventoryList, Rest, Wait, GenerateList, CustomInventoryForm, ProcessErrors, GetBasePath, Empty, GenerateForm,
SearchInit, PaginateInit, $routeParams, OrganizationList, LookUpInit) {
return function(params) {
var scope = params.scope,
id = params.id,
generator = GenerateForm,
form = CustomInventoryForm,
view = GenerateList,
list = CustomInventoryList,
master = {},
url = GetBasePath('inventory_scripts');
generator.inject(form, {
id:'custom-script-dialog',
mode: 'edit' ,
scope:scope,
related: false,
breadCrumbs: false,
activityStream: false
});
generator.reset();
LookUpInit({
url: GetBasePath('organization'),
scope: scope,
form: form,
// hdr: "Select Custom Inventory",
list: OrganizationList,
field: 'organization',
input_type: 'radio'
});
// Retrieve detail record and prepopulate the form
Wait('start');
Rest.setUrl(url + id+'/');
Rest.get()
.success(function (data) {
var fld;
for (fld in form.fields) {
if (data[fld]) {
scope[fld] = data[fld];
master[fld] = data[fld];
}
if (form.fields[fld].sourceModel && data.summary_fields &&
data.summary_fields[form.fields[fld].sourceModel]) {
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
}
}
Wait('stop');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to retrieve inventory script: ' + $routeParams.id + '. GET status: ' + status });
});
scope.formSave = function () {
generator.clearApiErrors();
Wait('start');
Rest.setUrl(url+ id+'/');
Rest.put({ name: scope.name, description: scope.description, organization: scope.organization, script: scope.script })
.success(function () {
view.inject( list, {
id : 'custom-script-dialog',
mode: 'edit',
scope: scope,
breadCrumbs: false,
activityStream: false,
showSearch: true
});
SearchInit({
scope: scope,
set: 'source_scripts', //'custom_inventories',
list: list,
url: url
});
PaginateInit({
scope: scope,
list: list,
url: url
});
scope.search(list.iterator);
Wait('stop');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to add new inventory script. PUT returned status: ' + status });
});
};
scope.formReset = function () {
generator.reset();
for (var fld in master) {
scope[fld] = master[fld];
}
scope.organization_name = master.organization_name;
};
};
}]);

View File

@ -3,7 +3,7 @@
*
* All Rights Reserved
*************************************************/
'use strict';
/**
@ -235,8 +235,8 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', listGenerator.name
* TODO: Document
*
*/
.factory('SourceChange', ['GetBasePath', 'CredentialList', 'LookUpInit', 'Empty', 'Wait', 'ParseTypeChange', 'CustomInventoryList', 'CreateSelect2',
function (GetBasePath, CredentialList, LookUpInit, Empty, Wait, ParseTypeChange, CustomInventoryList, CreateSelect2) {
.factory('SourceChange', ['GetBasePath', 'CredentialList', 'LookUpInit', 'Empty', 'Wait', 'ParseTypeChange', 'inventoryScriptsListObject', 'CreateSelect2',
function (GetBasePath, CredentialList, LookUpInit, Empty, Wait, ParseTypeChange, inventoryScriptsListObject, CreateSelect2) {
return function (params) {
var scope = params.scope,
@ -289,7 +289,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', listGenerator.name
scope: scope,
form: form,
hdr: "Select Custom Inventory",
list: CustomInventoryList,
list: inventoryScriptsListObject,
field: 'source_script',
input_type: 'radio'
});

View File

@ -0,0 +1,67 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
[ '$compile','SchedulerInit', 'Rest', 'Wait',
'inventoryScriptsFormObject', 'ProcessErrors', 'GetBasePath', 'Empty',
'GenerateForm', 'SearchInit' , 'PaginateInit',
'LookUpInit', 'OrganizationList', '$scope', 'transitionTo',
function(
$compile, SchedulerInit, Rest, Wait,
inventoryScriptsFormObject, ProcessErrors, GetBasePath, Empty,
GenerateForm, SearchInit, PaginateInit,
LookUpInit, OrganizationList, $scope, transitionTo
) {
var scope = $scope,
generator = GenerateForm,
form = inventoryScriptsFormObject,
url = GetBasePath('inventory_scripts');
generator.inject(form, {
mode: 'add' ,
scope:scope,
related: false
});
generator.reset();
LookUpInit({
url: GetBasePath('organization'),
scope: scope,
form: form,
list: OrganizationList,
field: 'organization',
input_type: 'radio'
});
// Save
scope.formSave = function () {
generator.clearApiErrors();
Wait('start');
Rest.setUrl(url);
Rest.post({
name: scope.name,
description: scope.description,
organization: scope.organization,
script: scope.script
})
.success(function () {
transitionTo('inventoryScriptsList');
Wait('stop');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to add new inventory script. POST returned status: ' + status });
});
};
// Cancel
scope.formReset = function () {
generator.reset();
};
}
];

View File

@ -0,0 +1,12 @@
<breadcrumbs>
<breadcrumb path="/setup" title="Setup"></breadcrumb>
<breadcrumb path="/inventory_scripts" title="Inventory Scripts"></breadcrumb>
<breadcrumb
path="/inventory_scripts/add"
title="Create Inventory Script">
</breadcrumb>
</breadcrumbs>
<div class="tab-pane" id="inventory_scripts_add">
<div ng-cloak id="htmlTemplate"></div>
</div>

View File

@ -0,0 +1,17 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default {
name: 'inventoryScriptsAdd',
route: '/inventory_scripts/add',
templateUrl: '/static/js/inventory-scripts/add/add.partial.html',
controller: 'addController',
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
};

View File

@ -0,0 +1,17 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
import route from './add.route';
import controller from './add.controller';
export default
angular.module('inventoryScriptsAdd', [])
.controller('addController', controller)
.config(['$routeProvider', function($routeProvider) {
var url = route.route;
delete route.route;
$routeProvider.when(url, route);
}]);

View File

@ -0,0 +1,103 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
[ 'Rest', 'Wait',
'inventoryScriptsFormObject', 'ProcessErrors', 'GetBasePath',
'GenerateForm', 'SearchInit' , 'PaginateInit',
'LookUpInit', 'OrganizationList', 'inventory_script',
'$scope', 'transitionTo',
function(
Rest, Wait,
inventoryScriptsFormObject, ProcessErrors, GetBasePath,
GenerateForm, SearchInit, PaginateInit,
LookUpInit, OrganizationList, inventory_script,
$scope, transitionTo
) {
var generator = GenerateForm,
id = inventory_script.id,
form = inventoryScriptsFormObject,
master = {},
url = GetBasePath('inventory_scripts');
$scope.inventory_script = inventory_script;
generator.inject(form, {
mode: 'edit' ,
scope:$scope,
breadCrumbs: true,
related: false,
activityStream: false
});
generator.reset();
LookUpInit({
url: GetBasePath('organization'),
scope: $scope,
form: form,
// hdr: "Select Custom Inventory",
list: OrganizationList,
field: 'organization',
input_type: 'radio'
});
// Retrieve detail record and prepopulate the form
Wait('start');
Rest.setUrl(url + id+'/');
Rest.get()
.success(function (data) {
var fld;
for (fld in form.fields) {
if (data[fld]) {
$scope[fld] = data[fld];
master[fld] = data[fld];
}
if (form.fields[fld].sourceModel && data.summary_fields &&
data.summary_fields[form.fields[fld].sourceModel]) {
$scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
}
}
Wait('stop');
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to retrieve inventory script: ' + id + '. GET status: ' + status });
});
$scope.formSave = function () {
generator.clearApiErrors();
Wait('start');
Rest.setUrl(url+ id+'/');
Rest.put({
name: $scope.name,
description: $scope.description,
organization: $scope.organization,
script: $scope.script
})
.success(function () {
transitionTo('inventoryScriptsList');
Wait('stop');
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to add new inventory script. PUT returned status: ' + status });
});
};
$scope.formReset = function () {
generator.reset();
for (var fld in master) {
$scope[fld] = master[fld];
}
$scope.organization_name = master.organization_name;
};
}
];

View File

@ -0,0 +1,9 @@
<breadcrumbs>
<breadcrumb path="/setup" title="Setup"></breadcrumb>
<breadcrumb path="/inventory_scripts" title="Inventory Scripts"></breadcrumb>
<breadcrumb path="/inventory_scripts/{{inventory_script.id}}" title="{{inventory_script.name}}" current="true"></breadcrumb>
</breadcrumbs>
<div class="tab-pane" id="inventory_scripts_edit">
<div ng-cloak id="htmlTemplate"></div>
</div>

View File

@ -0,0 +1,44 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default {
name: 'inventoryScriptsEdit',
route: '/inventory_scripts/:inventory_script',
templateUrl: '/static/js/inventory-scripts/edit/edit.partial.html',
controller: 'editController',
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}],
inventory_script:
[ '$route',
'$q',
'Rest',
'GetBasePath',
'ProcessErrors',
function($route, $q, rest, getBasePath, ProcessErrors) {
if ($route.current.hasModelKey('inventory_script')) {
return $q.when($route.current.params.model.inventory_script);
}
var inventoryScriptId = $route.current.params.inventory_script;
var url = getBasePath('inventory_scripts') + inventoryScriptId + '/';
rest.setUrl(url);
return rest.get()
.then(function(data) {
return data.data;
}).catch(function (response) {
ProcessErrors(null, response.data, response.status, null, {
hdr: 'Error!',
msg: 'Failed to get inventory script info. GET returned status: ' +
response.status
});
});
}
],
}
};

View File

@ -0,0 +1,17 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
import route from './edit.route';
import controller from './edit.controller';
export default
angular.module('inventoryScriptsEdit', [])
.controller('editController', controller)
.config(['$routeProvider', function($routeProvider) {
var url = route.route;
delete route.route;
$routeProvider.when(url, route);
}]);

View File

@ -0,0 +1,75 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
/**
* @ngdoc function
* @name forms.function:CustomInventory
* @description This form is for adding/editing an organization
*/
export default function() {
return {
// addTitle: 'Create Custom Inventory',
// editTitle: '{{ name }}',
// name: 'custom_inventory',
well: true,
showActions: true,
fields: {
name: {
label: 'Name',
type: 'text',
addRequired: true,
editRequired: true,
capitalize: false
},
description: {
label: 'Description',
type: 'text',
addRequired: false,
editRequired: false
},
organization: {
label: 'Organization',
type: 'lookup',
awRequiredWhen: {
variable: "orgrequired",
init: true
},
sourceModel: 'organization',
sourceField: 'name',
ngClick: 'lookUpOrganization()'
},
script: {
label: 'Custom Script',
type: 'textarea',
hintText: "Drag and drop an inventory script on the field below",
addRequired: true,
editRequired: true,
awDropFile: true,
// 'class': 'ssh-key-field',
rows: 10,
awPopOver: "<p>Drag and drop your custom inventory script file here or create one in the field to import your custom inventory. " +
"<br><br> Script must begin with a hashbang sequence: i.e.... #!/usr/bin/env python</p>",
dataTitle: 'Custom Script',
dataPlacement: 'right',
dataContainer: "body"
},
},
buttons: { //for now always generates <button> tags
save: {
ngClick: 'formSave()', //$scope.function to call on click, optional
ngDisabled: true //Disable when $pristine or $invalid, optional
},
reset: {
ngClick: 'formReset()',
ngDisabled: true //Disabled when $pristine
}
}
};
}

View File

@ -3,24 +3,19 @@
*
* All Rights Reserved
*************************************************/
export default
angular.module('CustomInventoryListDefinition', [])
.value('CustomInventoryList', {
name: 'source_scripts' , // 'custom_inventories',
iterator: 'source_script', //'custom_inventory',
selectTitle: 'Add custom inventory',
editTitle: 'Custom Inventories',
export default function(){
return {
name: 'inventory_scripts' ,
iterator: 'inventory_script',
index: false,
hover: false,
fields: {
name: {
key: true,
noLink: true,
label: 'Name',
columnClass: 'col-md-3 col-sm-9 col-xs-9',
modalColumnClass: 'col-md-8'
@ -32,8 +27,7 @@ export default
},
organization: {
label: 'Organization',
ngBind: 'source_script.summary_fields.organization.name',
// linkTo: '/#/organizations/{{ custom_inventory.organization }}',
ngBind: 'inventory_script.summary_fields.organization.name',
sourceModel: 'organization',
sourceField: 'name',
excludeModal: true,
@ -51,7 +45,7 @@ export default
fieldActions: {
edit: {
ngClick: "editCustomInv(source_script.id)",
ngClick: "editCustomInv(inventory_script.id)",
icon: 'fa-edit',
label: 'Edit',
"class": 'btn-sm',
@ -59,7 +53,7 @@ export default
dataPlacement: 'top'
},
"delete": {
ngClick: "deleteCustomInv(source_script.id, source_script.name)",
ngClick: "deleteCustomInv(inventory_script.id, inventory_script.name)",
icon: 'fa-trash',
label: 'Delete',
"class": 'btn-sm',
@ -67,4 +61,5 @@ export default
dataPlacement: 'top'
}
}
});
};
}

View File

@ -0,0 +1,79 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
[ '$rootScope','Wait', 'generateList', 'inventoryScriptsListObject',
'GetBasePath' , 'SearchInit' , 'PaginateInit',
'Rest' , 'ProcessErrors', 'Prompt', 'transitionTo',
function(
$rootScope,Wait, GenerateList, inventoryScriptsListObject,
GetBasePath, SearchInit, PaginateInit,
Rest, ProcessErrors, Prompt, transitionTo
) {
var scope = $rootScope.$new(),
defaultUrl = GetBasePath('inventory_scripts'),
list = inventoryScriptsListObject,
view = GenerateList;
view.inject( list, {
id : 'inventory_scripts',
mode: 'edit',
scope: scope,
breadCrumbs: false,
activityStream: false,
showSearch: true
});
SearchInit({
scope: scope,
set: 'inventory_scripts',
list: list,
url: defaultUrl
});
PaginateInit({
scope: scope,
list: list,
url: defaultUrl
});
scope.search(list.iterator);
scope.editCustomInv = function(){
transitionTo('inventoryScriptsEdit', {
inventory_script: this.inventory_script
});
};
scope.deleteCustomInv = function(id, name){
var action = function () {
$('#prompt-modal').modal('hide');
Wait('start');
var url = defaultUrl + id + '/';
Rest.setUrl(url);
Rest.destroy()
.success(function () {
scope.search(list.iterator);
})
.error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
});
};
var bodyHtml = "<div class=\"alert alert-info\">Are you sure you want to delete " + name + "?</div>";
Prompt({
hdr: 'Delete',
body: bodyHtml,
action: action
});
};
scope.addCustomInv = function(){
transitionTo('inventoryScriptsAdd');
};
}
];

View File

@ -0,0 +1,18 @@
<breadcrumbs>
<breadcrumb path="/setup" title="Setup"></breadcrumb>
<breadcrumb path="/inventory_scripts" title="Inventory Scripts"></breadcrumb>
<breadcrumb
path="/inventory_scripts/add"
title="Create Inventory Script"
ng-if="mode == 'add'">
</breadcrumb>
<breadcrumb
path="/inventory_scripts/{{source_script.id}}"
title="{{inventory_scripts}}"
ng-if="organization_id">
</breadcrumb>
</breadcrumbs>
<div class="tab-pane" id="inventory_scripts">
<div ng-cloak id="htmlTemplate"></div>
</div>

View File

@ -0,0 +1,17 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default {
name: 'inventoryScriptsList',
route: '/inventory_scripts',
templateUrl: '/static/js/inventory-scripts/list/list.partial.html',
controller: 'listController',
resolve: {
features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get();
}]
}
};

View File

@ -0,0 +1,25 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
var rest, getBasePath;
export default
[ 'Rest',
'GetBasePath',
function(_rest, _getBasePath) {
rest = _rest;
getBasePath = _getBasePath;
return deleteInventoryScript;
}
];
function deleteInventoryScript(id) {
var url = getBasePath('inventory_scripts');
url = url + id;
rest.setUrl(url);
return rest.destroy();
}

View File

@ -0,0 +1,17 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
import route from './list.route';
import controller from './list.controller';
export default
angular.module('inventoryScriptsList', [])
.controller('listController', controller)
.config(['$routeProvider', function($routeProvider) {
var url = route.route;
delete route.route;
$routeProvider.when(url, route);
}]);

View File

@ -0,0 +1,20 @@
/*************************************************
* Copyright (c) 2015 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
import inventoryScriptsList from './list/main';
import inventoryScriptsAdd from './add/main';
import inventoryScriptsEdit from './edit/main';
import list from './inventory-scripts.list';
import form from './inventory-scripts.form';
export default
angular.module('inventoryScripts', [
inventoryScriptsList.name,
inventoryScriptsAdd.name,
inventoryScriptsEdit.name
])
.factory('inventoryScriptsListObject', list)
.factory('inventoryScriptsFormObject', form);

View File

@ -8,9 +8,7 @@ import Admins from "./lists/Admins";
import CloudCredentials from "./lists/CloudCredentials";
import CompletedJobs from "./lists/CompletedJobs";
import AllJobs from "./lists/AllJobs";
import ConfigureTowerJobs from "./lists/ConfigureTowerJobs";
import Credentials from "./lists/Credentials";
import CustomInventory from "./lists/CustomInventory";
import Groups from "./lists/Groups";
import HomeGroups from "./lists/HomeGroups";
import HomeHosts from "./lists/HomeHosts";
@ -39,9 +37,7 @@ export
CloudCredentials,
CompletedJobs,
AllJobs,
ConfigureTowerJobs,
Credentials,
CustomInventory,
Groups,
HomeGroups,
HomeHosts,

View File

@ -5,7 +5,6 @@ export default
angular.module('setupMenu',
[ 'AboutAnsibleHelpModal',
'ConfigureTowerHelper',
'CreateCustomInventoryHelper',
icon.name
])
.config(['$routeProvider', function($routeProvider) {
@ -13,4 +12,3 @@ export default
delete route.route;
$routeProvider.when(url, route);
}]);

View File

@ -66,19 +66,16 @@
</div>
</div>
</button>
<button class="SetupItem SetupItem--button SetupItem--aside HoverIcon Media" ng-click="showInventoryScriptsModal()" ng-if="user_is_superuser">
<div class="SetupItem-firefoxFlexButtonFix">
<i class="HoverIcon-icon HoverIcon-icon--opacity HoverIcon-icon--color Media-figure SetupItem-icon SetupItem-icon--aside ">
<aw-icon name="InventoryScripts"></aw-icon>
</i>
<div class="Media-block">
<h4 class="SetupItem-title SetupItem-title--aside">Inventory Scripts</h4>
<p class="SetupItem-description SetupItem-description--aside">
Create and edit scripts to dynamically load hosts from any source.
</p>
</div>
<a link-to="inventoryScriptsList" class="SetupItem SetupItem--aside HoverIcon Media">
<i class="HoverIcon-icon HoverIcon-icon--opacity HoverIcon-icon--color Media-figure SetupItem-icon SetupItem-icon--aside ">
<aw-icon name="InventoryScripts"></aw-icon>
</i>
<div class="Media-block">
<h4 class="SetupItem-title SetupItem-title--aside">Inventory Scripts</h4>
<p class="SetupItem-description SetupItem-description--aside">
Create and edit scripts to dynamically load hosts from any source.
</div>
</button>
</a>
<a link-to="license" class="SetupItem SetupItem--button SetupItem--aside SetupItem--noIcon">
<h4 class="SetupItem-title SetupItem-title--aside">View Your License</h4>
</a>

View File

@ -3,13 +3,11 @@ export default
'$rootScope',
'AboutAnsibleHelp',
'ConfigureTower',
'CreateCustomInventory',
function(
$scope,
$rootScope,
showAboutModal,
configureTower,
showInventoryScriptsModal
configureTower
) {
$scope.showAboutModal = showAboutModal;
@ -19,9 +17,5 @@ export default
parent_scope: $rootScope
});
$scope.showInventoryScriptsModal = showInventoryScriptsModal.bind(null,
{ parent_scope: $rootScope
});
}
];

View File

@ -152,9 +152,9 @@
<div id="login-modal-dialog" style="display: none;"></div>
<div id="help-modal-dialog" style="display: none;"></div>
<div id="about-modal-dialog" style="display: none;" ng-include=" '{{ STATIC_URL }}assets/cowsay-about.html ' "></div>
<div id="custom-script-dialog" style="display:none;" > </div>
<div id='configure-tower-dialog' style="display:none" >
<div id="configure-jobs" ></div>
<div class="tab-pane" id="configure-schedules-tab">