Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

140 řádky
3.9 KiB

  1. import { Component, OnInit } from '@angular/core';
  2. import { Location } from '@angular/common';
  3. import { ActivatedRoute } from '@angular/router';
  4. import { MatchService } from '../services/match.service';
  5. import { ToastService } from '../services/toast.service';
  6. import { RawMatchData } from '../live/live.page';
  7. import { SocialSharing } from '@ionic-native/social-sharing/ngx';
  8. interface RawCommentaryForBall {
  9. Over: string;
  10. Id: string;
  11. Runs: string;
  12. ZAD: string;
  13. Detail: string;
  14. Isball: boolean;
  15. Bowler: string;
  16. Bowler_Name: string;
  17. Batsman: string;
  18. Batsman_Name: string;
  19. Batsman_Style: string;
  20. Commentary: string;
  21. Timestamp: string;
  22. Non_Striker: string;
  23. Non_Striker_Name: string;
  24. Score: string;
  25. Batsman_Runs: string;
  26. Bowler_Conceded_Runs: string;
  27. Extras_Runs: string;
  28. Ball_Speed: string;
  29. }
  30. // 200556
  31. export interface RawCommentary {
  32. InningNo: string;
  33. BattingTeam_Id: string;
  34. BattingTeam: string;
  35. BowlingTeam_Id: string;
  36. BowlingTeam: string;
  37. GameCode: string;
  38. MatchId: string;
  39. Timestamp: string;
  40. Commentary: Array<RawCommentaryForBall>;
  41. }
  42. @Component({
  43. selector: 'app-match-details',
  44. templateUrl: './match-details.page.html',
  45. styleUrls: ['./match-details.page.scss'],
  46. })
  47. export class MatchDetailsPage implements OnInit {
  48. isPlayerSelected: boolean = false;
  49. isHomeTeamSelected: boolean = true;
  50. selectedSegment: 'MATCH' | 'SCORE' = 'MATCH';
  51. selectedRoster: 'LIVE' | 'HOME' | 'AWAY' = 'LIVE';
  52. currentMatch: RawMatchData;
  53. selectedPlayer: string = '';
  54. commentaryList: Array<RawCommentary> = [];
  55. commentaryInterval: any;
  56. constructor(
  57. private location: Location,
  58. private route: ActivatedRoute,
  59. private matchService: MatchService,
  60. private toastService: ToastService,
  61. private socialSharing: SocialSharing
  62. ) { }
  63. shareMatchDetails() {
  64. console.log("Sharing match details...");
  65. let message: string;
  66. if (this.currentMatch.Innings) {
  67. this.currentMatch.Innings.forEach(inning => {
  68. message = this.currentMatch.Teams[inning.Battingteam].Name_Short + ' ' + inning.Total + '/' + inning.Wickets + '(' + inning.Overs + ')' + '\n';
  69. });
  70. } else {
  71. message = 'Match to start on, ' + this.currentMatch.Matchdetail.Match.Date + ' @' + this.currentMatch.Matchdetail.Match.Time + '\n' + this.currentMatch.Teams[this.currentMatch.Matchdetail.Team_Home].Name_Short + ' v/s ' + this.currentMatch.Teams[this.currentMatch.Matchdetail.Team_Away].Name_Short;
  72. }
  73. this.socialSharing.share(message);
  74. }
  75. ngOnInit() {
  76. let match_id = JSON.parse(this.route.snapshot.paramMap.get('match_id'));
  77. this.matchService.getMatchDetails(match_id).then((match_data: RawMatchData) => {
  78. this.currentMatch = match_data;
  79. });
  80. this.callCommentary(match_id);
  81. this.commentaryInterval = setInterval(() => {
  82. this.callCommentary(match_id);
  83. }, 30000);
  84. }
  85. callCommentary(match_id) {
  86. this.matchService.getCommentary(match_id).then((data: Array<RawCommentary>) => {
  87. this.commentaryList = data;
  88. }, (err) => {
  89. console.log(err);
  90. this.toastService.presentToastWithOptions("Failed to fetch Commentary", "danger");
  91. });
  92. }
  93. ngOnDestroy() {
  94. clearInterval(this.commentaryInterval);
  95. }
  96. getReversedArray(array: Array<RawCommentary>) {
  97. return array.reverse();
  98. }
  99. back() {
  100. this.location.back();
  101. }
  102. selectPlayerDetails(playerId: string) {
  103. this.selectedPlayer = playerId;
  104. this.isPlayerSelected = true;
  105. }
  106. limitDecimals(value: number) {
  107. return value.toPrecision(2);
  108. }
  109. getArrayOfPlayers(players) {
  110. return Object.keys(players);
  111. }
  112. }