fix add/edit/delete behavior across tower ui

This commit is contained in:
John Mitchell 2016-06-13 16:13:50 -04:00
parent 8a2c8d59a5
commit 1a0266fc54
32 changed files with 116 additions and 95 deletions

View File

@ -102,9 +102,10 @@ export function CredentialsList($scope, $rootScope, $location, $log,
Rest.setUrl(url);
Rest.destroy()
.success(function () {
$scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
if (parseInt($state.params.credential_id) === id) {
$state.go("^", null, {reload: true});
} else {
$scope.search(list.iterator);
}
})
.error(function (data, status) {

View File

@ -244,11 +244,13 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams,
Wait('start');
var url = defaultUrl + id + '/';
Rest.setUrl(url);
console.log($state);
Rest.destroy()
.success(function () {
$scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
if (parseInt($state.params.id) === id) {
$state.go("^", null, {reload: true});
} else {
$scope.search(list.iterator);
}
})
.error(function (data, status) {
@ -802,13 +804,7 @@ export function ProjectsEdit($scope, $rootScope, $compile, $location, $log,
Rest.put(params)
.success(function() {
Wait('stop');
/*$scope.scm_update_tooltip = "Start an SCM update";
$scope.scm_type_class = "";
if (Empty($scope.scm_type)) {
$scope.scm_update_tooltip = 'Manual projects do not require an SCM update';
$scope.scm_type_class = "btn-disabled";
}*/
ReturnToCaller();
$state.go($state.current, {}, {reload: true});
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to update project: ' + id + '. PUT status: ' + status });

View File

@ -97,9 +97,10 @@ export function TeamsList($scope, $rootScope, $location, $log, $stateParams,
.success(function () {
Wait('stop');
$('#prompt-modal').modal('hide');
$scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
if (parseInt($state.params.team_id) === id) {
$state.go("^", null, {reload: true});
} else {
$scope.search(list.iterator);
}
})
.error(function (data, status) {
@ -297,7 +298,7 @@ export function TeamsEdit($scope, $rootScope, $location,
Rest.setUrl(defaultUrl + id + '/');
var data = processNewData(form.fields);
Rest.put(data).success(function(){
$state.go('teams', null, {reload: true});
$state.go($state.current, null, {reload: true});
})
.error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to retrieve user: ' +

View File

@ -111,9 +111,10 @@ export function UsersList($scope, $rootScope, $location, $log, $stateParams,
Rest.setUrl(url);
Rest.destroy()
.success(function () {
$scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
if (parseInt($state.params.user_id) === id) {
$state.go("^", null, {reload: true});
} else {
$scope.search(list.iterator);
}
})
.error(function (data, status) {
@ -391,7 +392,7 @@ export function UsersEdit($scope, $rootScope, $location,
Rest.setUrl(defaultUrl + id + '/');
var data = processNewData(form.fields);
Rest.put(data).success(function(){
$state.go('users', null, {reload: true});
$state.go($state.current, null, {reload: true});
})
.error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to retrieve user: ' +

View File

@ -307,14 +307,7 @@ angular.module('CredentialsHelper', ['Utilities'])
Rest.put(data)
.success(function () {
Wait('stop');
var base = $location.path().replace(/^\//, '').split('/')[0];
if (base === 'credentials') {
ReturnToCaller();
}
else {
ReturnToCaller(1);
}
$state.go($state.current, {}, {reload: true});
})
.error(function (data, status) {
Wait('stop');

View File

@ -132,7 +132,7 @@ function InventoriesEdit($scope, $rootScope, $compile, $location,
Rest.put(data)
.success(function () {
Wait('stop');
$location.path('/inventories/');
$state.go($state.current, {}, {reload: true});
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, { hdr: 'Error!',

View File

@ -322,9 +322,10 @@ function InventoriesList($scope, $rootScope, $location, $log,
Rest.setUrl(url);
Rest.destroy()
.success(function () {
$scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
if (parseInt($state.params.inventory_id) === id) {
$state.go("^", null, {reload: true});
} else {
$scope.search(list.iterator);
}
})
.error(function (data, status) {

View File

@ -52,14 +52,14 @@
// no inventory source set, just create a new group
// '' is the value supplied for Manual source type
case null || '':
GroupManageService.put(group).then(() => $state.go('^', null, {reload: true}));
GroupManageService.put(group).then(() => $state.go($state.current, null, {reload: true}));
break;
// create a new group and create/associate an inventory source
// equal to case 'rax' || 'ec2' || 'azure' || 'azure_rm' || 'vmware' || 'foreman' || 'cloudforms' || 'openstack' || 'custom'
default:
GroupManageService.put(group)
.then(() => GroupManageService.putInventorySource(params, groupData.related.inventory_source))
.then(() => $state.go('^', null, {reload: true}));
.then(() => $state.go($state.current, null, {reload: true}));
break;
}
};

View File

@ -48,12 +48,26 @@
case 'promote':
GroupManageService.promote($scope.toDelete.id, $stateParams.inventory_id)
.then(() => {
if (parseInt($state.params.group_id) === $scope.toDelete.id) {
$state.go("inventoryManage", null, {reload: true});
} else {
$state.go($state.current, null, {reload: true});
}
$('#group-delete-modal').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
});
break;
case 'delete':
default:
GroupManageService.delete($scope.toDelete.id).then(() => {
if (parseInt($state.params.group_id) === $scope.toDelete.id) {
$state.go("inventoryManage", null, {reload: true});
} else {
$state.go($state.current, null, {reload: true});
}
$('#group-delete-modal').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
});
}
};

View File

@ -29,11 +29,11 @@
// assign the host to current group if not at the root level
if ($stateParams.group){
HostManageService.associateGroup(res.data, _.last($stateParams.group)).then(function(){
$state.go('inventoryManage', null, {reload: true});
$state.go('inventoryManage.editHost', {host_id: res.data.id}, {reload: true});
});
}
else{
$state.go('inventoryManage', null, {reload: true});
$state.go('inventoryManage.editHost', {host_id: res.data.id}, {reload: true});
}
});
};

View File

@ -25,7 +25,7 @@
enabled: $scope.host.enabled
};
HostManageService.put(host).then(function(){
$state.go('^', null, {reload: true});
$state.go($state.current, null, {reload: true});
});
};
var init = function(){

View File

@ -24,7 +24,11 @@
Wait('start');
HostManageService.delete(id).then(() => {
$('#prompt-modal').modal('hide');
$state.go($state.current.name, null, {reload: true});
if (parseInt($state.params.host_id) === id) {
$state.go("inventoryManage", null, {reload: true});
} else {
$state.go($state.current.name, null, {reload: true});
}
Wait('stop');
});
};
@ -81,4 +85,4 @@
$scope.search(list.iterator);
};
init();
}];
}];

View File

@ -49,8 +49,8 @@ export default
organization: scope.organization,
script: scope.script
})
.success(function () {
$state.go('inventoryScripts', {}, {reload: true});
.success(function (data) {
$state.go('inventoryScripts.edit', {inventory_script_id: data.id}, {reload: true});
Wait('stop');
})
.error(function (data, status) {

View File

@ -84,7 +84,7 @@ export default
script: $scope.script
})
.success(function () {
$state.transitionTo('inventoryScripts');
$state.go($state.current, null, {reload: true});
Wait('stop');
})
.error(function (data, status) {

View File

@ -7,11 +7,11 @@
export default
[ '$rootScope','Wait', 'generateList', 'inventoryScriptsListObject',
'GetBasePath' , 'SearchInit' , 'PaginateInit',
'Rest' , 'ProcessErrors', 'Prompt', '$state', '$location',
'Rest' , 'ProcessErrors', 'Prompt', '$state',
function(
$rootScope,Wait, GenerateList, inventoryScriptsListObject,
GetBasePath, SearchInit, PaginateInit,
Rest, ProcessErrors, Prompt, $state, $location
Rest, ProcessErrors, Prompt, $state
) {
var scope = $rootScope.$new(),
defaultUrl = GetBasePath('inventory_scripts'),
@ -58,9 +58,10 @@ export default
Rest.setUrl(url);
Rest.destroy()
.success(function () {
scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
if (parseInt($state.params.inventory_script_id) === id) {
$state.go("^", null, {reload: true});
} else {
scope.search(list.iterator);
}
})
.error(function (data, status) {

View File

@ -480,7 +480,7 @@ export default
});
function saveCompleted() {
$state.go('jobTemplates', null, {reload: true});
$state.go($state.current, {}, {reload: true});
}
if ($scope.removeTemplateSaveSuccess) {

View File

@ -77,9 +77,10 @@ export default
Rest.setUrl(url);
Rest.destroy()
.success(function () {
$scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
if (parseInt($state.params.template_id) === id) {
$state.go("^", null, {reload: true});
} else {
$scope.search(list.iterator);
}
})
.error(function (data) {

View File

@ -212,7 +212,7 @@ export default
Rest.setUrl(url+ id+'/');
Rest.put(params)
.success(function () {
$state.go('notifications', {}, {reload: true});
$state.go($state.current, null, {reload: true});
Wait('stop');
})
.error(function (data, status) {

View File

@ -8,12 +8,12 @@ export default
[ '$rootScope','Wait', 'generateList', 'NotificationTemplatesList',
'GetBasePath' , 'SearchInit' , 'PaginateInit', 'Rest' ,
'ProcessErrors', 'Prompt', '$state', 'GetChoices', 'Empty', 'Find',
'ngToast', '$compile', '$filter', '$location',
'ngToast', '$compile', '$filter',
function(
$rootScope,Wait, GenerateList, NotificationTemplatesList,
GetBasePath, SearchInit, PaginateInit, Rest,
ProcessErrors, Prompt, $state, GetChoices, Empty, Find, ngToast,
$compile, $filter, $location) {
$compile, $filter) {
var scope = $rootScope.$new(),
defaultUrl = GetBasePath('notification_templates'),
list = NotificationTemplatesList,
@ -182,9 +182,10 @@ export default
Rest.setUrl(url);
Rest.destroy()
.success(function () {
scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
if (parseInt($state.params.notification_template_id) === id) {
$state.go("^", null, {reload: true});
} else {
scope.search(list.iterator);
}
})
.error(function (data, status) {

View File

@ -8,7 +8,7 @@ import {templateUrl} from '../../shared/template-url/template-url.factory';
export default {
name: 'notifications',
route: '/notifications',
route: '/notification_templates',
templateUrl: templateUrl('notifications/notification-templates-list/list'),
controller: 'notificationTemplatesListController'
};

View File

@ -41,13 +41,8 @@ export default ['$scope', '$rootScope', '$compile', '$location',
})
.success(function(data) {
Wait('stop');
$scope.$emit("ReloadOrganzationCards", data.id);
if (base === 'organizations') {
$rootScope.flashMessage = "New organization successfully created!";
$location.path('/organizations/' + data.id);
} else {
ReturnToCaller(1);
}
$rootScope.$broadcast("EditIndicatorChange", "organizations", data.id);
$state.go('organizations.edit', {organization_id: data.id}, {reload: true});
})
.error(function(data, status) {
ProcessErrors($scope, data, status, form, {
@ -58,7 +53,6 @@ export default ['$scope', '$rootScope', '$compile', '$location',
};
$scope.formCancel = function() {
$scope.$emit("ReloadOrganzationCards");
$scope.$emit("ShowOrgListHeader");
$state.transitionTo('organizations');
};

View File

@ -27,9 +27,9 @@ export default ['$scope', '$rootScope', '$compile', '$location',
$scope.$parent.activeMode = 'edit';
$scope.$emit("HideOrgListHeader");
$scope.$parent.activeCard = parseInt(id);
$scope.$emit("ReloadOrganzationCards", id);
$scope.$emit("HideOrgListHeader");
$scope.organization_id = id;
@ -116,12 +116,11 @@ export default ['$scope', '$rootScope', '$compile', '$location',
}
Rest.setUrl(defaultUrl + id + '/');
Rest.put(params)
.success(function (data) {
.success(function () {
Wait('stop');
$scope.organization_name = $scope.name;
master = params;
$rootScope.flashMessage = "Your changes were successfully saved!";
$scope.$emit("ReloadOrganzationCards", data.id);
$state.go($state.current, {}, {reload: true});
})
.error(function (data, status) {
ProcessErrors($scope, data, status, OrganizationForm, { hdr: 'Error!',
@ -130,26 +129,22 @@ export default ['$scope', '$rootScope', '$compile', '$location',
};
$scope.formCancel = function () {
$scope.$emit("ReloadOrganzationCards");
$scope.$emit("ShowOrgListHeader");
$state.transitionTo('organizations');
$scope.$emit("ShowOrgListHeader");
};
// Related set: Add button
$scope.add = function (set) {
$rootScope.flashMessage = null;
$location.path('/' + base + '/' + $stateParams.organization_id + '/' + set);
};
// Related set: Edit button
$scope.edit = function (set, id) {
$rootScope.flashMessage = null;
$location.path('/' + set + '/' + id);
};
// Related set: Delete button
$scope['delete'] = function (set, itm_id, name, title) {
$rootScope.flashMessage = null;
var action = function () {
Wait('start');

View File

@ -65,7 +65,6 @@ export default ['$scope', '$rootScope', 'ProcessErrors', 'UserList', 'generateLi
$q.all(requests)
.then(function () {
Wait('stop');
$scope.$emit('ReloadOrganzationCards', $scope.$parent.org_id);
$scope.$parent.search('user');
$scope.closeModal();
}, function (error) {

View File

@ -93,6 +93,7 @@ export default ['$stateParams', '$scope', 'UserList', 'Rest', '$state', 'generat
};
$scope.formCancel = function(){
$scope.$emit("ReloadOrgListView");
$state.go('organizations');
};

View File

@ -336,6 +336,7 @@ export default ['$scope', '$rootScope', '$location', '$log',
};
$scope.formCancel = function(){
$scope.$parent.activeCard = null;
$state.go('organizations');
};

View File

@ -84,6 +84,7 @@ export default ['$scope', '$rootScope', '$location', '$log',
};
$scope.formCancel = function(){
$scope.$parent.activeCard = null;
$state.go('organizations');
};

View File

@ -343,6 +343,7 @@ export default ['$scope', '$rootScope', '$location', '$log',
};
$scope.formCancel = function(){
$scope.$parent.activeCard = null;
$state.go('organizations');
};

View File

@ -87,6 +87,7 @@ export default ['$scope', '$rootScope', '$location', '$log', '$stateParams',
};
$scope.formCancel = function(){
$scope.$parent.activeCard = null;
$state.go('organizations');
};
}

View File

@ -92,6 +92,7 @@
};
$scope.formCancel = function(){
$scope.$parent.activeCard = null;
$state.go('organizations');
};

View File

@ -27,9 +27,6 @@ export default ['$stateParams', '$scope', '$rootScope', '$location',
var val = {}, url = '/#/organizations/' + card.id + '/';
val.name = card.name;
val.id = card.id;
if (card.id + "" === cards.activeCard) {
val.isActiveCard = true;
}
val.description = card.description || undefined;
val.links = [];
val.links.push({
@ -73,14 +70,9 @@ export default ['$stateParams', '$scope', '$rootScope', '$location',
};
$scope.$on("ReloadOrgListView", function() {
if ($state.$current.self.name === "organizations") {
delete $scope.activeCard;
if ($scope.orgCards) {
$scope.orgCards = $scope.orgCards.map(function(card) {
delete card.isActiveCard;
return card;
});
}
if ($state.$current.self.name === "organizations" ||
$state.$current.self.name === "organizations.add") {
$scope.activeCard = null;
}
});
@ -118,10 +110,19 @@ export default ['$stateParams', '$scope', '$rootScope', '$location',
Rest.setUrl(url);
Rest.destroy()
.success(function() {
if ($state.current.name !== "organzations") {
$state.transitionTo("organizations");
Wait('stop');
if ($state.current.name !== "organizations") {
if ($state.current
.name === 'organizations.edit' &&
id === parseInt($state.params
.organization_id)) {
$state.go("organizations", {}, {reload: true});
} else {
$state.go($state.current, {}, {reload: true});
}
} else {
$state.go($state.current, {}, {reload: true});
}
$scope.$emit("ReloadOrganzationCards");
})
.error(function(data, status) {
ProcessErrors($scope, data, status, null, {

View File

@ -19,6 +19,11 @@
margin-top: 10px;
margin-bottom: 0px;
}
.OrgCards-search .TagSearch-bar {
margin-bottom: 0px;
}
.OrgCards .List-pagination{
width: 100%;
}

View File

@ -172,8 +172,12 @@ export default ['$location', '$compile', '$rootScope', 'SearchWidget', 'Paginate
// respond to changes to the edit indicator from
// the stateChangeStart event in app.js
this.scope.$on("EditIndicatorChange", function(e, list, id) {
e.targetScope.listBeingEdited = list;
e.targetScope.rowBeingEdited = id;
if (list === "organizations") {
e.targetScope.activeCard = parseInt(id);
} else {
e.targetScope.listBeingEdited = list;
e.targetScope.rowBeingEdited = id;
}
});
this.scope.$on("RemoveIndicator", function(e) {
@ -364,6 +368,9 @@ export default ['$location', '$compile', '$rootScope', 'SearchWidget', 'Paginate
}
html += (list.searchRowActions) ? "<div class='row'><div class=\"col-lg-8 col-md-8 col-sm-8 col-xs-12\">" : "";
if (list.searchRowActions && !list.searchSize) {
list.searchSize = 'col-lg-7 col-md-12 col-sm-12 col-xs-12';
}
if (options.showSearch=== undefined || options.showSearch === true) {
var tagSearch = getSearchHtml
.inject(getSearchHtml.getList(list),