blob: 30c68426d836b28b465fb967378e5de38590ce4e [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';
SANDHYA.JS99144582022-04-27 17:22:35 +053068import { NsUpdateComponent } from 'NsUpdateComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053069import { PageNotFoundComponent } from 'PageNotFound';
70import { PDUInstancesActionComponent } from 'PDUInstancesActionComponent';
71import { ProjectLinkComponent } from 'ProjectLinkComponent';
72import { ProjectsActionComponent } from 'ProjectsAction';
Barath Kumar R07698ab2021-03-30 11:50:42 +053073import { ScalingComponent } from 'ScalingComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053074import { SDNControllerActionComponent } from 'SDNControllerActionComponent';
SANDHYA.JS4a7a5422021-05-15 15:35:22 +053075import { SharedModule } from 'SharedModule';
kumaran.m3b4814a2020-05-01 19:48:54 +053076import { ShowInfoComponent } from 'ShowInfoComponent';
SANDHYA.JS3d81a282022-05-02 08:25:39 +053077import { StartStopRebuildComponent } from 'StartStopRebuildComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053078import { SwitchProjectComponent } from 'SwitchProjectComponent';
79import { UsersActionComponent } from 'UsersActionComponent';
80import { UserSettingsComponent } from 'UserSettingsComponent';
81import { VimAccountsActionComponent } from 'VimAccountsAction';
SANDHYA.JSfced3d42022-04-28 20:28:17 +053082import { VmMigrationComponent } from 'VmMigrationComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053083import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
84import { VNFLinkComponent } from 'VNFLinkComponent';
85import { VNFPackagesActionComponent } from 'VNFPackagesAction';
SANDHYA.JS99144582022-04-27 17:22:35 +053086import { WarningComponent } from 'WarningComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053087import { WIMAccountsActionComponent } from 'WIMAccountsAction';
88
89/**
90 * Custom angular notifier options
91 */
92const customNotifierOptions: NotifierOptions = {
93 position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
94 behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
95};
96
97/**
98 * An NgModule is a class adorned with the @NgModule decorator function.
99 * @NgModule takes a metadata object that tells Angular how to compile and run module code.
100 */
101@NgModule({
102 declarations: [
103 AppComponent,
104 LayoutComponent,
105 HeaderComponent,
106 SidebarComponent,
107 LoginComponent,
108 PageNotFoundComponent,
109 VNFPackagesActionComponent,
110 NsPackagesActionComponent,
111 NSInstancesActionComponent,
112 VNFInstancesActionComponent,
113 VNFLinkComponent,
114 NetsliceInstancesActionComponent,
115 BreadcrumbComponent,
116 DeleteComponent,
117 NetslicePackagesActionComponent,
118 UsersActionComponent,
119 VimAccountsActionComponent,
120 ProjectsActionComponent,
121 ProjectLinkComponent,
122 UserSettingsComponent,
123 ShowInfoComponent,
124 InstantiateNetSliceTemplateComponent,
125 InstantiateNsComponent,
126 ConfirmationTopologyComponent,
127 ComposePackages,
128 WIMAccountsActionComponent,
129 PDUInstancesActionComponent,
130 SDNControllerActionComponent,
131 SwitchProjectComponent,
Barath Kumar R07698ab2021-03-30 11:50:42 +0530132 GoToTopDirective,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530133 ScalingComponent,
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530134 ChangePasswordComponent,
SANDHYA.JS99144582022-04-27 17:22:35 +0530135 VmMigrationComponent,
136 NsUpdateComponent,
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530137 WarningComponent,
138 StartStopRebuildComponent
kumaran.m3b4814a2020-05-01 19:48:54 +0530139 ],
140 imports: [
141 NotifierModule.withConfig(customNotifierOptions),
142 CommonModule,
143 BrowserModule,
144 BrowserAnimationsModule,
145 FormsModule,
146 ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
147 Ng2SmartTableModule,
148 CodemirrorModule,
149 NgSelectModule,
150 HttpClientModule,
151 TranslateModule.forRoot({
152 loader: {
153 provide: TranslateLoader,
154 useFactory: HttpLoaderFactory,
155 deps: [HttpClient]
156 }
157 }),
158 NgbModule,
159 NgSelectModule,
Barath Kumar R5abb2742020-11-22 20:15:10 +0530160 RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }),
kumaran.m3b4814a2020-05-01 19:48:54 +0530161 NgIdleKeepaliveModule.forRoot(),
SANDHYA.JS4a7a5422021-05-15 15:35:22 +0530162 LoaderModule,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530163 SharedModule,
164 ChangePasswordModule
kumaran.m3b4814a2020-05-01 19:48:54 +0530165 ],
166 providers: [
167 {
168 provide: APP_INITIALIZER,
169 useFactory: appInitializerFactory,
170 deps: [TranslateService, Injector],
171 multi: true
172 },
173 {
174 provide: HTTP_INTERCEPTORS,
175 useClass: AuthInterceptorService,
176 multi: true
177 },
178 RestService,
179 AuthenticationService,
180 AuthGuardService,
181 DataService,
182 ProjectService,
183 SharedService,
184 DeviceCheckService
185 ],
186 bootstrap: [AppComponent],
187 entryComponents: [
188 VNFPackagesActionComponent,
189 NsPackagesActionComponent,
190 NSInstancesActionComponent,
191 VNFInstancesActionComponent,
192 VNFLinkComponent,
193 NetsliceInstancesActionComponent,
194 BreadcrumbComponent,
195 DeleteComponent,
196 NetslicePackagesActionComponent,
197 UsersActionComponent,
198 VimAccountsActionComponent,
199 ProjectsActionComponent,
200 ProjectLinkComponent,
201 UserSettingsComponent,
202 ShowInfoComponent,
203 InstantiateNetSliceTemplateComponent,
204 InstantiateNsComponent,
205 ConfirmationTopologyComponent,
206 ComposePackages,
207 WIMAccountsActionComponent,
208 PDUInstancesActionComponent,
209 SDNControllerActionComponent,
Barath Kumar R07698ab2021-03-30 11:50:42 +0530210 SwitchProjectComponent,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530211 ScalingComponent,
SANDHYA.JSfced3d42022-04-28 20:28:17 +0530212 ChangePasswordComponent,
SANDHYA.JS99144582022-04-27 17:22:35 +0530213 VmMigrationComponent,
214 NsUpdateComponent,
SANDHYA.JS3d81a282022-05-02 08:25:39 +0530215 WarningComponent,
216 StartStopRebuildComponent
kumaran.m3b4814a2020-05-01 19:48:54 +0530217 ]
218})
219
220/** Exporting a class @exports AppModule */
221export class AppModule {
222 /** Variables declared to avoid state-less class */
223 private appModule: string;
224}
225
226/**
227 * HttpLoaderFactory is for translate service of the application.
228 */
229// tslint:disable:function-name
230export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
231 const now: number = new Date().getTime();
232 return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
233}
234/**
235 * HttpLoaderFactory is for translate service of the application.
236 */
237// tslint:disable:function-name
238export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
239 // tslint:disable-next-line: no-any
240 return async (): Promise<any> => {
241 await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
242 translate.setDefaultLang('en');
243 const languageCode: string = localStorage.getItem('languageCode');
244 if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
SANDHYA.JSa9816552022-04-12 09:07:08 +0530245 await translate.use(languageCode).toPromise().catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530246 translate.setDefaultLang('en');
247 });
248 } else {
249 await translate.use('en').toPromise();
250 localStorage.setItem('languageCode', 'en');
251 }
252 };
253}