Skip to content

Commit

Permalink
Merge branch 'filter-line'
Browse files Browse the repository at this point in the history
  • Loading branch information
NecroKote committed Mar 25, 2024
2 parents 5008871 + 45f3212 commit 44adb95
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 9 deletions.
1 change: 0 additions & 1 deletion dist/editor.7baf97f9.js.map

This file was deleted.

37 changes: 36 additions & 1 deletion dist/editor.7baf97f9.js → dist/editor.cf2e8dd3.js

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

1 change: 1 addition & 0 deletions dist/editor.cf2e8dd3.js.map

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions dist/hasl4-departure-card.js

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

2 changes: 1 addition & 1 deletion dist/hasl4-departure-card.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Card fully supports configuration through the UI
| show_icon | bool | optional | Render transport icon for each line. |
| show_departures | bool | optional | Render departures section. |
| max_departures | number | optional | Max departures to show, default to all. |
| direction | number | optional | Render departures only in said direction |
| hide_departed | bool | optional | If set, will hide already departured vehicles. |
| show_departed_offset | bool | optional | If set, will show some departed vehicles, which departed less than the offset minutes ago. |
| adjust_departure_time | bool | optional | Adjust departure time taking last update into account. |
Expand Down
2 changes: 2 additions & 0 deletions src/DepartureCard/DepartureCard.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface DepartureCardConfig extends LovelaceCardConfig {
show_header?: boolean
show_icon?: boolean
show_departures: boolean
direction: number
max_departures: number
hide_departed: boolean
show_departed_offeset?: number
Expand All @@ -44,6 +45,7 @@ export const DEFAULT_CONFIG: Partial<DepartureCardConfig> = {
show_header: true,
show_icon: true,
show_departures: true,
direction: 0,
max_departures: 5,
hide_departed: true,
show_departed_offeset: 5,
Expand Down
1 change: 1 addition & 0 deletions src/DepartureCard/DepartureCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class HASLDepartureCard extends LitElement implements LovelaceCard {
showName: this.config?.show_entity_name,
showIcon: this.config?.show_icon,
friendlyName: attrs.friendly_name,
direction: this.config?.direction,
hideDeparted: this.config?.hide_departed,
departedOffset: this.config?.show_departed_offeset,
lastUpdated: new Date(data.last_updated),
Expand Down
2 changes: 2 additions & 0 deletions src/DepartureCard/DepartureEntity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type DepartureEntityConfig = {
showName: boolean
showIcon: boolean
friendlyName: string
direction: number
hideDeparted: boolean
departedOffset: number
lastUpdated: Date
Expand All @@ -23,6 +24,7 @@ export const DEFAULT_CONFIG: DepartureEntityConfig = {
showName: true,
showIcon: true,
friendlyName: '',
direction: 0,
hideDeparted: false,
departedOffset: 0,
lastUpdated: new Date(),
Expand Down
9 changes: 8 additions & 1 deletion src/DepartureCard/DepartureEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ export class HASLDepartureEntity extends LitElement {
const c = {...DEFAULT_CONFIG, ...this.config}
const _ = translateTo(c.lang)

const departures = this.departures?.filter((d) => {
const departures = this.departures
// filter direction
?.filter((d) => {
if (c.direction === 0) return true
return d.direction_code === c.direction
})
// filter by departure time
.filter((d) => {
if (!c.hideDeparted) return true;

const diffBase = c.adjustTime ? c.lastUpdated : new Date()
Expand Down
22 changes: 22 additions & 0 deletions src/DepartureCardEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ export class HASLDepartureCardEditor extends LitElement implements LovelaceCardE
<ha-switch .checked=${this._config?.show_departures} @change=${this.checkboxHandler} .configValue=${`show_departures`}/>
</ha-formfield>
</div>
<ha-selector
.hass=${this.hass}
.required=${false}
.label=${_(`editor_direction`)}
.selector=${{ select: { mode: 'list', options: [
{ value: 0, label: _(`editor_direction_all`) },
{ value: 1, label: _(`editor_direction_left`) },
{ value: 2, label: _(`editor_direction_right`) },
]}}}
.value=${this._config?.direction}
.configValue=${'direction'}
@value-changed=${this.emptyPicketHandler}>
</ha-selector>
<ha-formfield .label=${_(`editor_show_departure_header`)}>
<ha-switch .disabled=${disabled} .checked=${this._config?.show_header} @change=${this.checkboxHandler} .configValue=${`show_header`}/>
</ha-formfield>
Expand Down Expand Up @@ -204,4 +217,13 @@ export class HASLDepartureCardEditor extends LitElement implements LovelaceCardE
}
}
})

private emptyPicketHandler = this.inputChangedHandler((ev) => {
const target = ev.target;
const value = ev.detail.value;

if (target.configValue) {
return {...this._config, [target.configValue]: value};
}
})
}
12 changes: 12 additions & 0 deletions src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const defaultTranslation = {
editor_show_time_always: 'Always show departure time in HH:MM form',
editor_adjust_departure_time: 'Adjust departure time to update time',
editor_show_updated: `Show 'Last Updated'`,
editor_direction: `Direction filter`,
editor_direction_all: `All`,
editor_direction_left: `Left`,
editor_direction_right: `Right`,
language: 'Language',
}
type Translation = typeof defaultTranslation
Expand Down Expand Up @@ -49,6 +53,10 @@ export const translations: {[lang: string]: Translation} = {
editor_show_time_always: 'Visa alltid avgångstid i HH:MM-form',
editor_adjust_departure_time: 'Justera avgångstid till uppdateringstid',
editor_show_updated: `Visa 'Senast uppdaterad'`,
editor_direction: `Riktning filter`,
editor_direction_all: `Alla`,
editor_direction_left: `Vänster`,
editor_direction_right: `Höger`,
language: 'Språk',
},
'fr-FR': {
Expand All @@ -72,6 +80,10 @@ export const translations: {[lang: string]: Translation} = {
editor_show_time_always: 'Toujours afficher l\'heure de départ en HH:MM',
editor_adjust_departure_time: 'Ajuster l\'heure de départ à l\'heure de mise à jour',
editor_show_updated: `Afficher 'Mis à jour'`,
editor_direction: `Filtre de direction`,
editor_direction_all: `Tous`,
editor_direction_left: `Gauche`,
editor_direction_right: `Droite`,
language: 'Langue',
}
}
Expand Down

0 comments on commit 44adb95

Please sign in to comment.