PyDIET web client

Global

Members

constant

etc_urlstring

Exposure-time calculator API root URL.

Type

  • string

Source

constant

root_urlstring

Application root URL from #root_path metadata.

Type

  • string

Source

constant

theme_iconsArray.<string>

Ionic icon names corresponding to themes.

Type

  • Array.<string>

Source

constant

themesArray.<string>

Display names of the supported themes.

Type

  • Array.<string>

Source

constant

ui_auth_urlstring

Root URL for UI authentication components.

Type

  • string

Source

constant

ui_urlstring

Root URL for UI components.

Type

  • string

Source

Methods

fetch_data(url) → {Promise.<(*|false)>}

Fetch and decode JSON using the browser's current credentials.

HTTP, network, and JSON-decoding errors are converted to false.

Parameters

  • url string | URL

    Resource URL.

Returns

  • Promise.<(*|false)>

    Decoded JSON value, or false on failure.

Example

const instruments = await fetch_data('/api/instruments');
if (instruments === false) console.error('Request failed');

Source

fetch_html(selector, url, optionsopt) → {Promise.<boolean>}

Fetch an HTML fragment and inject it into an element.

GET data is encoded as query parameters. Any method other than the literal string "get" sends a POST request whose body is data. Request and injection errors are converted to false.

Parameters

  • selector string

    CSS selector passed to inject_html.

  • url string | URL

    Resource URL.

  • options object <optional>
    {}

    Request options.

    Properties

    • method string <optional>
      'get'

      Request method selector.

    • data * <optional>

      Query values for GET or request body for POST.

Returns

  • Promise.<boolean>

    true after successful injection; otherwise false.

Example

await fetch_html('#results', '/ui/demo/results', {
  data: {brightness: 20, snr: 10}
});

Source

get_filterID(instrumentID) → nullable{string}

Return the persisted filter identifier for an instrument.

Parameters

  • instrumentID string

    Instrument identifier.

Returns

  • string

    Stored filter identifier, or null if none exists.

Example

localStorage.setItem('pyDIETDefaultFilter_megacam', 'g');
get_filterID('megacam'); // 'g'

Source

get_instrumentID() → nullable{string}

Return the persisted default instrument identifier.

Returns

  • string

    Stored identifier, or null when no choice exists.

Example

localStorage.setItem('pyDIETDefaultInstrument', 'megacam');
get_instrumentID(); // 'megacam'

Source

get_instruments() → {Promise.<(object|false)>}

Load the available instruments, caching the request promise.

The first call briefly presents an Ionic loading indicator and requests the /api/instruments endpoint. Later calls reuse the same promise, including a promise that resolved to false after a failed request.

Returns

  • Promise.<(object|false)>

    Instrument mapping, or false on failure.

Example

const instruments = await get_instruments();
if (instruments) console.log(Object.keys(instruments));

Source

get_theme() → nullable{string}

Return the persisted theme selection.

Returns

  • string

    Stored lower-case theme name, or null when unset.

Example

localStorage.setItem('pyDIETDefaultTheme', 'dark');
get_theme(); // 'dark'

Source

inject_html(selector, html) → {void}

Replace an element's contents with HTML and execute inserted scripts.

Existing contents are removed before insertion. Script elements are replaced with newly created elements so that both inline and external scripts run.

Parameters

  • selector string

    CSS selector for the target element.

  • html string

    HTML markup to insert.

Returns

  • void

Example

inject_html('#message', '<strong>Ready</strong>');

Throws

If the selector does not match an element.

Type
TypeError

Source

inject_node(selector, nodenullable) → nullable{Node}

Replace an element's contents with a DOM node.

Passing a falsy node clears the target without appending a replacement.

Parameters

  • selector string

    CSS selector for the target element.

  • node Node <nullable>

    Node to append, or a falsy value to only clear the target.

Returns

  • Node

    The supplied node.

Example

const status = document.createElement('span');
status.textContent = 'Ready';
inject_node('#message', status);

Throws

If the selector does not match an element.

Type
TypeError

Source

plot_filter(filter, atmosphere, canvas, wave_minopt, wave_maxopt) → {void}

Create an interactive transmission chart.

