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