blob: 451e0f13673b8b4ba1e58440e82ddb803e7227ce [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';
80import { VNFInstancesActionComponent } from 'VNFInstancesActionComponent';
81import { VNFLinkComponent } from 'VNFLinkComponent';
82import { VNFPackagesActionComponent } from 'VNFPackagesAction';
83import { WIMAccountsActionComponent } from 'WIMAccountsAction';
84
85/**
86 * Custom angular notifier options
87 */
88const customNotifierOptions: NotifierOptions = {
89 position: { horizontal: { position: 'right' }, vertical: { position: 'top' } },
90 behaviour: { autoHide: 3000, onClick: 'hide', onMouseover: 'pauseAutoHide' }
91};
92
93/**
94 * An NgModule is a class adorned with the @NgModule decorator function.
95 * @NgModule takes a metadata object that tells Angular how to compile and run module code.
96 */
97@NgModule({
98 declarations: [
99 AppComponent,
100 LayoutComponent,
101 HeaderComponent,
102 SidebarComponent,
103 LoginComponent,
104 PageNotFoundComponent,
105 VNFPackagesActionComponent,
106 NsPackagesActionComponent,
107 NSInstancesActionComponent,
108 VNFInstancesActionComponent,
109 VNFLinkComponent,
110 NetsliceInstancesActionComponent,
111 BreadcrumbComponent,
112 DeleteComponent,
113 NetslicePackagesActionComponent,
114 UsersActionComponent,
115 VimAccountsActionComponent,
116 ProjectsActionComponent,
117 ProjectLinkComponent,
118 UserSettingsComponent,
119 ShowInfoComponent,
120 InstantiateNetSliceTemplateComponent,
121 InstantiateNsComponent,
122 ConfirmationTopologyComponent,
123 ComposePackages,
124 WIMAccountsActionComponent,
125 PDUInstancesActionComponent,
126 SDNControllerActionComponent,
127 SwitchProjectComponent,
Barath Kumar R07698ab2021-03-30 11:50:42 +0530128 GoToTopDirective,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530129 ScalingComponent,
130 ChangePasswordComponent
kumaran.m3b4814a2020-05-01 19:48:54 +0530131 ],
132 imports: [
133 NotifierModule.withConfig(customNotifierOptions),
134 CommonModule,
135 BrowserModule,
136 BrowserAnimationsModule,
137 FormsModule,
138 ReactiveFormsModule.withConfig({ warnOnNgModelWithFormControl: 'never' }),
139 Ng2SmartTableModule,
140 CodemirrorModule,
141 NgSelectModule,
142 HttpClientModule,
143 TranslateModule.forRoot({
144 loader: {
145 provide: TranslateLoader,
146 useFactory: HttpLoaderFactory,
147 deps: [HttpClient]
148 }
149 }),
150 NgbModule,
151 NgSelectModule,
Barath Kumar R5abb2742020-11-22 20:15:10 +0530152 RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }),
kumaran.m3b4814a2020-05-01 19:48:54 +0530153 NgIdleKeepaliveModule.forRoot(),
SANDHYA.JS4a7a5422021-05-15 15:35:22 +0530154 LoaderModule,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530155 SharedModule,
156 ChangePasswordModule
kumaran.m3b4814a2020-05-01 19:48:54 +0530157 ],
158 providers: [
159 {
160 provide: APP_INITIALIZER,
161 useFactory: appInitializerFactory,
162 deps: [TranslateService, Injector],
163 multi: true
164 },
165 {
166 provide: HTTP_INTERCEPTORS,
167 useClass: AuthInterceptorService,
168 multi: true
169 },
170 RestService,
171 AuthenticationService,
172 AuthGuardService,
173 DataService,
174 ProjectService,
175 SharedService,
176 DeviceCheckService
177 ],
178 bootstrap: [AppComponent],
179 entryComponents: [
180 VNFPackagesActionComponent,
181 NsPackagesActionComponent,
182 NSInstancesActionComponent,
183 VNFInstancesActionComponent,
184 VNFLinkComponent,
185 NetsliceInstancesActionComponent,
186 BreadcrumbComponent,
187 DeleteComponent,
188 NetslicePackagesActionComponent,
189 UsersActionComponent,
190 VimAccountsActionComponent,
191 ProjectsActionComponent,
192 ProjectLinkComponent,
193 UserSettingsComponent,
194 ShowInfoComponent,
195 InstantiateNetSliceTemplateComponent,
196 InstantiateNsComponent,
197 ConfirmationTopologyComponent,
198 ComposePackages,
199 WIMAccountsActionComponent,
200 PDUInstancesActionComponent,
201 SDNControllerActionComponent,
Barath Kumar R07698ab2021-03-30 11:50:42 +0530202 SwitchProjectComponent,
SANDHYA.JSa9816552022-04-12 09:07:08 +0530203 ScalingComponent,
204 ChangePasswordComponent
kumaran.m3b4814a2020-05-01 19:48:54 +0530205 ]
206})
207
208/** Exporting a class @exports AppModule */
209export class AppModule {
210 /** Variables declared to avoid state-less class */
211 private appModule: string;
212}
213
214/**
215 * HttpLoaderFactory is for translate service of the application.
216 */
217// tslint:disable:function-name
218export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
219 const now: number = new Date().getTime();
220 return new TranslateHttpLoader(http, './assets/i18n/', '.json?locale=' + now);
221}
222/**
223 * HttpLoaderFactory is for translate service of the application.
224 */
225// tslint:disable:function-name
226export function appInitializerFactory(translate: TranslateService, injector: Injector): Object {
227 // tslint:disable-next-line: no-any
228 return async (): Promise<any> => {
229 await injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
230 translate.setDefaultLang('en');
231 const languageCode: string = localStorage.getItem('languageCode');
232 if (languageCode !== null && languageCode !== undefined && languageCode !== '') {
SANDHYA.JSa9816552022-04-12 09:07:08 +0530233 await translate.use(languageCode).toPromise().catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530234 translate.setDefaultLang('en');
235 });
236 } else {
237 await translate.use('en').toPromise();
238 localStorage.setItem('languageCode', 'en');
239 }
240 };
241}