File

src/app/modules/groups/components/activity/activity-list/activity-list.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs

Constructor

constructor(configService: ConfigService, router: Router, activateRoute: ActivatedRoute, resourceService: ResourceService, groupService: GroupsService, toasterService: ToasterService, playerService: PlayerService, layoutService: LayoutService, activityDashboardService: ActivityDashboardService)
Parameters :
Name Type Optional
configService ConfigService No
router Router No
activateRoute ActivatedRoute No
resourceService ResourceService No
groupService GroupsService No
toasterService ToasterService No
playerService PlayerService No
layoutService LayoutService No
activityDashboardService ActivityDashboardService No

Inputs

activityList
Type : any
currentMember
Type : any
groupData
Type : any

Methods

addTelemetry
addTelemetry(id, cdata?, extra?, obj?)
Parameters :
Name Optional
id No
cdata Yes
extra Yes
obj Yes
Returns : void
getMenuData
getMenuData(event)
Parameters :
Name Optional
event No
Returns : void
getTitle
getTitle(title)
Parameters :
Name Optional
title No
Returns : any
initLayout
initLayout()

used to archive the both theme

Returns : void
isCourse
isCourse(type)
Parameters :
Name Optional
type No
Returns : boolean
isSelectedType
isSelectedType(type)
Parameters :
Name Optional
type No
Returns : boolean
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
openActivity
openActivity(event: any, activityType)
Parameters :
Name Type Optional
event any No
activityType No
Returns : void
removeActivity
removeActivity()
Returns : void
toggleModal
toggleModal(show)
Parameters :
Name Optional Default value
show No false
Returns : void
toggleViewAll
toggleViewAll(visibility: boolean, type?)
Parameters :
Name Type Optional
visibility boolean No
type Yes
Returns : void
viewSelectedTypeContents
viewSelectedTypeContents(type, list, index)
Parameters :
Name Optional
type No
list No
index No
Returns : boolean

Properties

