889f4be027d6afa036bbc1de4c736110c215b3e4
[osm/NG-UI.git] / src / app / AppModule.ts
1 /*
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  */
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 { InstantiateNetSliceTemplateComponent } from 'InstantiateNetSliceTemplate';
49 import { InstantiateNsComponent } from 'InstantiateNs';
50 import { LayoutComponent } from 'LayoutComponent';
51 import { LoaderModule } from 'LoaderModule';
52 import { LoginComponent } from 'LoginComponent';
53 import { NetsliceInstancesActionComponent } from 'NetsliceInstancesActionComponent';
54 import { NetslicePackagesActionComponent } from 'NetslicePackagesAction';
55 import { Ng2SmartTableModule } from 'ng2-smart-table';
56 import { ToastrModule } from 'ngx-toastr';
57 import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
58 import { NsPackagesActionComponent } from 'NsPackagesAction';
59 import { NsUpdateComponent } from 'NsUpdateComponent';
60 import { PageNotFoundComponent } from 'PageNotFound';
61 import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
62 import { ProjectLinkComponent } from 'ProjectLinkComponent';
63 import { ProjectsActionComponent } from 'ProjectsAction';
64 import { ProjectService } from 'ProjectService';
65 import { RestService } from 'RestService';
66 import { ScalingComponent } from 'ScalingComponent';
67 import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
68 import { SharedModule } from 'SharedModule';
69 import { SharedService } from 'SharedService';
70 import { ShowInfoComponent } from 'ShowInfoComponent';
71 import { SidebarComponent } from 'SidebarComponent';
72 import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
73 import { SwitchProjectComponent } from 'SwitchProjectComponent';
74 import { UsersActionComponent } from 'UsersActionComponent';
75 import { UserSettingsComponent } from 'UserSettingsComponent';
76 import { VerticalScalingComponent } from 'VerticalScalingComponent';
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';
86
87 /**
88  * Custom angular notifier options
89  */
90 const customNotifierOptions: NotifierOptions = {
91     position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
92     behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
93 };
94
95 /**
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.
98  */
99 @NgModule({
100     declarations: [
101         AppComponent,
102         LayoutComponent,
103         HeaderComponent,
104         SidebarComponent,
105         LoginComponent,
106         PageNotFoundComponent,
107         VNFPackagesActionComponent,
108         NsPackagesActionComponent,
109         NSInstancesActionComponent,
110         VNFInstancesActionComponent,
111         VNFLinkComponent,
112         NetsliceInstancesActionComponent,
113         BreadcrumbComponent,
114         DeleteComponent,
115         NetslicePackagesActionComponent,
116         UsersActionComponent,
117         VimAccountsActionComponent,
118         ProjectsActionComponent,
119         ProjectLinkComponent,
120         UserSettingsComponent,
121         ShowInfoComponent,
122         InstantiateNetSliceTemplateComponent,
123         InstantiateNsComponent,
124         ConfirmationTopologyComponent,
125         ComposePackages,
126         WIMAccountsActionComponent,
127         PDUInstancesActionComponent,
128         SDNControllerActionComponent,
129         SwitchProjectComponent,
130         GoToTopDirective,
131         ScalingComponent,
132         ChangePasswordComponent,
133         VmMigrationComponent,
134         NsUpdateComponent,
135         WarningComponent,
136         StartStopRebuildComponent,
137         VerticalScalingComponent
138     ],
139     imports: [
140         NotifierModule.withConfig(customNotifierOptions),
141         CommonModule,
142         BrowserModule,
143         BrowserAnimationsModule,
144         FormsModule,
145         ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
146         Ng2SmartTableModule,
147         CodemirrorModule,
148         NgSelectModule,
149         HttpClientModule,
150         TranslateModule.forRoot({
151             loader: {
152                 provide: TranslateLoader,
153                 useFactory: HttpLoaderFactory,
154                 deps: [HttpClient]
155             }
156         }),
157         NgbModule,
158         NgSelectModule,
159         RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }),
160         NgIdleKeepaliveModule.forRoot(),
161         LoaderModule,
162         SharedModule,
163         ChangePasswordModule,
164         ToastrModule.forRoot({
165             timeOut: 500,
166             positionClass: 'toast-bottom-right'
167         })
168     ],
169     providers: [
170         {
171             provide: APP_INITIALIZER,
172             useFactory: appInitializerFactory,
173             deps: [TranslateService, Injector],
174             multi: true
175         },
176         {
177             provide: HTTP_INTERCEPTORS,
178             useClass: AuthInterceptorService,
179             multi: true
180         },
181         RestService,
182         AuthenticationService,
183         AuthGuardService,
184         DataService,
185         ProjectService,
186         SharedService,
187         DeviceCheckService
188     ],
189     bootstrap: [AppComponent]
190 })
191
192 /** Exporting a class @exports AppModule */
193 export class AppModule {
194     /** Variables declared to avoid state-less class */
195     private appModule: string;
196 }
197
198 /**
199  * HttpLoaderFactory is for translate service of the application.
200  */
201 /* eslint-disable  */
202 export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
203     const now: number = new Date().getTime();
204     return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
205 }
206 /**
207  * HttpLoaderFactory is for translate service of the application.
208  */
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');
218             });
219         } else {
220             await translate.use('en').toPromise();
221             sessionStorage.setItem('languageCode', 'en');
222         }
223     };
224 }