Instruments and filters

instrument.js loads the available instruments and remembers instrument and filter selections in browser storage.

instrument.get_instruments()

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));
instrument.get_instrumentID()

Return the persisted default instrument identifier.

Returns:

string -- Stored identifier, or null when no choice exists.

Example

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

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.

Arguments:
  • instrumentID (string) -- Key in the instrument mapping.

Returns:

void

instrument.get_filterID(instrumentID)

Return the persisted filter identifier for an instrument.

Arguments:
  • instrumentID (string) -- Instrument identifier.

Returns:

string -- Stored filter identifier, or null if none exists.

Example

localStorage.setItem('pyDIETDefaultFilter_megacam', 'g');
get_filterID('megacam'); // 'g'
instrument.update_filter(instrumentID, filterID)

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.

Arguments:
  • instrumentID (string) -- Instrument identifier.

  • filterID (string) -- Filter identifier to store.

Returns:

string -- New or previously stored filter identifier.

Example

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