import {Component} from '../../../lib/vues6.js' import {GridCellRenderType} from '../Grid.component.js' import {api} from '../../module/api.js' const template = `

Matchups & Scores - Week {{ current_week }}

` /** * Component representing the scores & match-ups page. * @extends Component */ class ScoresComponent extends Component { static get selector() { return 'page-scores' } static get template() { return template } static get props() { return [] } /** * The number of the current week shown in the interface * @type {number} */ current_week = 1 /** * Most recent week number. * @type {number} */ max_week = 1 /** * Least recent week number. * @type {number} */ min_week = 1 /** * Array of arrays of data for each week with first item being week 1, second being week 2, &c. * @type {object[][]} */ week_x_data = [] /** * Column definitions for the matchups grid. * @type {object[]} */ column_defs = [ { header: 'Date', type: GridCellRenderType.HTML, key: 'date', renderer: (_, data) => { return `${data.date} @ ${data.team_1}` } }, { header: 'Team 1', type: GridCellRenderType.HTML, key: 'team_1', renderer: (_, data) => `
${data.team_1}

Projection: ${data.team_1_projection}

` }, { header: 'Team 2', type: GridCellRenderType.HTML, key: 'team_2', renderer: (_, data) => `
${data.team_2}

Projection: ${data.team_2_projection}

` }, { header: 'Outcome', type: GridCellRenderType.HTML, key: 'winner', renderer: (_, data) => { if ( data && data.winner ) { return `
Winner: ${data.winner}
Score: ${data.winner_score} / ${data.loser_score}
` } else { return `N/A` } }, } ] /** * The currently shown week's data. * @type {object[]} */ data = [] /** * Called when the component is instantiated. Initializes the current week to the most recent week. * @return {Promise} */ async vue_on_create() { this.week_x_data = await api.get_matchups() this.max_week = this.current_week = this.week_x_data.length this.data = this.week_x_data[this.max_week - 1]; } /** * When called, advances the data to the next-most recent week, if one exists. */ to_next_week() { if ( this.current_week < this.max_week ) { this.current_week += 1; this.data = this.week_x_data[this.current_week - 1]; } } /** * When called, advances the data to the next-least recent week, if one exists. */ to_previous_week() { if ( this.current_week > this.min_week ) { this.current_week -= 1; this.data = this.week_x_data[this.current_week - 1]; } } } export default ScoresComponent