1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

adding delete jt service

This commit is contained in:
Jared Tabor 2015-03-27 14:03:16 -04:00
parent 1afeed3588
commit 2401865f59
6 changed files with 68 additions and 17 deletions

View File

@ -55,6 +55,8 @@ import 'tower/shared/InventoryTree';
import 'tower/shared/Timer'; import 'tower/shared/Timer';
import 'tower/shared/Socket'; import 'tower/shared/Socket';
import 'tower/job-templates/main';
/*#if DEBUG#*/ /*#if DEBUG#*/
import {__deferLoadIfEnabled} from 'tower/debug'; import {__deferLoadIfEnabled} from 'tower/debug';
__deferLoadIfEnabled(); __deferLoadIfEnabled();
@ -74,6 +76,7 @@ var tower = angular.module('Tower', [
'UserFormDefinition', 'UserFormDefinition',
'FormGenerator', 'FormGenerator',
'OrganizationListDefinition', 'OrganizationListDefinition',
'jobTemplates',
'UserListDefinition', 'UserListDefinition',
'UserHelper', 'UserHelper',
'PromptDialog', 'PromptDialog',

View File

@ -13,6 +13,7 @@
* @description This controller's for the Inventory page * @description This controller's for the Inventory page
*/ */
import 'tower/job-templates/main';
export function InventoriesList($scope, $rootScope, $location, $log, $routeParams, $compile, $filter, Rest, Alert, InventoryList, generateList, export function InventoriesList($scope, $rootScope, $location, $log, $routeParams, $compile, $filter, Rest, Alert, InventoryList, generateList,
LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, Wait, Stream, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, GetBasePath, Wait, Stream,
@ -483,7 +484,7 @@ InventoriesAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log
export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm, GenerateForm, Rest, export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm, GenerateForm, Rest,
Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, generateList, OrganizationList, SearchInit, PaginateInit, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, generateList, OrganizationList, SearchInit, PaginateInit,
LookUpInit, GetBasePath, ParseTypeChange, Wait, ToJSON, ParseVariableString, Stream, RelatedSearchInit, RelatedPaginateInit, LookUpInit, GetBasePath, ParseTypeChange, Wait, ToJSON, ParseVariableString, Stream, RelatedSearchInit, RelatedPaginateInit,
Prompt, PlaybookRun, CreateDialog) { Prompt, PlaybookRun, CreateDialog, deleteJobTemplate) {
ClearScope(); ClearScope();
@ -491,7 +492,6 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $
var defaultUrl = GetBasePath('inventory'), var defaultUrl = GetBasePath('inventory'),
form = InventoryForm(), form = InventoryForm(),
generator = GenerateForm, generator = GenerateForm,
jobtemplateUrl = GetBasePath('job_templates'),
inventory_id = $routeParams.inventory_id, inventory_id = $routeParams.inventory_id,
master = {}, master = {},
fld, json_data, data, fld, json_data, data,
@ -689,15 +689,6 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $
"label": "Copy", "label": "Copy",
"onClick": function() { "onClick": function() {
copyAction(); copyAction();
// setTimeout(function(){
// scope.$apply(function(){
// if(mode==='survey-taker'){
// scope.$emit('SurveyTakerCompleted');
// } else{
// scope.saveSurvey();
// }
// });
// });
}, },
"icon": "fa-copy", "icon": "fa-copy",
"class": "btn btn-primary", "class": "btn btn-primary",
@ -816,9 +807,7 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $
action = function () { action = function () {
$('#prompt-modal').modal('hide'); $('#prompt-modal').modal('hide');
Wait('start'); Wait('start');
var url = jobtemplateUrl+id; deleteJobTemplate(id)
Rest.setUrl(url);
Rest.destroy()
.success(function () { .success(function () {
$('#prompt-modal').modal('hide'); $('#prompt-modal').modal('hide');
$scope.search(form.related.scan_job_templates.iterator); $scope.search(form.related.scan_job_templates.iterator);
@ -826,7 +815,7 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $
.error(function (data) { .error(function (data) {
Wait('stop'); Wait('stop');
ProcessErrors($scope, data, status, null, { hdr: 'Error!', ProcessErrors($scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status }); msg: 'DELETE returned status: ' + status });
}); });
}; };
@ -835,6 +824,7 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $
body: '<div class=\"alert alert-info\">Delete job template ' + this.scan_job_template.name + '?</div>', body: '<div class=\"alert alert-info\">Delete job template ' + this.scan_job_template.name + '?</div>',
action: action action: action
}); });
}; };
} }
@ -842,7 +832,7 @@ export function InventoriesEdit($scope, $rootScope, $compile, $location, $log, $
InventoriesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm', 'GenerateForm', InventoriesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm', 'GenerateForm',
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'generateList', 'OrganizationList', 'SearchInit', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'generateList', 'OrganizationList', 'SearchInit',
'PaginateInit', 'LookUpInit', 'GetBasePath', 'ParseTypeChange', 'Wait', 'ToJSON', 'ParseVariableString', 'Stream', 'RelatedSearchInit', 'RelatedPaginateInit', 'PaginateInit', 'LookUpInit', 'GetBasePath', 'ParseTypeChange', 'Wait', 'ToJSON', 'ParseVariableString', 'Stream', 'RelatedSearchInit', 'RelatedPaginateInit',
'Prompt', 'PlaybookRun', 'CreateDialog' 'Prompt', 'PlaybookRun', 'CreateDialog', 'deleteJobTemplate'
]; ];

View File

@ -0,0 +1,24 @@
import jobTemplates from 'tower/job-templates/main';
import {describeModule} from '../describe-module';
describeModule(jobTemplates.name)
.testService('deleteJobTemplate', function(test, restStub) {
var service;
test.withService(function(_service) {
service = _service;
});
it('deletes the job template', function() {
var result = {};
var actual = service();
restStub.succeedOn('destroy', result);
restStub.flush();
expect(actual).to.eventually.equal(result);
});
});

View File

@ -0,0 +1,20 @@
var rest, getBasePath;
export default
[ 'Rest',
'GetBasePath',
function(_rest, _getBasePath) {
rest = _rest;
getBasePath = _getBasePath;
return deleteJobTemplate;
}
];
function deleteJobTemplate(id) {
var url = getBasePath('job_templates');
url = url + id;
rest.setUrl(url);
return rest.destroy();
}

View File

@ -0,0 +1,5 @@
import deleteJobTemplate from './delete-job-template.service';
export default
angular.module('jobTemplates', [])
.service('deleteJobTemplate', deleteJobTemplate);

View File

@ -35,10 +35,19 @@ RestStub.prototype =
return this.deferred.promise; return this.deferred.promise;
}, },
destroy: function() {
this.deferred = this.deferred || {};
this.deferred.destroy = this[this.currentUrl];
return this.deferred.destroy.promise;
},
succeedAt: function(url, value) { succeedAt: function(url, value) {
assertUrlDeferred(url, this); assertUrlDeferred(url, this);
this[url].resolve(value); this[url].resolve(value);
}, },
succeedOn: function(method, value) {
this.deferred[method] = value;
},
succeed: function(value) { succeed: function(value) {
this.deferred.resolve(value); this.deferred.resolve(value);
}, },