Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add range steps into sliders #141

Open
mStirner opened this issue Sep 26, 2024 · 5 comments
Open

Add range steps into sliders #141

mStirner opened this issue Sep 26, 2024 · 5 comments

Comments

@mStirner
Copy link
Member

Currently command parameters type=number are renderted as range sliders:

grafik

The have no inidcaiton about the steps/range.
Add a step indicator, example:

grafik

@mStirner
Copy link
Member Author

Note: There is also no value shown.
How to get the current value and display it?

Example:
grafik

A command parameter (as rendered in the gui above) does not have a state, it is just set when the command is send to the backend. Its one way. There is no way to get the "current parameter value"

@mStirner
Copy link
Member Author

Add a link between params & states?
A state could be used to keep track of setted parameters.

E.g. Temperature.
You set the tempretature via Command parameter in the range of 16-32°C.
The command is send to the device, and this "should" temperature is then setted as state.

Then there needs a link between the command "set temperature" & the state temperature.

@mStirner
Copy link
Member Author

Feels like this can already be done.

A quick guess how it could be done: command & state alias. If they are both the same, the (can) are linked. Either automatically or with labels:

oh.link[0].state=POWER
oh.link[0].cmd=POWER

-- or --

oh.links[].enabled=POWER

But what then? When commands & states are linked, what now?
OpenHausIO/backend#501 (comment)

When there is a state with the same command alias, just display the state value inside the command parameter view as seen in the screenshots above.

In combination with a additional added hidden property, the state can be hidden from the endpoint view but seen as value in the command trigger view.

@mStirner
Copy link
Member Author

Icons for each setp/setting would also be very nice.
grafik
grafik
https://valetudo.cloud/

@mStirner
Copy link
Member Author

Quick bootstrap & chatgpt draft:
grafik

<!DOCTYPE html>
<html lang="de">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bootstrap Range Slider mit Tooltip-ähnlichem Thumb-Label</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">


    <style>
        .range-slider-container {
            position: relative;
            width: 300px;
            margin: 50px auto;
        }

        .thumb-label {
            position: absolute;
            top: -35px;
            /* Positionierung über dem Slider */
            left: 0;
            transform: translateX(-50%);
            background-color: #000;
            /* Schwarzer Hintergrund wie Bootstrap Tooltip */
            color: #fff;
            padding: 4px 8px;
            /* Kleinere Padding-Werte */
            border-radius: 4px;
            font-size: 12px;
            /* Kleinere Schriftgröße */
            white-space: nowrap;
            text-align: center;
            display: none;
            /* Standardmäßig versteckt */
        }

        .thumb-label::after {
            content: '';
            position: absolute;
            top: 100%;
            /* Positionierung des Pfeils direkt unter dem Label */
            left: 50%;
            transform: translateX(-50%);
            border-width: 5px;
            border-style: solid;
            border-color: #000 transparent transparent transparent;
            /* Pfeil-Farbe wie der Hintergrund */
        }

        .range-slider-container input[type="range"]:hover+.thumb-label {
            display: block;
            /* Anzeigen, wenn über den Slider-Knopf gehovert wird */
        }

        .range-labels {
            display: flex;
            justify-content: space-between;
            position: absolute;
            width: 100%;
            bottom: -25px;
            /* Labels unter dem Slider platzieren */
        }

        .range-labels span {
            font-size: 14px;
        }

        input[type="range"] {
            width: 100%;
        }
    </style>
</head>

<body>
    <div class="container">
       
        <div class="range-slider-container">
            <input type="range" class="form-control-range form-range" min="1" max="5" step="1" id="rangeSlider"
                value="1">
            <div class="thumb-label" id="thumbLabel">1</div>
            <div class="range-labels">
                <span>
                    <i class="fa fa-wind"></i>
                </span>
                <span>
                    <i class="fa fa-fan"></i>
                </span>
                <span>
                    <i class="fa fa-level-up-alt"></i>
                </span>
                <span>
                    <i class="fa fa-cogs"></i>
                </span>
                <span>
                    <i class="fa fa-level-down-alt"></i>
                </span>
            </div>
        </div>
    </div>

    <script>
        const rangeSlider = document.getElementById('rangeSlider');
        const thumbLabel = document.getElementById('thumbLabel');

        function updateThumbLabel() {
            // Aktualisiere den Wert des Labels
            thumbLabel.textContent = rangeSlider.value;

            // Berechne die Position des Labels relativ zur Slider-Position
            const max = rangeSlider.max;
            const min = rangeSlider.min;
            const value = rangeSlider.value;
            const percentage = ((value - min) / (max - min)) * 100;

            // Setze die Position des Labels basierend auf dem Prozentsatz
            thumbLabel.style.left = `calc(${percentage}% + (${8 - percentage * 0.15}px))`;
        }

        // Initiales Update und Event Listener für Änderungen
        updateThumbLabel();
        rangeSlider.addEventListener('input', updateThumbLabel);
        rangeSlider.addEventListener('mousemove', updateThumbLabel);
    </script>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
        crossorigin="anonymous"></script>

</body>

</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant