작업실에 PCB 탭 — 작업실 프로젝트에 연결된 PCB 프로젝트를 iframe으로
- PCB 프로젝트 목록(`/api/pcb/projects`)에 workshopId를 포함(project.json의 workshopId). - 작업실 화면에 "🔌 PCB" 탭: 이 작업실 프로젝트와 workshopId가 같은 PCB 프로젝트가 있으면 그걸(`?p=`), 없으면 마지막으로 연 것을 pcb-app.html로 띄운다. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
73f0c89a98
commit
5c972b70c4
3 files changed
+22
-4
No files matched your search
@@ -23,17 +23,17 @@ export class PcbProjects {
|
||||
return d;
|
||||
}
|
||||
|
||||
list(): { name: string; updated: number; parts: number; nets: number; routed: boolean; gcode: boolean }[] {
|
||||
list(): { name: string; updated: number; parts: number; nets: number; routed: boolean; gcode: boolean; workshopId: string }[] {
|
||||
if (!fs.existsSync(this.root)) return [];
|
||||
const out = [];
|
||||
for (const e of fs.readdirSync(this.root, { withFileTypes: true })) {
|
||||
if (!e.isDirectory() || e.name.startsWith('.')) continue;
|
||||
const f = path.join(this.root, e.name, 'project.json');
|
||||
if (!fs.existsSync(f)) continue;
|
||||
let parts = 0, nets = 0, routed = false;
|
||||
try { const j = JSON.parse(fs.readFileSync(f, 'utf8')); parts = j.parts?.length || 0; nets = j.nets?.length || 0; routed = !!(j.routed && j.routed.traces?.length); } catch { /* 깨진 파일은 목록에서 0으로 */ }
|
||||
let parts = 0, nets = 0, routed = false, workshopId = '';
|
||||
try { const j = JSON.parse(fs.readFileSync(f, 'utf8')); parts = j.parts?.length || 0; nets = j.nets?.length || 0; routed = !!(j.routed && j.routed.traces?.length); workshopId = String(j.workshopId || ''); } catch { /* 깨진 파일은 목록에서 0으로 */ }
|
||||
const g = path.join(this.root, e.name, 'gcode');
|
||||
out.push({ name: e.name, updated: fs.statSync(f).mtimeMs, parts, nets, routed, gcode: fs.existsSync(g) && fs.readdirSync(g).length > 0 });
|
||||
out.push({ name: e.name, updated: fs.statSync(f).mtimeMs, parts, nets, routed, workshopId, gcode: fs.existsSync(g) && fs.readdirSync(g).length > 0 });
|
||||
}
|
||||
return out.sort((a, b) => b.updated - a.updated);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
<div class="rb-main">
|
||||
<div class="rb-tabs">
|
||||
<button class="rb-tab-btn active" data-tab="parts" onclick="switchTab('parts')">부품</button>
|
||||
<button class="rb-tab-btn" data-tab="pcb" onclick="switchTab('pcb')">🔌 PCB</button>
|
||||
<button class="rb-tab-btn" data-tab="tasks" onclick="switchTab('tasks')">작업</button>
|
||||
<button class="rb-tab-btn" data-tab="assembly" onclick="switchTab('assembly')">조립</button>
|
||||
<button class="rb-tab-btn" data-tab="equip" onclick="switchTab('equip')">장비</button>
|
||||
@@ -92,6 +93,8 @@
|
||||
|
||||
<div class="rb-pane" id="pane-assembly"></div>
|
||||
|
||||
<div class="rb-pane" id="pane-pcb"></div>
|
||||
|
||||
<div class="rb-pane" id="pane-equip">
|
||||
<div class="rb-equip-grid">
|
||||
<div class="rb-equip-card">
|
||||
|
||||
@@ -463,6 +463,20 @@ function showSaveIndicator(msg){
|
||||
saveTimer=setTimeout(()=>{el.textContent='';},2000);
|
||||
}
|
||||
|
||||
// PCB 탭: PCB 앱을 iframe으로 띄운다. 이 작업실 프로젝트에 연결된(workshopId) PCB 프로젝트가 있으면 그걸, 없으면 마지막으로 연 것을 연다.
|
||||
let pcbPaneFor='';
|
||||
async function loadPcbPane(){
|
||||
const pane=document.getElementById('pane-pcb'),proj=currentProject();
|
||||
if(!pane||!proj||pcbPaneFor===proj.id)return;
|
||||
let q='';
|
||||
try{
|
||||
const r=await fetch('/api/pcb/projects',{headers:authH()});
|
||||
if(r.ok){const m=((await r.json()).projects||[]).find(x=>x.workshopId===proj.id);if(m)q='?p='+encodeURIComponent(m.name);}
|
||||
}catch(e){}
|
||||
pcbPaneFor=proj.id;
|
||||
pane.innerHTML='<iframe src="/html/pcb-app.html'+q+'" style="width:100%;height:calc(100vh - 140px);border:0" title="PCB"></iframe>';
|
||||
}
|
||||
|
||||
// ── Tabs ──────────────────────────────────────────────────────────────────────
|
||||
function switchTab(tab){
|
||||
document.querySelectorAll('.rb-tab-btn').forEach(b=>b.classList.toggle('active',b.dataset.tab===tab));
|
||||
@@ -473,6 +487,7 @@ function switchTab(tab){
|
||||
else if(typeof stopEquipTimers==='function')stopEquipTimers();
|
||||
if(tab==='files')loadFiles();
|
||||
if(tab==='assembly')refreshAssemblyPane(true);
|
||||
if(tab==='pcb')loadPcbPane();
|
||||
// 콘솔 탭(지연 로딩 workshop-console.js): 열 때 터미널 준비, 나갈 때는 세션을 유지한 채 숨김
|
||||
if(tab==='console')withLazyModule('console','pane-console',()=>openConsole());
|
||||
else if(typeof closeConsoleTab==='function')closeConsoleTab();
|
||||
|
||||
Reference in new issue
Block a user