Public activityDashboardService
Type : ActivityDashboardService
config
Type : any
disableViewAllMode
Default value : false
layoutConfiguration
Type : any
modal
Decorators :
@ViewChild('modal')
numberOfSections
Default value : new Array(this.configService.appConfig.SEARCH.PAGE_LIMIT)
Public resourceService
Type : ResourceService
selectedActivity
Type : IActivity
selectedTypeContents
Type : object
Default value : {}
showLoader
Default value : false
showMenu
Default value : false
showModal
Default value : false
unsubscribe$
Default value : new Subject<void>()
import { PlayerService } from '@sunbird/core';
import { Component, Input, ViewChild, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import * as _ from 'lodash-es';
import { fromEvent, Subject } from 'rxjs';
import { takeUntil, delay } from 'rxjs/operators';
import { GroupsService } from '../../../services/groups/groups.service';
import { ToasterService, ConfigService, ResourceService, LayoutService, ActivityDashboardService } from '../../../../shared/services';
export interface IActivity {
  name: string;
  identifier: string;
  appIcon: string;
  organisation: string[];
  subject: string;
  type: string;
  contentType?: string;
  trackable?: { enabled: string };
}
@Component({
  selector: 'app-activity-list',
  templateUrl: './activity-list.component.html',
  styleUrls: ['./activity-list.component.scss']
})
export class ActivityListComponent implements OnInit, OnDestroy {
  @ViewChild('modal') modal;
  @Input() groupData;
  @Input() currentMember;
  numberOfSections = new Array(this.configService.appConfig.SEARCH.PAGE_LIMIT);
  showLoader = false;
  @Input() activityList: any;
  showMenu = false;
  selectedActivity: IActivity;
  showModal = false;
  unsubscribe$ = new Subject<void>();
  disableViewAllMode = false;
  selectedTypeContents = {};
  config: any;
  layoutConfiguration: any;


  constructor(
    private configService: ConfigService,
    private router: Router,
    private activateRoute: ActivatedRoute,
    public resourceService: ResourceService,
    private groupService: GroupsService,
    private toasterService: ToasterService,
    private playerService: PlayerService,
    private layoutService: LayoutService,
    public activityDashboardService: ActivityDashboardService,
  ) {
    this.config = this.configService.appConfig;
  }

  ngOnInit() {
    this.showLoader = false;
    this.initLayout();
    fromEvent(document, 'click')
      .pipe(takeUntil(this.unsubscribe$))
      .subscribe(item => {
        if (this.showMenu) {
          this.showMenu = false;
          this.addTelemetry('activity-kebab-menu-close');
        }
      });
    this.groupService.showMenu.subscribe(data => {
      this.showMenu = data === 'activity';
    });

    this.resourceService.languageSelected$.pipe(delay(600), takeUntil(this.unsubscribe$)).subscribe(item => {
      this.showLoader = false;
      const response = this.groupService.groupContentsByActivityType(false, this.groupData);
      this.activityList = response.activities;
    });

  }
  /**
   * used to archive the both theme
   */
  initLayout() {
    this.layoutConfiguration = this.layoutService.initlayoutConfig();
    this.layoutService.switchableLayout().
    pipe(takeUntil(this.unsubscribe$)).subscribe(layoutConfig => {
    if (layoutConfig != null) {
      this.layoutConfiguration = layoutConfig.layout;
    }
   });
  }

  openActivity(event: any, activityType) {
      if (!this.groupData.active) {
        this.addTelemetry('activity-suspend-card', [], {},
      {id: _.get(event, 'data.identifier'), type: _.get(event, 'data.primaryCategory'),
      ver: _.get(event, 'data.pkgVersion') ? `${_.get(event, 'data.pkgVersion')}` : '1.0'});
        return;
      }
      this.addTelemetry('activity-card', [{id: _.get(event, 'data.identifier'), type: _.get(event, 'data.resourceType')}]);
      const options = { relativeTo: this.activateRoute, queryParams: { primaryCategory: _.get(event, 'data.primaryCategory'),
      title: activityType, mimeType: _.get(event, 'data.mimeType'), groupId: _.get(this.groupData, 'id')}};
      this.activityDashboardService.isActivityAdded = true; // setting this value to enable or disable the activity dashboard button in activity-dashboard directive
      this.playerService.playContent(_.get(event, 'data'), {groupId: _.get(this.groupData, 'id')});
  }

  getMenuData(event) {
      this.showMenu = !this.showMenu;
      this.groupService.emitMenuVisibility('activity');
      this.selectedActivity = _.get(event, 'data');
      this.addTelemetry('activity-kebab-menu-open', [], {}, {id: _.get(event, 'data.identifier'), type: _.get(event, 'data.primaryCategory'),
      ver: _.get(event, 'data.pkgVersion') ? `${_.get(event, 'data.pkgVersion')}` : '1.0'});
  }

  getTitle(title) {
    const name =  this.resourceService.frmelmnts.lbl[title];
    return name ? name : title;
  }

  toggleModal(show = false) {
    const activity = {id: _.get(this.selectedActivity, 'identifier'), type: _.get(this.selectedActivity, 'primaryCategory'),
    ver: _.get(this.selectedActivity, 'pkgVersion') ? `${_.get(this.selectedActivity, 'pkgVersion')}` : '1.0'};
    show ? this.addTelemetry('remove-activity-kebab-menu-btn', [], {}, activity) :
    this.addTelemetry('close-remove-activity-popup', [], {}, activity);
    this.showModal = show;
  }

  removeActivity() {
    this.addTelemetry('confirm-remove-activity-button', [], {},
    {id: _.get(this.selectedActivity, 'identifier'), type: _.get(this.selectedActivity, 'primaryCategory'),
    ver: _.get(this.selectedActivity, 'pkgVersion') ? `${_.get(this.selectedActivity, 'pkgVersion')}` : '1.0'});
    const activityIds = [this.selectedActivity.identifier];
    this.showLoader = true;
    this.groupService.removeActivities(this.groupData.id, { activityIds })
      .pipe(takeUntil(this.unsubscribe$))
      .subscribe(response => {
        Object.keys(this.activityList).forEach(key => {
          this.activityList[key] = this.activityList[key].filter(activity => _.get(activity, 'identifier') !== _.get(this.selectedActivity, 'identifier'));
        });
        this.toasterService.success(this.resourceService.messages.smsg.activityRemove);
        this.showLoader = false;
      }, error => {
        this.showLoader = false;
        this.toasterService.error(this.resourceService.messages.emsg.activityRemove);
      });
    this.toggleModal();

    // TODO: add telemetry here
  }

  addTelemetry (id, cdata?, extra?, obj?) {
    this.groupService.addTelemetry({id, extra}, this.activateRoute.snapshot, cdata || [], _.get(this.groupData, 'id'), obj);
  }

  toggleViewAll(visibility: boolean, type?) {
    this.disableViewAllMode = visibility;
    this.selectedTypeContents = _.pick(this.activityList, type) || {};
  }

  isCourse(type) {
    return (_.lowerCase(this.resourceService.frmelmnts.lbl[type]) === _.lowerCase(this.configService.appConfig.contentType.Course) ||
    (_.lowerCase(this.resourceService.frmelmnts.lbl[type]) === _.lowerCase(this.configService.appConfig.contentType.Courses)));
  }

  viewSelectedTypeContents(type, list, index) {
    return (_.isEmpty(this.selectedTypeContents) ? (list.length > 3 ?  index <= 2 : true) :
    !_.isEmpty(_.get(this.selectedTypeContents, type)));
  }

  isSelectedType (type) {
   return _.isEmpty(this.selectedTypeContents) ? true : !_.isEmpty(_.get(this.selectedTypeContents, type));
  }

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

    if (this.showModal && this.modal.deny) {
      this.modal.deny();
    }
  }
}
<div *ngFor="let list of groupData?.activitiesGrouped">
  <div class="header" *ngIf="activityList[list?.title]?.length && isSelectedType(list?.title)">
      <div class="title">
        {{getTitle(list?.title)}}
      </div>
  <button *ngIf="activityList[list?.title]?.length > 3 && disableViewAllMode && isSelectedType(list?.title)" class="sb-btn sb-btn-normal sb-btn-error ml-auto sb-cls-btn" tabindex="0" (click)="toggleViewAll(false); addTelemetry('close-view-all', [], {type: list?.title})">{{resourceService?.frmelmnts?.btn?.close}} <i class="close icon"></i></button>
  <button *ngIf="activityList[list?.title]?.length > 3 && !disableViewAllMode && isSelectedType(list?.title)" class="sb-btn sb-btn-xs sb-btn-secondary ml-auto" tabindex="0" (click)="toggleViewAll(true, list?.title);addTelemetry('open-view-all', [], {type: list?.title})">{{resourceService?.frmelmnts?.lnk?.viewall}}</button>
  </div>

  <!--Show loader-->
  <div class="sb-card-grid" *ngIf="showLoader && activityList[list?.title]?.length">
      <div class="sb-grid--item" *ngFor="let i of (activityList[list?.title] || numberOfSections)">
          <sb-course-card [isLoading]="true"></sb-course-card>
      </div>
  </div>

  <!--Show Activity List-->
  <div  *ngIf="activityList[list?.title]?.length && !showLoader" class="sb-card-grid" [ngClass]="{'hideActivityType': !isSelectedType(list?.title)}"> 
       <div class="sb-card-grid--item relative" *ngFor="let activity of activityList[list?.title]; let i=index;">
          <sb-course-card *ngIf="isCourse(activity?.type) && viewSelectedTypeContents(list?.title, activityList[list?.title], i)"(cardClick)="openActivity($event, list?.title)" [course]="activity" [section]="null" [isMenu]="groupData?.isAdmin" [cardImg]="activity?.appIcon
      || config?.assetsPath?.book" (menuClick)="getMenuData($event, activity)">
          </sb-course-card>

          <sb-library-card *ngIf="!isCourse(activity?.type) && viewSelectedTypeContents(list?.title, activityList[list?.title], i)"(cardClick)="openActivity($event, list?.title)" [content]="activity" [section]="null" [isMenu]="groupData?.isAdmin" [cardImg]="activity?.appIcon
          || config?.assetsPath?.book" (menuClick)="getMenuData($event, activity)">
          </sb-library-card>
          <div class="kabab-menu-dropdown-content" *ngIf="showMenu &&
      selectedActivity?.identifier === activity?.identifier">
              <div class="list sb-color-error" tabindex="0" (click)="toggleModal(true)">
                  <span>{{resourceService?.frmelmnts?.lbl?.removeActivity}}</span>
              </div>
          </div>
      </div> 
  </div>
