github.com/sym3tri/etcd@v0.2.1-0.20140422215517-a563d82f95d6/mod/dashboard/app/etcd-dashboard.js (about)

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