File

src/app/tabs/tabs.page.ts

Implements

OnInit AfterViewInit

Metadata

Index

Properties
Methods

Constructor

constructor(container: ContainerService, events: Events, toastCtrl: ToastController, appGlobalService: AppGlobalService, preferences: SharedPreferences, profileService: ProfileService, commonUtilService: CommonUtilService, router: Router, onboardingConfigurationService: OnboardingConfigurationService)
Parameters :
Name Type Optional
container ContainerService No
events Events No
toastCtrl ToastController No
appGlobalService AppGlobalService No
preferences SharedPreferences No
profileService ProfileService No
commonUtilService CommonUtilService No
router Router No
onboardingConfigurationService OnboardingConfigurationService No

Methods

checkAndroidWebViewVersion
checkAndroidWebViewVersion()
Returns : void
Async checkOnboardingProfileDetails
checkOnboardingProfileDetails()
Returns : any
Private Async getInitialTabs
getInitialTabs(session)
Parameters :
Name Optional
session No
Returns : Promise<any[]>
ionTabsDidChange
ionTabsDidChange(event: any)
Parameters :
Name Type Optional
event any No
Returns : void
ionViewWillEnter
ionViewWillEnter()
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void
Async ngOnInit
ngOnInit()
Returns : any
Public Async onTabClick
onTabClick(tab)
Parameters :
Name Optional
tab No
Returns : any
openScanner
openScanner(tab)
Parameters :
Name Optional
tab No
Returns : void
Private Async refreshTabs
refreshTabs(data?)
Parameters :
Name Optional
data Yes
Returns : any
setQRStyles
setQRStyles()
Returns : void
Private setQRTabRoot
setQRTabRoot(tab: string)
Parameters :
Name Type Optional
tab string No
Returns : void

Properties