</div>

<!-- No Activity[cardType]="getType(selectedContentType?.type)" -->
<app-add-activity *ngIf="!showLoader && ((activityList | json) === '{}')"></app-add-activity>

<!-- Remove Activity from the group -->
<app-modal-wrapper *ngIf="showModal" #modal [config]="{disableClose: true, size: 'small', panelClass: 'material-modal'}">
  <ng-template sbModalContent let-data>
    <div class="sb-mat__modal">
      <div mat-dialog-title>
        <div class="title" tabindex="0">{{resourceService?.frmelmnts?.lbl?.removeActivity}}</div>
        <button type="button" aria-label="close dialog" class="close-btn" (click)="toggleModal()" mat-dialog-close
          tabindex="0"></button>
      </div>
      <mat-dialog-content>
        <div class="sb-mat__modal__content">
          <p tabindex="0"> {{resourceService?.messages?.imsg?.removeActivityWarning}}</p>
        </div>
      </mat-dialog-content>
      <mat-dialog-actions class="sb-mat__modal__actions">
        <button class="sb-btn sb-btn-normal sb-btn-error mb-16" tabindex="0"
        (click)="removeActivity()">{{resourceService?.frmelmnts?.btn?.remove}}</button>
      </mat-dialog-actions>
    </div>
  </ng-template>
</app-modal-wrapper>

./activity-list.component.scss

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

:host {
  .header {
    display: flex;
    flex-direction: row;
    padding: 0;
    align-items: center;
    [dir=ltr] &,
    [dir=rtl] & {
      margin: 1.5rem 0 1rem;
    }
    .title {
      font-family: inherit;
      text-overflow: ellipsis;
      overflow: hidden;
      flex: 1;
      height: 1.5rem;
      color: var(--primary-color);
      font-size: 1.125rem;
      font-weight: 700;
      text-transform: capitalize;
      line-height: 1.625rem;
      display: flex;
      align-items: center;
    }
  }
}

.hideActivityType {
  display: none;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""