Skip to content

Commit

Permalink
fix: default value for $state.current on refresh (#1698)
Browse files Browse the repository at this point in the history
* Prevent $state.current to become empty afer refresh in
- User Management
- Account Edit
- Billing Sercice Updare
- Inventory actions modal

* Update and improve the check of state params in
- Account Management
- Inventory`
  • Loading branch information
lomamech authored and jniles committed May 30, 2017
1 parent 5bd3e00 commit eafc0bd
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
22 changes: 18 additions & 4 deletions client/src/modules/accounts/edit/accounts.edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ angular.module('bhima.controllers')
.controller('AccountEditController', AccountEditController);

AccountEditController.$inject = [
'$rootScope', '$state', 'AccountStoreService', 'AccountService', 'NotifyService', 'util', 'bhConstants', 'ModalService'
'$rootScope', '$state', 'AccountStoreService', 'AccountService', 'NotifyService', 'util', 'bhConstants', 'ModalService', 'appcache'
];

function AccountEditController($rootScope, $state, AccountStore, Accounts, Notify, util, Constants, ModalService) {
function AccountEditController($rootScope, $state, AccountStore, Accounts, Notify, util, Constants, ModalService, AppCache) {
var accountStore, typeStore;
var cache = AppCache('AccountEdit');
var vm = this;
var id = $state.params.id, parentId = $state.params.parentId;
vm.stateParams = {};
vm.stateCurrent = {};

if($state.params.id || $state.current.name){
vm.stateParams = cache.stateParams = $state.params;
vm.stateCurrent = cache.stateCurrent = $state.current;
} else {
vm.stateParams = cache.stateParams;
vm.stateCurrent = cache.stateCurrent;
}

var id = vm.stateParams.id,
parentId = vm.stateParams.parentId;

vm.Constants = Constants;

// expose utility methods
Expand All @@ -31,7 +45,7 @@ function AccountEditController($rootScope, $state, AccountStore, Accounts, Notif
edit : 'accounts.edit'
};

vm.state = angular.copy($state.current.name);
vm.state = angular.copy(vm.stateCurrent.name);
vm.isCreateState = vm.state === vm.states.create;

// varaibles to track custom modal error handling, these will be replaced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('bhima.controllers')
.controller('BillingServicesUpdateController', BillingServicesUpdateController);

BillingServicesUpdateController.$inject = [
'$state', 'BillingServicesService', '$uibModalInstance', 'util',
'$state', 'BillingServicesService', '$uibModalInstance', 'util', 'appcache'
];

/**
Expand All @@ -12,8 +12,15 @@ BillingServicesUpdateController.$inject = [
* Importantly, both this controller and the BillingServicesUpdateController
* use the same template, billing-services/form.html.
*/
function BillingServicesUpdateController($state, BillingServices, ModalInstance, util) {
function BillingServicesUpdateController($state, BillingServices, ModalInstance, util, AppCache) {
var vm = this;
var cache = AppCache('BillingServices');

if($state.params.id){
vm.stateParams = cache.stateParams = $state.params;
} else {
vm.stateParams = cache.stateParams;
}

// the form title is defined in the JS to allow us to reuse templates
vm.title = 'BILLING_SERVICES.FORM.UPDATE';
Expand Down Expand Up @@ -42,7 +49,7 @@ function BillingServicesUpdateController($state, BillingServices, ModalInstance,
function startup() {

// load the billing service by id
BillingServices.read($state.params.id)
BillingServices.read(vm.stateParams.id)
.then(function (service) {

// set the label to the label of the fetched service
Expand Down Expand Up @@ -75,7 +82,7 @@ function BillingServicesUpdateController($state, BillingServices, ModalInstance,
}

// submit data to the server
return BillingServices.update($state.params.id, vm.model)
return BillingServices.update(vm.stateParams.id, vm.model)
.then(function (data) {
ModalInstance.close(data.id);
})
Expand Down
3 changes: 3 additions & 0 deletions client/src/modules/inventory/inventory.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ angular.module('bhima.routes')
})
.state('inventory.create', {
url : '/create',
params : {
creating : { value : true }
},
onEnter :['$state', 'ModalService', onEnterFactory('create')],
onExit : ['$uibModalStack', closeModal]
})
Expand Down
17 changes: 13 additions & 4 deletions client/src/modules/inventory/list/modals/actions.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ angular.module('bhima.controllers')

InventoryListActionsModalController.$inject = [
'AccountService', 'InventoryService','NotifyService',
'$uibModalInstance', '$state', 'util'
'$uibModalInstance', '$state', 'util', 'appcache'
];

function InventoryListActionsModalController(Account, Inventory, Notify, Instance, $state, util) {
function InventoryListActionsModalController(Account, Inventory, Notify, Instance, $state, util, AppCache) {
var vm = this;

var cache = AppCache('InventoryList');

// this is the model
vm.item = {};
vm.stateParams = {};

vm.stateParams = cache.stateParams = $state.params;
if($state.params.uuid || $state.params.creating){
vm.stateParams = cache.stateParams = $state.params;
} else {
vm.stateParams = cache.stateParams;
}

// this is the UUID of the update state.
vm.identifier = $state.params.uuid;
vm.identifier = vm.stateParams.uuid;
vm.isUpdateState = angular.isDefined(vm.identifier);
vm.isCreateState = !angular.isDefined(vm.identifier);

Expand Down
19 changes: 15 additions & 4 deletions client/src/modules/users/user.modal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
angular.module('bhima.controllers')
.controller('UserModalController', UserModalController);

UserModalController.$inject = ['$state', 'ProjectService', 'UserService', 'NotifyService'];
UserModalController.$inject = ['$state', 'ProjectService', 'UserService', 'NotifyService', 'appcache'];

function UserModalController($state, Projects, Users, Notify) {
function UserModalController($state, Projects, Users, Notify, AppCache) {
var vm = this;

var cache = AppCache('UserModal');

// the user object that is either edited or created
vm.user = {};
vm.isCreating = $state.params.creating;
vm.stateParams = {};

if($state.params.creating || $state.params.id){
vm.stateParams = cache.stateParams = $state.params;
} else {
vm.stateParams = cache.stateParams;
}


vm.isCreating = vm.stateParams.creating;

//exposed methods
vm.submit = submit;
Expand All @@ -24,7 +35,7 @@ function UserModalController($state, Projects, Users, Notify) {

if (!vm.isCreating) {

Users.read($state.params.id)
Users.read(vm.stateParams.id)
.then(function (user) {
vm.user = user;
})
Expand Down
13 changes: 10 additions & 3 deletions client/src/modules/users/userPermission.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ angular.module('bhima.controllers')
.controller('UserPermissionModalController', UserPermissionModalController);

UserPermissionModalController.$inject = [
'$translate', '$http', '$state', 'util', 'UserService', 'NodeTreeService', 'NotifyService'
'$translate', '$http', '$state', 'util', 'UserService', 'NodeTreeService', 'NotifyService', 'appcache'
];


function UserPermissionModalController($translate, $http, $state, util, Users, NT, Notify) {
function UserPermissionModalController($translate, $http, $state, util, Users, NT, Notify, AppCache) {
var vm = this;
var cache = AppCache('UserPermission');

if($state.params.id){
vm.stateParams = cache.stateParams = $state.params;
} else {
vm.stateParams = cache.stateParams;
}

vm.user = {}; // the user object that is either edited or created

Expand Down Expand Up @@ -129,7 +136,7 @@ function UserPermissionModalController($translate, $http, $state, util, Users, N
$state.go('users.list');
}

Users.read($state.params.id)
Users.read(vm.stateParams.id)
.then(function (user) {
vm.user = user;
editPermissions(user);
Expand Down

0 comments on commit eafc0bd

Please sign in to comment.