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 | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 3 | |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 4 | import * as angular from 'angular'; |
Matteo Scandolo | d819c92 | 2016-12-02 14:06:14 -0800 | [diff] [blame] | 5 | |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 6 | import 'angular-ui-router'; |
| 7 | import 'angular-resource'; |
| 8 | import 'angular-cookies'; |
| 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 | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 23 | import {IXosCrudData} from './app/views/crud/crud'; |
Matteo Scandolo | 5655bdc | 2016-12-16 08:32:15 -0800 | [diff] [blame] | 24 | import {IXosPageTitleService} from './app/core/services/page-title'; |
Matteo Scandolo | 0496423 | 2017-01-07 12:53:46 -0800 | [diff] [blame] | 25 | import {IXosAuthService} from './app/datasources/rest/auth.rest'; |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 26 | import {IXosModelSetupService} from './app/core/services/helpers/model-setup.helpers'; |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 27 | import {IXosNavigationRoute} from './app/core/services/navigation'; |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 28 | |
| 29 | export interface IXosState extends angular.ui.IState { |
| 30 | data: IXosCrudData; |
| 31 | }; |
| 32 | |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 33 | export interface IXosAppConfig { |
| 34 | apiEndpoint: string; |
| 35 | websocketClient: string; |
| 36 | } |
| 37 | |
| 38 | export interface IXosStyleConfig { |
| 39 | projectName: string; |
| 40 | payoff: string; |
| 41 | favicon: string; |
| 42 | background: string; |
| 43 | logo: string; |
| 44 | routes: IXosNavigationRoute[]; |
| 45 | } |
| 46 | |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 47 | angular |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 48 | .module('app', [ |
| 49 | xosCore, |
| 50 | xosDataSources, |
| 51 | xosViews, |
| 52 | 'ui.router', |
| 53 | 'ngResource', |
| 54 | xosTemplate // template module |
| 55 | ]) |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 56 | .config(routesConfig) |
| 57 | .config(interceptorConfig) |
| 58 | .factory('UserStatusInterceptor', userStatusInterceptor) |
| 59 | .factory('CredentialsInterceptor', CredentialsInterceptor) |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 60 | .factory('NoHyperlinksInterceptor', NoHyperlinksInterceptor) |
| 61 | .component('xos', main) |
Matteo Scandolo | 828d1e8 | 2017-01-17 14:49:38 -0800 | [diff] [blame] | 62 | .run(function($rootScope: ng.IRootScopeService, $transitions: any, StyleConfig: IXosStyleConfig) { |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 63 | $rootScope['favicon'] = `./app/images/brand/${StyleConfig.favicon}`; |
Matteo Scandolo | 266907e | 2016-12-20 13:41:42 -0800 | [diff] [blame] | 64 | $transitions.onSuccess({ to: '**' }, (transtion) => { |
| 65 | if (transtion.$to().name === 'login') { |
| 66 | $rootScope['class'] = 'blank'; |
| 67 | } |
| 68 | else { |
| 69 | $rootScope['class'] = ''; |
| 70 | } |
| 71 | }); |
| 72 | }) |
Matteo Scandolo | 5655bdc | 2016-12-16 08:32:15 -0800 | [diff] [blame] | 73 | .run(( |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 74 | $transitions: any, |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 75 | $location: ng.ILocationService, |
| 76 | $state: ng.ui.IStateService, |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 77 | ModelSetup: IXosModelSetupService, |
Matteo Scandolo | 0496423 | 2017-01-07 12:53:46 -0800 | [diff] [blame] | 78 | AuthService: IXosAuthService, |
Matteo Scandolo | bac2245 | 2017-01-03 16:35:32 -0800 | [diff] [blame] | 79 | toastr: ng.toastr.IToastrService, |
Matteo Scandolo | 5655bdc | 2016-12-16 08:32:15 -0800 | [diff] [blame] | 80 | PageTitle: IXosPageTitleService |
| 81 | ) => { |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 82 | |
Matteo Scandolo | 0496423 | 2017-01-07 12:53:46 -0800 | [diff] [blame] | 83 | // check the user login |
| 84 | $transitions.onSuccess({ to: '**' }, (transtion) => { |
| 85 | if (!AuthService.getUser()) { |
| 86 | $state.go('login'); |
| 87 | } |
| 88 | }); |
| 89 | |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 90 | // save the last visited state before reload |
| 91 | const lastRoute = window.location.hash.replace('#', ''); |
| 92 | |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 93 | // if the user is authenticated |
| 94 | if (AuthService.getUser()) { |
| 95 | ModelSetup.setup() |
| 96 | .then(() => { |
| 97 | // after setting up dynamic routes, redirect to previous state |
| 98 | $location.path(lastRoute); |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 99 | }); |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 100 | } |
Matteo Scandolo | e0d71ea | 2016-12-19 11:56:12 -0800 | [diff] [blame] | 101 | |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 102 | }); |
Matteo Scandolo | 80c3a65 | 2017-01-06 10:48:31 -0800 | [diff] [blame] | 103 | |