src/app/manage-learn/shared/components/task-card/task-card.component.ts
OnInit
changeDetection | ChangeDetectionStrategy.OnPush |
selector | app-task-card |
styleUrls | ./task-card.component.scss |
templateUrl | ./task-card.component.html |
Properties |
Methods |
Inputs |
Outputs |
constructor(router: Router, projectService: ProjectService, popoverController: PopoverController, translate: TranslateService, alert: AlertController, db: DbService, util: UtilsService)
|
||||||||||||||||||||||||
Parameters :
|
data | |
Type : any
|
|
viewOnly | |
Type : boolean
|
|
Default value : false
|
|
actionEvent | |
Type : EventEmitter
|
|
Async askPermissionToDelete | ||||||
askPermissionToDelete(type, index)
|
||||||
Parameters :
Returns :
any
|
checkReport | ||||
checkReport(task)
|
||||
Parameters :
Returns :
void
|
loadMore |
loadMore()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
onCardClick | ||||
onCardClick(task)
|
||||
Parameters :
Returns :
void
|
onObservatonActionButtonClick | ||||||
onObservatonActionButtonClick(task, index)
|
||||||
Parameters :
Returns :
void
|
Async openPopover | |||||||||
openPopover(ev: any, taskIndex)
|
|||||||||
Parameters :
Returns :
unknown
|
openResources | ||||
openResources(task)
|
||||
Parameters :
Returns :
void
|
allStrings |
Public popoverController |
Type : PopoverController
|
showLoadMore |
Type : boolean
|
Default value : false
|
statuses |
Default value : taskStatus
|
upperLimit |
Type : number
|
Default value : 2
|
import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { Router } from '@angular/router';
import { RouterLinks } from '@app/app/app.constant';
import { DbService, ProjectService, statusType, taskStatus, UtilsService } from '@app/app/manage-learn/core';
import { menuConstants } from '@app/app/manage-learn/core/constants/menuConstants';
import { PopoverController, AlertController } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { PopoverComponent } from '../popover/popover.component';
import * as _ from 'underscore';
@Component({
selector: 'app-task-card',
templateUrl: './task-card.component.html',
styleUrls: ['./task-card.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TaskCardComponent implements OnInit {
@Input() data: any;
@Output() actionEvent = new EventEmitter();
@Input() viewOnly: boolean = false;
statuses = taskStatus;
upperLimit=2;
allStrings;
showLoadMore: boolean = false;
constructor(private router: Router,
private projectService: ProjectService,
public popoverController: PopoverController,
private translate: TranslateService,
private alert: AlertController,
private db: DbService,
private util: UtilsService
) { }
ngOnInit() {
let count = this.util.getTaskCount(this.data);
if (count > 2) {
this.showLoadMore = true;
}
}
onCardClick(task) {
if(this.viewOnly){
return;
}
const viewOnlyMode = (this.data.status === statusType.submitted);
this.router.navigate([`${RouterLinks.PROJECT}/${RouterLinks.TASK_VIEW}`, this.data?._id, task?._id], {
queryParams: { viewOnlyMode: viewOnlyMode },
state: {
projectDetails: this.data
}
});
}
onObservatonActionButtonClick(task, index) {
const submissionDetails = this.data?.tasks[index]?.submissionDetails;
if(submissionDetails?.observationId) {
this.router.navigate([`/${RouterLinks.OBSERVATION}/${RouterLinks.OBSERVATION_SUBMISSION}`], {
queryParams: {
programId: submissionDetails.programId,
solutionId: submissionDetails.solutionId,
observationId: submissionDetails.observationId,
entityId: submissionDetails.entityId,
entityName: submissionDetails.entityName,
disableObserveAgain: this.data?.tasks[index].status === statusType.completed,
},
});
} else {
this.projectService.startAssessment(this.data._id, task._id);
}
}
checkReport(task) {
this.projectService.checkReport(this.data._id, task._id);
}
openResources(task) {
this.router.navigate([`${RouterLinks.PROJECT}/${RouterLinks.LEARNING_RESOURCES}`, this.data._id, task._id]);
}
async openPopover(ev: any, taskIndex) {
let menu:any =[];
const selectedTask = this.data.tasks[taskIndex];
if(this.viewOnly){
let shareOption = {
TITLE: 'FRMELEMNTS_LBL_SHARE',
VALUE: 'shareTask',
ICON: 'share'
}
menu.push(shareOption);
}
if(!this.viewOnly){
menu = JSON.parse(JSON.stringify(menuConstants.TASK));
if (selectedTask.isDeletable) {
let deleteOption = {
TITLE: 'DELETE',
VALUE: 'deleteTask',
ICON: 'trash'
}
menu.push(deleteOption);
}
}
const popover = await this.popoverController.create({
component: PopoverComponent,
componentProps: { menus: menu },
event: ev,
translucent: true,
});
popover.onDidDismiss().then((data) => {
if (data.data) {
switch (data.data) {
case 'editTask':
this.router.navigate([`${RouterLinks.PROJECT}/${RouterLinks.TASK_VIEW}`, this.data._id, selectedTask._id]);
break;
case 'shareTask':
this.projectService.openSyncSharePopup("shareTask", selectedTask.name, this.data, selectedTask._id);
break;
case 'deleteTask':
this.askPermissionToDelete(data.data, taskIndex);
break
}
}
});
return await popover.present();
}
async askPermissionToDelete(type, index) {
let data;
this.translate.get(["FRMELEMNTS_MSG_DELETE_TASK_CONFIRMATION", "NO", "YES"]).subscribe((text) => {
data = text;
});
const alert = await this.alert.create({
message: data["FRMELEMNTS_MSG_DELETE_TASK_CONFIRMATION"],
cssClass: 'central-alert',
buttons: [
{
text: data["NO"],
role: "cancel",
cssClass: "secondary",
handler: (blah) => { },
},
{
text: data["YES"],
handler: () => {
const obj = {
type: type,
taskId: this.data.tasks[index]._id
}
this.actionEvent.emit(obj);
},
}
],
});
await alert.present();
}
loadMore() {
this.upperLimit = this.data?.tasks?.length;
this.showLoadMore = false;
}
}
<div *ngFor="let task of data?.tasks | slice:0:upperLimit ;let i = index">
<ion-card (click)="onCardClick(task)" class="sb-dt-card task-card" *ngIf="!task?.isDeleted">
<ion-row>
<ion-col size="1">
<ion-icon *ngIf="task?.status == statuses['completed'].value" name="checkmark-circle" class="check-icon"
color="success"></ion-icon>
</ion-col>
<ion-col size="11">
<div class="display-flex-space-btn">
<div class="title-break">{{task?.name}}</div>
<div class="mandatory-ribben-label" *ngIf="!task.isDeletable">
{{'FRMELEMNTS_LBL_MANDATORY' | translate}}
</div>
<div class="options">
<ion-buttons>
<ion-icon name="ellipsis-vertical-outline" class="action-icon" color="primary"
(click)="$event.stopPropagation();openPopover($event,i)">
</ion-icon>
</ion-buttons>
</div>
</div>
<div class="display-flex-space-btn">
<div> {{statuses[task?.status]?.label}}</div>
</div>
<div class="last-row">
<div> {{'FRMELEMNTS_LBL_END_DATE' | translate}} : {{(task?.endDate) ? (task.endDate | date : 'dd/MM/yyyy') : "__"}}</div>
<div class="viewBtn">
<ion-label class="link-label" *ngIf="task?.type =='simple'"
(click)="$event.stopPropagation();onCardClick(task)">
{{'FRMELEMNTS_BTN_VIEW_TASK_DETAILS' | translate}}<ion-icon name="chevron-forward"></ion-icon>
</ion-label>
<ion-button size="small" class="action-btn custom-btn-txt-transform-none" *ngIf="task?.type=='content'&&task?.learningResources?.length"
(click)="$event.stopPropagation();openResources(task)">
{{'FRMELEMNTS_LBL_VIEW_RESOURCES' | translate}}
</ion-button>
<ion-button size="small" class="action-btn custom-btn-txt-transform-none"
*ngIf="(task?.type=='assessment' || task?.type=='observation')&&task?.status!='completed' "
(click)="$event.stopPropagation();onObservatonActionButtonClick(task, i)">
{{'START' | translate}} {{task?.type | lowercase }}
</ion-button>
<ion-button size="small" class="action-btn custom-btn-txt-transform-none"
*ngIf="(task?.type=='assessment' || task?.type=='observation')&&task?.status=='completed' "
(click)="$event.stopPropagation(); onObservatonActionButtonClick(task, i)">
{{'FRMELEMNTS_LBL_VIEW_REPORTS' | translate}}
</ion-button>
</div>
</div>
</ion-col>
</ion-row>
</ion-card>
</div>
<div *ngIf="upperLimit < data.tasks.length">
<ion-button class="view-more _full-width custom-btn-txt-transform-none" fill="outline" (click)="loadMore()">
{{ 'FRMELEMNTS_BTN_LOAD_MORE_TASKS' | translate }}
</ion-button>
</div>
./task-card.component.scss
@import "src/assets/styles/_variables.scss";
.task-card{
padding: 10px;
margin: 15px 0px !important;
.last-row {
display: flex;
margin: 5px 0px;
justify-content: space-between;
}
.display-flex-space-btn{
display: flex;
margin: 5px 0px;
.action-icon{
font-size: 1.25rem;
}
.link-label{
color: var(--app-primary);
font-size: 1rem;
ion-icon{
color: var(--app-primary);
display: inline-block;
font-size: 1rem;
vertical-align: middle;
}
}
ion-button {
font-size: $font-size-base;
text-transform: capitalize;
}
.title-break{
flex:1;
word-break: break-all;
color: #000;
}
}
.check-icon{
font-size: 1.5rem;
margin-top: 3px;
padding-left: 0px;
}
.mandatory-ribben-label{
background-color: var(--app-primary-header) !important;
padding: 2px 15px;
color: #000;
text-transform: uppercase;
font-size: 0.813rem !important;
border-radius: 4px;
font-weight: 500;
align-self: flex-start;
}
.action-btn{
--background: var(--app-primary-header) !important;
color: var(--app-primary) !important;
text-transform: none;
}
.options {
align-self: flex-start;
}
.viewBtn {
justify-content: flex-end;
ion-icon{
vertical-align: middle;
}
}
}
.view-more {
--background: transparent !important;
--border-color: var(--app-primary-medium) !important;
--color: var(--app-primary-medium) !important;
width: 100%;
text-transform: none;
font-weight: bold;
font-size: 1rem;
margin: 10px 0;
}
ion-col {
font-size: 0.875rem;
}