Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 1 | /// <reference path="../typings/index.d.ts" /> |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 2 | |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 3 | import * as angular from 'angular'; |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 4 | |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 5 | import 'angular-ui-router'; |
| 6 | import 'angular-resource'; |
| 7 | import 'angular-cookies'; |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 8 | import '../node_modules/ngprogress/build/ngProgress'; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 9 | import routesConfig from './routes'; |
| 10 | |
| 11 | import {main} from './app/main'; |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 12 | |
| 13 | import './index.scss'; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 14 | import {xosCore} from './app/core/index'; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 15 | import {xosDataSources} from './app/datasources/index'; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 16 | import {xosViews} from './app/views/index'; |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 17 | import {xosTemplate} from './app/template/index'; |
| 18 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 19 | import { |
| 20 | interceptorConfig, userStatusInterceptor, CredentialsInterceptor, |
| 21 | NoHyperlinksInterceptor |
| 22 | } from './interceptors'; |
Matteo Scandolo | 5655bdc | 2016-12-16 08:32:15 -0800 | [diff] [blame] | 23 | import {IXosPageTitleService} from './app/core/services/page-title'; |
Matteo Scandolo | 0496423 | 2017-01-07 12:53:46 -0800 | [diff] [blame] | 24 | import {IXosAuthService} from './app/datasources/rest/auth.rest'; |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 25 | import {IXosNavigationRoute} from './app/core/services/navigation'; |
Matteo Scandolo | 17bf824 | 2017-01-23 17:30:39 -0800 | [diff] [blame] | 26 | import XosLogDecorator from './decorators'; |
Matteo Scandolo | 4e87023 | 2017-01-30 13:43:05 -0800 | [diff] [blame] | 27 | import {xosExtender} from './app/extender/index'; |
Matteo Scandolo | 5053cbe | 2017-01-31 17:37:56 -0800 | [diff] [blame] | 28 | import {IXosKeyboardShortcutService} from './app/core/services/keyboard-shortcut'; |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 29 | import {IXosModelDiscovererService} from './app/datasources/helpers/model-discoverer.service'; |
Matteo Scandolo | a62adbc | 2017-03-02 15:37:34 -0800 | [diff] [blame] | 30 | import {xosServiceGraph} from './app/service-graph/index'; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 31 | |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 32 | export interface IXosAppConfig { |
| 33 | apiEndpoint: string; |
| 34 | websocketClient: string; |
| 35 | } |
| 36 | |
| 37 | export interface IXosStyleConfig { |
| 38 | projectName: string; |
| 39 | payoff: string; |
| 40 | favicon: string; |
| 41 | background: string; |
| 42 | logo: string; |
| 43 | routes: IXosNavigationRoute[]; |
| 44 | } |
| 45 | |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 46 | angular |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 47 | .module('app', [ |
| 48 | xosCore, |
| 49 | xosDataSources, |
| 50 | xosViews, |
Matteo Scandolo | 4e87023 | 2017-01-30 13:43:05 -0800 | [diff] [blame] | 51 | xosExtender, |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 52 | xosTemplate, // template module |
Matteo Scandolo | a62adbc | 2017-03-02 15:37:34 -0800 | [diff] [blame] | 53 | xosServiceGraph, |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 54 | 'ui.router', |
| 55 | 'ngResource', |
Matteo Scandolo | 042ea63 | 2017-03-01 19:02:34 -0800 | [diff] [blame] | 56 | 'ngProgress' |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 57 | ]) |
Matteo Scandolo | 17bf824 | 2017-01-23 17:30:39 -0800 | [diff] [blame] | 58 | .config(XosLogDecorator) |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 59 | .config(routesConfig) |
| 60 | .config(interceptorConfig) |
| 61 | .factory('UserStatusInterceptor', userStatusInterceptor) |
| 62 | .factory('CredentialsInterceptor', CredentialsInterceptor) |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 63 | .factory('NoHyperlinksInterceptor', NoHyperlinksInterceptor) |
| 64 | .component('xos', main) |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 65 | .provider('XosConfig', function(){ |
| 66 | // save the last visited state before reload |
| 67 | const lastVisitedUrl = window.location.hash.replace('#', ''); |
| 68 | this.$get = [() => { |
| 69 | return { |
| 70 | lastVisitedUrl |
| 71 | }; |
| 72 | }] ; |
| 73 | return this; |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 74 | }) |
Matteo Scandolo | 5655bdc | 2016-12-16 08:32:15 -0800 | [diff] [blame] | 75 | .run(( |
Matteo Scandolo | 17bf824 | 2017-01-23 17:30:39 -0800 | [diff] [blame] | 76 | $rootScope: ng.IRootScopeService, |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 77 | $transitions: any, |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 78 | $log: ng.ILogService, |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 79 | $location: ng.ILocationService, |
| 80 | $state: ng.ui.IStateService, |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 81 | StyleConfig: IXosStyleConfig, |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 82 | XosModelDiscoverer: IXosModelDiscovererService, |
Matteo Scandolo | 0496423 | 2017-01-07 12:53:46 -0800 | [diff] [blame] | 83 | AuthService: IXosAuthService, |
Matteo Scandolo | 5053cbe | 2017-01-31 17:37:56 -0800 | [diff] [blame] | 84 | XosKeyboardShortcut: IXosKeyboardShortcutService, |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 85 | PageTitle: IXosPageTitleService // NOTE this service is not used, but needs to be loaded somewhere |
Matteo Scandolo | 5655bdc | 2016-12-16 08:32:15 -0800 | [diff] [blame] | 86 | ) => { |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 87 | // handle style configs |
| 88 | $rootScope['favicon'] = `./app/images/brand/${StyleConfig.favicon}`; |
| 89 | if ($state.current.data && $state.current.data.specialClass) { |
| 90 | $rootScope['class'] = $state.current.data.specialClass; |
| 91 | } |
| 92 | $transitions.onSuccess({ to: '**' }, (transtion) => { |
| 93 | if ($state.current.data && $state.current.data.specialClass) { |
| 94 | $rootScope['class'] = transtion.$to().data.specialClass; |
| 95 | } |
| 96 | else { |
| 97 | $rootScope['class'] = ''; |
| 98 | } |
| 99 | }); |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 100 | |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 101 | // check the user login (on route change) |
Matteo Scandolo | 0496423 | 2017-01-07 12:53:46 -0800 | [diff] [blame] | 102 | $transitions.onSuccess({ to: '**' }, (transtion) => { |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 103 | if (!AuthService.isAuthenticated()) { |
Matteo Scandolo | 520a8a1 | 2017-03-10 17:31:37 -0800 | [diff] [blame] | 104 | AuthService.clearUser(); |
Matteo Scandolo | 0496423 | 2017-01-07 12:53:46 -0800 | [diff] [blame] | 105 | $state.go('login'); |
| 106 | } |
| 107 | }); |
| 108 | |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 109 | // if the user is authenticated |
Matteo Scandolo | 520a8a1 | 2017-03-10 17:31:37 -0800 | [diff] [blame] | 110 | $log.info(`[XOS] Is user authenticated? ${AuthService.isAuthenticated()}`); |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 111 | if (AuthService.isAuthenticated()) { |
Matteo Scandolo | 9b46004 | 2017-04-14 16:24:45 -0700 | [diff] [blame] | 112 | $state.go('loader'); |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 113 | } |
Matteo Scandolo | 520a8a1 | 2017-03-10 17:31:37 -0800 | [diff] [blame] | 114 | else { |
| 115 | AuthService.clearUser(); |
| 116 | $state.go('login'); |
| 117 | } |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 118 | |
Matteo Scandolo | 5053cbe | 2017-01-31 17:37:56 -0800 | [diff] [blame] | 119 | // register keyboard shortcut |
| 120 | XosKeyboardShortcut.setup(); |
| 121 | |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 122 | XosKeyboardShortcut.registerKeyBinding({ |
Matteo Scandolo | c817849 | 2017-04-11 17:55:13 -0700 | [diff] [blame] | 123 | key: 'D', |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 124 | cb: () => { |
| 125 | if (window.localStorage.getItem('debug') === 'true') { |
| 126 | $log.info(`[XosKeyboardShortcut] Disabling debug`); |
| 127 | window.localStorage.setItem('debug', 'false'); |
| 128 | } |
| 129 | else { |
| 130 | window.localStorage.setItem('debug', 'true'); |
| 131 | $log.info(`[XosKeyboardShortcut] Enabling debug`); |
| 132 | } |
| 133 | }, |
| 134 | description: 'Toggle debug messages in browser console' |
| 135 | }, 'global'); |
| 136 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 137 | }); |
Matteo Scandolo | 80c3a65 | 2017-01-06 10:48:31 -0800 | [diff] [blame] | 138 | |