Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. //rate-passangers-modal
  2.  
  3. import {Component} from '@angular/core';
  4. import {MatDialogRef} from '@angular/material';
  5. import {Passenger} from './passenger';
  6. import {StarClickMeta} from '../rating/starClickMeta';
  7.  
  8. @Component({
  9. selector: 'rate-passengers-modal',
  10. templateUrl: './rate-passengers-modal.component.html',
  11. styleUrls: ['./rate-passengers-modal.component.sass'],
  12. })
  13. export class RatePassengersModalComponent {
  14. passengers: Passenger[] = [
  15. {id: 0, name: 'Ivan', rating: 0},
  16. {id: 1, name: 'Egor', rating: 0},
  17. {id: 2, name: 'Semen', rating: 0},
  18. {id: 3, name: 'Fedor', rating: 0},
  19. ];
  20.  
  21. constructor(public dialogRef: MatDialogRef<RatePassengersModalComponent>) {}
  22.  
  23. rateUser(clickObj: StarClickMeta): void {
  24. const passenger = this.passengers.find(
  25. (i: Passenger) => i.id === clickObj.itemId
  26. );
  27. if (!!passenger) {
  28. passenger.rating = clickObj.rating;
  29. }
  30. }
  31. exitTrip(): void {
  32. this.dialogRef.close();
  33. }
  34.  
  35. trackById(index, item) {
  36. return item.id;
  37. }
  38. }
  39. ///
  40. <div class="table-content">
  41. <h2 class="title">Rate Passengers</h2>
  42.  
  43. <table class="table">
  44. <thead>
  45. <tr class="table-tr">
  46. <th class="table-th">Passenger</th>
  47. <th class="table-th">Stars</th>
  48. <th class="table-th">Rating</th>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. <tr *ngFor="let passenger of passengers; trackBy: trackById">
  53. <td>
  54. {{ passenger.name }}
  55. </td>
  56. <td>
  57. <app-rating
  58. [rating]="passenger.rating"
  59. [itemId]="passenger.id"
  60. (ratingClick)="rateUser($event)"
  61. ></app-rating>
  62. </td>
  63. <td>{{ passenger.rating }} Stars</td>
  64. </tr>
  65. </tbody>
  66. </table>
  67. <div class="button-container">
  68. <button
  69. class="exit-button"
  70. mat-raised-button
  71. color="primary"
  72. (click)="exitTrip()"
  73. >
  74. exit trip
  75. </button>
  76. </div>
  77. </div>
  78. ///
  79. .table-content
  80. .table
  81. width: 100%
  82. .title
  83. text-align: center
  84. .table-tr
  85. text-align: center
  86. .button-container
  87. display: flex
  88. align-items: center
  89. justify-content: center
  90. .exit-button
  91. width: 6rem
  92. height: 2rem
  93. .table-th
  94. width: 4rem
  95. ///
  96. rating component (звёздочки)
  97.  
  98. import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
  99. import {Rate} from './rate';
  100. import {StarClickMeta} from './starClickMeta';
  101.  
  102. @Component({
  103. selector: 'app-rating',
  104. templateUrl: './rating.component.html',
  105. styleUrls: ['./rating.component.sass'],
  106. })
  107. export class RatingComponent implements OnInit {
  108. @Input() rating: number;
  109. @Input() itemId: number;
  110. @Output() ratingClick: EventEmitter<StarClickMeta> = new EventEmitter<
  111. StarClickMeta
  112. >();
  113. inputName: string;
  114.  
  115. ratings: Rate[] = [
  116. {title: 'Rocks', value: 5},
  117. {title: 'Pretty good', value: 4},
  118. {title: 'Meh', value: 3},
  119. {title: 'Kinda bad', value: 2},
  120. {title: 'Sucks big time', value: 1},
  121. ];
  122.  
  123. constructor() {}
  124.  
  125. ngOnInit() {
  126. this.inputName = this.itemId + '_rating';
  127. }
  128.  
  129. onClick(rating: number): void {
  130. this.rating = rating;
  131. this.ratingClick.emit({
  132. itemId: this.itemId,
  133. rating,
  134. });
  135. }
  136. trackById(index, item) {
  137. return item.id;
  138. }
  139. }
  140. /////
  141. <fieldset class="rating">
  142. <ng-container *ngFor="let rate of ratings; trackBy: trackById">
  143. <input
  144. type="radio"
  145. [name]="inputName"
  146. [value]="rate.value"
  147. [checked]="rating === rate.value"
  148. />
  149. <label [title]="rate.title" (click)="onClick(rate.value)"
  150. >{{ rate.value }} stars</label
  151. >
  152. </ng-container>
  153. </fieldset>
  154. ////
  155. @import "../../../../styles/fonts-constants"
  156. @import "../../../../styles/colour-constants"
  157.  
  158. .rating
  159. float: left
  160. border: none
  161. .rating:not(:checked) > input
  162. position: absolute
  163. clip: rect(0,0,0,0)
  164.  
  165. .rating:not(:checked) > label
  166. float: right
  167. width: 1rem
  168. padding: 0.1rem
  169. overflow: hidden
  170. white-space: nowrap
  171. cursor pointer
  172. font-size: $button
  173. line-height: 1rem
  174. color: $grey
  175. .rating:not(:checked) > label:before
  176. content: '★ '
  177.  
  178. .rating > input:checked ~ label
  179. color: $orange
  180.  
  181. .rating:not(:checked) > label:hover,
  182. .rating:not(:checked) > label:hover ~ label
  183. color: $gold
  184.  
  185. .rating > input:checked ~ label:hover,
  186. .rating > input:checked ~ label:hover ~ label,
  187. .rating > label:hover ~ input:checked ~ label
  188. color: $light-orange
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement