src/app/modules/workspace/components/batch-page-section/batch-page-section.component.ts
OnInit
OnDestroy
AfterViewInit
selector | app-batch-page-section |
templateUrl | ./batch-page-section.component.html |
Properties |
|
Methods |
|
constructor(pageApiService: PageApiService, modalService: SuiModalService, searchService: SearchService, batchService: BatchService, workSpaceService: WorkSpaceService, activatedRoute: ActivatedRoute, route: Router, userService: UserService, toasterService: ToasterService, resourceService: ResourceService, config: ConfigService, navigationhelperService: NavigationHelperService)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Constructor to create injected service(s) object Default method of Draft Component class
Parameters :
|
Public fetchPageData |
fetchPageData()
|
This method sets the make an api call to get all batch with page No and offset
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
onCardClick | ||||
onCardClick(event)
|
||||
Parameters :
Returns :
void
|
Public prepareCarouselData | ||||||||
prepareCarouselData(sections: [])
|
||||||||
This method prepares batch card data with count of partipants, adds userName and prepares data structure to reuse exising page section component used in consumption pages for content cars
Parameters :
Returns :
void
|
Public prepareVisits | ||||
prepareVisits(event)
|
||||
Parameters :
Returns :
void
|
Public setTelemetryImpression |
setTelemetryImpression()
|
Returns :
void
|
Public viewAll | ||||
viewAll(event)
|
||||
Parameters :
Returns :
void
|
delete | ||||
delete(contentIds)
|
||||
Inherited from
WorkSpace
|
||||
Defined in
WorkSpace:111
|
||||
Delete Api call .
Parameters :
Returns :
any
|
getBatches | ||||
getBatches(searchParams)
|
||||
Inherited from
WorkSpace
|
||||
Defined in
WorkSpace:128
|
||||
Batchlist Api call
Parameters :
Returns :
any
|
getChannelDetails | ||||
getChannelDetails(channelId)
|
||||
Inherited from
WorkSpace
|
||||
Defined in
WorkSpace:164
|
||||
get channel Api call
Parameters :
Returns :
any
|
getLinkedCollections | ||||||
getLinkedCollections(contentId: ContentIDParam)
|
||||||
Inherited from
WorkSpace
|
||||||
Defined in
WorkSpace:157
|
||||||
search collection Api call
Parameters :
Returns :
any
|
handleContentLockError | ||||
handleContentLockError(errObj)
|
||||
Inherited from
WorkSpace
|
||||
Defined in
WorkSpace:142
|
||||
handle content lock api error
Parameters :
Returns :
string
|
lockContent | ||||
lockContent(content)
|
||||
Inherited from
WorkSpace
|
||||
Defined in
WorkSpace:97
|
||||
this call will prepare reuest object and call lock api
Parameters :
Returns :
any
|
removeContent | ||||||
removeContent(contentList, requestData)
|
||||||
Inherited from
WorkSpace
|
||||||
Defined in
WorkSpace:120
|
||||||
Method to remove content localcaly
Parameters :
Returns :
any
|
search | ||||
search(searchParams)
|
||||
Inherited from
WorkSpace
|
||||
Defined in
WorkSpace:33
|
||||
Search Api call
Parameters :
Returns :
any
|
searchContentWithLockStatus | ||||
searchContentWithLockStatus(searchParams)
|
||||
Inherited from
WorkSpace
|
||||
Defined in
WorkSpace:40
|
||||
Search Api call and returns contents with lock status of each one
Parameters :
Returns :
any
|
UserList | ||||
UserList(searchParams)
|
||||
Inherited from
WorkSpace
|
||||
Defined in
WorkSpace:135
|
||||
userList Api call
Parameters :
Returns :
any
|
Private activatedRoute |
Type : ActivatedRoute
|
To send activatedRoute.snapshot to router navigation service for redirection to draft component |
batchList |
Type : []
|
Default value : []
|
Contains list of batchList of logged-in user |
Public carouselData |
Type : Array<ICaraouselData>
|
Default value : []
|
category |
Type : string
|
Current page category of batch list, defaults to assigned |
Public config |
Type : ConfigService
|
to get url app config |
filters |
Type : object
|
inviewLogs |
Type : []
|
Default value : []
|
loaderMessage |
Type : ILoaderMessage
|
loader message |
Public modalService |
Type : SuiModalService
|
Public navigationhelperService |
Type : NavigationHelperService
|
noResult |
Default value : false
|
To show / hide no result message when no result found |
noResultMessage |
Type : INoResultMessage
|
no result message |
pageid |
Type : string
|
pageLimit |
Type : number
|
Contains page limit of batch list |
pager |
Type : IPagination
|
Contains returned object of the pagination service which is needed to show the pagination on inbox view |
Public resourceService |
Type : ResourceService
|
To call resource service which helps to use language constant |
route |
Type : Router
|
To navigate to other pages |
Public searchService |
Type : SearchService
|
Inherited from
WorkSpace
|
Defined in
WorkSpace:121
|
showError |
Default value : false
|
To show / hide error |
showLoader |
Default value : true
|
To show / hide loader |
telemetryImpression |
Type : IImpressionEventInput
|
telemetryImpression |
Private toasterService |
Type : ToasterService
|
To show toaster(error, success etc) after any API calls |
totalCount |
Type : Number
|
totalCount of the list |
Public unsubscribe$ |
Default value : new Subject<void>()
|
Public workSpaceService |
Type : WorkSpaceService
|
Inherited from
WorkSpace
|
Defined in
WorkSpace:123
|
Public userService |
Type : UserService
|
Inherited from
WorkSpace
|
Defined in
WorkSpace:26
|
import { Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { WorkSpace } from '../../classes/workspace';
import { SearchService, UserService, PageApiService } from '@sunbird/core';
import {
ServerResponse, ConfigService, ToasterService, IPagination,
ResourceService, ILoaderMessage, INoResultMessage, ICaraouselData, NavigationHelperService
} from '@sunbird/shared';
import { WorkSpaceService, BatchService } from '../../services';
import * as _ from 'lodash-es';
import { SuiModalService } from 'ng2-semantic-ui-v9';
import { IImpressionEventInput } from '@sunbird/telemetry';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
@Component({
selector: 'app-batch-page-section',
templateUrl: './batch-page-section.component.html'
})
export class BatchPageSectionComponent extends WorkSpace implements OnInit, OnDestroy , AfterViewInit {
public unsubscribe$ = new Subject<void>();
pageid: string;
inviewLogs = [];
/**
* To navigate to other pages
*/
route: Router;
/**
* To send activatedRoute.snapshot to router navigation
* service for redirection to draft component
*/
private activatedRoute: ActivatedRoute;
public carouselData: Array<ICaraouselData> = [];
/**
* Contains list of batchList of logged-in user
*/
batchList = [];
/**
* To show / hide loader
*/
showLoader = true;
/**
* loader message
*/
loaderMessage: ILoaderMessage;
/**
* To show / hide no result message when no result found
*/
noResult = false;
/**
* To show / hide error
*/
showError = false;
/**
* no result message
*/
noResultMessage: INoResultMessage;
/**
* to get url app config
*/
public config: ConfigService;
/**
* Contains page limit of batch list
*/
pageLimit: number;
/**
* Current page category of batch list, defaults to assigned
*/
category: string;
/**
* totalCount of the list
*/
totalCount: Number;
/**
* Contains returned object of the pagination service
* which is needed to show the pagination on inbox view
*/
pager: IPagination;
filters: object;
/**
* To show toaster(error, success etc) after any API calls
*/
private toasterService: ToasterService;
/**
* To call resource service which helps to use language constant
*/
public resourceService: ResourceService;
/**
* telemetryImpression
*/
telemetryImpression: IImpressionEventInput;
/**
* Constructor to create injected service(s) object
Default method of Draft Component class
* @param {SearchService} SearchService Reference of SearchService
* @param {UserService} UserService Reference of UserService
* @param {Router} route Reference of Router
* @param {ActivatedRoute} activatedRoute Reference of ActivatedRoute
* @param {ConfigService} config Reference of ConfigService
*/
constructor(private pageApiService: PageApiService, public modalService: SuiModalService, public searchService: SearchService,
private batchService: BatchService,
public workSpaceService: WorkSpaceService,
activatedRoute: ActivatedRoute,
route: Router, userService: UserService,
toasterService: ToasterService, resourceService: ResourceService,
config: ConfigService, public navigationhelperService: NavigationHelperService) {
super(searchService, workSpaceService, userService);
this.route = route;
this.activatedRoute = activatedRoute;
this.toasterService = toasterService;
this.resourceService = resourceService;
this.config = config;
this.loaderMessage = {
'loaderMessage': this.resourceService.messages.stmsg.m0108,
};
this.noResultMessage = {
'message': 'messages.stmsg.m0020',
'messageText': 'messages.stmsg.m0008'
};
}
ngOnInit() {
this.activatedRoute.params.pipe(takeUntil(this.unsubscribe$))
.subscribe(params => {
this.category = params.category;
this.fetchPageData();
});
this.batchService.updateEvent
.subscribe((data) => {
this.fetchPageData();
});
}
/**
* This method sets the make an api call to get all batch with page No and offset
*/
public fetchPageData() {
this.showLoader = true;
this.filters = {createdFor: this.userService.userProfile.organisationIds};
if (this.category === 'created') {
this.filters['createdBy'] = this.userService.userid;
} else {
this.filters['mentors'] = this.userService.userid;
}
const option: any = {
source: 'web',
name: 'User Courses',
filters: this.filters,
sort_by: { createdDate: this.config.appConfig.WORKSPACE.createdDate },
params: {fields: 'participants'}
};
this.pageApiService.getBatchPageData(option).pipe(takeUntil(this.unsubscribe$))
.subscribe(data => {
this.prepareCarouselData(_.get(data, 'sections'));
}, err => {
this.showLoader = false;
this.carouselData = [];
this.toasterService.error(this.resourceService.messages.fmsg.m0004);
});
}
onCardClick (event) {
const batchData = event.data;
if (batchData.enrollmentType === 'open') {
this.batchService.setBatchData(batchData);
}
this.route.navigate(['update/batch', batchData.identifier], {queryParamsHandling: 'merge', relativeTo: this.activatedRoute});
}
/**
This method prepares batch card data with count of partipants,
adds userName and prepares data structure to reuse exising page section component used in
consumption pages for content cars
*/
public prepareCarouselData(sections = []) {
this.batchList = _.flatten(_.map(sections, 'contents'));
if (!this.batchList || !this.batchList.length) {
this.carouselData = [];
this.showLoader = false;
return;
}
const courseIds = _.map(this.batchList, 'courseId');
const searchOption = {
'filters': {
'identifier': _.uniq(courseIds),
'status': ['Live'],
'contentType': ['Course']
},
'fields': ['name']
};
// Get course details for the batches to show content name on batch card
this.searchService.contentSearch(searchOption, false)
.subscribe(data => {
if (_.get(data, 'result.content')) {
_.map(this.batchList, (batchData) => {
batchData.courseDetails = _.find(_.get(data, 'result.content'), courseData => courseData.identifier === batchData.courseId);
});
}
});
const userList = _.compact(_.uniq(_.map(this.batchList, 'createdBy')));
const { slickSize } = this.config.appConfig.CourseBatchPageSection;
const req = {
filters: { identifier: userList }
};
this.UserList(req).pipe(takeUntil(this.unsubscribe$))
.subscribe((res: ServerResponse) => {
if (res.result.response.count && res.result.response.content.length > 0) {
const userNamesKeyById = _.keyBy(res.result.response.content, 'identifier');
_.forEach(sections, (section, sectionIndex) => {
_.forEach(section.contents, (content, contentIndex) => {
sections[sectionIndex].contents[contentIndex]['userName'] = (userNamesKeyById[content.createdBy].firstName || '')
+ ' ' + (userNamesKeyById[content.createdBy].lastName || '');
sections[sectionIndex].contents[contentIndex]['metaData'] = {identifier: content.identifier};
sections[sectionIndex].contents[contentIndex]['label'] = content.participantCount || 0;
});
});
this.carouselData = sections;
this.showLoader = false;
} else {
this.toasterService.error(this.resourceService.messages.fmsg.m0056);
}
},
(err: ServerResponse) => {
this.showLoader = false;
this.noResult = false;
this.showError = true;
this.toasterService.error(this.resourceService.messages.fmsg.m0056);
}
);
}
public prepareVisits(event) {
_.forEach(event, (inView, index) => {
if (inView.metaData.identifier) {
this.inviewLogs.push({
objid: inView.metaData.identifier,
objtype: 'batch',
index: index,
section: inView.section,
});
}
});
if (this.telemetryImpression) {
this.telemetryImpression.edata.visits = this.inviewLogs;
this.telemetryImpression.edata.subtype = 'pageexit';
this.telemetryImpression = Object.assign({}, this.telemetryImpression);
}
}
public viewAll(event) {
const searchQuery = JSON.parse(event.searchQuery);
const searchQueryParams: any = {};
_.forIn(searchQuery.request.filters, (value, key) => {
if (_.isPlainObject(value)) {
searchQueryParams.dynamic = JSON.stringify({[key]: value});
} else {
searchQueryParams[key] = value;
}
});
searchQueryParams.defaultSortBy = JSON.stringify(searchQuery.request.sort_by);
searchQueryParams.exists = searchQuery.request.exists;
const queryParams = { ...searchQueryParams, ...this.filters };
const sectionUrl = '/workspace/batches/view-all/' + event.name.replace(/\s/g, '-');
this.route.navigate([sectionUrl, 1], {queryParams: queryParams});
}
public 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,
subtype: this.activatedRoute.snapshot.data.telemetry.subtype,
uri: this.activatedRoute.snapshot.data.telemetry.uri + '/' + this.activatedRoute.snapshot.params.category,
visits: this.inviewLogs,
duration: this.navigationhelperService.getPageLoadTime()
}
};
}
ngAfterViewInit () {
setTimeout(() => {
this.setTelemetryImpression();
});
}
ngOnDestroy() {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
}
<div class="ui container">
<div [appTelemetryImpression]="telemetryImpression" *ngIf="!showLoader" class="ui grid stackable my-0">
<div class="twelve wide column py-0" *ngFor="let section of carouselData;let last = last" [ngClass]="{'last mb-0':last}">
<app-page-section cardType="batch" (visits)="prepareVisits($event)" [section]="section" (playEvent)="onCardClick($event)" (viewAll)="viewAll($event)"></app-page-section>
</div>
<div class="twelve wide column" *ngIf="batchList.length === 0 && !showLoader" >
<app-no-result [data]="noResultMessage"></app-no-result>
</div>
</div>
<div *ngIf="showLoader" class="ui grid stackable my-0">
<div class="twelve wide column">
<app-loader [data]='loaderMessage'></app-loader>
</div>
</div>
</div>
<router-outlet></router-outlet>