Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
- import { BsModalService } from 'ngx-bootstrap';
- import { SkillAssessmentRequestModalComponent } from '../skill-assessment-request-modal/skill-assessment-request-modal.component';
- import { AssessmentCycleRequest } from '../../../../models/assessment-cycle-request.model';
- import { User } from '@shared/models';
- import { AssessmentCycleRequestInfo } from '../../../../models/assessment-cycle-reviewed.model';
- import { AssessmentCycleAnswer } from '../../../../models/assessment-cycle-answer.model';
- @Component({
- selector: 'requests-card',
- templateUrl: './requests-card.component.html',
- styleUrls: ['./requests-card.component.scss']
- })
- export class AssessmentRequestsCardComponent implements OnInit {
- @Input() request!: AssessmentCycleRequest;
- // to do type
- @Input() scales!: any;
- @Input() userReviewer!: User;
- @Output() notifyAssessmentRequestSent = new EventEmitter();
- remainingDays!: any;
- answersResult: any[] = [];
- progress!: number;
- progressStatusClass = '';
- cardStatus = {
- class: '',
- value: '',
- btnValue: ''
- };
- constructor(private modalService: BsModalService) { }
- ngOnInit(): void {
- this.remainingDays = this.getRemainingDays(this.request.reviewed);
- if (this.remainingDays === 0) {this.request.status = 2;}
- this.getCardStatus();
- this.progress = this.getRequestProgress(this.request.answer);
- }
- getRequestProgress(answerRequest: any) {
- let answerQuantity = 0;
- if (answerRequest) {
- for (const skillGroupId of Object.keys(answerRequest.skillGroups)) {
- const answerObj = answerRequest.skillGroups[skillGroupId];
- for (const answerId of Object.keys(answerObj)) {
- this.answersResult.push(answerObj[answerId]);
- }
- }
- this.answersResult.map((answer: AssessmentCycleAnswer) => {
- if (answer.value) {
- answerQuantity++;
- }
- });
- const result = ((answerQuantity * 100) / this.answersResult.length);
- this.progressStatusClass = result === 100 ? 'done' : 'in-progress';
- if (this.request.status === 1 && !answerRequest) {
- }
- return result;
- }
- return 0;
- }
- openModalCompleteAssessment(request: AssessmentCycleRequest, scales: any): void {
- const modal = this.modalService.show(SkillAssessmentRequestModalComponent, {
- class: 'modal-lg',
- initialState: { request, scales }
- });
- modal.content.save.subscribe((requestItem: AssessmentCycleRequest) => {
- this.progress = this.getRequestProgress(requestItem);
- if (modal) {
- modal.hide();
- this.notifyAssessmentRequestSent.emit({answer: requestItem, status: 3});
- this.getCardStatus();
- }
- });
- modal.content.submit.subscribe((requestItem: AssessmentCycleRequest) => {
- this.progress = this.getRequestProgress(requestItem);
- if (modal) {
- modal.hide();
- this.notifyAssessmentRequestSent.emit({ answer: requestItem, status: 4});
- this.getCardStatus();
- }
- });
- }
- getRemainingDays(reviewed: AssessmentCycleRequestInfo): number | undefined {
- if (reviewed && reviewed.assessmentCycle.endAt) {
- if (+(reviewed.assessmentCycle.endAt) < Date.now()) {
- return 0;
- }
- const finishedDate = reviewed.assessmentCycle.endAt;
- const timeDiff = finishedDate - Date.now();
- const days = Math.ceil(timeDiff / (1000 * 3600 * 24));
- return days;
- }
- return undefined;
- }
- getCardStatus() {
- switch (this.request.status) {
- case 2:
- this.cardStatus.class = 'badge-declined';
- this.cardStatus.value = 'Declined';
- this.cardStatus.btnValue = 'View Info';
- return this.cardStatus;
- case 3:
- this.cardStatus.class = 'badge-in-process';
- this.cardStatus.value = 'In process';
- this.cardStatus.btnValue = 'Resume';
- return this.cardStatus;
- case 4:
- this.cardStatus.class = 'badge-done';
- this.cardStatus.value = 'Done';
- this.cardStatus.btnValue = 'View';
- return this.cardStatus;
- default:
- this.cardStatus.class = 'badge-to-do';
- this.cardStatus.value = 'To Do';
- this.cardStatus.btnValue = 'Submit';
- return this.cardStatus;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement