File

src/app/modules/groups/components/my-groups/my-groups.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

constructor(groupService: GroupsService, router: Router, resourceService: ResourceService, userService: UserService, activatedRoute: ActivatedRoute, layoutService: LayoutService, toasterService: ToasterService, tncService: TncService, navigationhelperService: NavigationHelperService)
Parameters :
Name Type Optional
groupService GroupsService No
router Router No
resourceService ResourceService No
userService UserService No
activatedRoute ActivatedRoute No
layoutService LayoutService No
toasterService ToasterService No
tncService TncService No
navigationhelperService NavigationHelperService No

Methods

acceptAllGroupsTnc
acceptAllGroupsTnc()
Returns : void
acceptGroupTnc
acceptGroupTnc()
Returns : void
addTelemetry
addTelemetry(id, groupId?, extra?)
Parameters :
Name Optional
id No
groupId Yes
extra Yes
Returns : void
addTelemetryWithData
addTelemetryWithData(id, edata, groupId?, extra?)
Parameters :
Name Optional Description
id No
edata No

? - it's an object to specify the type and subtype of edata

groupId Yes
extra Yes
Returns : void
checkUserAcceptedTnc
checkUserAcceptedTnc()
Returns : void
closeModal
closeModal()
Returns : void
getLatestTnc
getLatestTnc()
Returns : void
getMyGroupList
getMyGroupList()
Returns : void
goBack
goBack()
Returns : void
handleGroupTnc
handleGroupTnc(event?: literal type)
Parameters :
Name Type Optional
event literal type Yes
Returns : void
initLayout
initLayout()
Returns : void
isTncUpdatedAfterAcceptance
isTncUpdatedAfterAcceptance(accepted: boolean)
Parameters :
Name Type Optional
accepted boolean No
Returns : void
navigate
navigate(event)
Parameters :
Name Optional
event No
Returns : void
Public navigateToDetailPage
navigateToDetailPage(event)
Parameters :
Name Optional
event No
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
reload
reload()
Returns : void
setTelemetryImpression
setTelemetryImpression(edata?)
Parameters :
Name Optional
edata Yes
Returns : void
Public showCreateFormModal
showCreateFormModal()
Returns : void
showFtuPopup
showFtuPopup()
Returns : void

Properties

Public groupService
Type : GroupsService
groupsList
Type : IGroupCard[]
Default value : []
isContentLoaded
Default value : new EventEmitter()
isLoader
Default value : true
isTncAccepted
Default value : true
layoutConfiguration
Public resourceService
Type : ResourceService
Public router
Type : Router
Public SELECT_CREATE_GROUP
Default value : SELECT_CREATE_GROUP
selectedGroup
Type : literal type
selectedType
Type : acceptTnc
Default value : acceptTnc.ALL
showGroupCreateForm
Default value : false
Public showModal
Default value : false
showTncModal
Default value : false
telemetryImpression
Type : IImpressionEventInput
Private unsubscribe$
Default value : new Subject<void>()
import { UserService, TncService } from '@sunbird/core';
import { IGroupCard, GROUP_DETAILS, MY_GROUPS, CREATE_GROUP, acceptTnc } from './../../interfaces';
import { Component, OnInit, OnDestroy, EventEmitter } from '@angular/core';
import { GroupsService } from '../../services';
import { ResourceService, LayoutService, ToasterService, NavigationHelperService } from '@sunbird/shared';
import { Router, ActivatedRoute } from '@angular/router';
import * as _ from 'lodash-es';
import { Subject } from 'rxjs';
import { takeUntil, map } from 'rxjs/operators';
import { IImpressionEventInput } from '@sunbird/telemetry';
import { CsGroupSearchCriteria } from '@project-sunbird/client-services/services/group/interface';
import { SELECT_CREATE_GROUP, PAGE_LOADED, SELECT_GROUP } from '../../interfaces/telemetryConstants';
@Component({
  selector: 'app-my-groups',
  templateUrl: './my-groups.component.html',
  styleUrls: ['./my-groups.component.scss']
})
export class MyGroupsComponent implements OnInit, OnDestroy {
  showGroupCreateForm = false;
  groupsList: IGroupCard[] = [];
  public showModal = false;
  private unsubscribe$ = new Subject<void>();
  telemetryImpression: IImpressionEventInput;
  isLoader = true;
  layoutConfiguration;
  showTncModal = false;
  selectedType: acceptTnc = acceptTnc.ALL;
  selectedGroup: {};
  isTncAccepted = true;
  isContentLoaded = new EventEmitter();
  public SELECT_CREATE_GROUP = SELECT_CREATE_GROUP;

