From ba7375fe15000dbc82ce1638b501cbf43c99ef44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Wed, 16 Jul 2025 10:50:31 +0200 Subject: [PATCH] wip --- sql/0010.sql | 18 ++++++++++++++++++ static/js/component.mjs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 sql/0010.sql create mode 100644 static/js/component.mjs diff --git a/sql/0010.sql b/sql/0010.sql new file mode 100644 index 0000000..4f4cf84 --- /dev/null +++ b/sql/0010.sql @@ -0,0 +1,18 @@ +CREATE TABLE public.script ( + id serial NOT NULL, + name varchar NOT NULL, + "source" text NOT NULL, + updated timestamptz DEFAULT NOW() NOT NULL, + CONSTRAINT script_pk PRIMARY KEY (id), + CONSTRAINT script_unique_name UNIQUE (name) +); + +CREATE TABLE public."execute" ( + id serial NOT NULL, + node_id int4 NOT NULL, + script_id int4 NOT NULL, + ssh varchar DEFAULT '' NOT NULL, + CONSTRAINT execute_pk PRIMARY KEY (id), + CONSTRAINT execute_node_fk FOREIGN KEY (node_id) REFERENCES public.node(id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT execute_script_fk FOREIGN KEY (script_id) REFERENCES public.script(id) ON DELETE CASCADE ON UPDATE CASCADE +); diff --git a/static/js/component.mjs b/static/js/component.mjs new file mode 100644 index 0000000..a6a207e --- /dev/null +++ b/static/js/component.mjs @@ -0,0 +1,35 @@ +export class Component { + constructor() { + this._component_name = Object.getPrototypeOf(this).constructor.name + this._template = document.createElement('template') + this._debug = (sessionStorage.getItem('debug') === 'true') + } + render() { + const component = this.renderComponent() + this._template.content.appendChild(component) + + for (const e of this._template.content.children) { + e.setAttribute('data-component-name', this._component_name) + + if (this._debug) { + e.setAttribute('data-tooltip', this._component_name) + e.classList.add('tooltip') + e.classList.add('left') + + e.addEventListener('mouseover', event=>{ + if (event.target !== e) + return + e.style.border = '1px solid #f0f'; + }) + + e.addEventListener('mouseout', event=>{ + if (event.target !== e) + return + e.style.border = 'none'; + }) + } + } + + return this._template.content + } +}