The initial wavelength limits come from filter.wave_range; wave_min and wave_max are currently accepted but ignored. Chart.js zooming and panning are enabled, including shift-drag zoom.

Parameters

  • filter object

    Instrument transmission model.

    Properties

    • name string

      Filter display name.

    • wave Object

      Wavelength samples.

    • response Object

      Transmission samples.

    • wave_range Object

      Initial wavelength limits.

  • atmosphere object

    Atmospheric transmission model.

    Properties

    • wave Object

      Wavelength samples.

    • response Object

      Transmission samples.

  • canvas HTMLCanvasElement | string

    Canvas or canvas ID accepted by Chart.js.

  • wave_min number <optional>

    Currently unused requested lower wavelength.

  • wave_max number <optional>

    Currently unused requested upper wavelength.

Returns

  • void

Example

plot_filter(
  {
    name: 'g',
    wave: {value: [400, 500], unit: 'nm'},
    response: {value: [0.2, 0.8]},
    wave_range: {value: [400, 500]}
  },
  {wave: {value: [400, 500]}, response: {value: [0.9, 0.95]}},
  'transmission-chart'
);

Source

setup_health() → {void}

Start API health monitoring.

A check runs immediately and then every ten seconds. Each request is aborted after two seconds. The element with ID health-monitor receives either the ok or fail class and a corresponding title.

Returns

  • void

Example

// HTML: <span id="health-monitor"></span>
setup_health();

Throws

If the health-monitor element is absent when status is set.

Type
TypeError

Source

setup_instrument_settings(instruments) → {void}

Populate and activate the instrument selector when present.

The persisted instrument is selected if its ID is in instruments. Otherwise the first API default, or ultimately the first instrument, is selected. An empty instrument dictionary leaves the selector inactive. Selection changes rebuild the ETC form.

Parameters

  • instruments object.<string, object>

    Instruments keyed by identifier.

Returns

  • void

Example

setup_instrument_settings({
  demo: {name: 'Demo camera', default: true}
});

Source

setup_theme_settings() → {void}

Populate and activate the theme selector when present.

Three Ionic segment buttons are appended to #theme-segment. The persisted theme is applied immediately and later ionChange events update it.

Returns

  • void

Example

// HTML: <ion-segment id="theme-segment"></ion-segment>
setup_theme_settings();

Source

update_etcform(instrument) → {Promise.<void>}

Replace the current ETC form for an instrument and attach submission logic.

The form fragment is loaded asynchronously. After insertion, filter options are populated and form submission loads results into #modal-slot. A filter upload switches the results request from GET query parameters to POST form data.

Parameters

  • instrument object

    Instrument returned by the instruments API.

    Properties

    • id string

      Instrument identifier used in UI URLs.

    • filters object

      Instrument filter configuration.

Returns

  • Promise.<void>

    Resolves before the fragment request necessarily completes.

Example

await update_etcform({
  id: 'demo',
  filters: {transmissions: {g: {name: 'g', default: true}}}
});

Source

update_filter(instrumentID, filterIDnullable) → nullable{string}

Store or retrieve the selected filter for an instrument.

A truthy filterID is persisted and returned. A falsy value leaves storage unchanged and returns the previously stored identifier.

Parameters

  • instrumentID string

    Instrument identifier.

  • filterID string <nullable>

    Filter identifier to store.

Returns

  • string

    New or previously stored filter identifier.

Example

update_filter('megacam', 'g'); // 'g'
update_filter('megacam'); // 'g'

Source

update_instrument(instrumentID) → {void}

Select an instrument and asynchronously rebuild the ETC form.

The selection is persisted after the cached instrument request resolves. This function does not return the asynchronous operation.

Parameters

  • instrumentID string

    Key in the instrument mapping.

Returns

  • void

Source

update_theme(themenullable) → {void}

Persist and apply a theme selection.

Names containing "dark" enable dark mode; names containing "light" disable it. Other, missing, or non-string values follow the operating-system preference. A truthy value is stored before application.

Parameters

  • theme string <nullable>

    Theme selection, or a falsy value to reuse storage.

Returns

  • void

Example

update_theme('dark');
document.body.classList.contains('dark'); // true

Source