This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
/
index.ts
121 lines (103 loc) · 3.32 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright (C) 2018-present evan GmbH.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License, version 3,
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see http://www.gnu.org/licenses/ or
write to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA, 02110-1301 USA, or download the license from
the following URL: https://evan.network/license/
*/
import {
getDomainName
} from '@evan.network/ui-dapp-browser';
import {
NgModule, // @angular/core
CommonModule, // @angular/common
RouterModule, Routes, // @angular/router
IonicModule, IonicApp, // ionic-angular
BrowserAnimationsModule, // @angular/platform-browser/animations
} from '@evan.network/ui-angular-libs';
import {
AngularCore,
DAppLoaderComponent,
buildModuleRoutes,
BootstrapComponent,
startAngularApplication,
createIonicAppElement
} from '@evan.network/ui-angular-core';
import { DashboardComponent } from './components/dashboard/dashboard';
import { DashboardTranslations } from './i18n/registry';
/**************************************************************************************************/
function getRoutes(): Routes {
return buildModuleRoutes(
`dashboard.${ getDomainName() }`,
DashboardComponent,
[
{
path: '',
redirectTo: `favorites.${getDomainName()}`,
pathMatch: 'full'
},
{
path: '**',
component: DAppLoaderComponent,
data: {
state: 'unkown',
navigateBack: true
}
}
]
);
}
/**
* Returns the module configuration for the normal or dispatcher module.
* In case of the dispatcher module, Router configurations and BrowserModule imports are excluded
* to load the module during runtime by the dispatcher service.
*
* @param isDispatcher boolean value if the config is used for the dispatcher module
*/
function getConfig(isDispatcher?: boolean) {
let config: any = {
imports: [
CommonModule,
AngularCore,
],
providers: [
DashboardTranslations,
],
};
if (!isDispatcher) {
config.imports.unshift(BrowserAnimationsModule);
config.imports.unshift(RouterModule.forRoot(getRoutes(), { enableTracing: false, }));
config.imports.push(IonicModule.forRoot(BootstrapComponent, {
mode: 'md'
}));
config.bootstrap = [
IonicApp
];
config.declarations = [
BootstrapComponent,
DashboardComponent,
];
}
return config;
}
@NgModule(getConfig(true))
export class DispatcherModule {
constructor() { }
}
@NgModule(getConfig(false))
class DashboardModule {
constructor(private translations: DashboardTranslations) { }
}
export async function startDApp(container, dbcpName) {
const ionicAppEl = createIonicAppElement(container, dbcpName);
await startAngularApplication(DashboardModule, getRoutes());
container.appendChild(ionicAppEl);
}