  constructor(public groupService: GroupsService,
    public router: Router,
    public resourceService: ResourceService,
    private userService: UserService,
    private activatedRoute: ActivatedRoute,
    private layoutService: LayoutService,
    private toasterService: ToasterService,
    private tncService: TncService,
    private navigationhelperService: NavigationHelperService,
    ) { }

  ngOnInit() {
    this.showModal = !localStorage.getItem('login_ftu_groups');
    this.initLayout();
    this.getLatestTnc();
    this.getMyGroupList();
    this.setTelemetryImpression({type: PAGE_LOADED});
    this.groupService.closeForm.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
      this.getMyGroupList();
    });
  }

  initLayout() {
    this.layoutConfiguration = this.layoutService.initlayoutConfig();
    this.layoutService.switchableLayout().
    pipe(takeUntil(this.unsubscribe$)).subscribe(layoutConfig => {
    if (layoutConfig != null) {
      this.layoutConfiguration = layoutConfig.layout;
    }
   });
  }

  getMyGroupList() {
    this.isLoader = true;
    this.groupsList = [];
    const request: CsGroupSearchCriteria = {filters: {userId: this.userService.userid}};
    this.groupService.searchUserGroups(request).pipe(takeUntil(this.unsubscribe$)).subscribe(groups => {
      this.groupService.groupListCount = groups.length;
      this.isLoader = false;
      groups = this.groupService.addGroupPaletteList(groups || []);
      _.forEach(groups, (group) => {
        if (group) {
          group = this.groupService.addGroupFields(group);
          this.groupsList.push(group);
        }
      });
      this.checkUserAcceptedTnc();
    }, (err) => {
      this.isLoader = false;
      this.groupsList = [];
    });
  }

  checkUserAcceptedTnc() {
    const accepted = this.groupService.isUserAcceptedTnc();
    if (accepted) {
      this.isTncUpdatedAfterAcceptance(accepted);
    } else {
      this.showTncModal = this.groupsList.length > 0;
    }
  }

  getLatestTnc() {
    this.tncService.getGroupsTnc().subscribe(data => {
      this.groupService.groupsTncDetails = _.get(data, 'result.response');
    });
  }

  /**
   * @param  {boolean} accepted
   * @description - It will check if the tnc is updated which was previously accepted
   */
  isTncUpdatedAfterAcceptance(accepted: boolean) {
    if (accepted) {
      this.showTncModal =  this.groupService.isTncUpdated() ? this.groupsList.length > 0 : false;
    }
  }

  public showCreateFormModal() {
    this.router.navigate([`${MY_GROUPS}/${CREATE_GROUP}`]);
  }

  public navigateToDetailPage(event) {

    (_.get(event, 'data.status') === 'suspended') ?
    this.addTelemetry('suspended-group-card', _.get(event, 'data.id')) :
    this.addTelemetryWithData('group-card', { type: SELECT_GROUP}, _.get(event, 'data.id'));

    this.selectedType = acceptTnc.GROUP;
    this.selectedGroup = event.data;
    this.showTncModal = _.get(event, 'data.visited') === false;

    if (!this.showTncModal) {
      this.navigate(event);
    }
  }

  navigate(event) {
    this.router.navigate([`${MY_GROUPS}/${GROUP_DETAILS}`, _.get(event, 'data.id')]);
  }

  showFtuPopup() {
    this.showModal = !this.showModal;
  }

  closeModal() {
    this.showModal = false;
    localStorage.setItem('login_ftu_groups', 'login_user');
  }

  addTelemetry (id, groupId?, extra?) {
    const selectedGroup = _.find(this.groupsList, {id: groupId});
    const obj = selectedGroup ? {id: groupId, type: 'group', ver: '1.0'} : {};
    const extras = extra ? extra : {status: _.get(selectedGroup, 'status')};
    this.groupService.addTelemetry({id, extra: extras}, this.activatedRoute.snapshot, [], groupId, obj);
  }

   /**
   * @description - To set the telemetry Intract event data
   * @param  {} edata? - it's an object to specify the type and subtype of edata
   */
  addTelemetryWithData (id, edata, groupId?, extra?) {
    const selectedGroup = _.find(this.groupsList, {id: groupId});
    const obj = selectedGroup ? {id: groupId, type: 'group', ver: '1.0'} : {};
    const extras = extra ? extra : {status: _.get(selectedGroup, 'status')};
    this.groupService.addTelemetry({id, extra: extras, edata: edata}, this.activatedRoute.snapshot, [], groupId, obj);
  }

  setTelemetryImpression(edata?) {
    this.telemetryImpression = this.groupService.getImpressionObject(this.activatedRoute.snapshot, this.router.url, edata);
  }

  handleGroupTnc(event?: {type: string}) {
    if (event) {
      switch (event.type) {
        case acceptTnc.ALL:
          this.addTelemetry('accept-all-group-tnc', _.get(this.selectedGroup, 'id'));
          this.acceptAllGroupsTnc();
          break;
        case acceptTnc.GROUP:
          this.addTelemetry('accept-group-tnc',  _.get(this.selectedGroup, 'id'));
          this.acceptGroupTnc();
          break;
      }
    } else {
      this.showTncModal = false;
    }
  }

  acceptGroupTnc() {
    const request = {
      userId: this.userService.userid,
      groups: [{
        groupId: _.get(this.selectedGroup, 'id'),
        visited: true
      }]
    };

    this.groupService.updateGroupGuidelines(request)
    .subscribe(data => {
      this.showTncModal = false;
      this.addTelemetry('success-accept-group-tnc', _.get(this.selectedGroup, 'id'),
      { status: _.get(this.selectedGroup, 'status'), tncver: _.get(this.groupService.latestTnc, 'value.latestVersion')}
      );
      this.navigate({data: this.selectedGroup});
    }, err => {
      this.showTncModal = false;
    });
  }

  acceptAllGroupsTnc() {
    const groupIds = _.map(this.groupsList, group => {
      group.visited = true;
      return {
        groupId: group.id,
        visited: true
      };
    });

    const groupUpdateRequest = {
      userId: this.userService.userid,
      groups: groupIds
    };

    const userProfileUpdateRequest = {
      request: {
        tncType: _.get(this.groupService.latestTnc, 'field'),
        version:  _.get(this.groupService.latestTnc, 'value.latestVersion')
      }
    };

    if (!_.isEmpty(_.get(this.userService.userProfile, 'managedBy'))) {
      userProfileUpdateRequest.request['userId'] = this.userService.userid;
    }

    this.userService.acceptTermsAndConditions(userProfileUpdateRequest).pipe(
      takeUntil(this.unsubscribe$),
      map((data) => {
        return this.groupService.updateGroupGuidelines(groupUpdateRequest);
      }),
    ).subscribe((result) => {
      this.addTelemetry('success-accept-all-group-tnc', _.get(this.selectedGroup, 'id'),
      { status: _.get(this.selectedGroup, 'status'), tncver: _.get(this.groupService.latestTnc, 'value.latestVersion') }
      );
      this.toasterService.success(this.resourceService.frmelmnts.msg.guidelinesacceptsuccess);
      this.showTncModal = false;
      this.isTncAccepted = true;
      if (this.groupsList.length > 0) {
        this.reload();
      }
    }, (err) => {
      this.toasterService.error(this.resourceService.frmelmnts.msg.guidelinesacceptfailed);
      this.showTncModal = true;
      this.isTncAccepted = false;
    });
  }

  reload() {
    this.userService.getUserData(this.userService.userid).pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
      this.groupService.userData = _.get(data, 'result.response');
      this.getMyGroupList();
    });
  }

  goBack() {
    this.navigationhelperService.goBack();
  }

  ngOnDestroy() {
    this.unsubscribe$.next();
    this.unsubscribe$.complete();
  }
}

