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 { NsUpdateComponent } from 'NsUpdateComponent';
69 import { PageNotFoundComponent } from 'PageNotFound';
70 import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
71 import { ProjectLinkComponent } from 'ProjectLinkComponent';
72 import { ProjectsActionComponent } from 'ProjectsAction';
73 import { ScalingComponent } from 'ScalingComponent';
74 import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
75 import { SharedModule } from 'SharedModule';
76 import { ShowInfoComponent } from 'ShowInfoComponent';
77 import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
78 import { SwitchProjectComponent } from 'SwitchProjectComponent';
79 import { UsersActionComponent } from 'UsersActionComponent';
80 import { UserSettingsComponent } from 'UserSettingsComponent';
81 import { VimAccountsActionComponent } from 'VimAccountsAction';
82 import { VmMigrationComponent } from 'VmMigrationComponent';
83 import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
84 import { VNFLinkComponent } from 'VNFLinkComponent';
85 import { VNFPackagesActionComponent } from 'VNFPackagesAction';
86 import { WarningComponent } from 'WarningComponent';
87 import { WIMAccountsActionComponent } from 'WIMAccountsAction';
90 * Custom angular notifier options
92 const customNotifierOptions: NotifierOptions = {
93 position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
94 behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
98 * An NgModule is a class adorned with the @NgModule decorator function.
99 * @NgModule takes a metadata object that tells Angular how to compile and run module code.
108 PageNotFoundComponent,
109 VNFPackagesActionComponent,
110 NsPackagesActionComponent,
111 NSInstancesActionComponent,
112 VNFInstancesActionComponent,
114 NetsliceInstancesActionComponent,
117 NetslicePackagesActionComponent,
118 UsersActionComponent,
119 VimAccountsActionComponent,
120 ProjectsActionComponent,
121 ProjectLinkComponent,
122 UserSettingsComponent,
124 InstantiateNetSliceTemplateComponent,
125 InstantiateNsComponent,
126 ConfirmationTopologyComponent,
128 WIMAccountsActionComponent,
129 PDUInstancesActionComponent,
130 SDNControllerActionComponent,
131 SwitchProjectComponent,
134 ChangePasswordComponent,
135 VmMigrationComponent,
138 StartStopRebuildComponent
141 NotifierModule.withConfig(customNotifierOptions),
144 BrowserAnimationsModule,
146 ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
151 TranslateModule.forRoot({
153 provide: TranslateLoader,
154 useFactory: HttpLoaderFactory,
160 RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }),
161 NgIdleKeepaliveModule.forRoot(),
168 provide: APP_INITIALIZER,
169 useFactory: appInitializerFactory,
170 deps: [TranslateService, Injector],
174 provide: HTTP_INTERCEPTORS,
175 useClass: AuthInterceptorService,
179 AuthenticationService,
186 bootstrap: [AppComponent],
188 VNFPackagesActionComponent,
189 NsPackagesActionComponent,
190 NSInstancesActionComponent,
191 VNFInstancesActionComponent,
193 NetsliceInstancesActionComponent,
196 NetslicePackagesActionComponent,
197 UsersActionComponent,
198 VimAccountsActionComponent,
199 ProjectsActionComponent,
200 ProjectLinkComponent,
201 UserSettingsComponent,
203 InstantiateNetSliceTemplateComponent,
204 InstantiateNsComponent,
205 ConfirmationTopologyComponent,
207 WIMAccountsActionComponent,
208 PDUInstancesActionComponent,
209 SDNControllerActionComponent,
210 SwitchProjectComponent,
212 ChangePasswordComponent,
213 VmMigrationComponent,
216 StartStopRebuildComponent
220 /** Exporting a class @exports AppModule */
221 export class AppModule {
222 /** Variables declared to avoid state-less class */
223 private appModule: string;
227 * HttpLoaderFactory is for translate service of the application.
229 // tslint:disable:function-name
230 export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
231 const now: number = new Date().getTime();
232 return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
235 * HttpLoaderFactory is for translate service of the application.
237 // tslint:disable:function-name
238 export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
239 // tslint:disable-next-line: no-any
240 return async (): Promise<any> => {
241 await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
242 translate.setDefaultLang('en');
243 const languageCode: string = localStorage.getItem('languageCode');
244 if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
245 await translate.use(languageCode).toPromise().catch((): void => {
246 translate.setDefaultLang('en');
249 await translate.use('en').toPromise();
250 localStorage.setItem('languageCode', 'en');