File
Implements
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Outputs
|
|
Outputs
closeModal
|
Type : EventEmitter
|
|
Methods
Public
changeOptions
|
changeOptions(options)
|
|
|
dismissModal
|
dismissModal()
|
|
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
ratingChange
|
ratingChange(event)
|
|
|
Public
activatedRoute
|
Type : ActivatedRoute
|
|
|
Public
feedbackText
|
Type : string
|
Default value : ''
|
|
modal
|
Decorators :
@ViewChild('modal')
|
|
|
Public
showContentRatingModal
|
Default value : true
|
|
Public
showTextarea
|
Default value : false
|
|
Public
startext
|
Type : string
|
Default value : ''
|
|
Private
toasterService
|
Type : ToasterService
|
|
To show toaster(error, success etc) after any API calls
|
import {
Component, OnInit, Input, ViewChild, OnDestroy, Output, EventEmitter
} from '@angular/core';
import { ResourceService, ToasterService } from '@sunbird/shared';
import { TelemetryService } from '@sunbird/telemetry';
import { ActivatedRoute } from '@angular/router';
import { FormService } from '@sunbird/core';
import * as _ from 'lodash-es';
@Component({
selector: 'app-content-rating',
templateUrl: './content-rating.component.html',
styleUrls: ['./content-rating.component.scss']
})
export class ContentRatingComponent implements OnInit, OnDestroy {
/**
*Output for Sharelink;
*/
@ViewChild('modal') modal;
@Input() contentData?: any;
public startext = '';
public feedbackText = '';
public feedbackObj;
public showTextarea = false;
public showContentRatingModal = true;
public resourceService: ResourceService;
/**
* To show toaster(error, success etc) after any API calls
*/
private toasterService: ToasterService;
private telemetryService: TelemetryService;
/**
* To get url params
*/
public activatedRoute: ActivatedRoute;
contentRating: number;
enableSubmitBtn: boolean;
@Output() closeModal = new EventEmitter();
/**
* Constructor to create injected service(s) object
*Default method of unpublished Component class
*@param {ResourceService} SearchService Reference of SearchService
*/
constructor(resourceService: ResourceService, toasterService: ToasterService, public formService: FormService,
telemetryService: TelemetryService , activatedRoute: ActivatedRoute) {
this.resourceService = resourceService;
this.toasterService = toasterService;
this.telemetryService = telemetryService;
this.activatedRoute = activatedRoute;
}
ngOnInit() {
this.startext = _.get(this.resourceService, 'frmelmnts.lbl.defaultstar');
this.resourceService.languageSelected$.subscribe(item => {
const formReadInputParams = {
formType: 'contentfeedback',
contentType: item.value,
formAction: 'get'
};
this.formService.getFormConfig(formReadInputParams).subscribe(
(formResponsedata) => {
this.feedbackObj = formResponsedata[0];
}, (error) => {
this.feedbackObj = { };
});
});
}
ratingChange(event) {
this.contentRating = event;
this.startext = this.feedbackObj[event]['ratingText'];
this.enableSubmitBtn = true;
this.showTextarea = false;
_.forEach(this.feedbackObj[this.contentRating]['options'], (feedback) => {
feedback['checked'] = false;
});
}
public changeOptions(options) {
if (options['key'] === 'OTHER' && !this.showTextarea) {
this.showTextarea = true;
} else if (options['key'] === 'OTHER' && this.showTextarea) {
this.showTextarea = false;
}
}
public submit() {
if (this.contentRating) {
const feedbackTelemetry = {
context: {
env: _.get(this.activatedRoute.snapshot.data.telemetry, 'env')
},
object: {
id: _.get(this.activatedRoute.snapshot.params, 'contentId') || _.get(this.activatedRoute.snapshot.params, 'collectionId') ||
_.get(this.activatedRoute.snapshot.params, 'courseId'),
type: _.get(this.contentData , 'contentType'),
ver: _.get(this.contentData , 'pkgVersion') ? _.get(this.contentData , 'pkgVersion').toString() : '1.0'
},
edata: { }
};
_.forEach(this.feedbackObj[this.contentRating]['options'], (feedback) => {
if (feedback['checked']) {
const feedbackTelemetryClone = _.clone(feedbackTelemetry);
feedbackTelemetryClone['edata'] = { };
feedbackTelemetryClone['edata']['commentid'] = feedback['key'];
if (feedback['key'] === 'OTHER') {
feedbackTelemetryClone['edata']['commenttxt'] = this.feedbackText;
} else {
feedbackTelemetryClone['edata']['commenttxt'] = feedback['value'];
}
this.telemetryService.feedback(feedbackTelemetryClone);
}
});
feedbackTelemetry['edata'] = {
rating: this.contentRating
};
this.telemetryService.feedback(feedbackTelemetry);
this.toasterService.success(this.resourceService.messages.smsg.m0050);
}
this.startext = this.resourceService.frmelmnts.lbl.defaultstar;
this.enableSubmitBtn = false;
this.showContentRatingModal = false;
this.closeModal.emit(true);
}
dismissModal() {
this.startext = this.resourceService.frmelmnts.lbl.defaultstar;
this.enableSubmitBtn = false;
this.showContentRatingModal = false;
this.closeModal.emit(true);
}
ngOnDestroy() {
if (this.modal && this.modal.deny) {
this.modal.deny();
}
}
}
<app-modal-wrapper *ngIf="showContentRatingModal" [config]="{disableClose: false, size: 'normal'}"
(dismiss)="dismissModal()" #modal>
<ng-template sbModalContent>
<div class="sb-modal">
<div class="transition ui dimmer page modals active visible">
<div class="ui modal transition active visible normal">
<!--Header-->
<i class="close icon" role="img" aria-label="close" tabindex="0" (click)="modal.deny()"></i>
<div class="sb-modal-header">
{{resourceService?.frmelmnts?.lbl?.enjoyedContent}}
</div>
<!--/Header-->
<!--Content-->
<div class="sb-modal-content p-0">
<div class="field px-16 py-24">
<sui-rating (valueChange)="ratingChange($event)" tabindex="0" [maximum]="5"
class="sb-rating ui huge star rating"></sui-rating>
<div class="fs-0-92 mt-8"> {{startext}}</div>
</div>
<div class="sb-content-rating-container px-16 py-24" *ngIf="enableSubmitBtn">
<div class="sb-content-rating">
<div class="rating-header pb-24 fs-0-92">
{{feedbackObj[contentRating]['question']}}
</div>
<div class="rating-checkbox">
<!-- <div class="sb-checkbox sb-checkbox-primary" *ngFor="let feedback of feedbackObj[contentRating]['options']">
<input type="checkbox" role="checkbox" [(ngModel)]="feedback.checked" (click)="changeOptions(feedback)">
<label [class.options-content-checked]="feedback.checked">{{feedback['value']}}</label>
</div> -->
<div class="sb-checkbox sb-checkbox-primary sb-checkbox-rightaligned"
*ngFor="let feedback of feedbackObj[contentRating]['options']">
<input type="checkbox" id="{{feedback['value']}}" [(ngModel)]="feedback.checked" tabindex="0"
(click)="changeOptions(feedback)">
<label for="{{feedback['value']}}" class="fsmall mb-16" role="img"
title="{{feedback['value']}}">{{feedback['value']}}</label>
</div>
<div *ngIf="showTextarea">
<textarea rows="5" maxlength="1000" class="sb-form-control" [(ngModel)]="feedbackText"></textarea>
</div>
</div>
</div>
</div>
</div>
<!--/Content-->
<!--Actions-->
<div class="sb-modal-actions">
<button (click)="submit()" tabindex="0" class="sb-btn sb-btn-normal sb-btn-primary"
[disabled]="!enableSubmitBtn" [ngClass]="{'sb-btn-disabled': !enableSubmitBtn}">
{{resourceService?.frmelmnts.btn.submit}}
</button>
</div>
<!--/Actions-->
</div>
</div>
</div>
</ng-template>
</app-modal-wrapper>
@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
::ng-deep {
.sb-rating.ui.star.rating {
.icon {
margin-right: calculateRem(4px);
}
.active.icon,
.icon.selected {
color: var(--primary-300) !important;
text-shadow: none !important;
}
}
}
.sb-content-rating-container {
width: 100%;
border-top: calculateRem(1px) solid var(--gray-100);
.sb-content-rating {
max-width: calculateRem(360px);
width: 100%;
}
}
@include respond-below(sm) {
.sb-modal-content {
.field,
.rating-header {
text-align: center;
}
}
.sb-modal-actions {
justify-content: center;
}
}
// Rating Modal
@include respond-below(sm) {
.sb-rating-modal {
&.sb-modal {
.ui.modal.normal {
width: 100% !important;
height: 100% !important;
max-width: 100% !important;
.sb-modal-content {
min-height: calc(100% - 96px);
max-height: 100%;
}
}
}
}
}
Legend
Html element with directive