src/app/modules/workspace/components/up-for-review/up-for-review.component.ts
The upforReview component search for all the upforreview content
selector | app-up-for-review |
templateUrl | up-for-review.component.html |
constructor(modalService: SuiModalService, searchService: any, workSpaceService: WorkSpaceService, paginationService: any, activatedRoute: ActivatedRoute, route: Router, userService: any, toasterService: any, resourceService: any, config: any, permissionService: any, navigationhelperService: any)
|
Constructor to create injected service(s) object
Parameters :
|
fecthUpForReviewContent |
fecthUpForReviewContent(limit: number, pageNumber: number, bothParams: any)
|
This method sets the make an api call to get all UpForReviewContent with page No and offset
Returns:
void
|
navigateToPage |
navigateToPage(page: number)
|
This method helps to navigate to different pages.
Parameters :
navigateToPage(1)
Returns:
void
|
contentClick |
contentClick(content: any)
|
Returns:
void
|
inview |
inview(event: any)
|
get inview Data
Returns:
void
|
getContentType |
getContentType()
|
Returns:
void
|
Private activatedRoute |
activatedRoute: |
To send activatedRoute.snapshot to router navigation |
Public config |
config: |
To get url, app configs |
contentIds |
contentIds: |
Contains unique contentIds id |
inviewLogs |
inviewLogs: |
inviewLogs |
loaderMessage |
loaderMessage: |
loader message |
modalService |
modalService: |
navigationhelperService |
navigationhelperService: |
noResult |
noResult: |
Default value: false
|
To show / hide no result message when no result found |
noResultMessage |
noResultMessage: |
no result message |
pageLimit |
pageLimit: |
Contains page limit of inbox list |
pageNumber |
pageNumber: |
Default value: 1
|
Current page number of inbox list |
pager |
pager: |
Contains returned object of the pagination service |
Private paginationService |
paginationService: |
For showing pagination on draft list |
Public permissionService |
permissionService: |
reference of permissionService service. |
queryParams |
queryParams: |
Public resourceService |
resourceService: |
To call resource service which helps to use language constant |
route |
route: |
To navigate to other pages |
searchService |
searchService: |
showError |
showError: |
Default value: false
|
To show / hide error |
showLoader |
showLoader: |
Default value: true
|
To show / hide loader |
sort |
sort: |
state |
state: |
telemetryImpression |
telemetryImpression: |
telemetryImpression |
Private toasterService |
toasterService: |
To show toaster(error, success etc) after any API calls |
totalCount |
totalCount: |
totalCount of the list |
upForReviewContentData |
upForReviewContentData: |
Contains list of published course(s) of logged-in user |
userRoles |
userRoles: |
userRoles |
workSpaceService |
workSpaceService: |
import { combineLatest, Observable } from 'rxjs';
import { WorkSpace } from './../../classes/workspace';
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { SearchService, UserService, PermissionService } from '@sunbird/core';
import {
ServerResponse, PaginationService, ConfigService, ToasterService,
ResourceService, IContents, ILoaderMessage, INoResultMessage, IUserData,
NavigationHelperService
} from '@sunbird/shared';
import { WorkSpaceService } from '../../services';
import * as _ from 'lodash-es';
import { SuiModalService, TemplateModalConfig, ModalTemplate } from 'ng2-semantic-ui-v9';
import { IInteractEventInput, IImpressionEventInput } from '@sunbird/telemetry';
/**
* The upforReview component search for all the upforreview content
*/
@Component({
selector: 'app-up-for-review',
templateUrl: './up-for-review.component.html'
})
export class UpForReviewComponent extends WorkSpace implements OnInit, AfterViewInit {
/**
* To navigate to other pages
*/
route: Router;
/**
* To send activatedRoute.snapshot to router navigation
* service for redirection to draft component
*/
private activatedRoute: ActivatedRoute;
/**
* Contains unique contentIds id
*/
contentIds: string;
/**
* Contains list of published course(s) of logged-in user
*/
upForReviewContentData: Array<IContents> = [];
/**
* 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;
/**
* For showing pagination on draft list
*/
private paginationService: PaginationService;
/**
* To get url, app configs
*/
public config: ConfigService;
/**
* Contains page limit of inbox list
*/
pageLimit: number;
/**
* Current page number of inbox list
*/
pageNumber = 1;
/**
* totalCount of the list
*/
totalCount: Number;
/**
* Contains returned object of the pagination service
* which is needed to show the pagination on inbox view
*/
pager;
/**
* To show toaster(error, success etc) after any API calls
*/
private toasterService: ToasterService;
queryParams: any;
sort: object;
state: string;
/**
* userRoles
*/
userRoles = [];
/**
* To call resource service which helps to use language constant
*/
public resourceService: ResourceService;
/**
* reference of permissionService service.
*/
public permissionService: PermissionService;
/**
* telemetryImpression
*/
telemetryImpression: IImpressionEventInput;
/**
* inviewLogs
*/
inviewLogs = [];
/**
* 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 {PaginationService} paginationService Reference of PaginationService
* @param {ActivatedRoute} activatedRoute Reference of ActivatedRoute
* @param {ConfigService} config Reference of ConfigService
* @param {permissionService} permissionService Refrence of permission service to check permission
*/
constructor(public modalService: SuiModalService, public searchService: SearchService,
public workSpaceService: WorkSpaceService,
paginationService: PaginationService,
activatedRoute: ActivatedRoute,
route: Router, userService: UserService,
toasterService: ToasterService, resourceService: ResourceService,
config: ConfigService, permissionService: PermissionService,
public navigationhelperService: NavigationHelperService) {
super(searchService, workSpaceService, userService);
this.paginationService = paginationService;
this.route = route;
this.activatedRoute = activatedRoute;
this.toasterService = toasterService;
this.resourceService = resourceService;
this.config = config;
this.loaderMessage = {
'loaderMessage': this.resourceService.messages.stmsg.m0032,
};
this.state = 'upForReview';
this.permissionService = permissionService;
}
ngOnInit() {
combineLatest(
this.activatedRoute.params,
this.activatedRoute.queryParams,
(params: any, queryParams: any) => {
return {
params: params,
queryParams: queryParams
};
})
.subscribe(bothParams => {
if (bothParams.params.pageNumber) {
this.pageNumber = Number(bothParams.params.pageNumber);
}
this.queryParams = bothParams.queryParams;
this.fecthUpForReviewContent(this.config.appConfig.WORKSPACE.PAGE_LIMIT, this.pageNumber, bothParams);
});
}
/**
* This method sets the make an api call to get all UpForReviewContent with page No and offset
*/
fecthUpForReviewContent(limit: number, pageNumber: number, bothParams) {
this.showLoader = true;
if (bothParams.queryParams.sort_by) {
const sort_by = bothParams.queryParams.sort_by;
const sortType = bothParams.queryParams.sortType;
this.sort = {
[sort_by]: _.toString(sortType)
};
} else {
this.sort = { lastUpdatedOn: this.config.appConfig.WORKSPACE.lastUpdatedOn };
}
const rolesMap = this.userService.RoleOrgMap;
const searchParams = {
filters: {
status: ['Review'],
createdFor: this.userService.RoleOrgMap && _.compact(_.union(rolesMap['CONTENT_REVIEWER'],
rolesMap['BOOK_REVIEWER'],
rolesMap['CONTENT_REVIEW'])),
createdBy: { '!=': this.userService.userid },
objectType: this.config.appConfig.WORKSPACE.objectType,
board: bothParams.queryParams.board,
subject: bothParams.queryParams.subject,
medium: bothParams.queryParams.medium,
gradeLevel: bothParams.queryParams.gradeLevel,
},
limit: limit,
offset: (pageNumber - 1) * (limit),
query: _.toString(bothParams.queryParams.query),
sort_by: this.sort
};
searchParams.filters['contentType'] = _.get(bothParams, 'queryParams.contentType') || this.getContentType();
this.search(searchParams).subscribe(
(data: ServerResponse) => {
if (data.result.count && data.result.content.length > 0) {
this.upForReviewContentData = data.result.content;
this.totalCount = data.result.count;
this.pager = this.paginationService.getPager(data.result.count, pageNumber, limit);
this.showLoader = false;
this.noResult = false;
} else {
this.showError = false;
this.noResult = true;
this.showLoader = false;
this.noResultMessage = {
'message': 'messages.stmsg.m0008',
'messageText': 'messages.stmsg.m0035'
};
}
},
(err: ServerResponse) => {
this.showLoader = false;
this.noResult = false;
this.showError = true;
this.toasterService.error(this.resourceService.messages.fmsg.m0021);
}
);
}
/**
* This method helps to navigate to different pages.
* If page number is less than 1 or page number is greater than total number
* of pages is less which is not possible, then it returns.
*
* @param {number} page Variable to know which page has been clicked
*
* @example navigateToPage(1)
*/
navigateToPage(page: number): undefined | void {
if (page < 1 || page > this.pager.totalPages) {
return;
}
this.pageNumber = page;
this.route.navigate(['workspace/content/upForReview', this.pageNumber], { queryParams: this.queryParams });
}
contentClick(content) {
this.workSpaceService.navigateToContent(content, this.state);
}
/**
* get inview Data
*/
inview(event) {
_.forEach(event.inview, (inview, key) => {
const obj = _.find(this.inviewLogs, (o) => {
return o.objid === inview.data.identifier;
});
if (obj === undefined) {
this.inviewLogs.push({
objid: inview.data.identifier,
objtype: inview.data.contentType,
index: inview.id
});
}
});
this.telemetryImpression.edata.visits = this.inviewLogs;
this.telemetryImpression.edata.subtype = 'pageexit';
this.telemetryImpression = Object.assign({}, this.telemetryImpression);
}
ngAfterViewInit () {
setTimeout(() => {
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.pageNumber,
visits: this.inviewLogs
}
};
this.inview({ inview: [] });
});
}
getContentType() {
this.userService.userData$.subscribe(
(user: IUserData) => {
this.userRoles = user.userProfile.userRoles;
});
let contentType = [];
if (_.indexOf(this.userRoles, 'BOOK_REVIEWER') !== -1) {
contentType = ['TextBook'];
}
if (_.indexOf(this.userRoles, 'CONTENT_REVIEWER') !== -1) {
contentType = _.without(this.config.appConfig.WORKSPACE.contentType, 'TextBook');
}
if (_.indexOf(this.userRoles, 'CONTENT_REVIEWER') !== -1 &&
_.indexOf(this.userRoles, 'BOOK_REVIEWER') !== -1) {
contentType = this.config.appConfig.WORKSPACE.contentType;
}
return contentType;
}
}