fix(ui): 도면(3면도) 팝업이 about:blank로 열리던 것을 전용 뷰어 페이지로 교체
drawing-viewer.html이 /api/cad/render를 직접 호출해 표시(제목·주소 정상, 확대/PNG 저장/다시 생성). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f5652d63d9
commit
b1f7ba3ed0
3 files changed
+87
-28
No files matched your search
@@ -0,0 +1,76 @@
|
||||
<!doctype html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>도면</title>
|
||||
<style>
|
||||
:root{--bg:#1d1d1f;--bar:#2a2a2d;--fg:#eee;--mut:#9a9aa0;--acc:#f59e0b}
|
||||
*{box-sizing:border-box}
|
||||
html,body{margin:0;height:100%;background:var(--bg);color:var(--fg);font-family:system-ui,'Noto Sans KR',sans-serif}
|
||||
#bar{position:fixed;top:0;left:0;right:0;height:42px;background:var(--bar);display:flex;align-items:center;gap:10px;padding:0 14px;z-index:2;border-bottom:1px solid #000}
|
||||
#bar b{font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:55vw}
|
||||
#bar .sp{flex:1}
|
||||
button,a.btn{background:#3a3a3f;color:var(--fg);border:1px solid #4a4a50;border-radius:6px;padding:5px 10px;font-size:13px;cursor:pointer;text-decoration:none}
|
||||
button:hover,a.btn:hover{border-color:var(--acc)}
|
||||
#st{color:var(--mut);font-size:12px}
|
||||
#wrap{position:absolute;top:42px;left:0;right:0;bottom:0;overflow:auto;display:flex;align-items:flex-start;justify-content:center}
|
||||
#wrap.fit{align-items:center}
|
||||
img{display:block;max-width:100%;max-height:100%;object-fit:contain;background:#fff}
|
||||
#wrap:not(.fit) img{max-width:none;max-height:none}
|
||||
#msg{margin:auto;color:var(--mut);font-size:15px;text-align:center;padding:30px}
|
||||
#msg.err{color:#ef4444}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="bar">
|
||||
<b id="ttl">📐 도면</b><span id="st"></span><span class="sp"></span>
|
||||
<button id="b-fit" type="button">원본 크기</button>
|
||||
<button id="b-reload" type="button">다시 생성</button>
|
||||
<a class="btn" id="b-dl" download="drawing.png" style="display:none">PNG 저장</a>
|
||||
</div>
|
||||
<div id="wrap" class="fit"><div id="msg">📐 도면 생성 중… (몇 초 걸립니다)</div></div>
|
||||
<script>
|
||||
(function(){
|
||||
const q=new URLSearchParams(location.search);
|
||||
const path=q.get('path')||'';
|
||||
const view=q.get('view')||'three';
|
||||
const name=(path.split('/').pop()||path).replace(/\.stl$/i,'');
|
||||
const wrap=document.getElementById('wrap'), ttl=document.getElementById('ttl'), st=document.getElementById('st');
|
||||
const bFit=document.getElementById('b-fit'), bDl=document.getElementById('b-dl');
|
||||
document.title='도면 — '+name;
|
||||
ttl.textContent='📐 '+name;
|
||||
function authH(){let t='';try{t=sessionStorage.getItem('smallclaw_token')||localStorage.getItem('smallclaw_token')||'';}catch(e){}return t?{Authorization:'Bearer '+t}:{};}
|
||||
let url='';
|
||||
async function load(){
|
||||
wrap.className='fit';wrap.innerHTML='<div id="msg">📐 도면 생성 중… (몇 초 걸립니다)</div>';
|
||||
bDl.style.display='none';st.textContent='';
|
||||
if(!path){wrap.innerHTML='<div id="msg" class="err">path 파라미터가 없습니다.</div>';return;}
|
||||
const t0=Date.now();
|
||||
try{
|
||||
const r=await fetch('/api/cad/render?path='+encodeURIComponent(path)+'&view='+encodeURIComponent(view),{headers:authH()});
|
||||
if(!r.ok){const d=await r.json().catch(()=>({}));throw new Error(d.error||('HTTP '+r.status));}
|
||||
if(url)URL.revokeObjectURL(url);
|
||||
url=URL.createObjectURL(await r.blob());
|
||||
wrap.innerHTML='';
|
||||
const img=document.createElement('img');img.src=url;img.alt=name;
|
||||
img.onclick=toggle;img.style.cursor='zoom-in';
|
||||
wrap.appendChild(img);
|
||||
bDl.href=url;bDl.download='도면_'+name+'.png';bDl.style.display='';
|
||||
st.textContent=((Date.now()-t0)/1000).toFixed(1)+'초';
|
||||
}catch(e){
|
||||
wrap.innerHTML='';const m=document.createElement('div');m.id='msg';m.className='err';m.textContent='도면 생성 실패: '+e.message;wrap.appendChild(m);
|
||||
}
|
||||
}
|
||||
function toggle(){
|
||||
const fit=wrap.classList.toggle('fit');
|
||||
bFit.textContent=fit?'원본 크기':'화면 맞춤';
|
||||
const img=wrap.querySelector('img');if(img)img.style.cursor=fit?'zoom-in':'zoom-out';
|
||||
}
|
||||
bFit.onclick=toggle;
|
||||
document.getElementById('b-reload').onclick=load;
|
||||
load();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -187,25 +187,11 @@ function openDrawingForFile(relPath){
|
||||
if(!workspacePath)return;
|
||||
const w=1100,h=940;
|
||||
const left=Math.max(0,(screen.width-w)/2), top=Math.max(0,(screen.height-h)/2);
|
||||
const win=window.open('','cad-drawing',`width=${w},height=${h},left=${left},top=${top},menubar=no,toolbar=no,location=no,status=no,resizable=yes`);
|
||||
if(!win){alert('팝업이 차단됐습니다. 팝업 허용 후 다시 시도하세요.');return;}
|
||||
win.document.write('<!doctype html><html><head><meta charset="utf-8"><title>도면 생성 중…</title></head><body style="margin:0;font-family:sans-serif;background:#1a1a1a;color:#eee;display:flex;align-items:center;justify-content:center;height:100vh">📐 도면 생성 중… (OpenSCAD 3면도, 몇 초 걸림)</body></html>');
|
||||
(async()=>{
|
||||
try{
|
||||
const r=await fetch('/api/cad/render?path='+encodeURIComponent(workspacePath)+'&view=three',{headers:authH()});
|
||||
if(!r.ok){const d=await r.json().catch(()=>({}));throw new Error(d.error||('HTTP '+r.status));}
|
||||
const url=URL.createObjectURL(await r.blob());
|
||||
win.document.title='3면도';
|
||||
win.document.body.style.cssText='margin:0;background:#2a2a2a;display:flex;align-items:center;justify-content:center;height:100vh';
|
||||
win.document.body.innerHTML='';
|
||||
const img=win.document.createElement('img');
|
||||
img.src=url;img.style.cssText='max-width:100%;max-height:100%;object-fit:contain;';
|
||||
win.document.body.appendChild(img);
|
||||
}catch(e){
|
||||
win.document.body.style.cssText='margin:0;font-family:sans-serif;background:#1a1a1a;color:#ef4444;display:flex;align-items:center;justify-content:center;height:100vh';
|
||||
win.document.body.textContent='도면 생성 실패: '+e.message;
|
||||
}
|
||||
})();
|
||||
// 전용 뷰어 페이지(/html/drawing-viewer.html)로 연다 — about:blank 팝업이면 주소/사이트 정보가 about:blank로 나왔다(10-10).
|
||||
// 뷰어가 직접 /api/cad/render를 호출해 도면을 받아 표시한다(생성 중 표시·확대·PNG 저장·다시 생성).
|
||||
const url='/html/drawing-viewer.html?path='+encodeURIComponent(workspacePath)+'&view=three';
|
||||
const win=window.open(url,'cad-drawing',`width=${w},height=${h},left=${left},top=${top},menubar=no,toolbar=no,location=yes,status=no,resizable=yes`);
|
||||
if(!win){alert('팝업이 차단됐습니다. 팝업 허용 후 다시 시도하세요.');}
|
||||
}
|
||||
|
||||
// ── 슬라이서 연동(09-22) ────────────────────────────────────────────────────
|
||||
|
||||
@@ -494,17 +494,14 @@
|
||||
// ── 도면(3면도) ───────────────────────────────────────────────────────
|
||||
// 선택된 STL의 제작용 3면도(외곽 치수선)를 서버(OpenSCAD)에서 생성해 새 탭으로 연다.
|
||||
// /api/cad/render는 Authorization 헤더가 필요하므로 fetch→blob→objectURL.
|
||||
async function openDrawing() {
|
||||
function openDrawing() {
|
||||
const p = panelEl.querySelector('#ce-file').value;
|
||||
if (!p) { setErr('파일을 먼저 선택하세요.'); return; }
|
||||
setErr(''); setInfo('📐 도면 생성 중… (OpenSCAD 3면도, 몇 초 걸림)');
|
||||
try {
|
||||
const r = await fetch('/api/cad/render?path=' + encodeURIComponent(p) + '&view=three', { headers: authH() });
|
||||
if (!r.ok) { const d = await r.json().catch(() => ({})); throw new Error(d.error || ('HTTP ' + r.status)); }
|
||||
const url = URL.createObjectURL(await r.blob());
|
||||
window.open(url, '_blank');
|
||||
setInfo('📐 3면도를 새 탭으로 열었습니다.');
|
||||
} catch (e) { setErr('도면 생성 실패: ' + e.message); }
|
||||
setErr('');
|
||||
// 전용 뷰어 페이지로 연다(제목/주소가 about:blank·blob:으로 나오던 문제, 10-10).
|
||||
const win = window.open('/html/drawing-viewer.html?path=' + encodeURIComponent(p) + '&view=three', '_blank');
|
||||
if (!win) { setErr('팝업이 차단됐습니다. 팝업 허용 후 다시 시도하세요.'); return; }
|
||||
setInfo('📐 도면을 새 탭으로 열었습니다.');
|
||||
}
|
||||
|
||||
// ── UI 구축 ───────────────────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user