Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import {Component, EventEmitter, Input, Output} from '@angular/core';
  2. import {Activity} from '../../../link/models/_content/activity/activity.model';
  3. import {ActivitiesHttpService} from '../../../link/services/http_/content-http/activities/activities-http.service';
  4. import {UserService} from '../../../link/services/user/user.service';
  5. import {DisplayUtilsService} from '../../services/display-utils/display-utils.service';
  6. import {AnalyticsService} from '../../services/analytics/analytics.service';
  7.  
  8. @Component({
  9. selector: 'app-favorite',
  10. templateUrl: './favorite.component.html',
  11. styleUrls: ['./favorite.component.scss']
  12. })
  13. /**
  14. * Favorite component that shows a heart
  15. * Full when marked as favorite, empty otherwise
  16. */
  17. export class FavoriteComponent {
  18.  
  19. status: 'empty' | 'full' = 'empty';
  20.  
  21. @Input() data: {
  22. countryId: number,
  23. classId: number,
  24. disciplineId: number,
  25. chapterId: number,
  26. notionId: number,
  27. };
  28. @Input() activity: Activity;
  29. // Send true if favorite is NOW marked as favorite, false if favorite is not.
  30. @Output() onToggle:EventEmitter<boolean> = new EventEmitter<boolean>();
  31.  
  32. constructor(
  33. public activitiesHttp: ActivitiesHttpService,
  34. public userService: UserService,
  35. public displayUtils: DisplayUtilsService,
  36. public analytics:AnalyticsService,
  37. ) {
  38. }
  39.  
  40. /**
  41. * If the user is logged, toggle/untoggle the activity as a favorite
  42. * Else, displays the register popup
  43. */
  44. toggleFav() {
  45. if(!this.userService.user.logged){
  46. this.analytics.send('/register/before/favorites');
  47. this.displayUtils.showPopupRegister();
  48. return;
  49. }
  50.  
  51. this.activitiesHttp.markAsFavorite(
  52. this.data.countryId,
  53. this.data.classId,
  54. this.data.disciplineId,
  55. this.data.chapterId,
  56. this.data.notionId,
  57. this.activity.id,
  58. !this.activity.favorite,
  59. )
  60. .subscribe(data => {
  61. this.activity.favorite = data.favorite;
  62. this.activity.status = data.status;
  63. this.onToggle.emit(data.favorite);
  64. }, () => {
  65.  
  66. });
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement