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 { ChangePasswordComponent } from 'ChangePasswordComponent';
54 import { ChangePasswordModule } from 'ChangePasswordModule';
55 import { ComposePackages } from 'ComposePackages';
56 import { ConfirmationTopologyComponent } from 'ConfirmationTopology';
57 import { DeleteComponent } from 'DeleteComponent';
58 import { DeviceCheckService } from 'DeviceCheckService';
59 import { GoToTopDirective } from 'GoToTopDirective';
60 import { InstantiateNetSliceTemplateComponent } from 'InstantiateNetSliceTemplate';
61 import { InstantiateNsComponent } from 'InstantiateNs';
62 import { LoaderModule } from 'LoaderModule';
63 import { LoginComponent } from 'LoginComponent';
64 import { NetsliceInstancesActionComponent } from 'NetsliceInstancesActionComponent';
65 import { NetslicePackagesActionComponent } from 'NetslicePackagesAction';
66 import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
67 import { NsPackagesActionComponent } from 'NsPackagesAction';
68 import { PageNotFoundComponent } from 'PageNotFound';
69 import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
70 import { ProjectLinkComponent } from 'ProjectLinkComponent';
71 import { ProjectsActionComponent } from 'ProjectsAction';
72 import { ScalingComponent } from 'ScalingComponent';
73 import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
74 import { SharedModule } from 'SharedModule';
75 import { ShowInfoComponent } from 'ShowInfoComponent';
76 import { SwitchProjectComponent } from 'SwitchProjectComponent';
77 import { UsersActionComponent } from 'UsersActionComponent';
78 import { UserSettingsComponent } from 'UserSettingsComponent';
79 import { VimAccountsActionComponent } from 'VimAccountsAction';
80 import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
81 import { VNFLinkComponent } from 'VNFLinkComponent';
82 import { VNFPackagesActionComponent } from 'VNFPackagesAction';
83 import { WIMAccountsActionComponent } from 'WIMAccountsAction';
86 * Custom angular notifier options
88 const customNotifierOptions: NotifierOptions = {
89 position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
90 behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
94 * An NgModule is a class adorned with the @NgModule decorator function.
95 * @NgModule takes a metadata object that tells Angular how to compile and run module code.
104 PageNotFoundComponent,
105 VNFPackagesActionComponent,
106 NsPackagesActionComponent,
107 NSInstancesActionComponent,
108 VNFInstancesActionComponent,
110 NetsliceInstancesActionComponent,
113 NetslicePackagesActionComponent,
114 UsersActionComponent,
115 VimAccountsActionComponent,
116 ProjectsActionComponent,
117 ProjectLinkComponent,
118 UserSettingsComponent,
120 InstantiateNetSliceTemplateComponent,
121 InstantiateNsComponent,
122 ConfirmationTopologyComponent,
124 WIMAccountsActionComponent,
125 PDUInstancesActionComponent,
126 SDNControllerActionComponent,
127 SwitchProjectComponent,
130 ChangePasswordComponent
133 NotifierModule.withConfig(customNotifierOptions),
136 BrowserAnimationsModule,
138 ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
143 TranslateModule.forRoot({
145 provide: TranslateLoader,
146 useFactory: HttpLoaderFactory,
152 RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }),
153 NgIdleKeepaliveModule.forRoot(),
160 provide: APP_INITIALIZER,
161 useFactory: appInitializerFactory,
162 deps: [TranslateService, Injector],
166 provide: HTTP_INTERCEPTORS,
167 useClass: AuthInterceptorService,
171 AuthenticationService,
178 bootstrap: [AppComponent],
180 VNFPackagesActionComponent,
181 NsPackagesActionComponent,
182 NSInstancesActionComponent,
183 VNFInstancesActionComponent,
185 NetsliceInstancesActionComponent,
188 NetslicePackagesActionComponent,
189 UsersActionComponent,
190 VimAccountsActionComponent,
191 ProjectsActionComponent,
192 ProjectLinkComponent,
193 UserSettingsComponent,
195 InstantiateNetSliceTemplateComponent,
196 InstantiateNsComponent,
197 ConfirmationTopologyComponent,
199 WIMAccountsActionComponent,
200 PDUInstancesActionComponent,
201 SDNControllerActionComponent,
202 SwitchProjectComponent,
204 ChangePasswordComponent
208 /** Exporting a class @exports AppModule */
209 export class AppModule {
210 /** Variables declared to avoid state-less class */
211 private appModule: string;
215 * HttpLoaderFactory is for translate service of the application.
217 // tslint:disable:function-name
218 export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
219 const now: number = new Date().getTime();
220 return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
223 * HttpLoaderFactory is for translate service of the application.
225 // tslint:disable:function-name
226 export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
227 // tslint:disable-next-line: no-any
228 return async (): Promise<any> => {
229 await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
230 translate.setDefaultLang('en');
231 const languageCode: string = localStorage.getItem('languageCode');
232 if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
233 await translate.use(languageCode).toPromise().catch((): void => {
234 translate.setDefaultLang('en');
237 await translate.use('en').toPromise();
238 localStorage.setItem('languageCode', 'en');