File

src/app/modules/core/components/main-menu/main-menu.component.ts

Description

Main menu component

Metadata

selector app-main-menu
styleUrls main-menu.component.scss
templateUrl main-menu.component.html

Constructor

constructor(resourceService: any, userService: UserService, router: Router, activatedRoute: ActivatedRoute, permissionService: PermissionService, config: any, cacheService: CacheService, programsService: ProgramsService)

Methods

setInteractData
setInteractData()
Returns: void
getLogoutInteractEdata
getLogoutInteractEdata()
Returns: void
logout
logout()
Returns: void
showSideBar
showSideBar()
Returns: void
navigateTo
navigateTo(url: any)
Returns: void
getUrl
getUrl()
Returns: void
navigateToWorkspace
navigateToWorkspace()
Returns: void
getFeatureId
getFeatureId(featureId: any, taskId: any)
Returns: void

Properties

activatedRoute
activatedRoute: ActivatedRoute
browseEdata
browseEdata: any
Public config
config: any

reference of config service.

contributeMenuEdata
contributeMenuEdata: any
exploreRoutingUrl
exploreRoutingUrl: string
helpCenterEdata
helpCenterEdata: any
helpLinkVisibility
helpLinkVisibility: string
helpMenuIntractEdata
helpMenuIntractEdata: any
homeMenuIntractEdata
homeMenuIntractEdata: any
isOffline
isOffline: boolean
learnMenuIntractEdata
learnMenuIntractEdata: any
libraryMenuIntractEdata
libraryMenuIntractEdata: any
myLibraryMenuInteractEdata
myLibraryMenuInteractEdata: any
Public permissionService
permissionService: PermissionService

reference of permissionService service.

Public resourceService
resourceService: any

reference of resourceService service.

Private router
router: Router

reference of Router.

showContributeTab
showContributeTab: boolean
showExploreHeader
showExploreHeader: boolean
Default value: false
signInIntractEdata
signInIntractEdata: any

shows/hides contribute tab

slug
slug: string
userProfile
userProfile: any

user profile details.

Public userService
userService: UserService

reference of UserService service.

workspaceMenuIntractEdata
workspaceMenuIntractEdata: any
workSpaceRole
workSpaceRole: string[]

Workspace access roles

import { ConfigService, ResourceService, IUserData, IUserProfile } from '@sunbird/shared';
import { Component, OnInit, Input } from '@angular/core';
import { UserService, PermissionService, ProgramsService } from '../../services';
import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { IInteractEventObject, IInteractEventEdata } from '@sunbird/telemetry';
import { CacheService } from '../../../shared/services/cache-service/cache.service';
import { first, filter, tap } from 'rxjs/operators';
import * as _ from 'lodash-es';
import { environment } from '@sunbird/environment';
import { merge } from 'rxjs';
declare var jQuery: any;

/**
 * Main menu component
 */
@Component({
  selector: 'app-main-menu',
  templateUrl: './main-menu.component.html',
  styleUrls: ['./main-menu.component.scss']
})
export class MainMenuComponent implements OnInit {
  /**
   * Workspace access roles
   */
  workSpaceRole: Array<string>;
  /**
   * reference of resourceService service.
   */
  public resourceService: ResourceService;
  /**
   * reference of UserService service.
   */
  public userService: UserService;
  /**
   * reference of permissionService service.
   */
  public permissionService: PermissionService;
  /**
   * reference of config service.
   */
  public config: ConfigService;
  /**
 * user profile details.
 */
  userProfile: IUserProfile;
  /**
   * reference of Router.
   */
  private router: Router;
  homeMenuIntractEdata: IInteractEventEdata;
  learnMenuIntractEdata: IInteractEventEdata;
  libraryMenuIntractEdata: IInteractEventEdata;
  myLibraryMenuInteractEdata: IInteractEventEdata;
  browseEdata: IInteractEventEdata;
  helpCenterEdata: IInteractEventEdata;
  workspaceMenuIntractEdata: IInteractEventEdata;
  helpMenuIntractEdata: IInteractEventEdata;
  contributeMenuEdata: IInteractEventEdata;
  exploreRoutingUrl: string;
  showExploreHeader = false;
  helpLinkVisibility: string;
  isOffline: boolean = environment.isOffline;
  /**
   * shows/hides contribute tab
   */

