File

src/app/plugins/profile/components/profile-badge/profile-badge.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(resourceService: ResourceService, userService: UserService, badgeService: BadgesService, configService: ConfigService)
Parameters :
Name Type Optional
resourceService ResourceService No
userService UserService No
badgeService BadgesService No
configService ConfigService No

Methods

getBadgeData
getBadgeData()

This method is used to fetch detailed badge data

Returns : void
ngOnInit
ngOnInit()

This method is used to call getBadgeData method

Returns : void
toggle
toggle(viewMore)

This method is used to show/hide ViewMore based on the limit

Parameters :
Name Optional
viewMore No
Returns : void

Properties

badgeArray
Type : any
Default value : []

Contains array of badges

Public badgeService
Type : BadgesService
Public configService
Type : ConfigService
defaultLimit
Default value : this.configService.appConfig.PROFILE.defaultShowMoreLimit

Contains default limit to show awards

limit
Default value : this.defaultLimit

Used to store limit to show/hide awards

Public resourceService
Type : ResourceService
userProfile
Type : IUserProfile

Reference of User Profile interface

Public userService
Type : UserService
viewMore
Default value : true

Booloean value to hide/show awards

import { Component, OnInit } from '@angular/core';
import { ResourceService, ConfigService, IUserProfile, IUserData } from '../../../../modules/shared';
import { UserService, BadgesService } from '../../../../modules/core/services';
import * as _ from 'lodash-es';

@Component({
  selector: 'app-profile-badge',
  templateUrl: './profile-badge.component.html',
  styleUrls: ['./profile-badge.component.scss']
})
export class ProfileBadgeComponent implements OnInit {
  /**
   * Reference of User Profile interface
   */
  userProfile: IUserProfile;
  /**
   * Booloean value to hide/show awards
   */
  viewMore = true;
  /**
   * Contains default limit to show awards
   */
  defaultLimit = this.configService.appConfig.PROFILE.defaultShowMoreLimit;
  /**
   * Used to store limit to show/hide awards
   */
  limit = this.defaultLimit;
  /**
   * Contains array of badges
   */
  badgeArray: any = [];
  constructor(public resourceService: ResourceService, public userService: UserService,
    public badgeService: BadgesService, public configService: ConfigService) { }
  /**
   * This method is used to call getBadgeData method
   */
  ngOnInit() {
    this.getBadgeData();
  }
  /**
   * This method is used to fetch detailed badge data
   */
  getBadgeData() {
    this.userService.userData$.subscribe(
      (user: IUserData) => {
        if (user && !user.err && user.userProfile.badgeAssertions) {
          this.userProfile = user.userProfile;
          const badgeList = [];
          _.each(this.userProfile.badgeAssertions, (badge) => {
            badgeList.push(badge['badgeId']);
          });
          const req = {
            request: {
              filters: {
                'badgeList': badgeList,
                'type': 'user',
                'rootOrgId': this.userProfile.rootOrgId
              }
            }
          };
          this.badgeArray = [];
          this.badgeService.getDetailedBadgeAssertions(req, this.userProfile.badgeAssertions).subscribe((detailedAssertion) => {
            if (detailedAssertion) {
              this.badgeArray.push(detailedAssertion);
            }
          });
        }
      });
  }
  /**
   * This method is used to show/hide ViewMore based on the limit
   */
  toggle(viewMore) {
    if (viewMore === true) {
      this.limit = this.badgeArray.length;
      this.viewMore = false;
    } else {
      this.viewMore = true;
      this.limit = this.defaultLimit;
    }
  }
}
  <section class="d-flex flex-ai-center flex-jc-center flex-dc pt-30 pb-30" *ngIf="badgeArray && badgeArray.length > 0">
    <div class="fs-1-7 font-weight-bold mb-30">{{resourceService?.frmelmnts?.lbl?.myBadges}} ({{badgeArray.length}})&#x200E;</div>
    <div class="d-flex flex-ai-center flex-jc-center flex-dr flex-w-wrap badges-container">
      <div class="px-60 py-20" *ngFor="let badge of badgeArray | slice:0:limit">
          <img class="ui small custom badge image" src="{{badge.image || badge.badgeClassImage}}" alt="my badges">
      </div>
    </div>
    <div *ngIf="badgeArray.length > defaultLimit">
    <button class="ui semi-circular dodger-blue button mt-30" tabindex="0" *ngIf="viewMore" (click)="toggle(true)"> {{resourceService?.frmelmnts?.btn?.viewmore}} <i class="chevron down icon ml-5 mr-0"></i></button>
    <button class="ui semi-circular dodger-blue button mt-30" tabindex="0" (click)="toggle(false)" *ngIf="!viewMore">{{resourceService?.frmelmnts?.btn?.viewless}} <i class="chevron up icon ml-5 mr-0" ></i></button>
  </div>
  </section>

./profile-badge.component.scss

@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;

.ui.small.custom.badge.image {
  height: calculateRem(75px);
  width: calculateRem(75px);
  max-height: calculateRem(75px);
  max-width: calculateRem(75px);
}

.badges-container {
  max-width: calc(calculateRem(195px) * 4);
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""