blob: 07a9875f301d05123e4612e6b5dc924153508d5b [file] [log] [blame]
Matteo Scandolo9b460042017-04-14 16:24:45 -07001import {IXosModelDiscovererService} from '../../datasources/helpers/model-discoverer.service';
2import {IXosOnboarder} from '../../extender/services/onboard.service';
3class LoaderCtrl {
4 static $inject = [
5 '$log',
6 '$rootScope',
7 '$location',
8 '$timeout',
9 'XosConfig',
10 'XosModelDiscoverer',
11 `XosOnboarder`
12 ];
13
14 public aaaaa = 'ciao';
15
16 constructor (
17 private $log: ng.ILogService,
18 private $rootScope: ng.IScope,
19 private $location: ng.ILocationService,
20 private $timeout: ng.ITimeoutService,
21 private XosConfig: any,
22 private XosModelDiscoverer: IXosModelDiscovererService,
23 private XosOnboarder: IXosOnboarder
24 ) {
25
26 this.run();
27 }
28
29 public run() {
30 if (this.XosModelDiscoverer.areModelsLoaded()) {
31 this.moveOnTo(this.XosConfig.lastVisitedUrl);
32 }
33 else {
34 this.XosModelDiscoverer.discover()
35 // NOTE loading XOS Models
36 .then((res) => {
37 if (res) {
38 this.$log.info('[XosLoader] All models loaded');
39 }
40 else {
41 this.$log.info('[XosLoader] Failed to load some models, moving on.');
42 }
43 return this.XosOnboarder.onboard();
44 })
45 // NOTE loading GUI Extensions
46 .then(() => {
47 this.moveOnTo(this.XosConfig.lastVisitedUrl);
48 })
49 .finally(() => {
50 // NOTE it is in a timeout as the searchService is loaded after that
51 // we navigate to another page
52 this.$timeout(() => {
53 this.$rootScope.$emit('xos.core.modelSetup');
54 }, 500);
55 });
56 }
57 }
58
59 public moveOnTo(url: string) {
60 this.$log.info(`[XosLoader] Redirecting to: ${url}`);
61 switch (url) {
62 case '':
63 case '/':
64 case '/loader':
65 case '/login':
66 this.$location.path('/dashboard');
67 break;
68 default:
69 this.$timeout(() => {
70 this.$location.path(url);
71 }, 500);
72 break;
73 }
74 }
75}
76
77export const xosLoader: angular.IComponentOptions = {
78 template: `
79 <div class="loader"></div>
80 `,
81 controllerAs: 'vm',
82 controller: LoaderCtrl
83};