'use strict'; 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' ]) .config(function ($stateProvider, $urlRouterProvider, $authProvider) { $urlRouterProvider.otherwise('/welcome'); $stateProvider .state('welcome', { url: '/welcome', templateUrl: 'angular/welcome/welcome.html' }); $authProvider.oauth2({ name: 'example', url: 'http://localhost:5000/api/1/auth/ping', redirectUri: 'http://localhost:3000/', clientId: 'client-id', responseType: 'code', scope: ['openid', 'email', 'profile', 'address'], scopeDelimiter: ' ', authorizationEndpoint: 'https://example.com/as/authorization.oauth2', requiredUrlParams: ['scope'] }); }); 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.factory('LemurRestangular', function (Restangular, $location, $auth) { return Restangular.withConfig(function (RestangularConfigurer) { RestangularConfigurer.setBaseUrl('http://localhost:5000/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.setErrorInterceptor(function(response) { if (response.status === 400) { if (response.data.message) { var data = ''; _.each(response.data.message, function (value, key) { data = data + ' ' + key + ' ' + value; }); response.data.message = data; } } }); 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', '
'); }]);