File

src/app/modules/resource/components/curriculum-courses/curriculum-courses.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

constructor(searchService: SearchService, toasterService: ToasterService, resourceService: ResourceService, activatedRoute: ActivatedRoute, router: Router, navigationhelperService: NavigationHelperService, coursesService: CoursesService, telemetryService: TelemetryService, location: Location)
Parameters :
Name Type Optional
searchService SearchService No
toasterService ToasterService No
resourceService ResourceService No
activatedRoute ActivatedRoute No
router Router No
navigationhelperService NavigationHelperService No
coursesService CoursesService No
telemetryService TelemetryService No
location Location No

Methods

Private fetchEnrolledCourses
fetchEnrolledCourses()
Returns : void
getInteractData
getInteractData(course)
Parameters :
Name Optional
course No
Returns : void
goBack
goBack()
Returns : void
navigateToCourseDetails
navigateToCourseDetails(course)
Parameters :
Name Optional
course No
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Private setCourseList
setCourseList(enrolledCourses)
Parameters :
Name Optional
enrolledCourses No
Returns : void
setTelemetryImpression
setTelemetryImpression()
Returns : void

Properties

Public activatedRoute
Type : ActivatedRoute
Public channelId
Type : string
Public courseList
Type : any
Default value : []
defaultBg
Default value : false
Public defaultFilters
Type : object
Default value : { board: [], gradeLevel: [], medium: [] }
fallbackImg
Type : string
Default value : './../../../../../assets/images/book.png'
Public isCustodianOrg
Default value : true
Public mergedCourseList
Type : any
Default value : []
Public resourceService
Type : ResourceService
Public selectedCourse
Type : literal type
Public telemetryImpression
Type : IImpressionEventInput
Public title
Type : string
Private unsubscribe$
Default value : new Subject<void>()
import { Location } from '@angular/common';
// import { DatePipe } from '@angular/common';
import { Subject } from 'rxjs';
import { SearchService, CoursesService } from '@sunbird/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import {
  ResourceService, ToasterService, NavigationHelperService
} from '@sunbird/shared';
import { Router, ActivatedRoute } from '@angular/router';
import * as _ from 'lodash-es';
import { map } from 'rxjs/operators';
import { IImpressionEventInput, TelemetryService } from '@sunbird/telemetry';

@Component({
  selector: 'app-curriculum-courses',
  templateUrl: './curriculum-courses.component.html',
  styleUrls: ['./curriculum-courses.component.scss']
})
export class CurriculumCoursesComponent implements OnInit, OnDestroy {

  public channelId: string;
  public isCustodianOrg = true;
  private unsubscribe$ = new Subject<void>();
  defaultBg = false;
  public defaultFilters = {
    board: [],
    gradeLevel: [],
    medium: []
  };

  public selectedCourse: {};
  public courseList: any = [];
  public title: string;
  public mergedCourseList: any = [];
  fallbackImg = './../../../../../assets/images/book.png';

  public telemetryImpression: IImpressionEventInput;
  constructor(private searchService: SearchService, private toasterService: ToasterService,
    public resourceService: ResourceService, public activatedRoute: ActivatedRoute,
    private router: Router, private navigationhelperService: NavigationHelperService,
    private coursesService: CoursesService, private telemetryService: TelemetryService,
    private location: Location
  ) { }

  ngOnInit() {
    this.title = _.get(this.activatedRoute, 'snapshot.queryParams.title');
    if (!_.isEmpty(_.get(this.searchService, 'subjectThemeAndCourse.contents'))) {
      this.courseList = _.get(this.searchService, 'subjectThemeAndCourse.contents');
      this.selectedCourse = _.omit(_.get(this.searchService, 'subjectThemeAndCourse'), 'contents');
      this.fetchEnrolledCourses();
    } else {
      this.toasterService.error(this.resourceService.frmelmnts.lbl.fetchingContentFailed);
      this.location.back();
    }
    this.setTelemetryImpression();
  }

  setTelemetryImpression() {
    this.telemetryImpression = {
      context: {
        env: this.activatedRoute.snapshot.data.telemetry.env
      },
      edata: {
        type: this.activatedRoute.snapshot.data.telemetry.type,
        pageid: this.activatedRoute.snapshot.data.telemetry.pageid,
        uri: this.router.url,
        subtype: this.activatedRoute.snapshot.data.telemetry.subtype,
        duration: this.navigationhelperService.getPageLoadTime()
      }
    };
  }