<app-landing-section [textToDisplay]="" 
[layoutConfiguration]="layoutConfiguration" [noTitle]="true"></app-landing-section>

<div [ngClass]="layoutConfiguration ? 'sb-back-actionbar mt-0' : 'sb-bg-white cc-player__btn-back'" class="relative position mt-0">
  <div class="ui container d-flex flex-ai-center py-8">
    <app-back-button></app-back-button>
    <div class="d-flex flex-ai-center flex-jc-space-between flex-w-wrap ml-16 w-100">
      <div class="d-flex flex-dc">
        <h4 class="mb-4 font-weight-bold sb__ellipsis sb__ellipsis--one d-flex">{{resourceService?.frmelmnts?.tab?.mygroups}}</h4>
        <div class="fsmall"></div>
      </div>
      <div class="d-flex flex-ai-end flex-w-wrap content-header__buttons">
        <button class="sb-btn sb-btn-primary sb-btn-normal flex-ai-jc-center mr-8" 
              type="button"
              tabindex="0" (click)="showCreateFormModal();addTelemetryWithData('header-create-group-btn', { type: SELECT_CREATE_GROUP })">
            <i class="icon-svg icon-svg--xs icon-groups mr-4"><svg class="icon icon-svg--white">
              <use xlink:href="./assets/images/sprite.svg#groups"></use>
            </svg></i>
            {{ resourceService?.frmelmnts?.lbl?.createGroup }}
          </button>
        <button class="sb-btn sb-btn-normal sb-btn-link-primary min-w-auto p-0 px-8" aria-label="showFtuPopup" type="button" tabindex="0" (click)="showFtuPopup();addTelemetry('ftu-info')">
          <i class="icon-svg icon-svg--sm icon-info"><svg class="icon icon-svg--primary">
            <use xlink:href="./assets/images/sprite.svg#info"></use>
          </svg></i>
        </button>
      </div>
    </div>
  </div>
