File

src/app/modules/badging/components/assign-badges-content/assign-badges-content.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs

Constructor

constructor(resourceService: ResourceService, userService: UserService, badgeService: BadgesService, toasterService: ToasterService, activatedRoute: ActivatedRoute, contentBadgeService: ContentBadgeService)
Parameters :
Name Type Optional
resourceService ResourceService No
userService UserService No
badgeService BadgesService No
toasterService ToasterService No
activatedRoute ActivatedRoute No
contentBadgeService ContentBadgeService No

Inputs

data
Type : Array<object>

Methods

Public assignBadge
assignBadge(badge)
Parameters :
Name Optional
badge No
Returns : void
Public getBadgeDetails
getBadgeDetails()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public setBadge
setBadge(Badge)
Parameters :
Name Optional
Badge No
Returns : void
setInteractEventData
setInteractEventData()
Returns : void

Properties

Public activatedRoute
Type : ActivatedRoute
Public allBadgeList
Type : any
Public assignBadgeInteractEdata
Type : IInteractEventEdata
Public badge
Type : object
Public badgeInteractEdata
Type : IInteractEventEdata
Public badgeService
Type : BadgesService
Public cancelBadgeInteractEdata
Type : IInteractEventEdata
Public contentBadgeService
Type : ContentBadgeService
Public contentId
Type : string
Public resourceService
Type : ResourceService
showBadgeAssingModel
Type : boolean
Public telemetryInteractObject
Type : IInteractEventObject
Public toasterService
Type : ToasterService
Public unsubscribe
Default value : new Subject<void>()
userDataSubscription
Type : Subscription
userProfile
Type : IUserProfile

Reference of User Profile interface

Private userRoles
Type : Array<string>
Default value : []

all user role

Public userService
Type : UserService
import {takeUntil} from 'rxjs/operators';
import { Subscription ,  Subject } from 'rxjs';
import { Component, OnInit, Input, OnDestroy } from '@angular/core';
import { ResourceService, IUserData, IUserProfile, ToasterService } from '@sunbird/shared';
import { UserService, BadgesService } from '@sunbird/core';
import { ContentBadgeService } from './../../services';
import * as _ from 'lodash-es';
import { ActivatedRoute } from '@angular/router';
import { IInteractEventObject, IInteractEventEdata } from '@sunbird/telemetry';
@Component({
  selector: 'app-assign-badges-content',
  templateUrl: './assign-badges-content.component.html'
})
export class AssignBadgesContentComponent implements OnInit, OnDestroy {
  showBadgeAssingModel: boolean;
  @Input() data: Array<object>;
  public contentId: string;
  userDataSubscription: Subscription;
  public unsubscribe = new Subject<void>();
  /**
   * Reference of User Profile interface
   */
  userProfile: IUserProfile;
  /**
   * all user role
   */
  private userRoles: Array<string> = [];
  public badge: object;
  public allBadgeList: any;
  public badgeInteractEdata: IInteractEventEdata;
  public cancelBadgeInteractEdata: IInteractEventEdata;
  public assignBadgeInteractEdata: IInteractEventEdata;
  public telemetryInteractObject: IInteractEventObject;
  constructor(public resourceService: ResourceService, public userService: UserService,
    public badgeService: BadgesService, public toasterService: ToasterService,
    public activatedRoute: ActivatedRoute, public contentBadgeService: ContentBadgeService) { }

  ngOnInit() {
    this.userDataSubscription = this.userService.userData$.subscribe(
      (user: IUserData) => {
        if (user && !user.err) {
          this.userProfile = user.userProfile;
          this.userRoles = user.userProfile.userRoles;
          this.getBadgeDetails();
        }
      });
    this.activatedRoute.params.subscribe((params) => {
      this.contentId = params.collectionId;
    });
    this.setInteractEventData();
  }

