src/app/manage-learn/project/link-learning-resources/link-learning-resources.component.ts
OnInit
selector | app-link-learning-resources |
styleUrls | ./link-learning-resources.component.scss |
templateUrl | ./link-learning-resources.component.html |
Properties |
Methods |
Inputs |
constructor(location: Location, platform: Platform, modal: ModalController, kendraApiService: KendraApiService, loaderService: LoaderService, navigateService: NavigationService, contentService: ContentService)
|
||||||||||||||||||||||||
Parameters :
|
selectedResources | |
Type : {}
|
|
Default value : []
|
|
addResources |
addResources()
|
Returns :
void
|
close |
close()
|
Returns :
void
|
getFilters |
getFilters()
|
Returns :
void
|
getLearningResources |
getLearningResources()
|
Returns :
void
|
Private handleBackButton |
handleBackButton()
|
Returns :
void
|
ionViewWillEnter |
ionViewWillEnter()
|
Returns :
void
|
ionViewWillLeave |
ionViewWillLeave()
|
Returns :
void
|
loadMoreData |
loadMoreData()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
openResource | ||||
openResource(link)
|
||||
Parameters :
Returns :
void
|
search | ||||
search(event)
|
||||
Parameters :
Returns :
void
|
selectData | ||||
selectData(item)
|
||||
Parameters :
Returns :
void
|
setFilter | ||||
setFilter(filter)
|
||||
Parameters :
Returns :
void
|
validateCheckbox | ||||
validateCheckbox(data)
|
||||
Parameters :
Returns :
void
|
Private backButtonFunc |
Type : Subscription
|
dataCount |
filters |
limit |
Type : number
|
Default value : 25
|
page |
Type : number
|
Default value : 0
|
resources |
Type : []
|
Default value : []
|
searchText |
Type : any
|
selectedFilter |
import { Component, OnInit, Input, Inject } from '@angular/core';
import { Subscription } from 'rxjs';
import { Platform, ModalController } from '@ionic/angular';
import { Location } from '@angular/common';
import { KendraApiService } from '../../core/services/kendra-api.service';
import { LoaderService } from '../../core';
import * as _ from 'underscore';
import { ContentService, SearchType, ContentSearchResult } from 'sunbird-sdk';
import { NavigationService } from '@app/services/navigation-handler.service';
@Component({
selector: 'app-link-learning-resources',
templateUrl: './link-learning-resources.component.html',
styleUrls: ['./link-learning-resources.component.scss'],
})
export class LinkLearningResourcesComponent implements OnInit {
private backButtonFunc: Subscription;
selectedFilter;
@Input() selectedResources = [];
dataCount;
page = 0;
limit = 25;
filters;
resources = [];
searchText: any;
constructor(
private location: Location,
private platform: Platform,
private modal: ModalController,
private kendraApiService: KendraApiService,
private loaderService: LoaderService,
private navigateService: NavigationService,
@Inject('CONTENT_SERVICE') private contentService: ContentService
) {
this.search = _.debounce(this.search, 500);
}
ngOnInit() {
this.getFilters();
}
ionViewWillEnter() {
this.handleBackButton();
}
private handleBackButton() {
this.backButtonFunc = this.platform.backButton.subscribeWithPriority(10, () => {
this.location.back();
this.backButtonFunc.unsubscribe();
});
}
ionViewWillLeave() {
if (this.backButtonFunc) {
this.backButtonFunc.unsubscribe();
}
}
close() {
this.modal.dismiss();
}
setFilter(filter) {
this.filters.forEach((element: any) => {
element.name == filter.name ? (element.isActive = true) : (element.isActive = false);
if (element.isActive) {
this.selectedFilter = element;
this.page = 0;
this.limit = 25;
this.resources = [];
this.getLearningResources();
}
});
}
getFilters() {
this.filters = [
{
name: 'All',
icon: '',
value: [],
},
/* {
name: 'Audios',
icon: '',
value: ['audio/mp3', 'audio/wav', 'audio/x-wav', 'audio/mp4', 'audio/mpeg', 'audio/ogg'],
}, */
{
name: 'Documents',
icon: 'insert_drive_file',
value: ['application/pdf', 'application/epub'],
},
{
name: 'video',
icon: 'play_circle_outline',
value: ['video/mp4', 'video/x-youtube', 'video/webm', 'video/3gpp', 'video/mpeg', 'video/quicktime'],
},
{
name: 'interactive',
icon: 'touch_app',
value: [
'application/vnd.ekstep.ecml-archive',
'application/vnd.ekstep.h5p-archive',
'application/vnd.ekstep.html-archive',
'application/vnd.ekstep.content-archive',
],
},
];
this.setFilter(this.filters[0]);
}
getLearningResources() {
const contentSearchCriteria = {
name: 'Resource',
source: 'web',
limit: this.limit,
searchType: SearchType.SEARCH,
contentTypes: ['Resource'],
mimeType: this.selectedFilter.value,
mode: 'hard',
offset: this.page * this.limit,
query: this.searchText,
};
this.loaderService.startLoader();
this.contentService
.searchContent(contentSearchCriteria)
.toPromise()
.then((responseData: ContentSearchResult) => {
this.loaderService.stopLoader();
console.log(responseData);
let data;
if (responseData.contentDataList) {
data = responseData.contentDataList.map((list) => ({ name: list.name, id: list.identifier }));
this.dataCount = true;
} else {
data = [];
this.dataCount = false;
}
this.selectedResources ? this.validateCheckbox(data) : (this.resources = this.resources.concat(data));
if (responseData.contentDataList && responseData.contentDataList.length < contentSearchCriteria.limit) {
this.dataCount = false;
}
})
.catch((err) => {
this.loaderService.stopLoader();
console.log(err);
});
}
validateCheckbox(data) {
this.selectedResources.forEach((selectedResource) => {
selectedResource.isChecked = true;
data.forEach((resource) => {
if (selectedResource.id == resource.id) {
resource.isChecked = true;
}
});
});
this.resources = this.resources.concat(data);
}
search(event) {
this.page = 0;
this.limit = 25;
this.resources = [];
this.searchText = event.detail.data;
this.getLearningResources();
}
loadMoreData() {
this.page = this.page + 1;
this.getLearningResources();
}
addResources() {
let selected = [];
this.selectedResources.forEach((list) => {
if (list.isChecked) {
selected.push(list);
}
});
if (selected) {
this.modal.dismiss(selected);
}
}
selectData(item) {
item.isChecked = !item.isChecked;
let index = _.findIndex(this.selectedResources, (resource) => {
return resource.id == item.id;
});
if (item.isChecked)
index > -1 ? (this.selectedResources[index].isChecked = item.isChecked) : this.selectedResources.push(item);
else this.selectedResources = this.selectedResources.filter((r) => r.id !== item.id);
}
openResource(link) {
}
}
<ion-toolbar>
<ion-title>
{{'FRMELEMNTS_LBL_LEARNING_RESOURCES' | translate}}
</ion-title>
<ion-buttons (click)="close()" slot="start" class="padding">
<ion-icon role="button" aria-label="back" name="arrow-back" slot="icon-only" style="padding-left: 10px;"></ion-icon>
</ion-buttons>
</ion-toolbar>
<ion-content *ngIf="resources">
<ion-searchbar debounce="1000" (ionInput)="search($event)" placeholder="{{'FRMELEMNTS_LBL_SEARCH' | translate }}">
</ion-searchbar>
<div class="ion-padding">
<ion-icon name="funnel" color="primary"></ion-icon>
<ion-label>{{'FRMELEMNTS_LBL_FILTERS' | translate}} </ion-label> <ion-icon
name="chevron-forward" color="primary"></ion-icon>
<div class="filters">
<ion-button *ngFor="let filter of filters" class="custom-btn-txt-transform-none" shape="round" [color]="filter.isActive ? 'primary' : 'light'"(click)="setFilter(filter);">{{filter.name}} </ion-button>
</div>
<ion-item lines="none" *ngFor="let data of resources" class="data-list">
<ion-checkbox slot="start" ([ngModel])="data.isChecked" [checked]="data.isChecked" (ionChange)="selectData(data)">
</ion-checkbox>
<ion-label class="resources-label">{{data.name}}</ion-label>
</ion-item>
<div class="loadmore-btn" *ngIf="dataCount">
<ion-button (click)="loadMoreData()" class="custom-btn-txt-transform-none" expand="block">{{'FRMELEMNTS_BTN_LOAD_MORE' | translate}}</ion-button>
</div>
</div>
</ion-content>
<ion-footer *ngIf="resources">
<ion-button expand="block" (click)="addResources()" class="custom-btn-txt-transform-none" color="primary">{{'FRMELEMNTS_BTN_ATTACH' | translate}}</ion-button>
</ion-footer>
./link-learning-resources.component.scss
@import "../../../../assets/styles/variables";
@import "../../../../assets/styles/base/variables";
.data-list{
background:$white;
ion-checkbox{
margin-right: 0px;
}
ion-item{
--padding-start: 0px;
}
}
.search-bar-custom {
margin: 20px 15px 15px 15px;
border-radius: 20px;
max-height: 2.5rem;
padding: 0px;
box-shadow: 0px 3px 5px 1px $gray;
ion-input{
--padding-bottom: 18px;
font-weight: 600;
color: $black-color;
}
ion-icon
{
margin-bottom: 10px;
margin-left: 20px;
padding-right : 10px;
}
}
.filters{
display: flex;
overflow: auto;
ion-button{
margin: 4px;
}
}
.resources-label{
padding-left: 15px;
}