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