src/app/modules/observation/components/observation-listing/observation-listing.component.ts
OnInit
OnDestroy
AfterViewInit
selector | app-observation-listing |
styleUrls | ./observation-listing.component.scss |
templateUrl | ./observation-listing.component.html |
constructor(searchService: SearchService, router: Router, activatedRoute: ActivatedRoute, paginationService: PaginationService, resourceService: ResourceService, toasterService: ToasterService, changeDetectorRef: ChangeDetectorRef, configService: ConfigService, utilService: UtilService, coursesService: CoursesService, playerService: PlayerService, userService: UserService, cacheService: CacheService, browserCacheTtlService: BrowserCacheTtlService, orgDetailsService: OrgDetailsService, navigationhelperService: NavigationHelperService, layoutService: LayoutService, schemaService: SchemaService, contentManagerService: ContentManagerService, telemetryService: TelemetryService, offlineCardService: OfflineCardService, kendraService: KendraService, config: ConfigService, observationUtil: ObservationUtilService, location: Location)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters :
|
back |
back()
|
Returns :
void
|
Async fetchContentList | ||||||||
fetchContentList(page: number)
|
||||||||
Parameters :
Returns :
any
|
getDataParam |
getDataParam()
|
Returns :
void
|
Async getProfileCheck |
getProfileCheck()
|
Returns :
any
|
initLayout |
initLayout()
|
Returns :
void
|
Public inView | ||||
inView(event)
|
||||
Parameters :
Returns :
void
|
Private listenLanguageChange |
listenLanguageChange()
|
Returns :
void
|
Public navigateToPage | ||||||
navigateToPage(page: number)
|
||||||
Parameters :
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
Async ngOnInit |
ngOnInit()
|
Returns :
any
|
playContent | ||||
playContent(event)
|
||||
Parameters :
Returns :
void
|
redoLayout |
redoLayout()
|
Returns :
void
|
setFormat | ||||
setFormat(data)
|
||||
Parameters :
Returns :
void
|
Private setNoResultMessage |
setNoResultMessage()
|
Returns :
void
|
Private setTelemetryData |
setTelemetryData()
|
Returns :
void
|
Public activatedRoute |
Type : ActivatedRoute
|
Public allTabData |
Public browserCacheTtlService |
Type : BrowserCacheTtlService
|
Public cacheService |
Type : CacheService
|
Public cardIntractEdata |
Type : IInteractEventEdata
|
Public changeDetectorRef |
Type : ChangeDetectorRef
|
config |
Public configService |
Type : ConfigService
|
contentData |
contentList |
Type : any
|
Default value : []
|
Public contentManagerService |
Type : ContentManagerService
|
contentName |
Type : string
|
Public coursesService |
Type : CoursesService
|
FIRST_PANEL_LAYOUT |
Public initFilters |
Default value : false
|
Public inViewLogs |
Type : []
|
Default value : []
|
isDesktopApp |
Default value : false
|
layoutConfiguration |
Type : any
|
Public layoutService |
Type : LayoutService
|
Public limit |
Type : number
|
Default value : 50
|
Public navigationhelperService |
Type : NavigationHelperService
|
Public noResultMessage |
Public numberOfSections |
Default value : new Array(
this.configService.appConfig.SEARCH.PAGE_LIMIT
)
|
Public orgDetailsService |
Type : OrgDetailsService
|
pageTitleSrc |
Type : string
|
Default value : 'resourceService?.frmelmnts?.lbl?.observation'
|
Public paginationDetails |
Type : IPagination
|
Public paginationService |
Type : PaginationService
|
payload |
Type : any
|
queryParam |
Type : any
|
Default value : {}
|
Public resourceService |
Type : ResourceService
|
Public router |
Type : Router
|
searchData |
Type : any
|
Default value : ''
|
Public searchService |
Type : SearchService
|
SECOND_PANEL_LAYOUT |
selectedFilters |
Type : any
|
showEditUserDetailsPopup |
Type : any
|
Default value : true
|
Public showLoader |
Default value : true
|
svgToDisplay |
Type : string
|
Default value : 'textbooks-banner-img.svg'
|
Public telemetryImpression |
Type : IImpressionEventInput
|
Public telemetryService |
Type : TelemetryService
|
Public toasterService |
Type : ToasterService
|
totalCount |
Type : any
|
Default value : 0
|
Public unsubscribe$ |
Default value : new Subject<void>()
|
Public userService |
Type : UserService
|
Public utilService |
Type : UtilService
|
import {
PaginationService,
ResourceService,
ConfigService,
ToasterService,
UtilService,
BrowserCacheTtlService,
NavigationHelperService,
IPagination,
LayoutService,
COLUMN_TYPE,
OfflineCardService,
} from '@sunbird/shared';
import {
SearchService,
PlayerService,
CoursesService,
UserService,
OrgDetailsService,
SchemaService,
KendraService,
ObservationUtilService
} from '@sunbird/core';
import { Subject } from 'rxjs';
import {
Component,
OnInit,
OnDestroy,
ChangeDetectorRef,
AfterViewInit,
} from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import * as _ from 'lodash-es';
import {
IInteractEventEdata,
IImpressionEventInput,
TelemetryService,
} from '@sunbird/telemetry';
import {
takeUntil,
} from 'rxjs/operators';
import { CacheService } from '../../../shared/services/cache-service/cache.service';
import { ContentManagerService } from '../../../public/module/offline/services/content-manager/content-manager.service';
import {Location} from '@angular/common';
@Component({
selector: 'app-observation-listing',
templateUrl: './observation-listing.component.html',
styleUrls: ['./observation-listing.component.scss'],
})
export class ObservationListingComponent
implements OnInit, OnDestroy, AfterViewInit {
pageTitleSrc = 'resourceService?.frmelmnts?.lbl?.observation';
svgToDisplay = 'textbooks-banner-img.svg';
contentList: any = [];
public unsubscribe$ = new Subject<void>();
layoutConfiguration: any;
contentData;
contentName: string;
public inViewLogs = [];
public telemetryImpression: IImpressionEventInput;
public cardIntractEdata: IInteractEventEdata;
public showLoader = true;
public initFilters = false;
public noResultMessage;
isDesktopApp = false;
selectedFilters: any;
totalCount: any = 0;
FIRST_PANEL_LAYOUT;
SECOND_PANEL_LAYOUT;
public allTabData;
config;
searchData: any = '';
public numberOfSections = new Array(
this.configService.appConfig.SEARCH.PAGE_LIMIT
);
public paginationDetails: IPagination;
queryParam: any = {};
showEditUserDetailsPopup: any = true;
payload: any;
public limit = 50;
constructor(
public searchService: SearchService,
public router: Router,
public activatedRoute: ActivatedRoute,
public paginationService: PaginationService,
public resourceService: ResourceService,
public toasterService: ToasterService,
public changeDetectorRef: ChangeDetectorRef,
public configService: ConfigService,
public utilService: UtilService,
public coursesService: CoursesService,
private playerService: PlayerService,
public userService: UserService,
public cacheService: CacheService,
public browserCacheTtlService: BrowserCacheTtlService,
public orgDetailsService: OrgDetailsService,
public navigationhelperService: NavigationHelperService,
public layoutService: LayoutService,
private schemaService: SchemaService,
public contentManagerService: ContentManagerService,
public telemetryService: TelemetryService,
private offlineCardService: OfflineCardService,
private kendraService: KendraService,
config: ConfigService,
private observationUtil: ObservationUtilService,
private location: Location,
) {
this.config = config;
this.layoutConfiguration = this.layoutService.initlayoutConfig();
this.paginationDetails = this.paginationService.getPager(0, 1, this.configService.appConfig.SEARCH.PAGE_LIMIT);
}
async ngOnInit() {
this.initLayout();
this.showEditUserDetailsPopup = await this.observationUtil.getProfileInfo();
if (!this.showEditUserDetailsPopup) {
const metaData = this.observationUtil.getAlertMetaData();
metaData.type = 'update profile';
metaData.isClosed = true;
metaData.size = 'mini';
metaData.content.title = this.resourceService.frmelmnts.lbl.updateProfileTitle;
metaData.content.body.type = 'text';
metaData.content.body.data = this.resourceService.frmelmnts.lbl.updateprofilecontent;
metaData.footer.className = 'single-btn';
metaData.footer.buttons.push(
{
type: 'accept',
returnValue: true,
buttonText: this.resourceService.frmelmnts.btn.update,
className: 'popup-btn'
}
);
const returnData = await this.observationUtil.showPopupAlert(metaData);
if (returnData) {
const queryParam = {
showEditUserDetailsPopup: true
};
this.router.navigate(['profile'], {queryParams: queryParam});
}
return;
}
this.activatedRoute.queryParams.subscribe((params) => {
if (params['key']) {
this.searchData = params['key'];
return this.fetchContentList();
}
this.searchData = '';
this.fetchContentList();
});
this.listenLanguageChange();
}
async getProfileCheck() {
await this.observationUtil.getProfileInfo()
.then((result: any) => {
return result;
});
}
private listenLanguageChange() {
this.resourceService.languageSelected$.pipe(takeUntil(this.unsubscribe$)).subscribe((languageData) => {
this.setNoResultMessage();
});
}
private setNoResultMessage() {
const noContentfoundSubTitle = this.utilService.transposeTerms(_.get(this.resourceService, 'frmelmnts.lbl.noContentfoundSubTitle'), 'frmelmnts.lbl.noContentfoundSubTitle', this.resourceService.selectedLang);
const title = _.get(this.resourceService, 'messages.stmsg.m0006');
this.noResultMessage = { title, noContentfoundSubTitle };
}
getDataParam() {
this.observationUtil.getProfileDataList()
.then((result: any) => {
this.payload = result;
});
}
back(): void {
this.location.back();
}
async fetchContentList(page = 1) {
await this.getDataParam();
const paramOption = {
url: this.config.urlConFig.URLS.OBSERVATION.OBSERVATION_LISTING,
param: { page: page, limit: this.limit, search: this.searchData },
data: this.payload
};
this.kendraService.post(paramOption).subscribe(
(data: any) => {
this.totalCount = data.result.count;
this.paginationDetails.currentPage = page;
this.paginationDetails = this.paginationService.getPager(
data.result.count,
this.paginationDetails.currentPage,
this.limit
);
this.setFormat(data.result.data);
},
(error) => {}
);
window.scroll({
top: 0,
left: 0,
behavior: 'smooth',
});
}
public navigateToPage(page: number): void {
if (page < 1 || page > this.paginationDetails.totalPages) {
return;
}
this.fetchContentList(page);
}
setFormat(data) {
const result = [];
this.contentList = [];
data.forEach((value) => {
let solution_name: string = value.name;
solution_name = (solution_name && solution_name.length) ? solution_name[0].toUpperCase() + solution_name.slice(1) : '';
const subject: any = [];
subject.push(value.programName);
const obj = {
name: solution_name,
contentType: 'Observation',
metaData: {
identifier: value.solutionId,
},
entityType:value.entityType,
identifier: value.solutionId,
solutionId: value.solutionId,
programId: value.programId,
medium: value.language,
organization: value.creator,
_id: value._id,
subject: subject
};
if (value.creator && value.creator.length) {
const creator: any = [];
creator.push(value.creator);
obj['gradeLevel'] = creator;
}
result.push(obj);
this.contentList = result;
});
this.showLoader = false;
}
initLayout() {
this.layoutConfiguration = this.layoutService.initlayoutConfig();
this.redoLayout();
this.layoutService
.switchableLayout()
.pipe(takeUntil(this.unsubscribe$))
.subscribe((layoutConfig) => {
if (layoutConfig != null) {
this.layoutConfiguration = layoutConfig.layout;
}
this.redoLayout();
});
}
redoLayout() {
if (this.layoutConfiguration != null) {
this.FIRST_PANEL_LAYOUT = this.layoutService.redoLayoutCSS(
0,
this.layoutConfiguration,
COLUMN_TYPE.threeToNine,
true
);
this.SECOND_PANEL_LAYOUT = this.layoutService.redoLayoutCSS(
1,
this.layoutConfiguration,
COLUMN_TYPE.threeToNine,
true
);
} else {
this.FIRST_PANEL_LAYOUT = this.layoutService.redoLayoutCSS(
0,
null,
COLUMN_TYPE.fullLayout
);
this.SECOND_PANEL_LAYOUT = this.layoutService.redoLayoutCSS(
1,
null,
COLUMN_TYPE.fullLayout
);
}
}
ngOnDestroy() {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
ngAfterViewInit() {
setTimeout(() => {
this.setTelemetryData();
this.inView({ inview: [] });
});
}
private setTelemetryData() {
this.inViewLogs = []; // set to empty every time filter or page changes
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.userService.slug
? '/' + this.userService.slug + this.router.url
: this.router.url,
subtype: this.activatedRoute.snapshot.data.telemetry.subtype,
duration: this.navigationhelperService.getPageLoadTime(),
},
};
this.cardIntractEdata = {
id: 'content-card',
type: 'click',
pageid: this.activatedRoute.snapshot.data.telemetry.pageid,
};
}
playContent(event) {
const data = event.data;
this.queryParam = {
programId: data.programId,
solutionId: data.solutionId,
observationId: data._id,
solutionName: data.name,
programName: data.subject[0],
entityType:data.entityType
};
this.router.navigate(['observation/details'], {
queryParams: this.queryParam,
});
}
public inView(event) {
_.forEach(event.inview, (elem, key) => {
const obj = _.find(this.inViewLogs, {
objid: elem.data.metaData.identifier,
});
if (!obj) {
this.inViewLogs.push({
objid: elem.data.metaData.identifier,
objtype: elem.data.metaData.contentType || 'content',
index: elem.id,
});
}
});
if (this.telemetryImpression) {
this.telemetryImpression.edata.visits = this.inViewLogs;
this.telemetryImpression.edata.subtype = 'pageexit';
this.telemetryImpression = Object.assign({}, this.telemetryImpression);
}
}
}
<app-landing-section [textToDisplay]="resourceService?.frmelmnts?.lbl?.observation" [svgToDisplay]="svgToDisplay"
[layoutConfiguration]="layoutConfiguration"></app-landing-section>
<div [ngClass]="layoutConfiguration ? 'sbt-fluid-content-bg':''">
<div [ngClass]="layoutConfiguration ? 'sb-g sbt-container sbt-page-content' : 'sb-g'">
<div [ngClass]="FIRST_PANEL_LAYOUT">
<div *ngIf="layoutConfiguration">
<ng-container *ngIf="isDesktopApp">
<app-network-status></app-network-status>
<app-load-offline-content></app-load-offline-content>
<app-system-warning></app-system-warning>
</ng-container>
</div>
<div [ngClass]="isDesktopApp ? 'sb-desktop-filter-section' : ''">
<ng-container>
<app-global-search-filter [layoutConfiguration]="layoutConfiguration" [facets]="facets" [isOpen]='true'
*ngIf="initFilters && allTabData" (filterChange)="getFilters($event)">
</app-global-search-filter>
</ng-container>
</div>
</div>
<div [ngClass]="SECOND_PANEL_LAYOUT" class="w-100">
<div [ngClass]="layoutConfiguration ? 'sbt-page-content-area' : 'ui container mt-24'">
<div class="content-grid relative9">
<div class="sb-pageSection" *ngIf="!showLoader && totalCount > 0">
<div class="sb-pageSection-header">
<h4 class="sb-pageSection-title m-0 mr-5" [innerHTML]="resourceService?.frmelmnts?.lbl?.observation"></h4>
<span class="badge">{{totalCount}}</span>
</div>
<br/>
</div>
<div [appTelemetryImpression]="telemetryImpression" class="twelve wide column" *ngIf="!showLoader && contentList.length">
<app-global-search-selected-filter [facets]="facets" [selectedFilters]="selectedFilters"
*ngIf="initFilters && facets && layoutConfiguration" (filterChange)="getFilters($event)"></app-global-search-selected-filter>
<div class="sb-grid">
<div [id]="i" [data]="content" class="sb-grid--item"
*ngFor="let content of contentList;let i = index;">
<sb-library-card [indexToDisplay]="i" [layoutConfig]="layoutConfiguration" *ngIf="!isDesktopApp;else desktopCard"
appContentDirection appTelemetryInteract [telemetryInteractEdata]="cardIntractEdata" [telemetryInteractObject]="{id:content.metaData.identifier,type:content.metaData.contentType||'Content',ver:'1.0'}"
(cardClick)="playContent($event)" [content]="content" [cardImg]="'assets/images/book.png'" ></sb-library-card>
</div>
</div>
</div>
<div [appTelemetryImpression]="telemetryImpression" class="twelve wide column"
*ngIf="contentList.length === 0 && !showLoader && noResultMessage">
<app-no-result-found [title]="noResultMessage?.title" [subTitle]="noResultMessage?.subTitle"
[buttonText]="noResultMessage?.buttonText" [showExploreContentButton]="noResultMessage?.showExploreContentButton"></app-no-result-found>
</div>
<div class="twelve wide column" *ngIf="showLoader">
<div class="sb-grid">
<div [id]="i" [data]="content" class="sb-grid--item"
*ngFor="let i of numberOfSections">
<sb-library-card [layoutConfig]="layoutConfiguration" [isLoading]="true"></sb-library-card>
</div>
</div>
</div>
<div class="twelve wide column right aligned"
*ngIf="!showLoader">
<div class="sb-pagination-container flex-jc-flex-end mt-16" *ngIf="paginationDetails.pages.length">
<div class="sb-pagination my-0">
<a role="button" title="{{resourceService?.frmelmnts?.lbl?.first}}" attr.aria-label="{{resourceService?.frmelmnts?.lbl?.first}}" [ngClass]="{disabled:paginationDetails.currentPage===1 }" class="sb-item "
tabindex="0" (click)="navigateToPage(1) ">«</a>
<a role="button" title="{{resourceService?.frmelmnts?.lbl?.previous}}" attr.aria-label="{{resourceService?.frmelmnts?.lbl?.previous}}" [ngClass]="{disabled:paginationDetails.currentPage===1 }" class="sb-item "
tabindex="0" (click)="navigateToPage(paginationDetails.currentPage - 1)"><</a>
<a role=“button” aria-current=“page” title="{{page}}" attr.aria-label="{{page}}" *ngFor="let page of paginationDetails.pages" [ngClass]="{active:paginationDetails.currentPage===page}"
tabindex="0" (click)="navigateToPage(page)" class="sb-item">{{page}}</a>
<a role="button" title="{{resourceService?.frmelmnts?.lbl?.next}}" attr.aria-label="{{resourceService?.frmelmnts?.lbl?.next}}" [ngClass]="{disabled:paginationDetails.currentPage=== paginationDetails.totalPages}"
tabindex="0" (click)="navigateToPage(paginationDetails.currentPage + 1)" class="sb-item">></a>
<a role="button" title="{{resourceService?.frmelmnts?.lbl?.last}}" attr.aria-label="{{resourceService?.frmelmnts?.lbl?.last}}" [ngClass]="{disabled:paginationDetails.currentPage=== paginationDetails.totalPages}"
tabindex="0" (click)="navigateToPage(paginationDetails.totalPages)" class="sb-item ">»</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
./observation-listing.component.scss
.sb-grid {
display: grid;
grid-template-columns: repeat(auto-fill,minmax(252px,1fr));
grid-gap: 1rem;
grid-row-gap: 1.5rem;
}