Skip to content

Commit

Permalink
Merge pull request ansible#617 from jlmitch5/fixAddInteraction
Browse files Browse the repository at this point in the history
fixed add interaction with lists
  • Loading branch information
jlmitch5 committed Jan 14, 2016
2 parents 27bc2c9 + 3a1d49d commit bf96502
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 37 deletions.
13 changes: 11 additions & 2 deletions awx/ui/client/src/controllers/JobTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ JobTemplatesList.$inject = ['$scope', '$rootScope', '$location', '$log',
'$state'
];

export function JobTemplatesAdd($filter, $scope, $rootScope, $compile,
export function JobTemplatesAdd(Refresh, $filter, $scope, $rootScope, $compile,
$location, $log, $stateParams, JobTemplateForm, GenerateForm, Rest, Alert,
ProcessErrors, ReturnToCaller, ClearScope, GetBasePath, InventoryList,
CredentialList, ProjectList, LookUpInit, md5Setup, ParseTypeChange, Wait,
Expand Down Expand Up @@ -583,6 +583,15 @@ export function JobTemplatesAdd($filter, $scope, $rootScope, $compile,
.success(function(data) {
$scope.$emit('templateSaveSuccess', data);

$scope.addedItem = data.id;

Refresh({
scope: $scope,
set: 'job_templates',
iterator: 'job_template',
url: $scope.current_url
});

if(data.survey_enabled===true){
//once the job template information is saved we submit the survey info to the correct endpoint
var url = data.url+ 'survey_spec/';
Expand Down Expand Up @@ -656,7 +665,7 @@ export function JobTemplatesAdd($filter, $scope, $rootScope, $compile,
};
}

JobTemplatesAdd.$inject = ['$filter', '$scope', '$rootScope', '$compile',
JobTemplatesAdd.$inject = ['Refresh', '$filter', '$scope', '$rootScope', '$compile',
'$location', '$log', '$stateParams', 'JobTemplateForm', 'GenerateForm',
'Rest', 'Alert', 'ProcessErrors', 'ReturnToCaller', 'ClearScope',
'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList',
Expand Down
30 changes: 11 additions & 19 deletions awx/ui/client/src/controllers/Projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,6 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams,
});

$scope.cancelUpdate = function (id, name) {
// // Start the cancel process
// var i, project, found = false;
// for (i = 0; i < $scope.projects.length; i++) {
// if ($scope.projects[i].id === id) {
// project = $scope.projects[i];
// found = true;
// break;
// }
// }
Rest.setUrl(GetBasePath("projects") + id);
Rest.get()
.success(function (data) {
Expand All @@ -343,14 +334,6 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams,
};

$scope.refresh = function () {
/*Wait('start');
$scope.projectLoading = false;
Refresh({
scope: $scope,
set: 'projects',
iterator: 'project',
url: $scope.current_url
});*/
$scope.search(list.iterator);
};

Expand Down Expand Up @@ -398,7 +381,7 @@ ProjectsList.$inject = ['$scope', '$rootScope', '$location', '$log',
];


export function ProjectsAdd($scope, $rootScope, $compile, $location, $log,
export function ProjectsAdd(Refresh, $scope, $rootScope, $compile, $location, $log,
$stateParams, ProjectsForm, GenerateForm, Rest, Alert, ProcessErrors,
ClearScope, GetBasePath, ReturnToCaller, GetProjectPath, LookUpInit,
OrganizationList, CredentialList, GetChoices, DebugForm, Wait, $state) {
Expand Down Expand Up @@ -489,6 +472,15 @@ export function ProjectsAdd($scope, $rootScope, $compile, $location, $log,
Rest.setUrl(url);
Rest.post(data)
.success(function (data) {
$scope.addedItem = data.id;

Refresh({
scope: $scope,
set: 'projects',
iterator: 'project',
url: $scope.current_url
});

var id = data.id,
url = GetBasePath('projects') + id + '/organizations/',
org = { id: $scope.organization };
Expand Down Expand Up @@ -530,7 +522,7 @@ export function ProjectsAdd($scope, $rootScope, $compile, $location, $log,
};
}

ProjectsAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log',
ProjectsAdd.$inject = ['Refresh', '$scope', '$rootScope', '$compile', '$location', '$log',
'$stateParams', 'ProjectsForm', 'GenerateForm', 'Rest', 'Alert',
'ProcessErrors', 'ClearScope', 'GetBasePath', 'ReturnToCaller',
'GetProjectPath', 'LookUpInit', 'OrganizationList', 'CredentialList',
Expand Down
17 changes: 13 additions & 4 deletions awx/ui/client/src/helpers/Credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* All Rights Reserved
*************************************************/

/**
* @ngdoc function
* @name helpers.function:Credentials
Expand Down Expand Up @@ -190,8 +190,8 @@ angular.module('CredentialsHelper', ['Utilities'])
}
])

.factory('FormSave', ['$location', 'Alert', 'Rest', 'ProcessErrors', 'Empty', 'GetBasePath', 'CredentialForm', 'ReturnToCaller', 'Wait',
function ($location, Alert, Rest, ProcessErrors, Empty, GetBasePath, CredentialForm, ReturnToCaller, Wait) {
.factory('FormSave', ['Refresh', '$location', 'Alert', 'Rest', 'ProcessErrors', 'Empty', 'GetBasePath', 'CredentialForm', 'ReturnToCaller', 'Wait',
function (Refresh, $location, Alert, Rest, ProcessErrors, Empty, GetBasePath, CredentialForm, ReturnToCaller, Wait) {
return function (params) {
var scope = params.scope,
mode = params.mode,
Expand Down Expand Up @@ -254,7 +254,16 @@ angular.module('CredentialsHelper', ['Utilities'])
GetBasePath('users') + data.user + '/credentials/';
Rest.setUrl(url);
Rest.post(data)
.success(function () {
.success(function (data) {
scope.addedItem = data.id;

Refresh({
scope: scope,
set: 'credentials',
iterator: 'credential',
url: url
});

Wait('stop');
var base = $location.path().replace(/^\//, '').split('/')[0];
if (base === 'credentials') {
Expand Down
13 changes: 11 additions & 2 deletions awx/ui/client/src/helpers/refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* All Rights Reserved
*************************************************/

/**
* @ngdoc function
* @name helpers.function:refresh
Expand Down Expand Up @@ -69,7 +69,16 @@ export default

// if you're editing an object, make sure you're on the right
// page to display the element you are editing
if ($location.$$url.split("/")[1] === params.set && $location.$$url.split("/")[2] && !scope.getNewPage) {
if (scope.addedItem) {
var id = scope.addedItem + "";
delete scope.addedItem;
var restUrl = params.url.split("?")[0];
var pageSize = scope[iterator + '_page_size'];
pagination.getInitialPageForList(id, restUrl, pageSize)
.then(function (currentPage) {
scope.getPage(currentPage, set, iterator);
});
} else if ($location.$$url.split("/")[1] === params.set && $location.$$url.split("/")[2] && $location.$$url.split("/")[2] !== "add" && !scope.getNewPage) {
var id = $location.$$url.split("/")[2];
var restUrl = params.url.split("?")[0];
var pageSize = scope[iterator + '_page_size'];
Expand Down
11 changes: 6 additions & 5 deletions awx/ui/client/src/inventory-scripts/add/add.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*************************************************/

export default
[ '$compile','SchedulerInit', 'Rest', 'Wait',
[ '$rootScope', 'pagination', '$compile','SchedulerInit', 'Rest', 'Wait',
'inventoryScriptsFormObject', 'ProcessErrors', 'GetBasePath', 'Empty',
'GenerateForm', 'SearchInit' , 'PaginateInit',
'LookUpInit', 'OrganizationList', '$scope', '$state',
function(
$compile, SchedulerInit, Rest, Wait,
$rootScope, pagination, $compile, SchedulerInit, Rest, Wait,
inventoryScriptsFormObject, ProcessErrors, GetBasePath, Empty,
GenerateForm, SearchInit, PaginateInit,
LookUpInit, OrganizationList, $scope, $state
Expand Down Expand Up @@ -38,6 +38,7 @@ export default

// Save
scope.formSave = function () {

generator.clearApiErrors();
Wait('start');
Rest.setUrl(url);
Expand All @@ -47,10 +48,10 @@ export default
organization: scope.organization,
script: scope.script
})
.success(function () {
$state.transitionTo('inventoryScriptsList');
.success(function (data) {
$rootScope.addedItem = data.id;
$state.go('inventoryScripts', {}, {reload: true});
Wait('stop');

})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
Expand Down
5 changes: 5 additions & 0 deletions awx/ui/client/src/inventory-scripts/list/list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export default
list: list,
url: defaultUrl
});

if ($rootScope.addedItem) {
scope.addedItem = $rootScope.addedItem;
delete $rootScope.addedItem;
}
PaginateInit({
scope: scope,
list: list,
Expand Down
10 changes: 5 additions & 5 deletions awx/ui/client/src/shared/form-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,17 +942,17 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += (field.awSurveyQuestion) ? "aw-survey-question" : "";

if (field.ngDisabled || field.ask) {
var disabled = "";
var _disabled = "";
if (field.ngDisabled) {
disabled += field.ngDisabled;
_disabled += field.ngDisabled;
}
if (field.ngDisabled && field.ask) {
disabled += " || ";
_disabled += " || ";
}
if (field.ask) {
disabled += fld + "_ask";
_disabled += fld + "_ask";
}
html += "ng-disabled='" + disabled + "'";
html += "ng-disabled='" + _disabled + "'";
}
html += (field.autocomplete !== undefined) ? this.attr(field, 'autocomplete') : "";
html += (field.awRequiredWhen) ? "data-awrequired-init='" + field.awRequiredWhen.init + "' aw-required-when='" +
Expand Down

0 comments on commit bf96502

Please sign in to comment.