blob: 02fa73644016093caae2972c035b68ecdf20850d [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
2 Copyright 2020 TATA ELXSI
3
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17*/
18/**
19 * @file Instance Module file
20 */
21import { CommonModule, LOCATION_INITIALIZED } from '@angular/common';
22import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http';
23import { APP_INITIALIZER, Injector, NgModule } from '@angular/core';
24import { FormsModule, ReactiveFormsModule } from '@angular/forms';
25import { BrowserModule } from '@angular/platform-browser';
26import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
27import { RouterModule } from '@angular/router';
28import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
29import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
30import { TranslateHttpLoader } from '@ngx-translate/http-loader';
31import { NotifierModule, NotifierOptions } from 'angular-notifier';
32import { AuthInterceptorService } from 'AuthInterceptorService';
33import { HeaderComponent } from 'HeaderComponent';
34import { LayoutComponent } from 'LayoutComponent';
35import { Ng2SmartTableModule } from 'ng2-smart-table';
36import { RestService } from 'RestService';
37import { SidebarComponent } from 'SidebarComponent';
38import { AppComponent } from './AppComponent';
39
40import { appRoutes } from './approutes.module';
41
42import { DataService } from 'DataService';
43import { ProjectService } from 'ProjectService';
44import { SharedService } from 'SharedService';
45
46import { CodemirrorModule } from '@ctrl/ngx-codemirror';
47import { NgSelectModule } from '@ng-select/ng-select';
48
49import { NgIdleKeepaliveModule } from '@ng-idle/keepalive';
50import { AuthenticationService } from 'AuthenticationService';
51import { AuthGuardService } from 'AuthGuardService';
52import { BreadcrumbComponent } from 'BreadCrumb';
53import { ComposePackages } from 'ComposePackages';
54import { ConfirmationTopologyComponent } from 'ConfirmationTopology';
55import { DeleteComponent } from 'DeleteComponent';
56import { DeviceCheckService } from 'DeviceCheckService';
57import { GoToTopDirective } from 'GoToTopDirective';
58import { InstantiateNetSliceTemplateComponent } from 'InstantiateNetSliceTemplate';
59import { InstantiateNsComponent } from 'InstantiateNs';
60import { LoaderModule } from 'LoaderModule';
61import { LoginComponent } from 'LoginComponent';
62import { NetsliceInstancesActionComponent } from 'NetsliceInstancesActionComponent';
63import { NetslicePackagesActionComponent } from 'NetslicePackagesAction';
64import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
65import { NsPackagesActionComponent } from 'NsPackagesAction';
66import { PageNotFoundComponent } from 'PageNotFound';
67import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
68import { ProjectLinkComponent } from 'ProjectLinkComponent';
69import { ProjectsActionComponent } from 'ProjectsAction';
70import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
71import { ShowInfoComponent } from 'ShowInfoComponent';
72import { SwitchProjectComponent } from 'SwitchProjectComponent';
73import { UsersActionComponent } from 'UsersActionComponent';
74import { UserSettingsComponent } from 'UserSettingsComponent';
75import { VimAccountsActionComponent } from 'VimAccountsAction';
76import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
77import { VNFLinkComponent } from 'VNFLinkComponent';
78import { VNFPackagesActionComponent } from 'VNFPackagesAction';
79import { WIMAccountsActionComponent } from 'WIMAccountsAction';
80
81/**
82 * Custom angular notifier options
83 */
84const customNotifierOptions: NotifierOptions = {
85 position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
86 behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
87};
88
89/**
90 * An NgModule is a class adorned with the @NgModule decorator function.
91 * @NgModule takes a metadata object that tells Angular how to compile and run module code.
92 */
93@NgModule({
94 declarations: [
95 AppComponent,
96 LayoutComponent,
97 HeaderComponent,
98 SidebarComponent,
99 LoginComponent,
100 PageNotFoundComponent,
101 VNFPackagesActionComponent,
102 NsPackagesActionComponent,
103 NSInstancesActionComponent,
104 VNFInstancesActionComponent,
105 VNFLinkComponent,
106 NetsliceInstancesActionComponent,
107 BreadcrumbComponent,
108 DeleteComponent,
109 NetslicePackagesActionComponent,
110 UsersActionComponent,
111 VimAccountsActionComponent,
112 ProjectsActionComponent,
113 ProjectLinkComponent,
114 UserSettingsComponent,
115 ShowInfoComponent,
116 InstantiateNetSliceTemplateComponent,
117 InstantiateNsComponent,
118 ConfirmationTopologyComponent,
119 ComposePackages,
120 WIMAccountsActionComponent,
121 PDUInstancesActionComponent,
122 SDNControllerActionComponent,
123 SwitchProjectComponent,
124 GoToTopDirective
125 ],
126 imports: [
127 NotifierModule.withConfig(customNotifierOptions),
128 CommonModule,
129 BrowserModule,
130 BrowserAnimationsModule,
131 FormsModule,
132 ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
133 Ng2SmartTableModule,
134 CodemirrorModule,
135 NgSelectModule,
136 HttpClientModule,
137 TranslateModule.forRoot({
138 loader: {
139 provide: TranslateLoader,
140 useFactory: HttpLoaderFactory,
141 deps: [HttpClient]
142 }
143 }),
144 NgbModule,
145 NgSelectModule,
146 RouterModule.forRoot(appRoutes, { useHash: false }),
147 NgIdleKeepaliveModule.forRoot(),
148 LoaderModule
149 ],
150 providers: [
151 {
152 provide: APP_INITIALIZER,
153 useFactory: appInitializerFactory,
154 deps: [TranslateService, Injector],
155 multi: true
156 },
157 {
158 provide: HTTP_INTERCEPTORS,
159 useClass: AuthInterceptorService,
160 multi: true
161 },
162 RestService,
163 AuthenticationService,
164 AuthGuardService,
165 DataService,
166 ProjectService,
167 SharedService,
168 DeviceCheckService
169 ],
170 bootstrap: [AppComponent],
171 entryComponents: [
172 VNFPackagesActionComponent,
173 NsPackagesActionComponent,
174 NSInstancesActionComponent,
175 VNFInstancesActionComponent,
176 VNFLinkComponent,
177 NetsliceInstancesActionComponent,
178 BreadcrumbComponent,
179 DeleteComponent,
180 NetslicePackagesActionComponent,
181 UsersActionComponent,
182 VimAccountsActionComponent,
183 ProjectsActionComponent,
184 ProjectLinkComponent,
185 UserSettingsComponent,
186 ShowInfoComponent,
187 InstantiateNetSliceTemplateComponent,
188 InstantiateNsComponent,
189 ConfirmationTopologyComponent,
190 ComposePackages,
191 WIMAccountsActionComponent,
192 PDUInstancesActionComponent,
193 SDNControllerActionComponent,
194 SwitchProjectComponent
195 ]
196})
197
198/** Exporting a class @exports AppModule */
199export class AppModule {
200 /** Variables declared to avoid state-less class */
201 private appModule: string;
202}
203
204/**
205 * HttpLoaderFactory is for translate service of the application.
206 */
207// tslint:disable:function-name
208export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
209 const now: number = new Date().getTime();
210 return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
211}
212/**
213 * HttpLoaderFactory is for translate service of the application.
214 */
215// tslint:disable:function-name
216export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
217 // tslint:disable-next-line: no-any
218 return async (): Promise<any> => {
219 await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
220 translate.setDefaultLang('en');
221 const languageCode: string = localStorage.getItem('languageCode');
222 if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
223 await translate.use(languageCode).toPromise().catch(() => {
224 translate.setDefaultLang('en');
225 });
226 } else {
227 await translate.use('en').toPromise();
228 localStorage.setItem('languageCode', 'en');
229 }
230 };
231}