Advertisement
Guest User

LDG

a guest
Jan 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Component, Input, OnInit} from '@angular/core';
  2.  
  3. import {ChartSize} from '../../../charts/chart.size';
  4. import {Colors} from '../../pages.constants';
  5. import {ClassEntity} from '../../../services/domain/class.entity';
  6. import {ResourcesConsumptionEntity} from '../../../services/domain/resources-consumption.entity';
  7. import {ResourcesConsumptionTypeEntity} from '../../../services/domain/resources-consumption-type.entity';
  8. import {ChartLineSeries} from '../../../charts/line/chart-line.serie';
  9. import {ChartLineValue} from '../../../charts/line/chart-line.value';
  10. import {ChartPieValue} from '../../../charts/pie/chart-pie.value';
  11. import {LearningObjectiveAchievementEntity} from '../../../services/domain/learning-objective-achievement.entity';
  12. import {LearningObjectiveAchievementEvolutionEntity} from '../../../services/domain/learning-objective-achievement-evolution.entity';
  13. import {UserEntity} from '../../../services/domain/user.entity';
  14. import {Observable} from 'rxjs/Observable';
  15. import {UserService} from '../../../services/services/user.service';
  16.  
  17. @Component({
  18.   selector: 'app-page-class-evolution',
  19.   templateUrl: './page-class-evolution.component.html',
  20.   styleUrls: [
  21.     './page-class-evolution.component.scss'
  22.   ]
  23. })
  24. export class PageClassEvolutionComponent implements OnInit {
  25.  
  26.   private _cls: ClassEntity;
  27.   private _learningObjectiveAchievementEvolutionEntities: LearningObjectiveAchievementEvolutionEntity[];
  28.  
  29.   userEntity: UserEntity;
  30.  
  31.   @Input()
  32.   objectiveAchievement: LearningObjectiveAchievementEntity;
  33.  
  34.   @Input()
  35.   resourcesConsumption: ResourcesConsumptionEntity;
  36.  
  37.   chartEvolutionValues: ChartLineValue[];
  38.  
  39.   chartResourceTypeValues: ChartPieValue[];
  40.  
  41.   chartEvolutionSeries: ChartLineSeries[] = [];
  42.  
  43.   constructor (private userService: UserService){
  44.   }
  45.  
  46.   ngOnInit(): void {
  47.     this.userObservable
  48.       .subscribe(x => {
  49.         this.userEntity = x;
  50.       });
  51.   }
  52.  
  53.   @Input()
  54.   set cls(v: ClassEntity) {
  55.     this._cls = v;
  56.     this.updateClassEvolutionSeries();
  57.     this.updateObjectiveAchievementEvolution();
  58.   }
  59.  
  60.   get cls(): ClassEntity {
  61.     return this._cls;
  62.   }
  63.  
  64.   @Input()
  65.   set objectiveAchievementEvolution(v: LearningObjectiveAchievementEvolutionEntity[]) {
  66.     this._learningObjectiveAchievementEvolutionEntities = v;
  67.     this.updateObjectiveAchievementEvolution();
  68.   }
  69.  
  70.   @Input()
  71.   set resourcesConsumptionType(v: ResourcesConsumptionTypeEntity[]) {
  72.     this.updateResourcesConsumptionType(v);
  73.   }
  74.  
  75.   get colors(): any {
  76.     return Colors;
  77.   };
  78.  
  79.   get sizes(): any {
  80.     return ChartSize;
  81.   };
  82.  
  83.   private get userObservable(): Observable<UserEntity> {
  84.     return this.userService.getUser()
  85.   }
  86.  
  87.   private updateObjectiveAchievementEvolution() {
  88.     if (this._cls == null ||
  89.       this._learningObjectiveAchievementEvolutionEntities == null ||
  90.       this._learningObjectiveAchievementEvolutionEntities.length == 0) {
  91.       this.chartEvolutionValues = [];
  92.     } else
  93.       this.chartEvolutionValues = this._learningObjectiveAchievementEvolutionEntities.map(x => {
  94.         return {
  95.           category: x.date,
  96.           classValue: x.learningObjectiveAchievement,
  97.           groupValue: x.learningObjectiveAchievementComparison
  98.         }
  99.       });
  100.   }
  101.  
  102.   private updateResourcesConsumptionType(v: ResourcesConsumptionTypeEntity[]) {
  103.     if (v == null || v.length == 0) {
  104.       this.chartResourceTypeValues = [];
  105.     } else
  106.       this.chartResourceTypeValues = v.map(x => {
  107.         return {
  108.           category: x.type,
  109.           color: x.color,
  110.           value: x.consumption,
  111.           total: x.total
  112.         }
  113.       });
  114.   }
  115.  
  116.   private updateClassEvolutionSeries() {
  117.     if (this._cls && this._cls.groupCount > 1) {
  118.       this.chartEvolutionSeries = [{
  119.         color: Colors.purple,
  120.         field: "classValue"
  121.       },{
  122.         color: Colors.gray,
  123.         field: "groupValue"
  124.       }]
  125.     } else {
  126.       this.chartEvolutionSeries = [{
  127.         color: Colors.purple,
  128.         field: "classValue"
  129.       }]
  130.     }
  131.   }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement