From a71d420a5f1ab2df43a91a82da135a5560a9cba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Mon, 11 May 2026 23:27:54 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20frontend=20workspace=20engine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/workspace.js | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 frontend/workspace.js diff --git a/frontend/workspace.js b/frontend/workspace.js new file mode 100644 index 0000000..6f2b82c --- /dev/null +++ b/frontend/workspace.js @@ -0,0 +1,70 @@ +async function workspaceApi(url, payload = {}) { + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(payload) + }); + + return await response.json(); +} + +async function loadWorkspaceTree() { + const workspace = document.getElementById('workspacePath').value; + + const data = await workspaceApi('/api/files/tree', { + path: workspace + }); + + renderTree(data.tree || []); +} + +function renderTree(tree, level = 0) { + const container = document.getElementById('fileTree'); + + if (level === 0) { + container.innerHTML = ''; + } + + tree.forEach(node => { + const item = document.createElement('div'); + + item.className = 'tree-node'; + item.style.paddingLeft = `${level * 16}px`; + + if (node.type === 'directory') { + item.innerHTML = `📁 ${node.name}`; + container.appendChild(item); + + renderTree(node.children || [], level + 1); + } else { + item.innerHTML = `📄 ${node.name}`; + item.onclick = () => openFile(node.path); + container.appendChild(item); + } + }); +} + +async function openFile(path) { + const data = await workspaceApi('/api/files/read', { + path + }); + + document.getElementById('editorPath').innerText = path; + document.getElementById('editor').value = data.content || ''; +} + +async function saveCurrentFile() { + const path = document.getElementById('editorPath').innerText; + const content = document.getElementById('editor').value; + + const data = await workspaceApi('/api/files/save', { + path, + content + }); + + document.getElementById('editorStatus').innerText = data.success + ? 'Файл сохранен' + : 'Ошибка сохранения'; +}