Add solo button
This commit is contained in:
19
main.go
19
main.go
@@ -24,6 +24,7 @@ type activeRequest struct {
|
|||||||
AdminSecret string `json:"admin_secret"`
|
AdminSecret string `json:"admin_secret"`
|
||||||
ClientId string `json:"client_id"`
|
ClientId string `json:"client_id"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
|
Solo bool `json:"solo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type adminRequest struct {
|
type adminRequest struct {
|
||||||
@@ -212,7 +213,7 @@ func active(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Active = req.Active
|
c.Active = req.Active || req.Solo
|
||||||
if c.Active {
|
if c.Active {
|
||||||
c.ActiveStart = time.Now().Unix()
|
c.ActiveStart = time.Now().Unix()
|
||||||
} else {
|
} else {
|
||||||
@@ -222,6 +223,22 @@ func active(w http.ResponseWriter, r *http.Request) {
|
|||||||
rm.sendAdminEvent(&adminEvent{
|
rm.sendAdminEvent(&adminEvent{
|
||||||
Client: c,
|
Client: c,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if req.Solo {
|
||||||
|
for _, iter := range rm.clientById {
|
||||||
|
if iter == c {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if iter.Active {
|
||||||
|
iter.Active = false
|
||||||
|
iter.ActiveStart = 0
|
||||||
|
iter.update()
|
||||||
|
rm.sendAdminEvent(&adminEvent{
|
||||||
|
Client: iter,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func admin(w http.ResponseWriter, r *http.Request) {
|
func admin(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ tfoot tr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.admin,
|
.admin,
|
||||||
.active {
|
.active,
|
||||||
|
.solo {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
opacity: 0.3;
|
opacity: 0.3;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ function renderAdmin(roomId, adminSecret, prnt, es) {
|
|||||||
create(head1, "th", "Active Time");
|
create(head1, "th", "Active Time");
|
||||||
create(head1, "th", "👑");
|
create(head1, "th", "👑");
|
||||||
create(head1, "th", "👆");
|
create(head1, "th", "👆");
|
||||||
|
create(head1, "th", "🌟");
|
||||||
const body = create(table, "tbody");
|
const body = create(table, "tbody");
|
||||||
const rows = new Map();
|
const rows = new Map();
|
||||||
es.addEventListener("open", () => {
|
es.addEventListener("open", () => {
|
||||||
@@ -188,6 +189,7 @@ function renderAdmin(roomId, adminSecret, prnt, es) {
|
|||||||
}
|
}
|
||||||
row = document.createElement("tr");
|
row = document.createElement("tr");
|
||||||
row.dataset.name = client.name;
|
row.dataset.name = client.name;
|
||||||
|
row.dataset.active = client.active ? "active" : "";
|
||||||
row.dataset.activeStart = client.active_start;
|
row.dataset.activeStart = client.active_start;
|
||||||
let before = null;
|
let before = null;
|
||||||
for (const iter of body.children) {
|
for (const iter of body.children) {
|
||||||
@@ -211,9 +213,19 @@ function renderAdmin(roomId, adminSecret, prnt, es) {
|
|||||||
});
|
});
|
||||||
const activeCell = create(row, "td", "👆", client.active ? ["active", "enable"] : ["active"]);
|
const activeCell = create(row, "td", "👆", client.active ? ["active", "enable"] : ["active"]);
|
||||||
activeCell.addEventListener("click", () => {
|
activeCell.addEventListener("click", () => {
|
||||||
active(roomId, adminSecret, client.client_id, !activeCell.classList.contains("enable"));
|
active(roomId, adminSecret, client.client_id, !activeCell.classList.contains("enable"), false);
|
||||||
|
});
|
||||||
|
const soloCell = create(row, "td", "🌟", ["solo"]);
|
||||||
|
soloCell.addEventListener("click", () => {
|
||||||
|
if (soloCell.classList.contains("enable")) {
|
||||||
|
active(roomId, adminSecret, client.client_id, false, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
active(roomId, adminSecret, client.client_id, true, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
rows.set(client.client_id, row);
|
rows.set(client.client_id, row);
|
||||||
|
setSolo(rows);
|
||||||
});
|
});
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
@@ -227,12 +239,29 @@ function renderAdmin(roomId, adminSecret, prnt, es) {
|
|||||||
}
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
function active(roomId, adminSecret, clientId, val) {
|
function setSolo(rows) {
|
||||||
|
let activeCount = 0;
|
||||||
|
for (const row of rows.values()) {
|
||||||
|
if (row.dataset.active === "active") {
|
||||||
|
activeCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const row of rows.values()) {
|
||||||
|
if (activeCount === 1 && row.dataset.active === "active") {
|
||||||
|
row.children[4].classList.add("enable");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
row.children[4].classList.remove("enable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function active(roomId, adminSecret, clientId, val, solo) {
|
||||||
const req = {
|
const req = {
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
client_id: clientId,
|
client_id: clientId,
|
||||||
active: val,
|
active: val,
|
||||||
|
solo,
|
||||||
};
|
};
|
||||||
fetch("api/active", {
|
fetch("api/active", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ interface ActiveRequest {
|
|||||||
admin_secret: string;
|
admin_secret: string;
|
||||||
client_id: string;
|
client_id: string;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
|
solo: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AdminRequest {
|
interface AdminRequest {
|
||||||
@@ -267,6 +268,7 @@ function renderAdmin(roomId: string, adminSecret: string, prnt: HTMLElement, es:
|
|||||||
create(head1, "th", "Active Time");
|
create(head1, "th", "Active Time");
|
||||||
create(head1, "th", "👑");
|
create(head1, "th", "👑");
|
||||||
create(head1, "th", "👆");
|
create(head1, "th", "👆");
|
||||||
|
create(head1, "th", "🌟");
|
||||||
|
|
||||||
const body = create(table, "tbody");
|
const body = create(table, "tbody");
|
||||||
|
|
||||||
@@ -298,6 +300,7 @@ function renderAdmin(roomId: string, adminSecret: string, prnt: HTMLElement, es:
|
|||||||
|
|
||||||
row = document.createElement("tr") as HTMLTableRowElement;
|
row = document.createElement("tr") as HTMLTableRowElement;
|
||||||
row.dataset.name = client.name;
|
row.dataset.name = client.name;
|
||||||
|
row.dataset.active = client.active ? "active" : "";
|
||||||
row.dataset.activeStart = client.active_start;
|
row.dataset.activeStart = client.active_start;
|
||||||
|
|
||||||
let before = null;
|
let before = null;
|
||||||
@@ -325,10 +328,21 @@ function renderAdmin(roomId: string, adminSecret: string, prnt: HTMLElement, es:
|
|||||||
|
|
||||||
const activeCell = create(row, "td", "👆", client.active ? ["active", "enable"] : ["active"]) as HTMLTableCellElement;
|
const activeCell = create(row, "td", "👆", client.active ? ["active", "enable"] : ["active"]) as HTMLTableCellElement;
|
||||||
activeCell.addEventListener("click", () => {
|
activeCell.addEventListener("click", () => {
|
||||||
active(roomId, adminSecret, client.client_id, !activeCell.classList.contains("enable"));
|
active(roomId, adminSecret, client.client_id, !activeCell.classList.contains("enable"), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
const soloCell = create(row, "td", "🌟", ["solo"]) as HTMLTableCellElement;
|
||||||
|
soloCell.addEventListener("click", () => {
|
||||||
|
if (soloCell.classList.contains("enable")) {
|
||||||
|
active(roomId, adminSecret, client.client_id, false, false);
|
||||||
|
} else {
|
||||||
|
active(roomId, adminSecret, client.client_id, true, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
rows.set(client.client_id, row);
|
rows.set(client.client_id, row);
|
||||||
|
|
||||||
|
setSolo(rows);
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@@ -345,12 +359,31 @@ function renderAdmin(roomId: string, adminSecret: string, prnt: HTMLElement, es:
|
|||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
function active(roomId: string, adminSecret: string, clientId: string, val: boolean) {
|
function setSolo(rows: Map<string, HTMLTableRowElement>) {
|
||||||
|
let activeCount = 0;
|
||||||
|
|
||||||
|
for (const row of rows.values()) {
|
||||||
|
if (row.dataset.active === "active") {
|
||||||
|
activeCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const row of rows.values()) {
|
||||||
|
if (activeCount === 1 && row.dataset.active === "active") {
|
||||||
|
row.children[4].classList.add("enable");
|
||||||
|
} else {
|
||||||
|
row.children[4].classList.remove("enable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function active(roomId: string, adminSecret: string, clientId: string, val: boolean, solo: boolean) {
|
||||||
const req: ActiveRequest = {
|
const req: ActiveRequest = {
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
client_id: clientId,
|
client_id: clientId,
|
||||||
active: val,
|
active: val,
|
||||||
|
solo,
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch("api/active", {
|
fetch("api/active", {
|
||||||
|
|||||||
Reference in New Issue
Block a user