Advertisement
andreadc

rating

Feb 26th, 2020
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ngOnInit(): void {
  2.  
  3.     this.subscriptionGetRating = this.ratingService.getRating(this.userId).subscribe( data => {
  4.      
  5.       this.count = data['count'];
  6.       this.rating = data['rating'] / this.count;
  7.  
  8.       if(this.count == 0){
  9.  
  10.         this.rating = 0;
  11.  
  12.         for(let k=0;k<=4;k++){
  13.           this.ratingArray[k] = this.greyStar;
  14.         }
  15.  
  16.       } else{
  17.  
  18.         let trunc = Math.trunc(this.rating);
  19.    
  20.         for(let j=0;j<trunc+1;j++){
  21.    
  22.           if(this.rating>j && this.rating<j+1){
  23.             this.ratingArray[j] = this.midStar;
  24.           }else {
  25.             if(j!=trunc)
  26.               this.ratingArray[j] = this.yellowStar;
  27.           }
  28.          
  29.         }
  30.    
  31.         if (this.rating == Math.floor(this.rating)){
  32.           for(let k=trunc;k<=4;k++){
  33.             this.ratingArray[k] = this.greyStar;
  34.           }
  35.         } else {
  36.           for(let k=trunc+1;k<=4;k++){
  37.             this.ratingArray[k] = this.greyStar;
  38.           }
  39.         }
  40.  
  41.       }
  42.  
  43.     });
  44.  
  45.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement