Improve multi-currency support

This commit is contained in:
Djuri Baars 2024-09-05 13:10:58 +02:00
parent 3342e6a532
commit 3d69570099
3 changed files with 57 additions and 35 deletions

View File

@ -12,7 +12,8 @@
import { uiSettings } from '$lib/uiSettings'; import { uiSettings } from '$lib/uiSettings';
let settings = writable({ let settings = writable({
fgColor: '0' fgColor: '0',
bgColor: '0'
}); });
// let uiSettings = writable({ // let uiSettings = writable({

View File

@ -22,6 +22,7 @@
} from '@sveltestrap/sveltestrap'; } from '@sveltestrap/sveltestrap';
import EyeIcon from '../icons/EyeIcon.svelte'; import EyeIcon from '../icons/EyeIcon.svelte';
import EyeSlashIcon from '../icons/EyeSlashIcon.svelte'; import EyeSlashIcon from '../icons/EyeSlashIcon.svelte';
import { derived } from 'svelte/store';
export let settings; export let settings;
@ -160,6 +161,40 @@
let showPassword = false; let showPassword = false;
let textColor = '0';
const colorStore = derived(settings, ($settings) => ({
fgColor: $settings.fgColor,
bgColor: $settings.bgColor
}));
// $: {
// if ($colorStore) {
// console.log('Settings model changed:', $colorStore);
// if ($colorStore.fgColor < $colorStore.bgColor)
// textColor = "0";
// else
// textColor = "1"; // 65535
// }
// }
colorStore.subscribe(() => {
if ($colorStore) {
if ($colorStore.fgColor < $colorStore.bgColor) textColor = '0';
else textColor = '1'; // 65535
}
});
const setTextColor = () => {
console.log(textColor);
if (textColor == '1') {
$settings.fgColor = 65535;
$settings.bgColor = 0;
} else {
$settings.fgColor = 0;
$settings.bgColor = 65535;
}
};
export let xs = 12; export let xs = 12;
export let sm = xs; export let sm = xs;
export let md = sm; export let md = sm;
@ -176,41 +211,25 @@
<CardBody> <CardBody>
<Form on:submit={onSave}> <Form on:submit={onSave}>
<Row> <Row>
<Label md={6} for="fgColor" size={$uiSettings.inputSize} <Label md={6} for="textColor" size={$uiSettings.inputSize}
>{$_('section.settings.textColor', { default: 'Text color' })}</Label >{$_('section.settings.textColor', { default: 'Text color' })}</Label
> >
<Col md="6"> <Col md="6">
<Input <Input
type="select" type="select"
bind:value={$settings.fgColor} bind:value={textColor}
name="select" name="select"
id="fgColor" id="textColor"
on:change={setTextColor}
bsSize={$uiSettings.inputSize} bsSize={$uiSettings.inputSize}
class={$uiSettings.selectClass} class={$uiSettings.selectClass}
> >
<option value="0">{$_('colors.black')}</option> <option value="0">{$_('colors.black')} on {$_('colors.white')}</option>
<option value="65535">{$_('colors.white')}</option> <option value="1">{$_('colors.white')} on {$_('colors.black')}</option>
</Input>
</Col>
</Row>
<Row>
<Label md={6} for="bgColor" size={$uiSettings.inputSize}
>{$_('section.settings.backgroundColor')}</Label
>
<Col md="6">
<Input
type="select"
bind:value={$settings.bgColor}
name="select"
id="bgColor"
bsSize={$uiSettings.inputSize}
class={$uiSettings.selectClass}
>
<option value="0">{$_('colors.black')}</option>
<option value="65535">{$_('colors.white')}</option>
</Input> </Input>
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Label md={6} for="timePerScreen" size={$uiSettings.inputSize} <Label md={6} for="timePerScreen" size={$uiSettings.inputSize}
>{$_('section.settings.timePerScreen')}</Label >{$_('section.settings.timePerScreen')}</Label
@ -671,15 +690,17 @@
/> />
</Col> </Col>
{/if} {/if}
<Col md="6" xl="12" xxl="6"> {#if !$settings.actCurrencies}
<Input <Col md="6" xl="12" xxl="6">
id="fetchEurPrice" <Input
bind:checked={$settings.fetchEurPrice} id="fetchEurPrice"
type="switch" bind:checked={$settings.fetchEurPrice}
bsSize={$uiSettings.inputSize} type="switch"
label="{$_('section.settings.fetchEuroPrice')} ({$_('restartRequired')})" bsSize={$uiSettings.inputSize}
/> label="{$_('section.settings.fetchEuroPrice')} ({$_('restartRequired')})"
</Col> />
</Col>
{/if}
<Col md="6" xl="12" xxl="6"> <Col md="6" xl="12" xxl="6">
<Input <Input
id="ownDataSource" id="ownDataSource"

View File

@ -135,7 +135,7 @@
{/each} {/each}
</ButtonGroup> </ButtonGroup>
</div> </div>
{#if $settings.actCurrencies} {#if $settings.actCurrencies && $settings.ownDataSource}
<div class="d-flex justify-content-center d-none d-sm-flex mt-2"> <div class="d-flex justify-content-center d-none d-sm-flex mt-2">
<ButtonGroup size="sm"> <ButtonGroup size="sm">
{#each $settings.actCurrencies as c} {#each $settings.actCurrencies as c}
@ -248,7 +248,7 @@
{:else} {:else}
{$_('section.status.wsDataConnection')}: {$_('section.status.wsDataConnection')}:
<span> <span>
{#if $status.connectionStatus && $status.connectionStatus.price} {#if $status.connectionStatus && $status.connectionStatus.V2}
&#9989; &#9989;
{:else} {:else}
&#10060; &#10060;