From cb968d782a6b31c82a1eab32e36463dd929e2400 Mon Sep 17 00:00:00 2001 From: Sergey Stepanov Date: Sat, 21 Oct 2023 02:37:44 +0300 Subject: [PATCH] Show rooms in the list --- pkg/api/coordinator.go | 1 + pkg/coordinator/hub.go | 9 +++++++-- web/js/workerManager.js | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/api/coordinator.go b/pkg/api/coordinator.go index 6c79bc8b3..9cdf22b71 100644 --- a/pkg/api/coordinator.go +++ b/pkg/api/coordinator.go @@ -36,6 +36,7 @@ type Server struct { PingURL string `json:"ping_url"` Port string `json:"port,omitempty"` Replicas uint32 `json:"replicas,omitempty"` + Room string `json:"room,omitempty"` Tag string `json:"tag,omitempty"` Zone string `json:"zone,omitempty"` } diff --git a/pkg/coordinator/hub.go b/pkg/coordinator/hub.go index 8d19fb4fb..8b57df746 100644 --- a/pkg/coordinator/hub.go +++ b/pkg/coordinator/hub.go @@ -144,8 +144,9 @@ func (h *Hub) handleWorkerConnection() http.HandlerFunc { } func (h *Hub) GetServerList() (r []api.Server) { + debug := h.conf.Coordinator.Debug h.workers.ForEach(func(w *Worker) { - r = append(r, api.Server{ + server := api.Server{ Addr: w.Addr, Id: w.Id(), IsBusy: !w.HasSlot(), @@ -154,7 +155,11 @@ func (h *Hub) GetServerList() (r []api.Server) { Port: w.Port, Tag: w.Tag, Zone: w.Zone, - }) + } + if debug { + server.Room = w.RoomId + } + r = append(r, server) }) return } diff --git a/web/js/workerManager.js b/web/js/workerManager.js index d8fe4d18c..56f463e44 100644 --- a/web/js/workerManager.js +++ b/web/js/workerManager.js @@ -37,7 +37,7 @@ const workerManager = (() => { }, 'is_busy': { caption: 'State', - renderer: (data) => data?.is_busy === true ? 'R' : '' + renderer: renderStateEl }, 'use': { caption: 'Use', @@ -112,6 +112,17 @@ const workerManager = (() => { }) } + function renderStateEl(server) { + const state = server?.is_busy === true ? 'R' : '' + if (server.room) { + return gui.create('a', (el) => { + el.innerText = state; + el.href = "/?id="+server.room; + }) + } + return state + } + panel.toggle(false); trigger.addEventListener('click', () => {