File
Description
This display a a section
Implements
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Outputs
|
|
Accessors
|
|
layoutConfiguration
|
Type : any
|
|
Outputs
playEvent
|
Type : EventEmitter
|
|
viewAll
|
Type : EventEmitter
|
|
visits
|
Type : EventEmitter
|
|
Methods
getObjectRollup
|
getObjectRollup(content)
|
|
Returns : {}
|
handleAfterChange
|
handleAfterChange(event)
|
|
|
navigateToViewAll
|
navigateToViewAll(section)
|
|
|
ngOnChanges
|
ngOnChanges()
|
|
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
playContent
|
playContent(event)
|
|
|
reInitSlick
|
reInitSlick()
|
|
|
selectedLanguageTranslation
|
selectedLanguageTranslation(data)
|
|
|
updateContentViewed
|
updateContentViewed()
|
|
|
updateSlick
|
updateSlick()
|
|
|
Public
activatedRoute
|
Type : ActivatedRoute
|
|
contentList
|
Type : []
|
Default value : []
|
|
maxSlide
|
Type : number
|
Default value : 0
|
|
refresh
|
Default value : true
|
|
Private
resourceDataSubscription
|
Type : Subscription
|
|
slideConfig
|
Type : object
|
Default value : {}
|
|
Public
telemetryInteractCdata
|
Type : any
|
|
Accessors
sectionName
|
getsectionName()
|
|
import { ActivatedRoute } from '@angular/router';
import { ResourceService, ConfigService, ICaraouselData } from '@sunbird/shared';
import { Component, Input, EventEmitter, Output, OnDestroy, ChangeDetectorRef, OnChanges, OnInit } from '@angular/core';
import * as _ from 'lodash-es';
import { IInteractEventEdata } from '@sunbird/telemetry';
import { Subscription } from 'rxjs';
/**
* This display a a section
*/
@Component({
selector: 'app-page-section',
templateUrl: './page-section.component.html',
styleUrls: ['./page-section.component.scss']
})
export class PageSectionComponent implements OnInit, OnDestroy, OnChanges {
cardInteractEdata: IInteractEventEdata;
public telemetryInteractCdata: any;
refresh = true;
@Input() section: ICaraouselData;
@Input() cardType: string;
@Input() hideProgress: boolean;
@Input() layoutConfiguration;
@Output() playEvent = new EventEmitter<any>();
@Output() visits = new EventEmitter<any>();
@Output() viewAll = new EventEmitter<any>();
private resourceDataSubscription: Subscription;
slideConfig: object = {};
pageid: string;
contentList = [];
maxSlide = 0;
constructor(public config: ConfigService, public activatedRoute: ActivatedRoute, public resourceService: ResourceService,
private cdr: ChangeDetectorRef) {
// console.log(slick);
this.pageid = _.get(this.activatedRoute, 'snapshot.data.telemetry.pageid');
}
playContent(event) {
event.section = this.sectionName;
this.playEvent.emit(event);
}
ngOnInit() {
this.updateSlick();
this.slideConfig = this.cardType === 'batch'
? _.cloneDeep(this.config.appConfig.CourseBatchPageSection.slideConfig)
: _.cloneDeep(this.config.appConfig.CoursePageSection.slideConfig);
this.resourceDataSubscription = this.resourceService.languageSelected$.subscribe(item => {
this.selectedLanguageTranslation(item.value);
});
if (this.pageid) {
this.cardInteractEdata = {
id: this.cardType === 'batch' ? 'batch-card' : 'content-card',
type: 'click',
pageid: this.pageid
};
}
if (this.section) {
this.telemetryInteractCdata = [{
type: 'section',
id: this.sectionName
}];
}
}
updateSlick() {
if (this.contentList.length && this.contentList.length < this.section.contents.length) {
const upperLimit = _.get(this.config, 'appConfig.CoursePageSection.slideConfig.slidesToScroll') || 4;
this.contentList.push(...this.section.contents.slice(this.contentList.length, this.contentList.length + upperLimit));
} else if (this.contentList.length === 0) {
const upperLimit = (_.get(this.config, 'appConfig.CoursePageSection.slideConfig.slidesToScroll') || 4) * 2 - 1;
this.contentList.push(...this.section.contents.slice(0, upperLimit));
}
}
selectedLanguageTranslation(data) {
if (data === 'ur' && !this.slideConfig['rtl']) { // other language to urdu
this.slideConfig['rtl'] = true;
this.reInitSlick();
} else if (data !== 'ur' && this.slideConfig['rtl']) { // urdu to other language
this.slideConfig['rtl'] = false;
this.reInitSlick();
} else { // other language to other language
this.slideConfig['rtl'] = false;
}
try {
if (this.sectionName !== this.resourceService.frmelmnts.lbl.mytrainings) {
const display = JSON.parse(this.section['display']);
if (_.has(display.name, data) && !_.isEmpty(display.name[data])) {
this.section.name = display.name[data];
} else {
this.section.name = display.name['en'];
}
}
} catch (err) {
}
}
reInitSlick() {
this.contentList = [];
this.updateSlick();
this.maxSlide = 0;
this.refresh = false;
this.cdr.detectChanges();
this.refresh = true;
}
handleAfterChange(event) {
if (event.currentSlide > this.maxSlide) {
this.maxSlide = event.currentSlide;
this.updateSlick();
}
}
updateContentViewed() {
const visits = _.map(this.contentList, content => {
content.section = this.section.name;
return content;
});
if (visits.length > 0) {
this.visits.emit(visits);
}
}
navigateToViewAll(section) {
this.viewAll.emit(section);
}
ngOnDestroy() {
this.updateContentViewed();
if (this.resourceDataSubscription) {
this.resourceDataSubscription.unsubscribe();
}
}
getObjectRollup(content) {
const rollup = {};
const contentType = _.get(content, 'contentType') || _.get(content, 'metaData.contentType');
if (_.lowerCase(contentType) === 'course') {
rollup['l1'] = _.get(content, 'metaData.courseId') || _.get(content, 'metaData.identifier');
}
return rollup;
}
ngOnChanges() {
this.reInitSlick();
}
get sectionName() {
const { name } = this.section || {};
return _.get(this.resourceService, name) || name || '';
}
}
<div class="sb-pageSection" *ngIf="section && section.contents && section.contents.length">
<!--Header-->
<div *ngIf="section.name" class="sb-pageSection-header">
<!--Section Title-->
<h4 class="sb-pageSection-title sb-pageSection-sentenceCase m-0 mr-16"><span class="mr-8">{{sectionName}}</span>
<!--Count-->
<span class="sb-pageSection-count sb-label sb-label-xs sb-label-error">{{section.count}}</span>
<!--/Count-->
</h4>
<!--/Section Title-->
<!--View all button-->
<button class="sb-btn sb-btn-xs sb-btn-secondary ml-auto" type="button" *ngIf="section?.contents?.length >= 10"
(click)="navigateToViewAll(section)" tabindex="0" appTelemetryInteract
[telemetryInteractEdata]="{id:'viewall-button' , type:'click' ,pageid:pageid , extra : {section: section.name}}">
{{ resourceService?.frmelmnts?.lnk?.viewall}}
</button>
<!--/View all button-->
</div>
<!--/Header-->
<!--Content-->
<div *ngIf="refresh" class="sb-pageSection-content pt-8">
<app-slick *ngIf="contentList?.length > 0" [loadStatus]="'done'">
<ng-container>
<div *ngFor="let content of contentList; let i=index" class="mr-16 cardSlick">
<!--Batch Card-->
<app-batch-card appTelemetryInteract [telemetryInteractEdata]="cardInteractEdata"
[telemetryInteractObject]="{id:content.metaData.identifier}"
*ngIf="cardType && cardType === 'batch' else contentcard" [batch]="content"
(clickEvent)="playContent($event)">
</app-batch-card>
<!--/Batch Card-->
<!--Course & Resourse Card-->
<ng-template #contentcard>
<ng-container *ngIf="!layoutConfiguration">
<app-card appContentDirection appTelemetryInteract [telemetryInteractEdata]="cardInteractEdata"
[telemetryInteractCdata]="telemetryInteractCdata"
[telemetryInteractObject]="{id:content.metaData.identifier || content.metaData.courseId,type:content.metaData.contentType || 'Course',ver:content.metaData.pkgVersion ? content.metaData.pkgVersion.toString():'1.0', rollup: getObjectRollup(content)}"
(clickEvent)="playContent($event)" [hideProgress]="hideProgress" [data]="content"
class="d-block" [class.last-card]="mr-0">
</app-card>
</ng-container>
<ng-container *ngIf="layoutConfiguration">
<sb-library-card [indexToDisplay]="i" [layoutConfig]="layoutConfiguration" appTelemetryInteract
[telemetryInteractEdata]="cardInteractEdata"
[telemetryInteractCdata]="telemetryInteractCdata"
[telemetryInteractObject]="{id:content.identifier,type:content.contentType || 'content',ver:content.pkgVersion ? content.pkgVersion.toString():'1.0'}"
(cardClick)="playContent($event)" (enterKey)="playContent($event)" [content]="content"
[cardImg]="content?.image || 'assets/images/book.png'"></sb-library-card>
</ng-container>
</ng-template>
<!--/Course & Resourse Card-->
</div>
</ng-container>
</app-slick>
</div>
<!--/Content-->
<!--Page Section Divider-->
<!--<hr class="sb-pageSection-footer" *ngIf="cardType !== 'batch'" />-->
<!--/Page Section Divider-->
</div>
.cardSlick {
float: left;
height: 100%;
min-height: 0.0625rem;
}
Legend
Html element with directive