You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

299 lines
8.7 KiB

  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { IonSlides, ModalController } from '@ionic/angular';
  3. import * as moment from 'moment';
  4. import { ChatPage } from '../chat/chat.page';
  5. import * as faker from 'faker';
  6. import { Router } from '@angular/router';
  7. export type IscoreCard = {
  8. teamName: string,
  9. teamLogo: string,
  10. batting: Array<{
  11. name: string,
  12. jersey: number,
  13. score: number,
  14. ballsPlayed: number,
  15. wicketTo?: string,
  16. boundaries: number,
  17. sixes: number
  18. }>,
  19. bowling: Array<{
  20. name: string,
  21. jersey: number,
  22. runs: number,
  23. overs: number,
  24. wickets: number
  25. }>,
  26. totalScore: number,
  27. totalWickets: number,
  28. overs: number,
  29. extras: number
  30. }
  31. @Component({
  32. selector: 'app-live',
  33. templateUrl: './live.page.html',
  34. styleUrls: ['./live.page.scss'],
  35. })
  36. export class LivePage implements OnInit {
  37. @ViewChild('slides') slides: IonSlides;
  38. showScoreCard: boolean = true;
  39. showFixtures: boolean = false;
  40. selectedIndex: number = 0;
  41. slideOpts = {
  42. slidesPerView: 1.5,
  43. spaceBetween: 15,
  44. initialSlide: 0,
  45. centeredSlides: true,
  46. simulateTouch: false,
  47. followFinger: false,
  48. };
  49. matchStats: {
  50. stadium: string,
  51. homeTeam: IscoreCard,
  52. awayTeam: IscoreCard
  53. };
  54. teams = [{
  55. name: 'RCB',
  56. image: 'https://i.pinimg.com/originals/4f/f9/99/4ff99925fd51296daf76425b11c04195.jpg'
  57. }, {
  58. name: 'MI',
  59. image: 'assets/logos/mi.svg',
  60. }, {
  61. name: 'CSK',
  62. image: 'https://www.searchpng.com/wp-content/uploads/2019/02/Chennai-Super-Kings-Logo-PNG-Image-.png'
  63. }];
  64. stadiums = [{
  65. name: 'Chinnaswamy',
  66. sideView: 'https://www.royalchallengers.com/PRRCB01/public/styles/1061x767_landscape/public/2020-04/275679.jpg?h=61617f72&itok=6xKgHpE-',
  67. topView: 'assets/home-team/stadium-tv.svg',
  68. }, {
  69. name: 'IS Bindra',
  70. sideView: 'https://5.imimg.com/data5/VO/UB/MY-3103550/ae-cricket-stadium-lighting-500x500.jpg',
  71. topView: 'assets/home-team/stadium-tv.svg'
  72. }, {
  73. name: 'Chidambaram Stadium',
  74. sideView: 'https://sportzwiki.com/wp-content/uploads/2019/03/11.jpg',
  75. topView: 'assets/home-team/stadium-tv.svg',
  76. }];
  77. bookingSeatsData: Array<{
  78. dateTime: Date,
  79. staduim: {
  80. name: string,
  81. topView: string,
  82. sideView: string,
  83. },
  84. matchType: string,
  85. matchDetails: {
  86. home: {
  87. name: string,
  88. image: string,
  89. },
  90. away: {
  91. name: string,
  92. image: string,
  93. }
  94. },
  95. seatsAvailable: Array<{
  96. stand: 'Grand' | 'Pavilion' | 'First' | 'Second',
  97. seats: Array<{
  98. id: number | string,
  99. price: number
  100. }>
  101. }>
  102. }> = [];
  103. constructor(
  104. public modalController: ModalController,
  105. private router: Router
  106. ) { }
  107. getFormattedDateTime(dateTime: Date) {
  108. return moment(dateTime).format('DD MMM');
  109. }
  110. getEventDateTime(dateTime: Date) {
  111. return moment(dateTime).format('ddd, MMM DD YYYY hh:mm a');
  112. }
  113. selectIndex() {
  114. this.slides.getActiveIndex().then((index) => this.selectedIndex = index);
  115. }
  116. ngOnInit() {
  117. for (let i = 0; i < 3; i += 1) {
  118. this.bookingSeatsData.push({
  119. dateTime: faker.date.future(),
  120. staduim : this.stadiums[i],
  121. matchType: 'T20 League',
  122. matchDetails: {
  123. home: i !==1 ? this.teams[i] : { name: 'KXIP', image: 'assets/home-team/KXIP.svg' },
  124. away: i ===1 ? this.teams[i] : { name: 'KXIP', image: 'assets/home-team/KXIP.svg' }
  125. },
  126. seatsAvailable: [{
  127. stand: 'Grand',
  128. seats: [],
  129. }, {
  130. stand: 'Pavilion',
  131. seats: [],
  132. }, {
  133. stand: 'First',
  134. seats: [],
  135. }, {
  136. stand: 'Second',
  137. seats: [],
  138. }]
  139. });
  140. }
  141. for (let i = 0; i < this.bookingSeatsData.length; i += 1) {
  142. for (let j = 0; j < this.bookingSeatsData[i].seatsAvailable.length; j += 1) {
  143. let price = faker.commerce.price();
  144. let randomNumber = Math.random() * (15 - 0) + 0;
  145. for (let k = 0; k < randomNumber; k += 1) {
  146. this.bookingSeatsData[i].seatsAvailable[j].seats.push({
  147. id: this.bookingSeatsData[i].seatsAvailable[j].stand + '##' + k.toString(),
  148. price
  149. });
  150. }
  151. }
  152. }
  153. this.matchStats = {
  154. stadium: 'IS Bindra',
  155. homeTeam: {
  156. teamName: 'KXIP',
  157. teamLogo: 'assets/home-team/KXIP.svg',
  158. batting: [{
  159. name: 'V Sehwag',
  160. jersey: 44,
  161. score: 62,
  162. ballsPlayed: 30,
  163. wicketTo: 'c Sachin, b D.Steyn',
  164. boundaries: 8,
  165. sixes: 4,
  166. }, {
  167. name: 'KL Rahul',
  168. jersey: 10,
  169. score: 85,
  170. ballsPlayed: 80,
  171. boundaries: 10,
  172. sixes: 3,
  173. }, {
  174. name: 'G Maxwell',
  175. jersey: 11,
  176. score: 10,
  177. ballsPlayed: 10,
  178. boundaries: 0,
  179. sixes: 1,
  180. }],
  181. bowling: [{
  182. name: 'Harmeet Singh',
  183. jersey: 13,
  184. runs: 22,
  185. overs: 2,
  186. wickets: 1
  187. }, {
  188. name: 'Mishra',
  189. jersey: 25,
  190. runs: 10,
  191. overs: 1,
  192. wickets: 0
  193. }],
  194. totalScore: 157,
  195. overs: 20,
  196. extras: 0,
  197. totalWickets: 1,
  198. },
  199. awayTeam : {
  200. teamName: 'MI',
  201. teamLogo: 'assets/logos/mi.svg',
  202. batting: [{
  203. name: 'S Tendulkar',
  204. jersey: 10,
  205. score: 10,
  206. ballsPlayed: 12,
  207. wicketTo: 'b H.Singh',
  208. boundaries: 0,
  209. sixes: 1,
  210. }, {
  211. name: 'K Pollard',
  212. jersey: 22,
  213. score: 44,
  214. ballsPlayed: 11,
  215. boundaries: 1,
  216. sixes: 5,
  217. }, {
  218. name: 'D Bravo',
  219. jersey: 38,
  220. score: 5,
  221. ballsPlayed: 3,
  222. boundaries: 1,
  223. sixes: 0,
  224. }],
  225. bowling: [{
  226. name: 'D Steyn',
  227. jersey: 12,
  228. runs: 55,
  229. overs: 4,
  230. wickets: 1
  231. }, {
  232. name: 'D Bravo',
  233. jersey: 38,
  234. runs: 40,
  235. overs: 4,
  236. wickets: 0
  237. }, {
  238. name: 'S Tendulkar',
  239. jersey: 10,
  240. runs: 25,
  241. overs: 4,
  242. wickets: 0
  243. }, {
  244. name: 'Trent Boult',
  245. jersey: 17,
  246. runs: 37,
  247. overs: 4,
  248. wickets: 0
  249. }],
  250. totalScore: 60,
  251. overs: 3.2,
  252. extras: 1,
  253. totalWickets: 1,
  254. }
  255. }
  256. }
  257. async presentChatModal() {
  258. const modal = await this.modalController.create({
  259. component: ChatPage,
  260. cssClass: 'my-custom-class'
  261. });
  262. return await modal.present();
  263. }
  264. showBookingDetails(matchData) {
  265. this.router.navigate(['/booking-details' , { matchData: JSON.stringify(matchData) }]);
  266. }
  267. showBookingDetailsByIndex() {
  268. let index = this.selectedIndex;
  269. this.router.navigate(['/booking-details' , { matchData: JSON.stringify(this.bookingSeatsData[index]) }]);
  270. }
  271. showMatchDetails() {
  272. this.router.navigate(['/match-details', { matchStats: JSON.stringify(this.matchStats) }]);
  273. }
  274. }