2 Copyright 2020 TATA ELXSI
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
19 * @file Instance Module file
21 import { CommonModule, LOCATION_INITIALIZED } from '@angular/common';
22 import { HttpClient, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
23 import { APP_INITIALIZER, Injector, NgModule } from '@angular/core';
24 import { FormsModule, ReactiveFormsModule } from '@angular/forms';
25 import { BrowserModule } from '@angular/platform-browser';
26 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
27 import { RouterModule } from '@angular/router';
28 import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
29 import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
30 import { TranslateHttpLoader } from '@ngx-translate/http-loader';
31 import { NotifierModule, NotifierOptions } from 'angular-notifier';
32 import { AuthInterceptorService } from 'AuthInterceptorService';
33 import { HeaderComponent } from 'HeaderComponent';
34 import { LayoutComponent } from 'LayoutComponent';
35 import { Ng2SmartTableModule } from 'ng2-smart-table';
36 import { RestService } from 'RestService';
37 import { SidebarComponent } from 'SidebarComponent';
38 import { AppComponent } from './AppComponent';
40 import { appRoutes } from './approutes.module';
42 import { DataService } from 'DataService';
43 import { ProjectService } from 'ProjectService';
44 import { SharedService } from 'SharedService';
46 import { CodemirrorModule } from '@ctrl/ngx-codemirror';
47 import { NgSelectModule } from '@ng-select/ng-select';
49 import { NgIdleKeepaliveModule } from '@ng-idle/keepalive';
50 import { AuthenticationService } from 'AuthenticationService';
51 import { AuthGuardService } from 'AuthGuardService';
52 import { BreadcrumbComponent } from 'BreadCrumb';
53 import { ComposePackages } from 'ComposePackages';
54 import { ConfirmationTopologyComponent } from 'ConfirmationTopology';
55 import { DeleteComponent } from 'DeleteComponent';
56 import { DeviceCheckService } from 'DeviceCheckService';
57 import { GoToTopDirective } from 'GoToTopDirective';
58 import { InstantiateNetSliceTemplateComponent } from 'InstantiateNetSliceTemplate';
59 import { InstantiateNsComponent } from 'InstantiateNs';
60 import { LoaderModule } from 'LoaderModule';
61 import { LoginComponent } from 'LoginComponent';
62 import { NetsliceInstancesActionComponent } from 'NetsliceInstancesActionComponent';
63 import { NetslicePackagesActionComponent } from 'NetslicePackagesAction';
64 import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
65 import { NsPackagesActionComponent } from 'NsPackagesAction';
66 import { PageNotFoundComponent } from 'PageNotFound';
67 import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
68 import { ProjectLinkComponent } from 'ProjectLinkComponent';
69 import { ProjectsActionComponent } from 'ProjectsAction';
70 import { ScalingComponent } from 'ScalingComponent';
71 import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
72 import { SharedModule } from 'SharedModule';
73 import { ShowInfoComponent } from 'ShowInfoComponent';
74 import { SwitchProjectComponent } from 'SwitchProjectComponent';
75 import { UsersActionComponent } from 'UsersActionComponent';
76 import { UserSettingsComponent } from 'UserSettingsComponent';
77 import { VimAccountsActionComponent } from 'VimAccountsAction';
78 import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
79 import { VNFLinkComponent } from 'VNFLinkComponent';
80 import { VNFPackagesActionComponent } from 'VNFPackagesAction';
81 import { WIMAccountsActionComponent } from 'WIMAccountsAction';
84 * Custom angular notifier options
86 const customNotifierOptions: NotifierOptions = {
87 position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
88 behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
92 * An NgModule is a class adorned with the @NgModule decorator function.
93 * @NgModule takes a metadata object that tells Angular how to compile and run module code.
102 PageNotFoundComponent,
103 VNFPackagesActionComponent,
104 NsPackagesActionComponent,
105 NSInstancesActionComponent,
106 VNFInstancesActionComponent,
108 NetsliceInstancesActionComponent,
111 NetslicePackagesActionComponent,
112 UsersActionComponent,
113 VimAccountsActionComponent,
114 ProjectsActionComponent,
115 ProjectLinkComponent,
116 UserSettingsComponent,
118 InstantiateNetSliceTemplateComponent,
119 InstantiateNsComponent,
120 ConfirmationTopologyComponent,
122 WIMAccountsActionComponent,
123 PDUInstancesActionComponent,
124 SDNControllerActionComponent,
125 SwitchProjectComponent,
130 NotifierModule.withConfig(customNotifierOptions),
133 BrowserAnimationsModule,
135 ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
140 TranslateModule.forRoot({
142 provide: TranslateLoader,
143 useFactory: HttpLoaderFactory,
149 RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }),
150 NgIdleKeepaliveModule.forRoot(),
156 provide: APP_INITIALIZER,
157 useFactory: appInitializerFactory,
158 deps: [TranslateService, Injector],
162 provide: HTTP_INTERCEPTORS,
163 useClass: AuthInterceptorService,
167 AuthenticationService,
174 bootstrap: [AppComponent],
176 VNFPackagesActionComponent,
177 NsPackagesActionComponent,
178 NSInstancesActionComponent,
179 VNFInstancesActionComponent,
181 NetsliceInstancesActionComponent,
184 NetslicePackagesActionComponent,
185 UsersActionComponent,
186 VimAccountsActionComponent,
187 ProjectsActionComponent,
188 ProjectLinkComponent,
189 UserSettingsComponent,
191 InstantiateNetSliceTemplateComponent,
192 InstantiateNsComponent,
193 ConfirmationTopologyComponent,
195 WIMAccountsActionComponent,
196 PDUInstancesActionComponent,
197 SDNControllerActionComponent,
198 SwitchProjectComponent,
203 /** Exporting a class @exports AppModule */
204 export class AppModule {
205 /** Variables declared to avoid state-less class */
206 private appModule: string;
210 * HttpLoaderFactory is for translate service of the application.
212 // tslint:disable:function-name
213 export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
214 const now: number = new Date().getTime();
215 return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
218 * HttpLoaderFactory is for translate service of the application.
220 // tslint:disable:function-name
221 export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
222 // tslint:disable-next-line: no-any
223 return async (): Promise<any> => {
224 await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
225 translate.setDefaultLang('en');
226 const languageCode: string = localStorage.getItem('languageCode');
227 if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
228 await translate.use(languageCode).toPromise().catch(() => {
229 translate.setDefaultLang('en');
232 await translate.use('en').toPromise();
233 localStorage.setItem('languageCode', 'en');