mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
improve control main display structure
This commit is contained in:
@@ -55,10 +55,10 @@
|
|||||||
const mac = text_inputs_valid.mac.value === '' ? null : text_inputs_valid.mac.value;
|
const mac = text_inputs_valid.mac.value === '' ? null : text_inputs_valid.mac.value;
|
||||||
const name = text_inputs_valid.name.value;
|
const name = text_inputs_valid.name.value;
|
||||||
if (!!existing_display_id) {
|
if (!!existing_display_id) {
|
||||||
edit_display_data(existing_display_id, ip, mac, name);
|
await edit_display_data(existing_display_id, ip, mac, name);
|
||||||
} else {
|
} else {
|
||||||
const status = await ping_ip(text_inputs_valid.ip.value);
|
const status = await ping_ip(text_inputs_valid.ip.value);
|
||||||
add_display(ip, mac, name, status);
|
await add_display(ip, mac, name, status);
|
||||||
}
|
}
|
||||||
popup_close_function();
|
popup_close_function();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,32 @@
|
|||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
import { displays, update_displays_with_map } from "./stores/displays"
|
import { displays, run_on_all_selected_displays, update_displays_with_map, update_screenshot } from "./stores/displays"
|
||||||
import { ping_ip } from "./api_handler";
|
import { ping_ip } from "./api_handler";
|
||||||
import type { Display } from "./types";
|
import type { Display } from "./types";
|
||||||
import { change_file_path, update_all_display_files } from "./stores/files";
|
import { change_file_path, update_folder_elements_recursively } from "./stores/files";
|
||||||
|
|
||||||
const update_display_status_interval_seconds = 20;
|
const update_display_status_interval_seconds = 20;
|
||||||
|
|
||||||
export function on_start() {
|
export async function on_start() {
|
||||||
update_all_display_status();
|
await update_all_display_status();
|
||||||
setInterval(update_all_display_status, update_display_status_interval_seconds * 1000);
|
await setInterval(update_all_display_status, update_display_status_interval_seconds * 1000);
|
||||||
update_all_display_files('/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function update_all_display_status() {
|
async function update_all_display_status() {
|
||||||
update_displays_with_map(async (display: Display) => {
|
await update_displays_with_map(async (display: Display) => {
|
||||||
const new_status = await ping_ip(display.ip);
|
const new_status = await ping_ip(display.ip);
|
||||||
if (new_status === null && display.status !== null) return display;
|
if (new_status === null && display.status !== null) return display;
|
||||||
|
if (new_status === "app_online" && display.status !== "app_online") {
|
||||||
|
await on_display_start(display);
|
||||||
|
}
|
||||||
return { ...display, status: new_status, };
|
return { ...display, status: new_status, };
|
||||||
});
|
});
|
||||||
console.log("Display Status updated")
|
console.log("Display Status updated")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function on_display_start(display: Display) {
|
||||||
|
await update_folder_elements_recursively(display, '/');
|
||||||
|
await update_screenshot(display.id);
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ import type { Display, DisplayGroup, DisplayStatus } from "../types";
|
|||||||
import { is_selected, select, selected_display_ids } from "./select";
|
import { is_selected, select, selected_display_ids } from "./select";
|
||||||
import { get_uuid, image_content_hash } from "../utils";
|
import { get_uuid, image_content_hash } from "../utils";
|
||||||
import { get_screenshot } from "../api_handler";
|
import { get_screenshot } from "../api_handler";
|
||||||
import DisplayGroupObject from "../../components/DisplayGroupObject.svelte";
|
|
||||||
|
|
||||||
export const displays: Writable<DisplayGroup[]> = writable<DisplayGroup[]>([{
|
export const displays: Writable<DisplayGroup[]> = writable<DisplayGroup[]>([{
|
||||||
id: get_uuid(),
|
id: get_uuid(),
|
||||||
@@ -25,8 +24,8 @@ export function add_display(ip: string, mac: string | null, name: string, status
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function edit_display_data(display_id: string, ip: string, mac: string | null, name: string) {
|
export async function edit_display_data(display_id: string, ip: string, mac: string | null, name: string) {
|
||||||
update_displays_with_map((display: Display) => {
|
await update_displays_with_map((display: Display) => {
|
||||||
if (display.id !== display_id) return display;
|
if (display.id !== display_id) return display;
|
||||||
return { ...display, ip: ip, mac: mac, name: name };
|
return { ...display, ip: ip, mac: mac, name: name };
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export function get_display_ids_where_file_is_missing(path: string, file: Folder
|
|||||||
return [missing, colliding];
|
return [missing, colliding];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_changed_directory_paths(display: Display, file_path: string): Promise<string[] | null> {
|
async function get_changed_directory_paths(display: Display, file_path: string): Promise<string[] | null> {
|
||||||
const current_folder = await get_file_tree_data(display.ip, file_path);
|
const current_folder = await get_file_tree_data(display.ip, file_path);
|
||||||
if (current_folder === null) return null;
|
if (current_folder === null) return null;
|
||||||
const directory_strings = get_recursive_changed_directory_paths(display, file_path, current_folder, get(all_files));
|
const directory_strings = get_recursive_changed_directory_paths(display, file_path, current_folder, get(all_files));
|
||||||
@@ -100,15 +100,7 @@ function get_recursive_changed_directory_paths(display: Display, current_file_pa
|
|||||||
return has_changed;
|
return has_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function update_all_display_files(path: string) {
|
export async function update_folder_elements_recursively(display: Display, file_path: string = '/'): Promise<number> {
|
||||||
for (const display_group of get(displays)) {
|
|
||||||
for (const display of display_group.data) {
|
|
||||||
await update_folder_elements_recursively(display, path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function update_folder_elements_recursively(display: Display, file_path: string = '/'): Promise<number> {
|
|
||||||
const new_folder_elements = await get_file_data(display.ip, file_path);
|
const new_folder_elements = await get_file_data(display.ip, file_path);
|
||||||
all_files.update((files: Record<string, Record<string, FolderElement[]>>) => {
|
all_files.update((files: Record<string, Record<string, FolderElement[]>>) => {
|
||||||
if (!files.hasOwnProperty(file_path)) {
|
if (!files.hasOwnProperty(file_path)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user