app.config.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. app.run(function($rootScope, $location) {
  2. $rootScope.$on('$routeChangeSuccess', function() {
  3. $rootScope.currentMenuItem = $location.path() || '/home';
  4. });
  5. });
  6. app.run(['editableOptions', function(editableOptions) {
  7. editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
  8. }]);
  9. app.config(['$translateProvider', function($translateProvider) {
  10. // var translations = {
  11. // en: {
  12. // 'Authors': 'Authors'
  13. // },
  14. // ru: {
  15. // 'Authors': 'Автор'
  16. // }
  17. // }
  18. // $translateProvider
  19. // .translations('en', translations.en)
  20. // .translations('ru', translations.ru)
  21. // .preferredLanguage(localStorage.getItem('preferredLanguage') || 'en');
  22. $translateProvider.useStaticFilesLoader({
  23. prefix: 'i18n/',
  24. suffix: '.json'
  25. });
  26. $translateProvider.preferredLanguage(localStorage.getItem('preferredLanguage') || 'en');
  27. }]);
  28. // check authorization
  29. app.config(['$httpProvider', function($httpProvider) {
  30. $httpProvider.interceptors.push(['$q', '$location', function($q, $location) {
  31. return {
  32. request: function(config) {
  33. config.headers = config.headers || {};
  34. if (localStorage.getItem('authToken')) {
  35. config.headers.Authorization = 'Bearer ' + localStorage.getItem('authToken');
  36. }
  37. return config;
  38. },
  39. responseError: function(response) {
  40. if (response.status === 401) {
  41. $location.path('/');
  42. }
  43. return $q.reject(response);
  44. }
  45. };
  46. }]);
  47. }]);