Internationalization code 58/111158/1
authorSri Balaji Marripud <sri.balaji.marripud@att.com>
Tue, 11 Aug 2020 21:09:19 +0000 (17:09 -0400)
committerSri Balaji Marripud <sri.balaji.marripud@att.com>
Tue, 11 Aug 2020 21:09:29 +0000 (17:09 -0400)
Issue-ID: PORTAL-975
Change-Id: I4d4e25b883f36ee6ee1e16d98e75773636b1ee5b
Signed-off-by: Sri Balaji Marripud <sri.balaji.marripud@att.com>
12 files changed:
portal-FE-common/src/app/layout/components/header/header.component.html
portal-FE-common/src/app/layout/components/header/header.component.scss
portal-FE-common/src/app/layout/components/header/header.component.ts
portal-FE-common/src/app/layout/components/sidebar/sidebar.component.ts
portal-FE-common/src/app/layout/components/tabbar/tabbar.component.html
portal-FE-common/src/app/layout/components/tabbar/tabbar.component.spec.ts
portal-FE-common/src/app/layout/components/tabbar/tabbar.component.ts
portal-FE-common/src/app/layout/layout.component.html
portal-FE-common/src/app/layout/layout.component.spec.ts
portal-FE-common/src/app/layout/layout.component.ts
portal-FE-common/src/app/shared/services/menus/menus.service.ts
portal-FE-common/src/app/shared/services/sidebar/sidebar.service.ts

index 97f4a26..865ce07 100644 (file)
         <br>
     </div>
 </div>
+<div class = "language-dropdown">
+    <span class="dropdown-item-name"> {{ 'Language' }}: </span>
+    <select #langSelect (change)="setLanguage(langSelect.value)">
+        <option *ngFor="let lang of languages" [value]="lang.languageId" [selected]="lang.selected">
+            {{ lang.languageAlias }}
+        </option>
+    </select>
+</div>
 <hr>
 <div id="reg-logout-div" >
 <button type="button" class="btn btn-primary"  (click)="allAppsLogout()">
index 65a4be0..0d14531 100644 (file)
@@ -81,4 +81,7 @@ $topnav-background-color: #222;
   .header-menu-display {
     width: 250px;
   }
+  .language-dropdown {
+    padding: 0.25rem 1.5rem;
+  }
 }
index 429587d..74f6fb3 100644 (file)
@@ -35,7 +35,7 @@
  *
  * 
  */
-import { Component, OnInit } from '@angular/core';
+import { Component, OnInit, Output, EventEmitter } from '@angular/core';
 import { Router, NavigationEnd } from '@angular/router';
 import { UserProfileService, MenusService } from 'src/app/shared/services';
 import { CookieService } from 'ngx-cookie-service';