appLabel
Type : any
configData
Type : any
headerConfig
Type : object
Default value : { showHeader: true, showBurgerMenu: true, actionButtons: ['search', 'filter'], }
olderWebView
Default value : false
selectedLanguage
Type : string
selectedTab
Type : string
tabIndex
Type : number
Default value : 0
tabList
Type : any
tabRef
Type : IonTabs
Decorators :
@ViewChild('tabRef', {static: false})
tabs
Type : []
Default value : []
Public toastCtrl
Type : ToastController
import { AfterViewInit, Component, Inject, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { Router } from '@angular/router';
import { EventTopics, PreferenceKey, ProfileConstants, RouterLinks, SwitchableTabsConfig } from '@app/app/app.constant';
import { initTabs } from '@app/app/module.service';
import { OnTabViewWillEnter } from '@app/app/tabs/on-tab-view-will-enter';
import { PageId } from '@app/services';
import { AppGlobalService } from '@app/services/app-global-service.service';
import { CommonUtilService } from '@app/services/common-util.service';
import { ContainerService } from '@app/services/container.services';
import { IonTabs, ToastController } from '@ionic/angular';
import { Events } from '@app/util/events';
import { ProfileService, ProfileType, SharedPreferences } from 'sunbird-sdk';
import { OnboardingConfigurationService } from '@app/services/onboarding-configuration.service';

@Component({
  selector: 'app-tabs',
  templateUrl: './tabs.page.html',
  styleUrls: ['./tabs.page.scss'],
  encapsulation: ViewEncapsulation.None
})
export class TabsPage implements OnInit, AfterViewInit {

  configData: any;
  @ViewChild('tabRef', { static: false }) tabRef: IonTabs;
  tabIndex = 0;
  tabs = [];
  headerConfig = {
    showHeader: true,
    showBurgerMenu: true,
    actionButtons: ['search', 'filter'],
  };
  selectedLanguage: string;
  appLabel: any;
  olderWebView = false;
  tabList: any;
  selectedTab: string;

  constructor(
    private container: ContainerService,
    private events: Events,
    public toastCtrl: ToastController,
    private appGlobalService: AppGlobalService,
    @Inject('SHARED_PREFERENCES') private preferences: SharedPreferences,
    @Inject('PROFILE_SERVICE') private profileService: ProfileService,
    private commonUtilService: CommonUtilService,
    private router: Router,
    private onboardingConfigurationService: OnboardingConfigurationService
  ) {

  }

  async ngOnInit() {
    this.checkAndroidWebViewVersion();
    const session = await this.appGlobalService.authService.getSession().toPromise();
    if (session) {
      if ((await this.preferences.getString('SHOW_WELCOME_TOAST').toPromise()) === 'true') {
        this.preferences.putString('SHOW_WELCOME_TOAST', 'false').toPromise().then();

        const serverProfile = await this.profileService.getServerProfilesDetails({
          userId: session.userToken,
          requiredFields: ProfileConstants.REQUIRED_FIELDS,
        }).toPromise();
        this.commonUtilService.showToast(this.commonUtilService.translateMessage('WELCOME_BACK', serverProfile.firstName));
      }
    }
    this.refreshTabs();
    this.events.subscribe('UPDATE_TABS', async (data) => {
      this.refreshTabs(data);
    });
  }

  private async refreshTabs(data?) {
    this.selectedTab = '';
    initTabs(this.container, await this.getInitialTabs(await this.appGlobalService.authService.getSession().toPromise()));
    this.tabs = this.container.getAllTabs();
    if (!data || (data && !data.navigateToCourse)) {
    this.router.navigate(['/tabs/' + this.tabs[0].root]);
    }
  }

  ngAfterViewInit() {
    this.setQRStyles();
    this.setQRTabRoot(this.tabRef.getSelected());
  }

  setQRStyles() {
    setTimeout(async () => {
      if (document.getElementById('qrScannerIcon') && document.getElementById('backdrop')) {
        const backdropClipCenter = document.getElementById('qrScannerIcon').getBoundingClientRect().left +
          ((document.getElementById('qrScannerIcon').getBoundingClientRect().width) / 2);

        (document.getElementById('backdrop').getElementsByClassName('bg')[0] as HTMLDivElement).setAttribute(
          'style',
          `background-image: radial-gradient(circle at ${backdropClipCenter}px 56px, rgba(0, 0, 0, 0) 30px, rgba(0, 0, 0, 0.9) 30px);`
        );
      } else {
        this.setQRStyles();
      }

    }, 2000);
  }

  checkAndroidWebViewVersion() {
    let that = this;
    plugins['webViewChecker'].getCurrentWebViewPackageInfo()
      .then(function (packageInfo) {
        if (parseInt(packageInfo.versionName.split('.')[0], 10) <= 68) {
          that.olderWebView = true;
        }
      })
      .catch(function (error) { });
  }

  ionViewWillEnter() {
    if (this.tabRef.outlet.component['tabViewWillEnter']) {
      (this.tabRef.outlet.component as OnTabViewWillEnter).tabViewWillEnter();
    }
    this.tabs = this.container.getAllTabs();
    this.events.publish('update_header');
    this.events.subscribe('return_course', () => {
      setTimeout(() => {
        const tab:any = 'courses';
        this.tabRef.select(tab);
      }, 300);
    });
    this.events.subscribe('to_profile', () => {
      setTimeout(() => {
        const tab:any = 'profile';
        this.tabRef.select(tab);
      }, 300);
    });
  }

  openScanner(tab) {
    this.events.publish(EventTopics.TAB_CHANGE, tab.label);
  }

  ionTabsDidChange(event: any) {
    this.selectedTab = event.tab;
    this.setQRTabRoot(event.tab);
    if (event.tab === 'resources') {
      event.tab = PageId.LIBRARY;
      this.events.publish(EventTopics.TAB_CHANGE, event.tab);
    } else {
      this.events.publish(EventTopics.TAB_CHANGE, event.tab);
    }
    this.commonUtilService.currentTabName = this.tabRef.getSelected();
    this.checkOnboardingProfileDetails();
  }

  public async onTabClick(tab) {
    if (tab.disabled) {
      if (tab.availableLater) {
        this.commonUtilService.showToast('Will be available in later release', false, 'sb-toast available-later');
      } else {
        this.commonUtilService.showToast('AVAILABLE_FOR_TEACHERS', false, 'sb-toast available-later');
      }
    }
  }

  async checkOnboardingProfileDetails() {
    if (!this.appGlobalService.isUserLoggedIn() && !this.appGlobalService.isOnBoardingCompleted) {
      this.router.navigate([`/${RouterLinks.PROFILE_SETTINGS}`], {
        state: {
          hideBackButton: true
        }
      });
    }
  }

  private setQRTabRoot(tab: string) {
    if (this.tabs && this.tabs.find((ele) => ele.name === 'qrscanner')) {
      const objIndex = this.tabs.findIndex((obj => obj.name === 'qrscanner'));
      this.tabs[objIndex].root = tab;
    }
  }

  private async getInitialTabs(session): Promise<any[]> {
    const defaultSwitchableTabsConfig = SwitchableTabsConfig.RESOURCE_COURSE_TABS_CONFIG;
    const selectedSwitchableTabsConfig = (await this.preferences.getString(PreferenceKey.SELECTED_SWITCHABLE_TABS_CONFIG).toPromise()) ||
      defaultSwitchableTabsConfig;
    const selectedUserType = await this.preferences.getString(PreferenceKey.SELECTED_USER_TYPE).toPromise();
    this.tabList = await this.onboardingConfigurationService.initializedTabs(selectedSwitchableTabsConfig, selectedUserType);
    const config = {
      'GUEST_TEACHER': {
        [SwitchableTabsConfig.RESOURCE_COURSE_TABS_CONFIG]: this.tabList,
        [SwitchableTabsConfig.HOME_DISCOVER_TABS_CONFIG]: this.tabList
      },
      'GUEST_STUDENT': {
        [SwitchableTabsConfig.RESOURCE_COURSE_TABS_CONFIG]: this.tabList,
        [SwitchableTabsConfig.HOME_DISCOVER_TABS_CONFIG]: this.tabList
      },
      'LOGIN_USER': {
        [SwitchableTabsConfig.RESOURCE_COURSE_TABS_CONFIG]: this.tabList,
        [SwitchableTabsConfig.HOME_DISCOVER_TABS_CONFIG]: this.tabList
      },
      'LOGIN_ADMIN': {
        [SwitchableTabsConfig.RESOURCE_COURSE_TABS_CONFIG]: this.tabList,
        [SwitchableTabsConfig.HOME_DISCOVER_TABS_CONFIG]: this.tabList
      }
    };


    if (!session) {
      const profileType = this.appGlobalService.guestProfileType;
      if (this.commonUtilService.isAccessibleForNonStudentRole(profileType)) {
        return config['GUEST_TEACHER'][selectedSwitchableTabsConfig];
      } else {
        return config['GUEST_STUDENT'][selectedSwitchableTabsConfig];
      }
    } else {
      return selectedUserType === ProfileType.ADMIN ?
        config['LOGIN_ADMIN'][selectedSwitchableTabsConfig] :
        config['LOGIN_USER'][selectedSwitchableTabsConfig];
    }
  }
}
<ion-tabs (ionTabsDidChange)="ionTabsDidChange($event)" #tabRef>
  <ion-tab-bar slot="bottom" [ngClass]="{'rm-before': olderWebView}" >
    <ion-tab-button [tab]="tab.root" *ngFor="let tab of tabs; let i = index;" [disabled]="tab.disabled" [style.display]="!tab.is_visable ? 'none' : ''"
      [ngClass]="{'disabled': tab.disabled}" (click)="tab.label === '' ? openScanner(tab) : onTabClick(tab)" class= "{{tab.name}}">
      <ion-icon [attr.aria-label]="tab?.selected ?
      'selected ' + tab?.name : tab?.name" tabindex="0" [src]="(tab.root === selectedTab) ? tab?.icon?.active : 
      (tab.isSelected && !selectedTab) ? tab?.icon?.active : tab?.icon?.inactive"></ion-icon>
    </ion-tab-button>
  </ion-tab-bar>
</ion-tabs>

./tabs.page.scss

@import "src/assets/styles/base/_variables.scss";
@import "src/assets/styles/_custom-mixins.scss";
@import "src/assets/styles/_variables.scss";

ion-tabs {
  .rm-before{
    &::before {
      position: relative !important;
    }
  }
  ion-tab-bar {
    align-items: flex-end;
    contain: none;
    filter: drop-shadow(0px 5px 6px rgba(0, 0, 0, 0.3));
    border-top: 2px solid var(--app-primary-header);
  }

  ion-tab-button.tab-layout-icon-top.tab-has-label.tab-has-icon ion-label {
    font-size: 0.625rem;
    text-align: center;
    @include margin(0, null, null, null);
    font-weight: normal;
    text-transform: capitalize;
    line-height: 1.25rem;
  }

  ion-tab-button.qrscanner {
    filter: none;
    border: none;

    position: relative;
    
    height: calc(64px + (64px / 2));

    &::before {
      content: "";
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-40px);
      width: 5rem;
      height: 4rem;
      // background-image: radial-gradient(circle at center 0px, rgba(255, 255, 255, 0) 25px, rgba(0, 0, 0, 0.1) 35px);
      z-index: 1;
    }

    &::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-40px);
      width: 5rem;
      height: 4rem;
      // background-image: radial-gradient(circle at center 0px, rgba(255, 255, 255, 0) 36px, rgba(255, 255, 255, 1) 35px);
      z-index: 2;
    }

    ion-icon {
      bottom: 0.375rem;
      position: relative;
      background: var(--app-white);
      width: 4rem;
      height: 4rem;
      margin: 0px;
      padding: 0px;
      min-height: 4rem;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 0.5rem solid var(--app-tertiary-light);
      border-radius: 1rem;
      color: $white;

      .icon-inner {
        width: 3.5rem;
        height: 3.5rem;
      }
    }
  }

  ion-icon {
    background-repeat: no-repeat;
    background-position: center;
    height: 1.25rem;
    width: 1.25rem;
    background-size: contain;
  }
  ion-tab-button {
    --color-selected: #{$blue};
    background: transparent;
  }
  
  .tab-button[aria-selected="true"] {
    color: $primary-color;
  }

  ion-tab-button.tab-selected,
  ion-tab-button:not(.tab-selected) {
    ion-icon {
      font-size: 1.25rem;
    }
    ion-label {
      font-size: 0.75rem;
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""