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 { CodemirrorModule } from '@ctrl/ngx-codemirror';
29 import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
30 import { NgIdleKeepaliveModule } from '@ng-idle/keepalive';
31 import { NgSelectModule } from '@ng-select/ng-select';
32 import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
33 import { TranslateHttpLoader } from '@ngx-translate/http-loader';
34 import { NotifierModule, NotifierOptions } from 'angular-notifier';
35 import { AuthenticationService } from 'AuthenticationService';
36 import { AuthGuardService } from 'AuthGuardService';
37 import { AuthInterceptorService } from 'AuthInterceptorService';
38 import { BreadcrumbComponent } from 'BreadCrumb';
39 import { ChangePasswordComponent } from 'ChangePasswordComponent';
40 import { ChangePasswordModule } from 'ChangePasswordModule';
41 import { ComposePackages } from 'ComposePackages';
42 import { ConfirmationTopologyComponent } from 'ConfirmationTopology';
43 import { DataService } from 'DataService';
44 import { DeleteComponent } from 'DeleteComponent';
45 import { DeviceCheckService } from 'DeviceCheckService';
46 import { GoToTopDirective } from 'GoToTopDirective';
47 import { HeaderComponent } from 'HeaderComponent';
48 import { HealingComponent } from 'HealingComponent';
49 import { InstantiateNetSliceTemplateComponent } from 'InstantiateNetSliceTemplate';
50 import { InstantiateNsComponent } from 'InstantiateNs';
51 import { LayoutComponent } from 'LayoutComponent';
52 import { LoaderModule } from 'LoaderModule';
53 import { LoginComponent } from 'LoginComponent';
54 import { NetsliceInstancesActionComponent } from 'NetsliceInstancesActionComponent';
55 import { NetslicePackagesActionComponent } from 'NetslicePackagesAction';
56 import { Ng2SmartTableModule } from 'ng2-smart-table';
57 import { ToastrModule } from 'ngx-toastr';
58 import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
59 import { NsPackagesActionComponent } from 'NsPackagesAction';
60 import { NsUpdateComponent } from 'NsUpdateComponent';
61 import { PageNotFoundComponent } from 'PageNotFound';
62 import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
63 import { ProjectLinkComponent } from 'ProjectLinkComponent';
64 import { ProjectsActionComponent } from 'ProjectsAction';
65 import { ProjectService } from 'ProjectService';
66 import { RestService } from 'RestService';
67 import { ScalingComponent } from 'ScalingComponent';
68 import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
69 import { SharedModule } from 'SharedModule';
70 import { SharedService } from 'SharedService';
71 import { ShowInfoComponent } from 'ShowInfoComponent';
72 import { SidebarComponent } from 'SidebarComponent';
73 import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
74 import { SwitchProjectComponent } from 'SwitchProjectComponent';
75 import { UsersActionComponent } from 'UsersActionComponent';
76 import { UserSettingsComponent } from 'UserSettingsComponent';
77 import { VimAccountsActionComponent } from 'VimAccountsAction';
78 import { VmMigrationComponent } from 'VmMigrationComponent';
79 import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
80 import { VNFLinkComponent } from 'VNFLinkComponent';
81 import { VNFPackagesActionComponent } from 'VNFPackagesAction';
82 import { WarningComponent } from 'WarningComponent';
83 import { WIMAccountsActionComponent } from 'WIMAccountsAction';
84 import { AppComponent } from './AppComponent';
85 import { appRoutes } from './approutes.module';
88 * Custom angular notifier options
90 const customNotifierOptions: NotifierOptions = {
91 position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
92 behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
96 * An NgModule is a class adorned with the @NgModule decorator function.
97 * @NgModule takes a metadata object that tells Angular how to compile and run module code.
106 PageNotFoundComponent,
107 VNFPackagesActionComponent,
108 NsPackagesActionComponent,
109 NSInstancesActionComponent,
110 VNFInstancesActionComponent,
112 NetsliceInstancesActionComponent,
115 NetslicePackagesActionComponent,
116 UsersActionComponent,
117 VimAccountsActionComponent,
118 ProjectsActionComponent,
119 ProjectLinkComponent,
120 UserSettingsComponent,
122 InstantiateNetSliceTemplateComponent,
123 InstantiateNsComponent,
124 ConfirmationTopologyComponent,
126 WIMAccountsActionComponent,
127 PDUInstancesActionComponent,
128 SDNControllerActionComponent,
129 SwitchProjectComponent,
132 ChangePasswordComponent,
133 VmMigrationComponent,
136 StartStopRebuildComponent,
140 NotifierModule.withConfig(customNotifierOptions),
143 BrowserAnimationsModule,
145 ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
150 TranslateModule.forRoot({
152 provide: TranslateLoader,
153 useFactory: HttpLoaderFactory,
159 RouterModule.forRoot(appRoutes, { useHash: false }),
160 NgIdleKeepaliveModule.forRoot(),
163 ChangePasswordModule,
164 ToastrModule.forRoot({
166 positionClass: 'toast-bottom-right'
171 provide: APP_INITIALIZER,
172 useFactory: appInitializerFactory,
173 deps: [TranslateService, Injector],
177 provide: HTTP_INTERCEPTORS,
178 useClass: AuthInterceptorService,
182 AuthenticationService,
189 bootstrap: [AppComponent]
192 /** Exporting a class @exports AppModule */
193 export class AppModule {
194 /** Variables declared to avoid state-less class */
195 private appModule: string;
199 * HttpLoaderFactory is for translate service of the application.
202 export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
203 const now: number = new Date().getTime();
204 return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
207 * HttpLoaderFactory is for translate service of the application.
209 export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
210 // eslint-disable-next-line @typescript-eslint/no-explicit-any
211 return async (): Promise<any> => {
212 await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
213 translate.setDefaultLang('en');
214 const languageCode: string = sessionStorage.getItem('languageCode');
215 if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
216 await translate.use(languageCode).toPromise().catch((): void => {
217 translate.setDefaultLang('en');
220 await translate.use('en').toPromise();
221 sessionStorage.setItem('languageCode', 'en');