etcd-dashboard.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict';
  2. angular.module('etcd.module', []);
  3. angular.module('etcd.ui', []);
  4. angular.module('etcd.page', []);
  5. // The main etcd dashboard module.
  6. var etcdDashboard = angular.module('etcd.dashboard', [
  7. 'coreos',
  8. 'etcd.module',
  9. 'etcd.ui',
  10. 'etcd.page',
  11. 'ngRoute',
  12. 'ngResource',
  13. 'ngAnimate',
  14. 'ui.bootstrap',
  15. 'templates-views',
  16. 'underscore',
  17. 'jquery',
  18. 'd3'
  19. ]);
  20. // Routes
  21. etcdDashboard.config(function($routeProvider, $locationProvider, $httpProvider,
  22. $compileProvider, pollerSvcProvider, errorMessageSvcProvider,
  23. configSvcProvider) {
  24. var siteBasePath = '/mod/dashboard';
  25. // Make routes less verbose.
  26. function path(suffix) {
  27. return siteBasePath + suffix;
  28. }
  29. // coreos-web config.
  30. configSvcProvider.config({
  31. siteBasePath: siteBasePath,
  32. libPath: '/mod/dashboard/static/coreos-web'
  33. });
  34. // Use HTML5 push state.
  35. $locationProvider.html5Mode(true);
  36. // Parse error messages from the api.
  37. errorMessageSvcProvider.registerFormatter('etcdApi', function(resp) {
  38. if (resp.data && resp.data.message) {
  39. return resp.data.message;
  40. }
  41. return 'An error occurred.';
  42. });
  43. // Emit event for any request error.
  44. $httpProvider.interceptors.push('interceptorErrorSvc');
  45. // Poller settings.
  46. pollerSvcProvider.settings({
  47. interval: 5000,
  48. maxRetries: 5
  49. });
  50. // Configure routes.
  51. $routeProvider
  52. .when(path('/'), {
  53. redirectTo: path('/browser')
  54. })
  55. .when(path('/browser'), {
  56. controller: 'BrowserCtrl',
  57. templateUrl: '/page/browser/browser.html',
  58. title: 'Key Browser'
  59. })
  60. .when(path('/stats'), {
  61. controller: 'StatsCtrl',
  62. templateUrl: '/page/stats/stats.html',
  63. title: 'Stats'
  64. })
  65. .otherwise({
  66. templateUrl: '/404.html',
  67. title: 'Page Not Found (404)'
  68. });
  69. })
  70. // After bootstrap initialization.
  71. .run(function($http, $rootScope, $location, $window, $route, _, configSvc,
  72. toastSvc, CORE_EVENT) {
  73. // Show toast when poller fails.
  74. $rootScope.$on(CORE_EVENT.POLL_ERROR, function() {
  75. toastSvc.error('Error polling for data.');
  76. });
  77. // Show toast for any non-suppressed http response errors.
  78. $rootScope.$on(CORE_EVENT.RESP_ERROR, function(e, rejection) {
  79. var errorMsg = 'Request Error';
  80. if (rejection.data && rejection.data.message) {
  81. errorMsg = rejection.data.message;
  82. }
  83. toastSvc.error(errorMsg);
  84. });
  85. // Redirect to 404 page if event is thrown.
  86. $rootScope.$on(CORE_EVENT.PAGE_NOT_FOUND, function() {
  87. $location.url(configSvc.get().siteBaseUrl + '/404');
  88. });
  89. });