</div>

<div [ngClass]="layoutConfiguration ? 'sbt-center-container sbt-mygroups relative9' : 'sb-mygroups'">
<div class="flex-dc mt-48 sb-group-container sb-group-container--sm" *ngIf="!groupsList.length && !isLoader">
  <div class="d-flex flex-dc flex-ai-center flex-jc-center">
    <img alt="{{resourceService?.frmelmnts?.lbl?.createGroupDes}}" src="./assets/images/mygroups.svg" width="220">
    <div class="my-24 fs-1 text-center">
      {{resourceService?.frmelmnts?.lbl?.createGroupDes}}
     </div>
    <button class="sb-btn sb-btn-primary sb-btn-normal flex-ai-jc-center mb-8" type="button"
      tabindex="0" (click)="showCreateFormModal();addTelemetry('create-group-btn')">
      <i class="icon-svg icon-svg--xs icon-groups mr-4"><svg class="icon icon-svg--white">
        <use xlink:href="./assets/images/sprite.svg#groups"></use>
      </svg></i>
      {{ resourceService?.frmelmnts?.lbl?.createGroup }}
    </button>
  </div>
</div>

<div *ngIf="groupsList.length&& !isLoader" [appTelemetryImpression]="telemetryImpression">

  <div class="ui container mt-24">
    <div class="sb-card-grid">
      <div class="sbcard sbcard--resource sbcard--course" *ngFor="let group of groupsList">
        <sb-group-card [isSuspended]="group?.status === 'suspended'" [suspendBadgeText]="resourceService?.frmelmnts?.lbl?.deactivategrp" [group]= "group" [isAdmin]="group?.isAdmin" [initial]="group?.initial" (cardClick)="navigateToDetailPage($event)"></sb-group-card>
      </div>
    </div>
  </div>
</div>

<div class="ui container mt-24" *ngIf="isLoader">
  <div class="sb-card-grid">
    <div class="sbcard sbcard--resource sbcard--course" role="link"  tabindex="0"  *ngFor="let group of [1,2,3,4,5,6,7,8]">
      <sb-group-card [isLoading]="true"></sb-group-card>
    </div>
  </div>
</div>
<router-outlet></router-outlet>

</div>

<app-ftu-popup *ngIf="showModal" [showWelcomePopup]="showModal" (close)="closeModal()"></app-ftu-popup>

<app-modal *ngIf="showTncModal" [type]="selectedType"  (handleGroupTnc)="handleGroupTnc($event)"></app-modal>

./my-groups.component.scss

@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
@use 'pages/page-center-view' as *;

.sb-mygroups{
  .sb-bg-color-white{
    background: var(--sb-mygroups-bg) !important;
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""