  signInIntractEdata: IInteractEventEdata;
  slug: string;
  showContributeTab: boolean;
  /*
  * constructor
  */
  constructor(resourceService: ResourceService, userService: UserService, router: Router, public activatedRoute: ActivatedRoute,
    permissionService: PermissionService, config: ConfigService, private cacheService: CacheService,
    private programsService: ProgramsService) {
    this.resourceService = resourceService;
    this.userService = userService;
    this.permissionService = permissionService;
    this.router = router;
    this.config = config;
    this.workSpaceRole = this.config.rolesConfig.headerDropdownRoles.workSpaceRole;
  }

  ngOnInit() {
    this.slug = this.activatedRoute.snapshot.params.slug;
    try {
      this.helpLinkVisibility = (<HTMLInputElement>document.getElementById('helpLinkVisibility')).value;
    } catch (error) {
      this.helpLinkVisibility = 'false';
    }
    this.setInteractData();
    this.getUrl();
    this.userService.userData$.pipe(
      tap((user: IUserData) => {
        if (user && !user.err) {
          this.userProfile = _.get(user, 'userProfile');
        }
      })
    );
  }
  setInteractData() {
    this.homeMenuIntractEdata = {
      id: 'home-tab',
      type: 'click',
      pageid: 'home'
    };
    this.libraryMenuIntractEdata = {
      id: 'library-tab',
      type: 'click',
      pageid: 'library'
    };
    this.myLibraryMenuInteractEdata = {
      id: 'myLibrary-tab',
      type: 'click',
      pageid: 'library'
    };
    this.browseEdata = {
      id: 'browse-tab',
      type: 'click',
      pageid: 'browse'
    };
    this.helpCenterEdata = {
      id: 'help-center-tab',
      type: 'click',
      pageid: 'help-center'
    };
    this.learnMenuIntractEdata = {
      id: 'learn-tab',
      type: 'click',
      pageid: 'learn'
    };
    this.workspaceMenuIntractEdata = {
      id: 'workspace-menu-button',
      type: 'click',
      pageid: 'workspace'
    };
    this.helpMenuIntractEdata = {
      id: 'help-menu-tab',
      type: 'click',
      pageid: 'help'
    };
    this.contributeMenuEdata = {
      id: 'contribute-tab',
      type: 'click',
      pageid: 'contribute'
    };
    this.signInIntractEdata = {
      id: ' signin-tab',
      type: 'click',
    };
  }

  getLogoutInteractEdata() {
    return {
      id: 'logout',
      type: 'click',
      pageid: this.router.url.split('/')[1]
    };
  }

  logout() {
    window.location.replace('/logoff');
    this.cacheService.removeAll();
  }

  showSideBar() {
    jQuery('.ui.sidebar').sidebar('setting', 'transition', 'overlay').sidebar('toggle');
  }
  navigateTo(url) {
    return this.slug ? this.slug + url : url;
  }
  getUrl() {
    this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((urlAfterRedirects: NavigationEnd) => {
      this.slug = _.get(this.activatedRoute, 'snapshot.firstChild.firstChild.params.slug');
      if (_.includes(urlAfterRedirects.url, '/explore')) {
        this.showExploreHeader = true;
        const url = urlAfterRedirects.url.split('?')[0].split('/');
        if (url.indexOf('explore') === 2) {
          this.exploreRoutingUrl = url[1] + '/' + url[2];
        } else {
          this.exploreRoutingUrl = url[1];
        }
      } else if (_.includes(urlAfterRedirects.url, '/explore-course')) {
        this.showExploreHeader = true;
        const url = urlAfterRedirects.url.split('?')[0].split('/');
        if (url.indexOf('explore-course') === 2) {
          this.exploreRoutingUrl = url[1] + '/' + url[2];
        } else {
          this.exploreRoutingUrl = url[1];
        }
      } else {
        this.showExploreHeader = false;
      }
      this.signInIntractEdata['pageid'] = this.exploreRoutingUrl;
    });
  }

  navigateToWorkspace() {
    const authroles = this.permissionService.getWorkspaceAuthRoles();
    if (authroles) {
      return authroles.url;
    }
  }

  getFeatureId(featureId, taskId) {
    return [{ id: featureId, type: 'Feature' }, { id: taskId, type: 'Task' }];
  }

}

results matching ""

    No results matching ""