'use strict'; (function() { var lemur = angular .module('lemur', [ 'ui.router', 'ngTable', 'ngAnimate', 'chart.js', 'restangular', 'angular-loading-bar', 'ui.bootstrap', 'angular-spinkit', 'toaster', 'uiSwitch', 'mgo-angular-wizard', 'satellizer', 'ngLetterAvatar', 'angular-clipboard', 'ngFileSaver', 'ngSanitize', 'ui.select' ]); function fetchData() { var initInjector = angular.injector(['ng']); var $http = initInjector.get('$http'); return $http.get('http://localhost:8000/api/1/auth/providers').then(function(response) { lemur.constant('providers', response.data); }, function(errorResponse) { console.log('Could not fetch SSO providers' + errorResponse); }); } function bootstrapApplication() { angular.element(document).ready(function() { angular.bootstrap(document, ['lemur']); }); } fetchData().then(bootstrapApplication); lemur.config(function ($stateProvider, $urlRouterProvider, $authProvider, providers) { $urlRouterProvider.otherwise('/welcome'); $stateProvider .state('welcome', { url: '/welcome', templateUrl: 'angular/welcome/welcome.html' }); _.each(providers, function(provider) { if ($authProvider.hasOwnProperty(provider.name)) { $authProvider[provider.name](provider); } else { $authProvider.oauth2(provider); } }); }); lemur.service('MomentService', function () { this.diffMoment = function (start, end) { if (end !== 'None') { return moment(end, 'YYYY-MM-DD HH:mm Z').diff(moment(start, 'YYYY-MM-DD HH:mm Z'), 'minutes') + ' minutes'; } return 'Unknown'; }; this.createMoment = function (date) { if (date !== 'None') { return moment(date, 'YYYY-MM-DD HH:mm Z').fromNow(); } return 'Unknown'; }; }); lemur.controller('datePickerController', function ($scope, $timeout){ $scope.open = function() { $timeout(function() { $scope.opened = true; }); }; }); lemur.service('DefaultService', function (LemurRestangular) { var DefaultService = this; DefaultService.get = function () { return LemurRestangular.all('defaults').customGET().then(function (defaults) { return defaults; }); }; }); lemur.directive('lemurBadRequest', [function () { return { template: '

{{ directiveData.message }}

' + '
' + '{{ key | titleCase }} - {{ value }}' + '
' }; }]); lemur.factory('LemurRestangular', function (Restangular, $location, $auth) { return Restangular.withConfig(function (RestangularConfigurer) { RestangularConfigurer.setBaseUrl('http://localhost:8000/api/1'); RestangularConfigurer.setDefaultHttpFields({withCredentials: true}); RestangularConfigurer.addResponseInterceptor(function (data, operation) { var extractedData; // .. to look for getList operations if (operation === 'getList') { // .. and handle the data and meta data extractedData = data.items; extractedData.total = data.total; } else { extractedData = data; } return extractedData; }); RestangularConfigurer.addFullRequestInterceptor(function (element, operation, route, url, headers, params) { // We want to make sure the user is auth'd before any requests if (!$auth.isAuthenticated()) { $location.path('/login'); return false; } var regExp = /\[([^)]+)\]/; var s = 'sorting'; var f = 'filter'; var newParams = {}; for (var item in params) { if (item.indexOf(s) > -1) { newParams.sortBy = regExp.exec(item)[1]; newParams.sortDir = params[item]; } else if (item.indexOf(f) > -1) { var key = regExp.exec(item)[1]; newParams.filter = key + ';' + params[item]; } else { newParams[item] = params[item]; } } return { params: newParams }; }); }); }); lemur.run(['$templateCache', function ($templateCache) { $templateCache.put('ng-table/pager.html', '
'); }]); }());