  public getBadgeDetails() {

    const req = {
      request: {
        filters: {
          'issuerList': [],
          'rootOrgId': this.userProfile.rootOrgId,
          'roles': this.userRoles,
          'type': 'content',
        }
      }
    };
    this.badgeService.getAllBadgeList(req).pipe(
    takeUntil(this.unsubscribe))
    .subscribe((response) => {
      this.allBadgeList = _.differenceBy(response.result.badges, this.data, 'badgeId');
    }, (err) => {
      if (err && err.error && err.error.params) {
        this.toasterService.error(err.error.params.errmsg);
      } else {
        this.toasterService.error(this.resourceService.messages.fmsg.m0080);
      }
    });
  }
  public setBadge(Badge) {
    this.badge = Badge;
  }
  public assignBadge(badge) {
    this.showBadgeAssingModel = false;
    const req = {
      'issuerId': badge.issuerId,
      'badgeId': badge.badgeId,
      'recipientId': this.contentId,
      'recipientType': 'content'
    };
    this.contentBadgeService.addBadge(req).pipe(
    takeUntil(this.unsubscribe))
    .subscribe((response) => {
      if (this.data === undefined) {
        this.data = [];
      }
      this.data.push(badge);
      this.allBadgeList = this.allBadgeList.filter((badges) => {
        return badges.badgeId !== badge.badgeId;
      });
      this.contentBadgeService.setAssignBadge(badge);
      this.toasterService.success(this.resourceService.messages.smsg.m0044);
    }, (err) => {
      this.toasterService.error(this.resourceService.messages.fmsg.m0079);
    });
  }
  setInteractEventData() {
    this.badgeInteractEdata = {
      id: 'add-content-badge',
      type: 'click',
      pageid: 'content-badge'
    };
    this.cancelBadgeInteractEdata = {
      id: 'cancel-badge',
      type: 'click',
      pageid: 'content-badge'
    };
    this.assignBadgeInteractEdata = {
      id: 'assign-badge',
      type: 'click',
      pageid: 'content-badge'
    };
  }

  ngOnDestroy() {
    if (this.userDataSubscription) {
      this.userDataSubscription.unsubscribe();
      }
    this.unsubscribe.next();
    this.unsubscribe.complete();
  }
}





<div class="ui grid stackable">
  <div class="twelve wide column mt-0 pt-0" *ngIf="allBadgeList && allBadgeList.length > 0">
    <span>{{resourceService?.frmelmnts?.lbl?.markas}}:</span>
    <button appTelemetryInteract [telemetryInteractObject]="{id:badge.badgeId,type:'Badge',ver:'1.0'}"
      [telemetryInteractEdata]="badgeInteractEdata" tabindex="0"
      class="ui small basic primary compact button ml-10 mt-10" *ngFor="let badge of allBadgeList"
      (click)="setBadge(badge);showBadgeAssingModel=true;">{{badge.name | uppercase}}</button>
  </div>
</div>
<app-modal-wrapper *ngIf="showBadgeAssingModel"
  [config]="{disableClose: true, size: 'small', panelClass: 'material-modal'}" (dismiss)="showBadgeAssingModel=false"
  #modal>
  <ng-template sbModalContent>
    <div class="sb-mat__modal">

      <!--Header-->
      <div mat-dialog-title class="mb-0">
        <div class="title" tabindex="0">{{resourceService?.frmelmnts?.lbl?.markas}} '{{badge.name | uppercase}}'</div>
      </div>
      <!--/Header-->

      <!--Content-->
      <div class="sb-mat__modal__content">
        {{resourceService?.frmelmnts?.lbl?.badgeassignconfirmation}}
      </div>
      <!--/Content-->

      <!--Actions-->
      <mat-dialog-actions class="sb-mat__modal__actions">
        <button appTelemetryInteract [telemetryInteractObject]="{id:badge.badgeId,type:'Badge',ver:'1.0'}"
          [telemetryInteractEdata]="assignBadgeInteractEdata" class="sb-btn sb-btn-normal sb-btn-primary"
          (click)="assignBadge(badge)" tabindex="0">
          {{resourceService?.frmelmnts?.btn?.yesiamsure}}
        </button>
        <button tabindex="0" appTelemetryInteract [telemetryInteractObject]="{id:badge.badgeId,type:'Badge',ver:'1.0'}"
          [telemetryInteractEdata]="cancelBadgeInteractEdata" class="sb-btn sb-btn-normal sb-btn-outline-primary"
          (click)="showBadgeAssingModel=false;">
          {{resourceService?.frmelmnts?.btn?.cancel}}
        </button>
      </mat-dialog-actions>
      <!--/Actions-->

    </div>
  </ng-template>
</app-modal-wrapper>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""