8a4ebaf31c4a00246b120747de8cf3c79870a8b7
[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 { NSInstancesActionComponent } from 'NSInstancesActionComponent';
57 import { NsPackagesActionComponent } from 'NsPackagesAction';
58 import { NsUpdateComponent } from 'NsUpdateComponent';
59 import { PageNotFoundComponent } from 'PageNotFound';
60 import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
61 import { ProjectLinkComponent } from 'ProjectLinkComponent';
62 import { ProjectsActionComponent } from 'ProjectsAction';
63 import { ProjectService } from 'ProjectService';
64 import { RestService } from 'RestService';
65 import { ScalingComponent } from 'ScalingComponent';
66 import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
67 import { SharedModule } from 'SharedModule';
68 import { SharedService } from 'SharedService';
69 import { ShowInfoComponent } from 'ShowInfoComponent';
70 import { SidebarComponent } from 'SidebarComponent';
71 import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
72 import { SwitchProjectComponent } from 'SwitchProjectComponent';
73 import { UsersActionComponent } from 'UsersActionComponent';
74 import { UserSettingsComponent } from 'UserSettingsComponent';
75 import { VerticalScalingComponent } from 'VerticalScalingComponent';
76 import { VimAccountsActionComponent } from 'VimAccountsAction';
77 import { VmMigrationComponent } from 'VmMigrationComponent';
78 import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
79 import { VNFLinkComponent } from 'VNFLinkComponent';
80 import { VNFPackagesActionComponent } from 'VNFPackagesAction';
81 import { WarningComponent } from 'WarningComponent';
82 import { WIMAccountsActionComponent } from 'WIMAccountsAction';
83 import { AppComponent } from './AppComponent';
84 import { appRoutes } from './approutes.module';
85
86 /**
87  * Custom angular notifier options
88  */
89 const customNotifierOptions: NotifierOptions = {
90     position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
91     behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
92 };
93
94 /**
95  * An NgModule is a class adorned with the @NgModule decorator function.
96  * @NgModule takes a metadata object that tells Angular how to compile and run module code.
97  */
98 @NgModule({
99     declarations: [
100         AppComponent,
101         LayoutComponent,
102         HeaderComponent,
103         SidebarComponent,
104         LoginComponent,
105         PageNotFoundComponent,
106         VNFPackagesActionComponent,
107         NsPackagesActionComponent,
108         NSInstancesActionComponent,
109         VNFInstancesActionComponent,
110         VNFLinkComponent,
111         NetsliceInstancesActionComponent,
112         BreadcrumbComponent,
113         DeleteComponent,
114         NetslicePackagesActionComponent,
115         UsersActionComponent,
116         VimAccountsActionComponent,
117         ProjectsActionComponent,
118         ProjectLinkComponent,
119         UserSettingsComponent,
120         ShowInfoComponent,
121         InstantiateNetSliceTemplateComponent,
122         InstantiateNsComponent,
123         ConfirmationTopologyComponent,
124         ComposePackages,
125         WIMAccountsActionComponent,
126         PDUInstancesActionComponent,
127         SDNControllerActionComponent,
128         SwitchProjectComponent,
129         GoToTopDirective,
130         ScalingComponent,
131         ChangePasswordComponent,
132         VmMigrationComponent,
133         NsUpdateComponent,
134         WarningComponent,
135         StartStopRebuildComponent,
136         VerticalScalingComponent
137     ],
138     imports: [
139         NotifierModule.withConfig(customNotifierOptions),
140         CommonModule,
141         BrowserModule,
142         BrowserAnimationsModule,
143         FormsModule,
144         ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
145         Ng2SmartTableModule,
146         CodemirrorModule,
147         NgSelectModule,
148         HttpClientModule,
149         TranslateModule.forRoot({
150             loader: {
151                 provide: TranslateLoader,
152                 useFactory: HttpLoaderFactory,
153                 deps: [HttpClient]
154             }
155         }),
156         NgbModule,
157         NgSelectModule,
158         RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }),
159         NgIdleKeepaliveModule.forRoot(),
160         LoaderModule,
161         SharedModule,
162         ChangePasswordModule
163     ],
164     providers: [
165         {
166             provide: APP_INITIALIZER,
167             useFactory: appInitializerFactory,
168             deps: [TranslateService, Injector],
169             multi: true
170         },
171         {
172             provide: HTTP_INTERCEPTORS,
173             useClass: AuthInterceptorService,
174             multi: true
175         },
176         RestService,
177         AuthenticationService,
178         AuthGuardService,
179         DataService,
180         ProjectService,
181         SharedService,
182         DeviceCheckService
183     ],
184     bootstrap: [AppComponent]
185 })
186
187 /** Exporting a class @exports AppModule */
188 export class AppModule {
189     /** Variables declared to avoid state-less class */
190     private appModule: string;
191 }
192
193 /**
194  * HttpLoaderFactory is for translate service of the application.
195  */
196 /* eslint-disable  */
197 export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
198     const now: number = new Date().getTime();
199     return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
200 }
201 /**
202  * HttpLoaderFactory is for translate service of the application.
203  */
204 export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
205     // eslint-disable-next-line @typescript-eslint/no-explicit-any
206     return async (): Promise<any> => {
207         await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
208         translate.setDefaultLang('en');
209         const languageCode: string = localStorage.getItem('languageCode');
210         if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
211             await translate.use(languageCode).toPromise().catch((): void => {
212                 translate.setDefaultLang('en');
213             });
214         } else {
215             await translate.use('en').toPromise();
216             localStorage.setItem('languageCode', 'en');
217         }
218     };
219 }