Feature 10941: User Management Enhancements
[osm/NG-UI.git] / src / app / layouts / header / HeaderComponent.ts
index 4d7f3b1..9392177 100644 (file)
  * @file Header Component
  */
 import { Component, Injector, OnInit } from '@angular/core';
-import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
+import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
+import { TranslateService } from '@ngx-translate/core';
+import { AddEditUserComponent } from 'AddEditUserComponent';
 import { AuthenticationService } from 'AuthenticationService';
+import { MODALCLOSERESPONSEDATA } from 'CommonModel';
 import { environment } from 'environment';
 import { ProjectService } from 'ProjectService';
 import { Observable } from 'rxjs';
 import { SharedService } from 'SharedService';
-import { ProjectRoleMappings, UserDetail } from 'UserModel';
 import { UserSettingsComponent } from 'UserSettingsComponent';
 
 /**
@@ -61,9 +63,18 @@ export class HeaderComponent implements OnInit {
     /** Version holds packages version @public */
     public PACKAGEVERSION: string;
 
+    /** To check the role of the user is systemadmin or not @public */
+    public isSystemAdmin: boolean;
+
     /** Contains all methods related to shared @public */
     public sharedService: SharedService;
 
+    /** Property contains to show new version tag shared @public */
+    public toShowNewTag: Boolean = false;
+
+    /** handle translate @public */
+    public translateService: TranslateService;
+
     /** Utilizes auth service for any auth operations @private */
     private authService: AuthenticationService;
 
@@ -79,19 +90,27 @@ export class HeaderComponent implements OnInit {
         this.modalService = this.injector.get(NgbModal);
         this.projectService = this.injector.get(ProjectService);
         this.sharedService = this.injector.get(SharedService);
+        this.translateService = this.injector.get(TranslateService);
     }
 
     /** Lifecyle Hooks the trigger before component is instantiate @public */
     public ngOnInit(): void {
         this.isAdmin = (localStorage.getItem('isAdmin') === 'true') ? true : false;
+        this.isSystemAdmin = localStorage.getItem('admin_show') === 'true' ? true : false;
         this.selectedProject = this.authService.ProjectName;
-        this.authService.ProjectName.subscribe((projectNameFinal: string) => {
+        this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
             this.getSelectedProject = projectNameFinal;
         });
         this.username$ = this.authService.username;
         this.projectService.setHeaderProjects();
         this.projectList$ = this.projectService.projectList;
         this.PACKAGEVERSION = environment.packageVersion;
+        const getLocalStorageVersion: string = localStorage.getItem('osmVersion');
+        if (getLocalStorageVersion === null) {
+            this.showNewVersion();
+        } else if (getLocalStorageVersion !== this.sharedService.osmVersion) {
+            this.showNewVersion();
+        }
     }
 
     /** Logout function  @public */
@@ -99,8 +118,36 @@ export class HeaderComponent implements OnInit {
         this.authService.logout();
     }
 
+    /** Show Version function  @public */
+    public showNewVersion(): void {
+        this.toShowNewTag = true;
+    }
+
+    /** Close Version and add in local storage  @public */
+    public closeVersion(): void {
+        this.toShowNewTag = false;
+        localStorage.setItem('osmVersion', this.sharedService.osmVersion);
+    }
+
     /** Implementation of model for UserSettings options.@public */
     public userSettings(): void {
+        // eslint-disable-next-line security/detect-non-literal-fs-filename
         this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
     }
+
+    /** ChangePassword Function @public */
+    public changePassword(): void {
+        // eslint-disable-next-line security/detect-non-literal-fs-filename
+        const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static' });
+        modalRef.componentInstance.userID = localStorage.getItem('user_id');
+        modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
+        modalRef.componentInstance.userType = 'changePassword';
+        modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
+            if (result) {
+                this.sharedService.callData();
+            }
+        }).catch((): void => {
+            // Catch Navigation Error
+        });
+    }
 }