  private fetchEnrolledCourses() {
    this.coursesService.enrolledCourseData$.pipe(map(({ enrolledCourses, err }) => {
      return enrolledCourses;
    })).subscribe(enrolledCourses => {
      this.setCourseList(enrolledCourses);
    });
  }

  private setCourseList(enrolledCourses) {
    const unorderedList = this.courseList.map((course) => {
      const enrolledCourse = _.find(enrolledCourses, { courseId: course.identifier });
      if (enrolledCourse) {
        return {
          ...enrolledCourse,
          completionPercentage: enrolledCourse.completionPercentage || 0,
          isEnrolledCourse: true,
        };
      } else {
        return {
          ...course,
          isEnrolledCourse: false,
          courseName: course.name
        };
      }
    });

    this.mergedCourseList = _.orderBy(unorderedList, ['isEnrolledCourse', course => _.toLower(course.courseName)], ['desc', 'asc']);
  }

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

  goBack() {
    this.location.back();
  }

  navigateToCourseDetails(course) {
    this.getInteractData(course);
    const courseId = _.get(course, 'courseId') || course.identifier;

    if (course.batchId) {
      this.router.navigate(['/learn/course', courseId, 'batch', course.batchId]);
    } else {
      this.router.navigate(['/learn/course', courseId]);
    }
  }

  getInteractData(course) {
    const cardClickInteractData = {
      context: {
        cdata: [],
        env: this.activatedRoute.snapshot.data.telemetry.env,
      },
      edata: {
        id: _.get(course, 'identifier'),
        type: 'click',
        pageid: this.activatedRoute.snapshot.data.telemetry.pageid,
      },
      object: {
        id: course.identifier,
        type: course.contentType || 'course',
        ver: course.pkgVersion ? course.pkgVersion.toString() : '1.0'
      }
    };
    this.telemetryService.interact(cardClickInteractData);
  }
}
<div *ngIf="courseList.length > 0" [appTelemetryImpression]="telemetryImpression">

<div class="sb-bg-color-white" >
  <div class="ui container py-8">
    <button type="button" class="sb-btn sb-btn-normal sb-btn-link
      sb-btn-link-primary sb-left-icon-btn px-0" tabindex="0" (click)="goBack()">
      <i class="icon-svg icon-svg--xxs icon-back mr-4"><svg class="icon
          icon-svg--primary">
          <use xlink:href="./assets/images/sprite.svg#arrow-long-left"></use>
        </svg></i> {{resourceService?.frmelmnts?.btn?.back}}</button>
  </div>
</div>

<div class="content-header header-shadow" [ngStyle]="{'background': selectedCourse?.theme}">
  <div class="ui container py-16">
    <div class="d-flex flex-ai-center flex-jc-space-between flex-w-wrap">
      <div class="content-header__img mr-8" *ngIf="selectedCourse?.cardImg">
        <img [src]="selectedCourse?.cardImg">
      </div>

      <div class="flex-basis-1 mr-32 text-left">
        <h5 class="content-header__title mt-4 ellipsis" [ngStyle]="!defaultBg  && {'color': selectedCourse?.titleColor}">{{title}}</h5>
        <div class="content-header__info">
          <div class="d-flex flex-ai-center content-header__info fsmall mt-4"> {{courseList.length}} {{(resourceService?.frmelmnts?.lbl?.courses).toUpperCase()}}</div>
        </div>
        
      </div>
    </div>
  </div>
</div>

<div class="ui container mt-24 sb-library-cards right-flower-position-adjust-container">
  <div class="sbgrid">
    <div *ngFor="let course of mergedCourseList">
      <sb-my-course-card *ngIf="course.isEnrolledCourse" [course]="course" [cardImg]="course?.courseLogoUrl || course?.appIcon || fallbackImg" [hideProgress]="true" [section]="null" (cardClick)="navigateToCourseDetails(course)"></sb-my-course-card>
      <sb-course-card *ngIf="!course.isEnrolledCourse" [course]="course" [cardImg]="course?.appIcon" [section]="null" (cardClick)="navigateToCourseDetails(course)" ></sb-course-card>
    </div>
  </div>
</div>

</div>

./curriculum-courses.component.scss

@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
@use 'pages/content-header' as *;
.sbgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(291.98px, 1fr));
    grid-gap: 1rem;
    grid-row-gap: 1.5rem;
}
.header-shadow {
    min-height: calculateRem(80px);
    background-color: var(--gray-0);
    box-shadow: 0 calculateRem(10px) calculateRem(10px) calculateRem(-10px) rgba(var(--rc-rgba-black), 0.25);
    z-index: 99;
  }
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""