src/app/modules/workspace/components/request-changes-popup/request-changes-popup.component.ts
This component displays the checklist for request changes for reviewer and calls the reject API to reject the content
OnInit
OnDestroy
selector | app-request-changes-popup |
templateUrl | ./request-changes-popup.component.html |
Properties |
|
Methods |
constructor(route: Router, activatedRoute: ActivatedRoute, resourceService: ResourceService, toasterService: ToasterService, configService: ConfigService, routerNavigationService: RouterNavigationService, contentService: ContentService, formService: FormService, navigationHelperService: NavigationHelperService, workSpaceService: WorkSpaceService)
|
||||||||||||||||||||||||||||||||||||||||||||
Constructor to create injected service(s) object Default method of RequestChangesPopupComponent class
Parameters :
|
closeModalAfterError |
closeModalAfterError()
|
Returns :
void
|
createCheckedArray | ||||
createCheckedArray(checkedItem)
|
||||
This method pushes all the checked reason into a array
Parameters :
Returns :
void
|
getCheckListConfig |
getCheckListConfig()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
This method helps to get the content id from activated route
Returns :
void
|
redirect |
redirect()
|
Method to redirect to parent url
Returns :
void
|
submitRequestChanges |
submitRequestChanges()
|
This method builds the request body and call the reject API.
Returns :
void
|
validateModal |
validateModal()
|
This method checks whether the length of comments is greater than zero. It also checks whether a reject reason is checked. If both the validation is passed it enables the request changes button
Returns :
void
|
Private activatedRoute |
Type : ActivatedRoute
|
To send activatedRoute.snapshot to router navigation service for redirection to parent component |
checkListData |
Type : any
|
Checklist config |
closeUrl |
Type : any
|
To close url |
comment |
Type : string
|
Typed comment |
Public configService |
Type : ConfigService
|
To get url, app configs |
contentId |
Type : string
|
Content id which will be rejected |
Public contentService |
Type : ContentService
|
reference of ContentService. |
Public formService |
Type : FormService
|
Reference of FormService
|
isDisabled |
Default value : true
|
Flag to enable/disable request changes button |
modal |
Decorators :
@ViewChild('modal')
|
Public navigationHelperService |
Type : NavigationHelperService
|
reasons |
Type : []
|
Default value : []
|
Checked reasons |
rejectCheckListData |
Type : any
|
Public resourceService |
Type : ResourceService
|
To call resource service which helps to use language constant |
route |
Type : Router
|
To navigate to other pages |
Public routerNavigationService |
Type : RouterNavigationService
|
To navigate back to parent component |
showDefaultConfig |
Default value : false
|
showDefaultConfig |
showloader |
Default value : true
|
showModal |
Default value : false
|
Private toasterService |
Type : ToasterService
|
To show toaster(error, success etc) after any API calls |
Public unsubscribe |
Default value : new Subject<void>()
|
Public workSpaceService |
Type : WorkSpaceService
|
import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import * as _ from 'lodash-es';
import { ContentService, FormService } from '@sunbird/core';
import {
ResourceService, ConfigService, ToasterService, ServerResponse, RouterNavigationService,
NavigationHelperService
} from '@sunbird/shared';
import { WorkSpaceService } from './../../services';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
/**
* This component displays the checklist for request changes for reviewer and
* calls the reject API to reject the content
*/
@Component({
selector: 'app-request-changes-popup',
templateUrl: './request-changes-popup.component.html'
})
export class RequestChangesPopupComponent implements OnInit, OnDestroy {
@ViewChild('modal') modal;
/**
* To navigate to other pages
*/
route: Router;
/**
* Content id which will be rejected
*/
contentId: string;
/**
* Typed comment
*/
comment: string;
/**
* Checked reasons
*/
reasons = [];
/**
* Flag to enable/disable request changes button
*/
isDisabled = true;
/**
* To send activatedRoute.snapshot to router navigation
* service for redirection to parent component
*/
private activatedRoute: ActivatedRoute;
/**
* To call resource service which helps to use language constant
*/
public resourceService: ResourceService;
/**
* To show toaster(error, success etc) after any API calls
*/
private toasterService: ToasterService;
/**
* To navigate back to parent component
*/
public routerNavigationService: RouterNavigationService;
/**
* To get url, app configs
*/
public configService: ConfigService;
/**
* reference of ContentService.
*/
public contentService: ContentService;
/**
* Checklist config
*/
checkListData: any;
/**
* To close url
*/
closeUrl: any;
/**
* showDefaultConfig
*/
showDefaultConfig = false;
showloader = true;
rejectCheckListData: any;
showModal = false;
public unsubscribe = new Subject<void>();
/**
* Constructor to create injected service(s) object
*
* Default method of RequestChangesPopupComponent class
*
* @param {Router} route Reference of Router
* @param {ActivatedRoute} activatedRoute Reference of ActivatedRoute
* @param {ResourceService} resourceService Reference of ResourceService
* @param {ToasterService} toasterService Reference of ToasterService
* @param {ConfigService} config Reference of ConfigService
* @param {ContentService} contentService Reference of contentService
* @param {FormService} formService Reference of FormService
*/
constructor(route: Router,
activatedRoute: ActivatedRoute,
resourceService: ResourceService,
toasterService: ToasterService,
configService: ConfigService,
routerNavigationService: RouterNavigationService,
contentService: ContentService,
public formService: FormService,
public navigationHelperService: NavigationHelperService,
public workSpaceService: WorkSpaceService) {
this.route = route;
this.activatedRoute = activatedRoute;
this.resourceService = resourceService;
this.toasterService = toasterService;
this.configService = configService;
this.routerNavigationService = routerNavigationService;
this.contentService = contentService;
this.checkListData = this.configService.appConfig.CHECK_LIST_CONFIG;
}
/**
* This method pushes all the checked reason into a array
*/
createCheckedArray(checkedItem) {
if (checkedItem && (_.indexOf(this.reasons, checkedItem) === -1)) {
this.reasons.push(checkedItem);
} else if (checkedItem && (_.indexOf(this.reasons, checkedItem) !== -1)) {
this.reasons.splice(_.indexOf(this.reasons, checkedItem), 1);
}
this.validateModal();
}
/**
* This method checks whether the length of comments is greater than zero.
* It also checks whether a reject reason is checked.
* If both the validation is passed it enables the request changes button
*/
validateModal() {
if (this.reasons && this.reasons.length > 0 && this.comment
&& _.trim(this.comment).length > 0 && this.showDefaultConfig || (!this.rejectCheckListData && this.comment
&& _.trim(this.comment).length > 0 && this.showDefaultConfig)) {
this.isDisabled = false;
} else {
this.isDisabled = true;
}
}
/**
* This method builds the request body and call the reject API.
*/
submitRequestChanges() {
this.isDisabled = true;
const requestBody = {
request: {
content: {
rejectReasons: this.reasons,
rejectComment: _.trim(this.comment)
}
}
};
const option = {
url: `${this.configService.urlConFig.URLS.CONTENT.REJECT}/${this.contentId}`,
data: requestBody
};
this.contentService.post(option).pipe(
takeUntil(this.unsubscribe)).
subscribe(response => {
this.toasterService.success(this.resourceService.messages.smsg.m0005);
this.modal.deny();
if (this.closeUrl.url.includes('flagreviewer')) {
this.route.navigate(['workspace/content/flagreviewer/1']);
} else {
this.route.navigate(['workspace/content/upForReview/1']);
}
}, (err) => {
this.toasterService.error(this.resourceService.messages.fmsg.m0020);
this.modal.deny();
this.redirect();
});
}
/**
* Method to redirect to parent url
*/
redirect() {
this.route.navigate(['../'], { relativeTo: this.activatedRoute });
}
getCheckListConfig() {
this.showDefaultConfig = false;
const formServiceInputParams = {
formType: 'content',
formAction: 'requestforchanges',
subType: 'resource'
};
this.workSpaceService.getFormData(formServiceInputParams).subscribe(
(data: ServerResponse) => {
if (data.result.form) {
this.showModal = true;
this.showloader = false;
this.rejectCheckListData = data.result.form.data.fields[0];
if (!_.get(data.result.form, 'data.fields[0].checklist') || !_.get(data.result.form, 'data.fields[0].otherReason') ) {
this.showDefaultConfig = true;
}
} else {
this.showModal = true;
this.showloader = false;
this.showDefaultConfig = true;
}
},
(err: ServerResponse) => {
this.closeModalAfterError();
}
);
}
/**
* This method helps to get the content id from activated route
*/
ngOnInit() {
this.activatedRoute.parent.params.subscribe((params) => {
this.contentId = params.contentId;
this.getCheckListConfig();
});
this.closeUrl = this.navigationHelperService.getPreviousUrl();
}
closeModalAfterError() {
this.showModal = false;
this.showloader = false;
this.toasterService.error(this.resourceService.messages.emsg.m0005);
this.redirect();
}
ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
}
}
<sui-modal
[mustScroll]="true"
[isClosable]="false"
[transitionDuration]="0"
[size]="'normal'"
class="sb-modal"
appBodyScroll
(dismissed)="redirect()"
#modal
*ngIf="showModal"
>
<i class="icon close" (click)="modal.deny('denied')" tabindex="0"></i>
<!--Header-->
<div class="sb-modal-header">
{{resourceService.frmelmnts.btn.checkListRequestChanges}}
</div>
<!--/Header-->
<!--Content-->
<div class="sb-modal-content">
<div *ngIf="rejectCheckListData">
<div class="ui small header">
<h4>{{rejectCheckListData.title}}</h4>
</div>
<div class="ui three column grid">
<div class="column" *ngFor="let list of rejectCheckListData.contents">
<h5 class="ui tiny header">{{list.name}}</h5>
<div class="ui list" *ngFor="let item of list.checkList">
<div class="item">
<div class="ui checkbox checklist">
<input type="checkbox" class="listItem" tabindex="0" (click)="createCheckedArray(item)">
<label>{{item}}</label>
</div>
</div>
</div>
</div>
</div>
<h5>
<div class="ui checkbox checklist" *ngIf="rejectCheckListData.otherReason">
<input type="checkbox" class="listItem" tabindex="0" (click)="createCheckedArray('Others')">
<label>{{rejectCheckListData.otherReason}}</label>
</div>
</h5>
<h5 class="ui small header" *ngIf="!showDefaultConfig">{{resourceService.frmelmnts.btn.checkListComment}}</h5>
<div class="ui form mt-10" *ngIf="!showDefaultConfig">
<div class="field">
<textarea rows="3" [(ngModel)]="comment" (keyup)="validateModal()"></textarea>
</div>
</div>
</div>
<div *ngIf="showDefaultConfig">
<h5 *ngIf="showDefaultConfig && !rejectCheckListData" class="ui small header "> {{checkListData.reject.comments}}</h5>
<div class="ui form mt-10">
<div class="field">
<textarea rows="3" [(ngModel)]="comment" (keyup)="validateModal()"></textarea>
</div>
</div>
</div>
<div *ngIf="showloader">
<app-loader></app-loader>
</div>
</div>
<!--/Content-->
<!--Actions-->
<div class="sb-modal-actions">
<button
class="sb-btn sb-btn-normal sb-btn-primary"
type="button"
[disabled]="isDisabled"
tabindex="0" (click)="submitRequestChanges()"
>
{{resourceService.frmelmnts.btn.checkListRequestChanges}}
</button>
<button
class="sb-btn sb-btn-normal sb-btn-outline-primary mr-8"
type="button"
tabindex="0" (click)="redirect();modal.deny();"
>
{{resourceService.frmelmnts.btn.checklistCancel}}
</button>
</div>
<!--/Actions-->
</sui-modal>