blob: 06d100418ecfe5bf8048b575c53f6370680bbea1 [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
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 */
21import { CommonModule, LOCATION_INITIALIZED } from '@angular/common';
Barath Kumar R5abb2742020-11-22 20:15:10 +053022import { HttpClient, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
kumaran.m3b4814a2020-05-01 19:48:54 +053023import { APP_INITIALIZER, Injector, NgModule } from '@angular/core';
24import { FormsModule, ReactiveFormsModule } from '@angular/forms';
25import { BrowserModule } from '@angular/platform-browser';
26import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
27import { RouterModule } from '@angular/router';
28import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
29import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
30import { TranslateHttpLoader } from '@ngx-translate/http-loader';
31import { NotifierModule, NotifierOptions } from 'angular-notifier';
32import { AuthInterceptorService } from 'AuthInterceptorService';
33import { HeaderComponent } from 'HeaderComponent';
34import { LayoutComponent } from 'LayoutComponent';
35import { Ng2SmartTableModule } from 'ng2-smart-table';
36import { RestService } from 'RestService';
37import { SidebarComponent } from 'SidebarComponent';
38import { AppComponent } from './AppComponent';
39
40import { appRoutes } from './approutes.module';
41
42import { DataService } from 'DataService';
43import { ProjectService } from 'ProjectService';
44import { SharedService } from 'SharedService';
45
46import { CodemirrorModule } from '@ctrl/ngx-codemirror';
47import { NgSelectModule } from '@ng-select/ng-select';
48
49import { NgIdleKeepaliveModule } from '@ng-idle/keepalive';
50import { AuthenticationService } from 'AuthenticationService';
51import { AuthGuardService } from 'AuthGuardService';
52import { BreadcrumbComponent } from 'BreadCrumb';
SANDHYA.JSa9816552022-04-12 09:07:08 +053053import { ChangePasswordComponent } from 'ChangePasswordComponent';
54import { ChangePasswordModule } from 'ChangePasswordModule';
kumaran.m3b4814a2020-05-01 19:48:54 +053055import { ComposePackages } from 'ComposePackages';
56import { ConfirmationTopologyComponent } from 'ConfirmationTopology';
57import { DeleteComponent } from 'DeleteComponent';
58import { DeviceCheckService } from 'DeviceCheckService';
59import { GoToTopDirective } from 'GoToTopDirective';
60import { InstantiateNetSliceTemplateComponent } from 'InstantiateNetSliceTemplate';
61import { InstantiateNsComponent } from 'InstantiateNs';
62import { LoaderModule } from 'LoaderModule';
63import { LoginComponent } from 'LoginComponent';
64import { NetsliceInstancesActionComponent } from 'NetsliceInstancesActionComponent';
65import { NetslicePackagesActionComponent } from 'NetslicePackagesAction';
66import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
67import { NsPackagesActionComponent } from 'NsPackagesAction';
68import { PageNotFoundComponent } from 'PageNotFound';
69import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
70import { ProjectLinkComponent } from 'ProjectLinkComponent';
71import { ProjectsActionComponent } from 'ProjectsAction';
Barath Kumar R07698ab2021-03-30 11:50:42 +053072import { ScalingComponent } from 'ScalingComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053073import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
SANDHYA.JS4a7a5422021-05-15 15:35:22 +053074import { SharedModule } from 'SharedModule';
kumaran.m3b4814a2020-05-01 19:48:54 +053075import { ShowInfoComponent } from 'ShowInfoComponent';
76import { SwitchProjectComponent } from 'SwitchProjectComponent';
77import { UsersActionComponent } from 'UsersActionComponent';
78import { UserSettingsComponent } from 'UserSettingsComponent';
79import { VimAccountsActionComponent } from 'VimAccountsAction';
SANDHYA.JSfced3d42022-04-28 20:28:17 +053080import { VmMigrationComponent } from 'VmMigrationComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053081import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
82import { VNFLinkComponent } from 'VNFLinkComponent';
83import { VNFPackagesActionComponent } from 'VNFPackagesAction';
84import { WIMAccountsActionComponent } from 'WIMAccountsAction';
85
86/**
87 * Custom angular notifier options
88 */
89const 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,
Barath Kumar R07698ab2021-03-30 11:50:42 +0530129 GoToTopDirective,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530130 ScalingComponent,
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530131 ChangePasswordComponent,
132 VmMigrationComponent
kumaran.m3b4814a2020-05-01 19:48:54 +0530133 ],
134 imports: [
135 NotifierModule.withConfig(customNotifierOptions),
136 CommonModule,
137 BrowserModule,
138 BrowserAnimationsModule,
139 FormsModule,
140 ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
141 Ng2SmartTableModule,
142 CodemirrorModule,
143 NgSelectModule,
144 HttpClientModule,
145 TranslateModule.forRoot({
146 loader: {
147 provide: TranslateLoader,
148 useFactory: HttpLoaderFactory,
149 deps: [HttpClient]
150 }
151 }),
152 NgbModule,
153 NgSelectModule,
Barath Kumar R5abb2742020-11-22 20:15:10 +0530154 RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }),
kumaran.m3b4814a2020-05-01 19:48:54 +0530155 NgIdleKeepaliveModule.forRoot(),
SANDHYA.JS4a7a5422021-05-15 15:35:22 +0530156 LoaderModule,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530157 SharedModule,
158 ChangePasswordModule
kumaran.m3b4814a2020-05-01 19:48:54 +0530159 ],
160 providers: [
161 {
162 provide: APP_INITIALIZER,
163 useFactory: appInitializerFactory,
164 deps: [TranslateService, Injector],
165 multi: true
166 },
167 {
168 provide: HTTP_INTERCEPTORS,
169 useClass: AuthInterceptorService,
170 multi: true
171 },
172 RestService,
173 AuthenticationService,
174 AuthGuardService,
175 DataService,
176 ProjectService,
177 SharedService,
178 DeviceCheckService
179 ],
180 bootstrap: [AppComponent],
181 entryComponents: [
182 VNFPackagesActionComponent,
183 NsPackagesActionComponent,
184 NSInstancesActionComponent,
185 VNFInstancesActionComponent,
186 VNFLinkComponent,
187 NetsliceInstancesActionComponent,
188 BreadcrumbComponent,
189 DeleteComponent,
190 NetslicePackagesActionComponent,
191 UsersActionComponent,
192 VimAccountsActionComponent,
193 ProjectsActionComponent,
194 ProjectLinkComponent,
195 UserSettingsComponent,
196 ShowInfoComponent,
197 InstantiateNetSliceTemplateComponent,
198 InstantiateNsComponent,
199 ConfirmationTopologyComponent,
200 ComposePackages,
201 WIMAccountsActionComponent,
202 PDUInstancesActionComponent,
203 SDNControllerActionComponent,
Barath Kumar R07698ab2021-03-30 11:50:42 +0530204 SwitchProjectComponent,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530205 ScalingComponent,
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530206 ChangePasswordComponent,
207 VmMigrationComponent
kumaran.m3b4814a2020-05-01 19:48:54 +0530208 ]
209})
210
211/** Exporting a class @exports AppModule */
212export class AppModule {
213 /** Variables declared to avoid state-less class */
214 private appModule: string;
215}
216
217/**
218 * HttpLoaderFactory is for translate service of the application.
219 */
220// tslint:disable:function-name
221export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
222 const now: number = new Date().getTime();
223 return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
224}
225/**
226 * HttpLoaderFactory is for translate service of the application.
227 */
228// tslint:disable:function-name
229export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
230 // tslint:disable-next-line: no-any
231 return async (): Promise<any> => {
232 await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
233 translate.setDefaultLang('en');
234 const languageCode: string = localStorage.getItem('languageCode');
235 if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
SANDHYA.JSa9816552022-04-12 09:07:08 +0530236 await translate.use(languageCode).toPromise().catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530237 translate.setDefaultLang('en');
238 });
239 } else {
240 await translate.use('en').toPromise();
241 localStorage.setItem('languageCode', 'en');
242 }
243 };
244}