@@ -60,6 +60,10 @@ export class HeaderComponent implements OnInit {
     brandName: string;
     brandLogoImagePath: string;
     isSystemUser: boolean = false;
+       languages: string[] = [];
+    result: any;
+       
+    @Output() languageEvent = new EventEmitter();
 
     constructor(public router: Router, private userProfileService: UserProfileService, private menusService: MenusService, private cookieService: CookieService) {
 
@@ -87,6 +91,20 @@ export class HeaderComponent implements OnInit {
         if(this.api.brandLogoImagePath != ''){
            this.brandLogoImagePath = this.api.brandLogoImagePath;
         }
+               
+               this.menusService.getAllLanguages().subscribe(data =>{
+        this.result = data;
+            for(let lang of this.result.languageList ){
+                this.languages.push(lang);
+            }
+                       
+        this.menusService.getCurrentLang(this.loginSnippetUserid).subscribe(data=>{
+        this.result = data;
+                this.languages.map((obj:any)=>{
+                    obj.selected = obj.languageId == parseInt(this.result.languageId);
+                })   ;
+            });
+        });
     }
 
     getUserInformation() {
@@ -196,4 +214,12 @@ export class HeaderComponent implements OnInit {
     onLoggedout() {
         localStorage.removeItem('isLoggedin');
     }
+       
+       setLanguage(langId : string){
+        
+        this.menusService.setLanguage(langId, this.loginSnippetUserid).subscribe(data =>{
+            console.log("Language Applied :", data);
+            this.languageEvent.emit(langId);
+        });
+    }
 }
index 1c689e1..1723f69 100644 (file)
@@ -35,7 +35,7 @@
  *
  * 
  */
-import { Component, Output, EventEmitter, OnInit, Input } from '@angular/core';
+import { Component, Output, EventEmitter, OnInit, Input, OnChanges } from '@angular/core';
 import { Router, NavigationEnd } from '@angular/router';
 import { SidebarService } from '../../../shared/services/index'
 
@@ -57,6 +57,9 @@ export class SidebarComponent implements OnInit {
     menuData: Array<object> = [];
     page: any;
 
+    languageFinal : string;
+    @Input() langFromTab:string;
+
     @Output() collapsedEvent = new EventEmitter<boolean>();
 
     constructor(public router: Router, public sidebarService: SidebarService) {
@@ -71,64 +74,74 @@ export class SidebarComponent implements OnInit {
         });
     }
 
-    ngOnInit() {
+    ngOnChanges() {
+        this.changeLang(this.langFromTab);
+    }
+    
+    changeLang(lang){
+        this.menuData=[];
         this.isActive = false;
         this.collapsed = false;
+        this.languageFinal=lang;
         this.showMenu = '';
         this.pushRightClass = 'push-right';
         this.sidebarService.getLeftMenu()
-            .subscribe(data => {
-                this.result = data;
-                if (this.result.data && this.result.data2) {
-                    this.leftParentData = JSON.parse(this.result.data);
-                    this.leftChildData = JSON.parse(this.result.data2);
+        .subscribe(data => {
+            this.result = data;
+            if (this.result.data && this.result.data2) {
+                this.leftParentData = JSON.parse(this.result.data);
+                this.leftChildData = JSON.parse(this.result.data2);
+            } else {
+                this.labelName = this.result.label;
+                this.leftParentData = this.result.navItems;
+                this.showOnlyParentMenu = true;
+            }
+
+            for (var i = 0; i < this.leftParentData.length; i++) {
+                var parentItem = {
+                    name: null,
+                    imageSrc: null,
+                    href: null,
+                    menuItems: [],
+                    state: null
+                }
+                if (this.showOnlyParentMenu) {
+                    parentItem.name = this.leftParentData[i].name;
+                    parentItem.imageSrc = this.leftParentData[i].imageSrc;
+                    parentItem.state = '/'+this.leftParentData[i].state;
                 } else {
-                    this.labelName = this.result.label;
-                    this.leftParentData = this.result.navItems;
-                    this.showOnlyParentMenu = true;
+                    parentItem.name = this.leftParentData[i].label;
+                    parentItem.imageSrc = this.leftParentData[i].imageSrc;
                 }
+                // Add link to items with no subitems
+                if (!this.showOnlyParentMenu) {
+                    if (this.leftChildData[i].length == 0)
+                        parentItem.href = this.leftParentData[i].action;
 
-                for (var i = 0; i < this.leftParentData.length; i++) {
-                    var parentItem = {
-                        name: null,
-                        imageSrc: null,
-                        href: null,
-                        menuItems: [],
-                        state: null
-                    }
-                    if (this.showOnlyParentMenu) {
-                        parentItem.name = this.leftParentData[i].name;
-                        parentItem.imageSrc = this.leftParentData[i].imageSrc;
-                        parentItem.state = '/'+this.leftParentData[i].state;
-                    } else {
-                        parentItem.name = this.leftParentData[i].label;
-                        parentItem.imageSrc = this.leftParentData[i].imageSrc;
-                    }
-                    // Add link to items with no subitems
-                    if (!this.showOnlyParentMenu) {
-                        if (this.leftChildData[i].length == 0)
-                            parentItem.href = this.leftParentData[i].action;
-
-                        for (var j = 0; j < this.leftChildData[i].length; j++) {
-
-                            var childItem = {
-                                name: null,
-                                href: null
-                            };
-                            if (this.leftChildData[i][j].label != null && this.leftChildData[i][j].label.length > 0) {
-
-                                childItem.name = this.leftChildData[i][j].label;
-                                childItem.href = this.leftChildData[i][j].action;
-                                parentItem.menuItems.push(childItem);
-                            }
+                    for (var j = 0; j < this.leftChildData[i].length; j++) {
+
+                        var childItem = {
+                            name: null,
+                            href: null
+                        };
+                        if (this.leftChildData[i][j].label != null && this.leftChildData[i][j].label.length > 0) {
+
+                            childItem.name = this.leftChildData[i][j].label;
+                            childItem.href = this.leftChildData[i][j].action;
+                            parentItem.menuItems.push(childItem);
                         }
                     }
-                    this.menuData.push(parentItem);
                 }
+                this.menuData.push(parentItem);
+            }
 
-            });
+        });        
+    }
 
+    ngOnInit() {
+        this.changeLang("");
     }
+
     eventCalled() {
         this.isActive = !this.isActive;
     }
index db0b6af..a12a8df 100644 (file)
@@ -68,7 +68,7 @@
 
           <div style="display: flex; flex-direction:column; overflow-y: scroll; height: calc(100vh - 100px)">
             <div style="display: flex; flex-direction:row;">
-              <app-sidebar (collapsedEvent)="receiveCollapsed($event)"></app-sidebar>
+                         <app-sidebar (collapsedEvent)="receiveCollapsed($event)" [langFromTab]="inputedLanguage"></app-sidebar>
               <app-userbar></app-userbar>
               <div class="container" [ngStyle]="setStyle()">
                 <router-outlet></router-outlet>
index 066d73f..37a7e91 100644 (file)
@@ -40,7 +40,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { TabbarComponent } from './tabbar.component';
 import { NgMaterialModule } from 'src/app/ng-material-module';
-import { Component } from '@angular/core';
+import { Component, Input } from '@angular/core';
 import { ElipsisPipe } from 'src/app/shared/pipes/elipsis/elipsis.pipe';
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 import { HttpClientTestingModule} from '@angular/common/http/testing';
@@ -69,7 +69,7 @@ describe('TabbarComponent', () => {
 });
 
 @Component({selector: 'app-sidebar', template: ''})
-class AppSideBarStubComponent {}
+class AppSideBarStubComponent {@Input() langFromTab:string;}
 
 @Component({selector: 'router-outlet', template: ''})
 class RouterOutletStubComponent { }
index 86f7659..f44b4ef 100644 (file)
@@ -35,7 +35,7 @@
  *
  *
  */
-import { Component, OnInit } from '@angular/core';
+import { Component, OnInit, Input, OnChanges } from '@angular/core';
 import { FormControl } from '@angular/forms';
 import { DomSanitizer } from '@angular/platform-browser';
 import { Tab } from './tab';
@@ -54,6 +54,10 @@ export class TabbarComponent implements OnInit {
   mainTab = 'Home';
   selected = new FormControl(0);
   collapedSideBar: boolean;
+  inputedLanguage: string;
+  @Input() language:string;
+
 
   constructor(private sanitizer: DomSanitizer, private addTabFuntionService: AddTabFunctionService, private auditLogService: AuditLogService) {
 
@@ -68,6 +72,13 @@ export class TabbarComponent implements OnInit {
       
     })
   }
+  
+  ngOnChanges() {
+    this.changeLang(this.language);
+  }
+  changeLang(lang){
+    this.inputedLanguage=lang;
+  }
 
   addTab(selectAfterAdding: boolean, label: string, url: string) {
     const tab = new Tab(label);
index fa7ada0..4c2bb4d 100644 (file)
@@ -36,8 +36,8 @@
 
   -->
 
-  <app-header></app-header>
-  <app-tabbar></app-tabbar>
+   <app-header (languageEvent)="setLanguage($event)"></app-header>
+   <app-tabbar [language]="language"></app-tabbar>
 
 
 
index 3074c29..91b43c2 100644 (file)
@@ -38,7 +38,7 @@
 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { LayoutComponent } from './layout.component';
-import { Component } from '@angular/core';
+import { Component, Input } from '@angular/core';
 
 describe('LayoutComponent', () => {
   let component: LayoutComponent;
@@ -65,4 +65,4 @@ describe('LayoutComponent', () => {
 class AppheaderStubComponent {}
 
 @Component({selector: 'app-tabbar', template: ''})
-class AppTabBarStubComponent { }
\ No newline at end of file
+class AppTabBarStubComponent { @Input() language: string; }
\ No newline at end of file
index b512988..d74f84d 100644 (file)
@@ -45,6 +45,8 @@ import { Component, OnInit } from '@angular/core';
 export class LayoutComponent implements OnInit {
 
     collapedSideBar: boolean;
+       language: string;
+
 
     constructor() {}
 
@@ -53,4 +55,8 @@ export class LayoutComponent implements OnInit {
     receiveCollapsed($event) {
         this.collapedSideBar = $event;
     }
+       
+       setLanguage(lang) {
+        this.language= lang;
+    }
 }
index f0c16d6..392527a 100644 (file)
@@ -61,7 +61,19 @@ export class MenusService {
 
   setFavoriteItem(menuId) {
     return this.http.post(this.apiUrl.setFavoriteItem, menuId);
+  }
+  
+  getAllLanguages() {
+    return this.http.get(this.apiUrl.getLanguages);
+  }
+
+  setLanguage(langId, loginId) {
+    const body = { languageId: langId}
+    return this.http.post(this.apiUrl.updateLang.replace(':loginId',loginId ), body);
+  }
 
+  getCurrentLang(loginId) {
+    return this.http.get(this.apiUrl.getCurrentLang.replace(':loginId',loginId ));
   }
 
   removeFavoriteItem(menuId) {
index b0b21b3..5060534 100644 (file)
@@ -50,5 +50,9 @@ export class SidebarService {
     return this.http.get(this.api.leftmenuItems);
 
   }
+  
+  getAllLanguages() {
+    return this.http.get(this.api.getLanguages);
+  }
 
 }