src/app/modules/sourcing/components/recursive-tree/recursive-tree.component.ts
selector | app-recursive-tree |
styleUrls | recursive-tree.component.scss |
templateUrl | recursive-tree.component.html |
collectionUnits
|
dynamicHeaders
|
dynamicHeadersEnabled
|
level
|
originalCollectionData
|
programContext
|
reusedContributions
|
selectedChapter
|
selectedStatus
|
sessionContext
|
tags
|
emitSelectedNode
|
$event type: EventEmitter
|
nodeMeta
|
$event type: EventEmitter
|
constructor(userService: any, configService: any, programsService: any, helperService: HelperService, programTelemetryService: ProgramTelemetryService, resourceService: any, router: Router)
|
hasAccessFor |
hasAccessFor(roles: string[])
|
Returns:
void
|
includes |
includes(sourcingOrgReviewer: Boolean, selectedStatus: string[], currentStatus: String)
|
Returns:
void
|
shouldActionMenuBeVisible |
shouldActionMenuBeVisible()
|
Returns:
void
|
nodeMetaEmitter |
nodeMetaEmitter(event: any)
|
Returns:
void
|
addFromLibrary |
addFromLibrary(e: any, collection: any)
|
Returns:
void
|
createResource |
createResource(e: any, collection: any)
|
Returns:
void
|
deleteResource |
deleteResource(e: any, content: any, collection: any)
|
Returns:
void
|
removeResource |
removeResource(e: any, content: any, collection: any)
|
Returns:
void
|
moveResource |
moveResource(e: any, content: any, collection: any)
|
Returns:
void
|
previewResource |
previewResource(e: any, content: any, collection: any, origin: any, index: any)
|
Returns:
void
|
menuClick |
menuClick(e: any)
|
Returns:
void
|
goToAddLibrary |
goToAddLibrary(identifier: any)
|
Returns:
void
|
getIndex |
getIndex(collection: any, currentIndex: any)
|
Returns:
void
|
Public childlevel |
childlevel: |
configService |
configService: |
mvcLibraryFeatureConfiguration |
mvcLibraryFeatureConfiguration: |
Public nodeStatusMessage |
nodeStatusMessage: |
programTelemetryService |
programTelemetryService: |
resourceService |
resourceService: |
router |
router: |
Public showActionMenu |
showActionMenu: |
Public showAddresource |
showAddresource: |
Default value: false
|
Public showModal |
showModal: |
Default value: false
|
Public sourcingOrgReviewer |
sourcingOrgReviewer: |
Public telemetryInteractCdata |
telemetryInteractCdata: |
Public telemetryInteractPdata |
telemetryInteractPdata: |
Public telemetryPageId |
telemetryPageId: |
Public unitIdentifier |
unitIdentifier: |
Public userId |
userId: |
userService |
userService: |
visibility |
visibility: |
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import * as _ from 'lodash-es';
import { UserService, ProgramsService} from '@sunbird/core';
import { ConfigService, ResourceService } from '@sunbird/shared';
import { ProgramTelemetryService } from '../../../program/services';
import { Router } from '@angular/router';
import { HelperService } from '../../services/helper.service';
@Component({
selector: 'app-recursive-tree',
templateUrl: './recursive-tree.component.html',
styleUrls: ['./recursive-tree.component.scss']
})
export class RecursiveTreeComponent implements OnInit {
@Input() collectionUnits;
@Input() reusedContributions;
@Input() selectedChapter;
@Input() programContext;
@Input() sessionContext;
@Input() originalCollectionData;
@Input() level;
@Input() selectedStatus;
@Input() dynamicHeaders;
@Input() tags;
@Input() dynamicHeadersEnabled;
@Output() emitSelectedNode = new EventEmitter<any>();
@Output() nodeMeta = new EventEmitter<any>();
public showModal = false;
public showAddresource = false;
visibility: any;
mvcLibraryFeatureConfiguration: any;
public unitIdentifier;
public childlevel;
public telemetryInteractCdata: any;
public telemetryInteractPdata: any;
public sourcingOrgReviewer: boolean;
public nodeStatusMessage: string;
public telemetryPageId: string;
public userId: any;
public showActionMenu: any;
constructor(public userService: UserService, public configService: ConfigService, private programsService: ProgramsService,
private helperService: HelperService, public programTelemetryService: ProgramTelemetryService, public resourceService: ResourceService, public router: Router) { }
ngOnInit() {
this.childlevel = this.level + 1;
const currentRoles = _.filter(this.programContext.config.roles, role => this.sessionContext.currentRoles.includes(role.name));
this.sessionContext.currentRoleIds = !_.isEmpty(currentRoles) ? _.map(currentRoles, role => role.id) : null;
this.sourcingOrgReviewer = this.router.url.includes('/sourcing') ? true : false;
const submissionDateFlag = this.programsService.checkForContentSubmissionDate(this.programContext);
this.mvcLibraryFeatureConfiguration = this.helperService.mvcLibraryFeatureConfiguration;
this.telemetryPageId = this.sessionContext.telemetryPageDetails.telemetryPageId;
this.visibility = {};
// tslint:disable-next-line:max-line-length
this.visibility['showAddresource'] = submissionDateFlag && this.hasAccessFor(['CONTRIBUTOR']);
// tslint:disable-next-line:max-line-length
this.visibility['showEditResource'] = submissionDateFlag && this.hasAccessFor(['CONTRIBUTOR']);
// tslint:disable-next-line:max-line-length
this.visibility['showMoveResource'] = submissionDateFlag && this.hasAccessFor(['CONTRIBUTOR']);
// tslint:disable-next-line:max-line-length
this.visibility['showDeleteResource'] = submissionDateFlag && this.hasAccessFor(['CONTRIBUTOR']);
// tslint:disable-next-line:max-line-length
this.visibility['showPreviewResource'] = this.hasAccessFor(['REVIEWER']);
this.visibility['showActionMenu'] = this.shouldActionMenuBeVisible();
// tslint:disable-next-line:max-line-length
this.telemetryInteractCdata = _.get(this.sessionContext, 'telemetryPageDetails.telemetryInteractCdata') || [];
// tslint:disable-next-line:max-line-length
this.telemetryInteractPdata = this.programTelemetryService.getTelemetryInteractPdata(this.userService.appId, this.configService.appConfig.TELEMETRY.PID );
this.userId = this.userService.userid;
this.showActionMenu = this.visibility && this.visibility['showActionMenu'];
this.tags = this.tags.sort().reverse();
}
hasAccessFor(roles: Array<string>) {
return !_.isEmpty(_.intersection(roles, this.sessionContext.currentRoles || []));
}
includes(sourcingOrgReviewer: Boolean, selectedStatus: Array<string>, currentStatus: String) {
// Always return true if not sourcingOrgReviewer
if(!sourcingOrgReviewer) return true;
// Always return true if sampleContent
else if(this.sessionContext.sampleContent) return true;
else {
// Always return true if no status selected
return (!selectedStatus.length) || _.includes(selectedStatus, currentStatus)
}
}
shouldActionMenuBeVisible() {
return !!(
this.visibility['showAddresource'] ||
this.visibility['showEditResource'] ||
this.visibility['showMoveResource'] ||
this.visibility['showDeleteResource']
);
}
// canViewActionMenu(content) {
// return !!(this.visibility && this.visibility['showActionMenu'] && content.createdBy === this.userService.userid);
// }
nodeMetaEmitter(event) {
this.nodeMeta.emit({
action: event.action,
showPopup: event.action === 'add' ? true : false,
collection: event.collection,
content: event.content
});
}
addFromLibrary(e, collection) {
e.stopPropagation();
this.showModal = true;
this.nodeMeta.emit({
action: 'addFromLibrary',
showPopup: this.showModal,
collection: collection
});
}
createResource(e, collection) {
e.stopPropagation();
this.showModal = true;
this.nodeMeta.emit({
action: 'add',
showPopup: this.showModal,
collection: collection
});
}
deleteResource(e, content, collection) {
this.nodeMeta.emit({
action: 'delete',
content: content,
collection: collection,
showPopup: null,
});
}
removeResource(e, content, collection) {
this.nodeMeta.emit({
action: 'remove',
content: content,
collection: collection,
showPopup: null,
});
}
moveResource(e, content, collection) {
this.nodeMeta.emit({
action: 'beforeMove',
content: content,
collection: collection
});
}
previewResource(e, content, collection, origin, index) {
this.programsService.emitHeaderEvent(false);
content.originUnitStatus = collection.statusMessage ? 'Retired' : collection.status;
this.nodeMeta.emit({
action: 'preview',
content: content,
collection: collection,
originCollectionData: origin
});
}
menuClick(e) {
e.stopPropagation();
}
goToAddLibrary(identifier) {
// tslint:disable-next-line:max-line-length
this.router.navigateByUrl(`/contribute/program/${this.sessionContext.programId}/textbook/${this.sessionContext.collection}/${identifier}`);
}
getIndex(collection, currentIndex) {
let serialNumber = 1;
for (let i = 0; i < currentIndex; i++) {
const content = collection.leaf[i];
// tslint:disable-next-line:max-line-length
if (content.contentVisibility === true && this.includes(this.sourcingOrgReviewer, this.selectedStatus, content.sourcingStatus || content.status)) {
serialNumber++;
}
}
return serialNumber;
}
}