SHARE
TWEET

Untitled

a guest Mar 26th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
  2. import { BsModalService } from 'ngx-bootstrap';
  3. import { SkillAssessmentRequestModalComponent } from '../skill-assessment-request-modal/skill-assessment-request-modal.component';
  4. import { AssessmentCycleRequest } from '../../../../models/assessment-cycle-request.model';
  5. import { User } from '@shared/models';
  6. import { AssessmentCycleRequestInfo } from '../../../../models/assessment-cycle-reviewed.model';
  7. import { AssessmentCycleAnswer } from '../../../../models/assessment-cycle-answer.model';
  8.  
  9. @Component({
  10.   selector: 'requests-card',
  11.   templateUrl: './requests-card.component.html',
  12.   styleUrls: ['./requests-card.component.scss']
  13. })
  14. export class AssessmentRequestsCardComponent implements OnInit {
  15.   @Input() request!: AssessmentCycleRequest;
  16.   // to do type
  17.   @Input() scales!: any;
  18.   @Input() userReviewer!: User;
  19.  
  20.   @Output() notifyAssessmentRequestSent = new EventEmitter();
  21.  
  22.   remainingDays!: any;
  23.   answersResult: any[] = [];
  24.   progress!: number;
  25.   progressStatusClass = '';
  26.   cardStatus = {
  27.     class: '',
  28.     value: '',
  29.     btnValue: ''
  30.   };
  31.  
  32.   constructor(private modalService: BsModalService) { }
  33.  
  34.   ngOnInit(): void {
  35.     this.remainingDays = this.getRemainingDays(this.request.reviewed);
  36.  
  37.     if (this.remainingDays === 0) {this.request.status = 2;}
  38.     this.getCardStatus();
  39.  
  40.     this.progress = this.getRequestProgress(this.request.answer);
  41.   }
  42.  
  43.   getRequestProgress(answerRequest: any) {
  44.     let answerQuantity = 0;
  45.  
  46.     if (answerRequest) {
  47.       for (const skillGroupId of Object.keys(answerRequest.skillGroups)) {
  48.         const answerObj = answerRequest.skillGroups[skillGroupId];
  49.  
  50.         for (const answerId of Object.keys(answerObj)) {
  51.           this.answersResult.push(answerObj[answerId]);
  52.         }
  53.       }
  54.       this.answersResult.map((answer: AssessmentCycleAnswer) => {
  55.         if (answer.value) {
  56.           answerQuantity++;
  57.         }
  58.       });
  59.       const result = ((answerQuantity * 100) / this.answersResult.length);
  60.       this.progressStatusClass = result === 100 ? 'done' : 'in-progress';
  61.  
  62.       if (this.request.status === 1 && !answerRequest) {
  63.  
  64.       }
  65.  
  66.       return result;
  67.     }
  68.  
  69.  
  70.     return 0;
  71.   }
  72.  
  73.   openModalCompleteAssessment(request: AssessmentCycleRequest, scales: any): void {
  74.     const modal = this.modalService.show(SkillAssessmentRequestModalComponent, {
  75.       class: 'modal-lg',
  76.       initialState: { request, scales }
  77.     });
  78.  
  79.     modal.content.save.subscribe((requestItem: AssessmentCycleRequest) => {
  80.       this.progress = this.getRequestProgress(requestItem);
  81.       if (modal) {
  82.         modal.hide();
  83.         this.notifyAssessmentRequestSent.emit({answer: requestItem, status: 3});
  84.         this.getCardStatus();
  85.       }
  86.     });
  87.     modal.content.submit.subscribe((requestItem: AssessmentCycleRequest) => {
  88.       this.progress = this.getRequestProgress(requestItem);
  89.       if (modal) {
  90.         modal.hide();
  91.         this.notifyAssessmentRequestSent.emit({ answer: requestItem, status: 4});
  92.         this.getCardStatus();
  93.       }
  94.     });
  95.   }
  96.  
  97.   getRemainingDays(reviewed: AssessmentCycleRequestInfo): number | undefined {
  98.     if (reviewed && reviewed.assessmentCycle.endAt) {
  99.       if (+(reviewed.assessmentCycle.endAt) < Date.now()) {
  100.  
  101.         return 0;
  102.       }
  103.       const finishedDate = reviewed.assessmentCycle.endAt;
  104.       const timeDiff = finishedDate - Date.now();
  105.       const days = Math.ceil(timeDiff / (1000 * 3600 * 24));
  106.  
  107.       return days;
  108.     }
  109.  
  110.     return undefined;
  111.   }
  112.  
  113.   getCardStatus() {
  114.     switch (this.request.status) {
  115.       case 2:
  116.         this.cardStatus.class = 'badge-declined';
  117.         this.cardStatus.value = 'Declined';
  118.         this.cardStatus.btnValue = 'View Info';
  119.  
  120.         return this.cardStatus;
  121.       case 3:
  122.         this.cardStatus.class = 'badge-in-process';
  123.         this.cardStatus.value = 'In process';
  124.         this.cardStatus.btnValue = 'Resume';
  125.  
  126.         return this.cardStatus;
  127.       case 4:
  128.         this.cardStatus.class = 'badge-done';
  129.         this.cardStatus.value = 'Done';
  130.         this.cardStatus.btnValue = 'View';
  131.  
  132.         return this.cardStatus;
  133.       default:
  134.         this.cardStatus.class = 'badge-to-do';
  135.         this.cardStatus.value = 'To Do';
  136.         this.cardStatus.btnValue = 'Submit';
  137.  
  138.         return this.cardStatus;
  139.     }
  140.   }
  141. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top