Skip to content

Commit

Permalink
Fastest lap indication in results card (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcokreeft87 authored Aug 6, 2023
1 parent c0d22c1 commit b864f82
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 25 deletions.
23 changes: 14 additions & 9 deletions formulaone-card.js

Large diffs are not rendered by default.

Binary file modified formulaone-card.js.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formulaone-card",
"version": "1.8.4",
"version": "1.8.5",
"description": "Frontend card for Home Assistant to display Formula One data",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 0 additions & 5 deletions src/api/f1-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ export interface Root {
status: string
Time?: Time
FastestLap?: FastestLap | undefined
// FirstPractice: FirstPractice
// SecondPractice: SecondPractice
// ThirdPractice?: ThirdPractice
// Qualifying: Qualifying
// Sprint?: Sprint
}

export interface QualifyingResult {
Expand Down
14 changes: 10 additions & 4 deletions src/cards/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class Results extends BaseCard {
</tr>
</thead>
<tbody>
${reduceArray(selectedRace.SprintResults, this.config.row_limit).map(result => this.renderResultRow(result))}
${reduceArray(selectedRace.SprintResults, this.config.row_limit).map(result => this.renderResultRow(result, false))}
</tbody>
</table>`
: html`<table class="nopadding">
Expand Down Expand Up @@ -110,6 +110,7 @@ export default class Results extends BaseCard {
}

renderResults(selectedRace: Race): HTMLTemplateResult {
const fastest = selectedRace?.Results?.filter((result) => result.FastestLap?.rank === '1')[0];
return selectedRace ?
html`<table class="nopadding">
<thead>
Expand All @@ -123,8 +124,13 @@ export default class Results extends BaseCard {
</tr>
</thead>
<tbody>
${reduceArray(selectedRace.Results, this.config.row_limit).map(result => this.renderResultRow(result))}
${reduceArray(selectedRace.Results, this.config.row_limit).map(result => this.renderResultRow(result, result.position === fastest?.position))}
</tbody>
${fastest ? html`<tfoot>
<tfoot>
<tr>
<td colspan="6" class="text-right"><small>* Fastest lap: ${fastest.FastestLap.Time.time}</small></td>
</tfoot>` : ''}
</table>`
: html`<table class="nopadding">
<tr>
Expand All @@ -133,11 +139,11 @@ export default class Results extends BaseCard {
</table>`;
}

renderResultRow(result: Result): HTMLTemplateResult {
renderResultRow(result: Result, fastest: boolean): HTMLTemplateResult {
return html`
<tr>
<td class="width-50 text-center">${result.position}</td>
<td>${(this.config.standings?.show_flag ? html`<img height="10" width="20" src="${getCountryFlagByNationality(this, result.Driver.nationality)}">&nbsp;` : '')}${getDriverName(result.Driver, this.config)}</td>
<td>${(this.config.standings?.show_flag ? html`<img height="10" width="20" src="${getCountryFlagByNationality(this, result.Driver.nationality)}">&nbsp;` : '')}${getDriverName(result.Driver, this.config)}${fastest ? ' *' : ''}</td>
${(this.config.standings?.show_team ? html`${renderConstructorColumn(this, result.Constructor)}` : '')}
<td>${result.grid}</td>
<td class="width-60 text-center">${result.points}</td>
Expand Down
28 changes: 24 additions & 4 deletions tests/cards/results.test.ts

Large diffs are not rendered by default.

0 comments on commit b864f82

Please sign in to comment.