commit e9a103c5f64eba73d8db52bf4ed34527cf7005ab
parent ca78a5d834f337208aaafa0f8b2bc476d45b3f27
Author: Katja (ctucx) <git@ctu.cx>
Date: Sun, 26 Jan 2025 13:54:56 +0100
parent ca78a5d834f337208aaafa0f8b2bc476d45b3f27
Author: Katja (ctucx) <git@ctu.cx>
Date: Sun, 26 Jan 2025 13:54:56 +0100
show prices feature only when db profile is selected
3 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/src/journeyView.js b/src/journeyView.js @@ -125,7 +125,7 @@ const journeyTemplate = (data, profile) => { ${data.slug ? html`<a class="icon-back" href="#/${data.slug}/${settings.journeysViewMode}" title="${t('back')}">${t('back')}</a>` : nothing} <div class="content"> <h3>${formatName(data.legs[0].origin)} → ${formatName(data.legs[data.legs.length - 1].destination)}</h3> - <p><b>${t('duration')}: ${formatDuration(duration)} | ${t('changes')}: ${changes-1} | ${t('date')}: ${formatDateTime(data.legs[0].plannedDeparture, 'date')}${settings.showPrices && data.price ? html` | ${t('price')}: <td><span>${formatPrice(data.price)}</span></td>` : nothing}</b></p> + <p><b>${t('duration')}: ${formatDuration(duration)} | ${t('changes')}: ${changes-1} | ${t('date')}: ${formatDateTime(data.legs[0].plannedDeparture, 'date')}${settings.showPrices && settings.profile === 'db' && data.price ? html` | ${t('price')}: <td><span>${formatPrice(data.price)}</span></td>` : nothing}</b></p> </div> <a class="icon-reload" title="${t("reload")}" @click=${() => refreshJourneyView(data.refreshToken, profile)}>${t("reload")}</a> </header>
diff --git a/src/journeysView.js b/src/journeysView.js @@ -47,7 +47,7 @@ const journeysTemplate = (data) => html` <th>${t('duration')}</th> <th>${t('changes')}</th> <th>${t('products')}</th> - ${settings.showPrices ? html`<th>${t('price')}</th>` : nothing} + ${settings.showPrices && settings.profile === 'db' ? html`<th>${t('price')}</th>` : nothing} <th></th> </tr> </thead> @@ -106,7 +106,7 @@ const journeyOverviewTemplate = (profile, entry, slug, key) => { <td class="${cancelled ? 'cancelled' : ''}" title="${changesDuration > 0 ? 'including '+formatDuration(changesDuration)+' transfer durations' : ''}">${formatDuration(duration)}</td> <td>${changes-1}</td> <td>${productsString}</td> - ${settings.showPrices ? html`<td>${formatPrice(entry.price)}</td>` : nothing} + ${settings.showPrices && settings.profile === 'db' ? html`<td>${formatPrice(entry.price)}</td>` : nothing} <td><a class="icon-arrow1"></a></td> </tr>`; };
diff --git a/src/settingsView.js b/src/settingsView.js @@ -1,13 +1,16 @@ import { db, clearDataStorage } from './dataStorage.js'; import { modifySettings, settings } from './settings.js'; import { showModal, hideOverlay } from './overlays.js'; -import { ElementById } from './helpers.js'; +import { ElementById, hideElement, showElement } from './helpers.js'; import { t } from './app_functions.js'; import { html, render } from 'lit-html'; import { searchView } from './searchView.js'; import { initHafasClient } from './hafas_client'; -export const showSettings = async () => showModal(t('settings'), settingsTemplate()); +export const showSettings = async () => { + showModal(t('settings'), settingsTemplate()); + profileChangeHandler(settings.profile); +}; const settingsTemplate = () => html` <div class="settingsView"> @@ -22,7 +25,7 @@ const settingsTemplate = () => html` <div class="row"> <label for="profile">${t('datasource')}:</label> - <select id="profile"> + <select id="profile" @change="${(event) => {profileChangeHandler(event.target.value)}}"> <option value="db" ?selected=${settings.profile === 'db'}>DB</option> <option value="nahsh" ?selected=${settings.profile === 'nahsh'}>NAH.SH (${t("experimental")})</option> <option value="rmv" ?selected=${settings.profile === 'rmv'}>RMV (${t("experimental")})</option> @@ -35,8 +38,8 @@ const settingsTemplate = () => html` <div class="row"> <label>${t('options')}:</label> <div> - <label><input type="checkbox" id="showDS100" ?checked=${settings.showDS100}> ${t('showds100')}</label><br> - <label><input type="checkbox" id="showPrices" ?checked=${settings.showPrices}> ${t('show-prices')} (${t("experimental")})</label><br> + <label id="showPricesElement"><input type="checkbox" id="showPrices" ?checked=${settings.showPrices}> ${t('show-prices')} (${t("experimental")})<br></label> + <label id="showDS100Element"><input type="checkbox" id="showDS100" ?checked=${settings.showDS100}> ${t('showds100')}<br></label> <label><input type="checkbox" id="combineDateTime" ?checked=${settings.combineDateTime}> ${t('combineDateTime')}</label> </div> </div> @@ -48,6 +51,18 @@ const settingsTemplate = () => html` </div> `; +const profileChangeHandler = (profile) => { + switch (profile) { + case 'db': + showElement(ElementById('showPricesElement')) + break; + + default: + hideElement(ElementById('showPricesElement')) + break; + }; +}; + const clearStorage = () => { clearDataStorage(); location.reload();