From 3306c7fc8dcb7eecea3e993b43ef0ba3649c8490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 4 Apr 2023 12:19:14 +0200 Subject: [PATCH] Web: add support for worker clusters The support is still fairly minimal. Clusters cannot be managed via the webapp yet, so the API has to be used directly for that. Workers can be assigned to clusters via the webapp though. --- web/app/src/clipboard.js | 19 ++++- web/app/src/components/SwitchCheckbox.vue | 4 +- web/app/src/components/jobs/JobDetails.vue | 23 +++++- .../src/components/workers/WorkerDetails.vue | 70 ++++++++++++++++++- web/app/src/stores/workers.js | 27 +++++++ 5 files changed, 137 insertions(+), 6 deletions(-) diff --git a/web/app/src/clipboard.js b/web/app/src/clipboard.js index 3ccee2ad..6ce430eb 100644 --- a/web/app/src/clipboard.js +++ b/web/app/src/clipboard.js @@ -7,6 +7,7 @@ */ const flashAfterCopyDuration = 150; + /** * Copy the inner text of an element to the clipboard. * @@ -14,9 +15,24 @@ const flashAfterCopyDuration = 150; */ export function copyElementText(clickEvent) { const sourceElement = clickEvent.target; + copyElementValue(sourceElement, sourceElement.innerText); +} + +/** + * Copy the inner text of an element to the clipboard. + * + * @param {Event } clickEvent the click event that triggered this function call. + */ +export function copyElementData(clickEvent) { + const sourceElement = clickEvent.target; + window.sourceElement = sourceElement; + copyElementValue(sourceElement, sourceElement.dataset.clipboard); +} + +function copyElementValue(sourceElement, value) { const inputElement = document.createElement("input"); document.body.appendChild(inputElement); - inputElement.setAttribute("value", sourceElement.innerText); + inputElement.setAttribute("value", value); inputElement.select(); // Note that the `navigator.clipboard` interface is only available when using @@ -27,7 +43,6 @@ export function copyElementText(clickEvent) { document.execCommand("copy"); document.body.removeChild(inputElement); - flashElement(sourceElement); } diff --git a/web/app/src/components/SwitchCheckbox.vue b/web/app/src/components/SwitchCheckbox.vue index b8a61053..0c79f70f 100644 --- a/web/app/src/components/SwitchCheckbox.vue +++ b/web/app/src/components/SwitchCheckbox.vue @@ -1,5 +1,5 @@ diff --git a/web/app/src/stores/workers.js b/web/app/src/stores/workers.js index d90a9788..5e3e82d0 100644 --- a/web/app/src/stores/workers.js +++ b/web/app/src/stores/workers.js @@ -1,5 +1,8 @@ import { defineStore } from 'pinia' +import { WorkerMgtApi } from '@/manager-api'; +import { getAPIClient } from "@/api-client"; + // 'use' prefix is idiomatic for Pinia stores. // See https://pinia.vuejs.org/core-concepts/ export const useWorkers = defineStore('workers', { @@ -11,6 +14,12 @@ export const useWorkers = defineStore('workers', { * @type {string} */ activeWorkerID: "", + + /** @type {API.WorkerCluster[]} */ + clusters: [], + + /* Mapping from cluster UUID to API.WorkerCluster. */ + clustersByID: {}, }), actions: { setActiveWorkerID(workerID) { @@ -37,5 +46,23 @@ export const useWorkers = defineStore('workers', { activeWorkerID: "", }); }, + /** + * Fetch the available worker clusters from the Manager. + * + * @returns a promise. + */ + refreshClusters() { + const api = new WorkerMgtApi(getAPIClient()); + return api.fetchWorkerClusters() + .then((resp) => { + this.clusters = resp.clusters; + + let clustersByID = {}; + for (let cluster of this.clusters) { + clustersByID[cluster.id] = cluster; + } + this.clustersByID = clustersByID; + }) + }, }, })