Commit 407da3aa authored by vertighel's avatar vertighel
Browse files

refactor: merge widget_toggle into widget_standard



widget_toggle removed; widget_input renamed to widget_standard and made
inputs optional (default []) so it covers both toggle-only and input cases.

Co-Authored-By: default avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent f205be07
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
        
        <!-- AltAz Tab -->
        <div class="tab-pane fade" id="tab-altaz">
          {{ w.widget_input({
          {{ w.widget_standard({
            "label": "AltAz",
            "inputs": [
            {"placeholder": "45.0"},
@@ -46,7 +46,7 @@

        <!-- RaDec Tab -->
        <div class="tab-pane fade show active" id="tab-radec">
          {{ w.widget_input({
          {{ w.widget_standard({
            "label": "RaDec",
            "inputs": [{"type": "text", "placeholder": "Object name or HH MM SS ±DD MM SS", "autocomplete": "off"}],
            "unit": "hms ±dms / id",
@@ -64,7 +64,7 @@
    
    <section>

      {{ w.widget_input({
      {{ w.widget_standard({
      "label": "Focus",
      "info" : "telescope-focuser-position",
      "inputs": [{"value": 0}],
@@ -74,7 +74,7 @@
      "method": "PUT"}],
      }) }}

      {{ w.widget_input({
      {{ w.widget_standard({
         "label": "Offsets",
         "inputs": [
         {"label": "Zd", "value": -300},
@@ -100,7 +100,7 @@
    <section>
      <h4 class="mt-2 mb-2">Mode selector</h4>

      {{ w.widget_toggle({
      {{ w.widget_standard({
      "label": "Preset",
      "info": "stage-named",
      "buttons": [
@@ -110,7 +110,7 @@
      ],
      }) }}

      {{ w.widget_input({
      {{ w.widget_standard({
      "label": "Position",
      "info": "stage-position",
      "inputs": [{"value": 1}],
@@ -122,7 +122,7 @@
          {{ ctrl.stage_relative() }}
        -->

      {{ w.widget_toggle({
      {{ w.widget_standard({
      "label": "Init",
      "info": "stage-status",
      "buttons": [
@@ -143,7 +143,7 @@

    <section id="mode-panel-imaging" class="mode-panel" data-subsystem="camera">
      
      {{ w.widget_toggle({
      {{ w.widget_standard({
      "label": "Frame",
      "buttons": [
      {"label": "Full",  "endpoint": "/camera/frame/full", "method": "PUT"},
@@ -163,7 +163,7 @@
    
    <section id="mode-panel-spectro" class="mode-panel d-none" data-subsystem="camera2">

      {{ w.widget_toggle({
      {{ w.widget_standard({
      "label": "Frame",
      "buttons": [
      {"label": "Full",  "endpoint": "/camera2/frame/full", "method": "PUT"},
+19 −19
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
        <section>
            <h4 class="mt-2 mb-2">Telescope Status</h4>

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Power",
                "info": "telescope-power",
                "buttons": [
@@ -20,7 +20,7 @@
                ],
            }) }}

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Parked",
                "info": "telescope-coordinates-movement-atpark",
                "buttons": [
@@ -29,7 +29,7 @@
                ],
            }) }}

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Tracking",
                "info": "telescope-coordinates-tracking",
                "buttons": [
@@ -38,7 +38,7 @@
                ],
            }) }}

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Petals",
                "info": "telescope-cover",
                "buttons": [
@@ -47,7 +47,7 @@
                ],
            }) }}

            {{ w.widget_input({
            {{ w.widget_standard({
                "label": "Status",
                "info": "telescope-error",
                "inputs": [{"value": 2, "placeholder": "Error ID"}],
@@ -58,7 +58,7 @@

            <h4 class="p-2">Telescope Offsets</h4>

            {{ w.widget_input({
            {{ w.widget_standard({
                "label": "Focus",
                "info" : "telescope-focuser-position",
                "inputs": [{"value": 0}],
@@ -66,7 +66,7 @@
                "buttons": [{"label": "Set", "endpoint": "/telescope/focuser/movement", "method": "PUT"}],
            }) }}

            {{ w.widget_input({
            {{ w.widget_standard({
                "label": "Offsets",
                "inputs": [
                    {"label": "Zd", "value": -300},
@@ -81,7 +81,7 @@
                ]
            }) }}

            {{ w.widget_input({
            {{ w.widget_standard({
                "label": "Rotator",
                "inputs": [{"value": 0}],
                "unit": "°",
@@ -97,7 +97,7 @@
        <section>
            <h4 class="mt-2 mb-2">Dome</h4>

            {{ w.widget_input({
            {{ w.widget_standard({
                "label": "Azimuth",
                "inputs": [{"value": 0.1}],
                "unit": "°",
@@ -112,7 +112,7 @@
                ]
            }) }}

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Parked",
                "info": "dome-position-parked",
                "buttons": [
@@ -136,7 +136,7 @@
            <h4 class="p-2">Mirror Stage</h4>

            {#
            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Connection",
                "info": "stage-connection",
                "buttons": [
@@ -146,7 +146,7 @@
            }) }}
            #}
            
            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Power",
                "info": "stage-power",
                "buttons": [
@@ -155,7 +155,7 @@
                ],
            }) }}

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Init",
                "info": "stage-status",
                "buttons": [
@@ -172,7 +172,7 @@
        <section>
            <h4 class="mt-2 mb-2">Camera - Imaging</h4>

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Power",
                "info": "camera-power",
                "buttons": [
@@ -181,7 +181,7 @@
                ],
            }) }}

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Cooling",
                "info": "camera-cooler",
                "buttons": [
@@ -190,7 +190,7 @@
                ],
            }) }}

            {{ w.widget_input({
            {{ w.widget_standard({
                "label": "Temp_1",
                "inputs": [{"value": -10}],
                "unit": "°C",
@@ -206,7 +206,7 @@
        <section>
            <h4 class="mt-2 mb-2">Camera - Spectroscopy</h4>

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Power",
                "info": "camera2-power",
                "buttons": [
@@ -215,7 +215,7 @@
                ],
            }) }}

            {{ w.widget_toggle({
            {{ w.widget_standard({
                "label": "Cooling",
                "info": "camera2-cooler",
                "buttons": [
@@ -224,7 +224,7 @@
                ],
            }) }}

            {{ w.widget_input({
            {{ w.widget_standard({
                "label": "Temp_2",
                "inputs": [{"value": -10}],
                "unit": "°C",
+2 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
    Reusable webcam panel: snapshot image, Light/Lamp toggles, PTZ controls.
    Pages that include this macro must load webcam.js in their scripts block.
#}
{% from "macros/widgets.html" import widget_onoff, widget_toggle %}
{% from "macros/widgets.html" import widget_onoff, widget_standard %}

{% macro webcam_panel() %}
<div class="card mb-3" id="webcam-card" data-subsystem="webcam">
@@ -41,7 +41,7 @@
        </aside>

        <div class="col">
            {{ widget_toggle({'buttons': [
            {{ widget_standard({'buttons': [
                {'label': "Reset",    'endpoint': "/webcam/position", 'val': [15, 180], 'method': "PUT"},
                {'label': "Look top", 'endpoint': "/webcam/position", 'val': [55, 170], 'method': "PUT"}
            ]}) }}
+4 −45
Original line number Diff line number Diff line
@@ -17,49 +17,8 @@
{% endmacro %}


<!-- WIDGET: Toggle -->
{% macro widget_toggle(config) %}
{% set safe_id = config.label | replace(' ', '-') | replace('?', '') | lower %}
<fieldset class="row mt-1 widget-universal align-items-center" id="toggle-{{ safe_id }}">
  <label class="col-md-2 col-form-label">
    {{ config.label }}
  </label>
        
  <div class="col-md">
    <div class="input-group input-group-sm">
      {% if config.info %} 
      <span class="col-md-2 input-group-text status-container">
        <var class="badge bg-secondary w-100" data-status="{{ config.info.strip('/') | replace('/', '-') }}">Unk</var>
      </span>
      {% endif %}
      
      {% for btn in config.buttons %}
      <button class="col-md btn btn-outline-primary btn-universal" 
              data-method="{{ btn.method | default('PUT') }}" 
              data-url="{{ btn.endpoint }}" 
              data-safe-id="{{ safe_id }}"
              {% if btn.val is defined and btn.val is not none %}
              data-value='{{ btn.val | tojson }}'
              {% endif %}>
        {{ btn.label }}
      </button>
      {% endfor %}
    </div>
  </div>
</fieldset>
  
{% if config.extra_flags or config.info_list %}
<aside class="row">
  {% if config.extra_flags %} {{ render_flags(safe_id) }} {% endif %}
  {% if config.info_list %} {{ render_info(config.info_list) }} {% endif %}
</aside>
{% endif %}

{% endmacro %}


<!-- WIDGET: Input -->
{% macro widget_input(config) %}
<!-- WIDGET: Input (also handles toggle-style, inputs is optional) -->
{% macro widget_standard(config) %}
{% set safe_id = config.label | replace(' ', '-') | lower %}
<fieldset class="row mt-1 widget-universal align-items-center" id="input-{{ safe_id }}">
  <label class="col-md-2 col-form-label">
@@ -74,7 +33,7 @@
      </span>
      {% endif %}
      
      {% for inp in config.inputs %}
      {% for inp in config.inputs | default([]) %}
      <input class="col-md form-control bg-black" id="val{{ loop.index }}-{{ safe_id }}"
             type="{{ inp.type | default('number') }}"
             value="{{ inp.value | default('') }}"
@@ -91,7 +50,7 @@
              data-method="{{ btn.method | default('PUT') }}"
              data-url="{{ btn.endpoint }}"
              data-safe-id="{{ safe_id }}"
              data-inputs="{% for inp in config.inputs %}val{{ loop.index }}-{{ safe_id }}{% if not loop.last %},{% endif %}{% endfor %}"
              data-inputs="{% for inp in config.inputs | default([]) %}val{{ loop.index }}-{{ safe_id }}{% if not loop.last %},{% endif %}{% endfor %}"
              {% if btn.val is defined and btn.val is not none %}
              data-value='{{ btn.val | tojson }}'
              {% endif %}>
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
        <!-- Fallback list for generic subsystems -->
        <div class="alert alert-info">Generic monitor for unknown subsystem.</div>
        {% for key, data in endpoints.items() %}
            {{ w.widget_toggle({'label': key | title, 'info': data.path, 'buttons': [], 'extra_flags': True}) }}
            {{ w.widget_standard({'label': key | title, 'info': data.path, 'buttons': [], 'extra_flags': True}) }}
        {% endfor %}
    {% endif %}