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