Skip to content

Commit

Permalink
fix: cleanly manage $state on /settings page
Browse files Browse the repository at this point in the history
This commit fixes the settings page.  The problem originated from a
missing import of $routeParams into the setting controller, which was
superceded by a ui-router.  This change wasn't detected because no end
to end test was written for the settings page.  A subsequent commit will
fix this issue.
  • Loading branch information
jniles committed Apr 13, 2016
1 parent 4be4fa3 commit 04ff08d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
10 changes: 6 additions & 4 deletions client/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ <h4><a class="title-content">{{AppCtrl.projectName}}</a></h4>

<div class="flex-footer" ng-cloak>
<ul>
<li><a class="session" ng-click="AppCtrl.settings()">
<span class="glyphicon glyphicon-cog"></span>
<span class="link-label">User Settings</span>
</a></li>
<li>
<a class="session" ng-click="AppCtrl.settings()">
<span class="glyphicon glyphicon-cog"></span>
<span class="link-label">User Settings</span>
</a>
</li>
<li>
<a
id="expandnav"
Expand Down
2 changes: 1 addition & 1 deletion client/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function bhimaConfig($stateProvider, $urlRouterProvider, $urlMatcherFactoryProvi
templateUrl: 'partials/exchange/exchange.html'
})
.state('settings', {
url : '/settings',
url : '/settings?previous',
controller: 'settings as SettingsCtrl',
templateUrl: 'partials/settings/settings.html'
})
Expand Down
8 changes: 4 additions & 4 deletions client/src/partials/bhima/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ angular.module('bhima.controllers')
.controller('ApplicationController', ApplicationController);

ApplicationController.$inject = [
'$location', '$timeout', 'AppCache', 'appstate',
'connect', 'util', 'SessionService', 'LanguageService'
'$timeout', 'AppCache', 'appstate', 'connect', 'util',
'SessionService', 'LanguageService', '$state'
];

function ApplicationController($location, $timeout, AppCache, appstate, connect, util, Session, Languages) {
function ApplicationController($timeout, AppCache, appstate, connect, util, Session, Languages, $state) {
var vm = this;

// load in the application cache
Expand Down Expand Up @@ -130,6 +130,6 @@ function ApplicationController($location, $timeout, AppCache, appstate, connect,
};

vm.settings = function settings() {
$location.path('/settings');
$state.go('settings', { previous : $state.$current.name });
};
}
10 changes: 5 additions & 5 deletions client/src/partials/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
</select>
</div>


<button ng-if="SettingsCtrl.previous" class="btn btn-default" ui-sref="{{ SettingsCtrl.previous }}">
<span class="glyphicon glyphicon-circle-arrow-left"></span> {{ "UTIL.BACK" | translate }}
</button>

<button
class="btn btn-default"
ng-click="SettingsCtrl.logout()">
<span class="glyphicon glyphicon-log-out"></span> {{ "SETTINGS.LOGOUT" | translate }}
</button>

</div>
</div>

<button ng-if="!!SettingsCtrl.url" class="btn btn-sm btn-default" ng-click="SettingsCtrl.back()">
<span class="glyphicon glyphicon-circle-arrow-left"></span> {{ "UTIL.BACK" | translate }}
</button>
</div>
</div>
23 changes: 9 additions & 14 deletions client/src/partials/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,33 @@ angular.module('bhima.controllers')
.controller('settings', SettingsController);

SettingsController.$inject = [
'$http', '$routeParams', '$location', 'LanguageService', 'SessionService'
'$state', 'LanguageService', 'SessionService'
];

/**
* Settings Page Controller
*
* The settings page allows a user to control the local application settings,
* such as display language.
*
* @constructor
*/
function SettingsController($http, $routeParams, $location, Languages, Session) {
function SettingsController($state, Languages, Session) {
var vm = this;

// the url to return to (using the back button)
vm.url = $routeParams.url || '';
vm.previous = $state.params.previous;

// load settings from services
vm.settings = { language : Languages.key };

// bind methods/services to the view
vm.languageService = Languages;
vm.logout = Session.logout;

/** bind the language service for use in the view */
Languages.read()
.then(function (languages) {
vm.languages = languages;
});

vm.languageService = Languages;

/** returns a user to the previous url */
vm.back = back;

function back() {
$location.url(vm.url);
}

vm.logout = Session.logout;
}

0 comments on commit 04ff08d

Please sign in to comment.