All files / src index.ts

100% Statements 8/8
75% Branches 3/4
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100                      2x       2x                                                                                                                           2x                       2x 2x     3x 2x   1x      
import {
  INPUT_FORMATTED_PRESET_DESCRIPTIONS,
  INPUT_FORMATTED_PRESET_EXPRESSION,
  INPUT_STRINGS,
  makeWidgetDef
} from '@ska-octopus-widget-sdk/widget-sdk';
import type { OctopusHost } from '@ska-octopus-widget-sdk/widget-sdk';
import ClockWidget from './ClockWidget';
import { DEFAULT_TIMEZONES } from './constants';
import pkg from '../package.json';
 
const { version } = pkg;
 
export { ClockWidget };
 
const schema = {
  type: 'object',
  properties: {
    timezones: {
      type: INPUT_STRINGS,
      title: 'Timezones',
      propertyType: 'functionality',
      level: 2,
      description: `List of IANA timezone identifiers (e.g. "Europe/London"). You can also use sidereal tokens: "LST" (Greenwich) or "LST@116.7" (longitude in degrees). A clock is rendered for each entry. ${INPUT_FORMATTED_PRESET_DESCRIPTIONS[INPUT_FORMATTED_PRESET_EXPRESSION]}`,
      items: {
        title: 'Timezone',
        formatPreset: INPUT_FORMATTED_PRESET_EXPRESSION,
        description: `Timezone value template. Supports IANA names plus LST tokens like "LST" and "LST@116.7". ${INPUT_FORMATTED_PRESET_DESCRIPTIONS[INPUT_FORMATTED_PRESET_EXPRESSION]}`
      },
      minItems: 1,
      default: [...DEFAULT_TIMEZONES]
    },
    showDay: {
      type: 'boolean',
      title: 'Show day',
      propertyType: 'css',
      level: 2,
      description: 'Toggle the day label above the time',
      default: false
    },
    topTextMaxSize: {
      type: 'number',
      title: 'Top text max size (px)',
      propertyType: 'css',
      level: 2,
      description:
        'Maximum size in pixels for the top row text (timezone, UTC offset, day). Leave empty for auto.',
      minimum: 1
    },
    middleTextMaxSize: {
      type: 'number',
      title: 'Middle text max size (px)',
      propertyType: 'css',
      level: 2,
      description: 'Maximum size in pixels for the main clock time. Leave empty for auto.',
      minimum: 1
    },
    bottomTextMaxSize: {
      type: 'number',
      title: 'Bottom text max size (px)',
      propertyType: 'css',
      level: 2,
      description:
        'Maximum size in pixels for sunrise/sunset values and status text. Leave empty for auto.',
      minimum: 1
    },
    clockGap: {
      type: 'number',
      title: 'Clock spacing (px)',
      propertyType: 'css',
      level: 2,
      description: 'Spacing in pixels between clock cards. Leave empty for default auto spacing.',
      minimum: 0
    }
  }
} as const;
 
const widgetDef = makeWidgetDef({
  key: 'clock',
  component: ClockWidget,
  label: 'Clock',
  layout: { x: 0, y: 0, w: 35, h: 26 },
  config: { schema },
  polls: true, // allow Octopus to supply dashboard refresh rate for polling
  version,
  docsUrl: 'https://developer.skao.int/projects/ska-octopus-clock-widget/en/latest/'
});
 
function register(host: OctopusHost) {
  host.registerWidget(widgetDef as any);
}
 
(function wait(h: any) {
  if (typeof h.registerWidget === 'function') {
    register(h as OctopusHost);
  } else {
    setTimeout(wait, 50, h);
  }
})((globalThis as any).Octopus || ((globalThis as any).Octopus = {}));