97 lines
3.5 KiB
JavaScript
97 lines
3.5 KiB
JavaScript
/**
|
|
* STMATE w 8.0 — 구버전(DOS·7.x) → Win8 자료 변환 끼워 넣기 (scr_win8.js) · 1번(파일) 메뉴
|
|
* 원본: ST_U_Convert ST_ConvToWin8 · 판 가리기 ST_U_Archive Chk_STDir
|
|
* 서버: api_conv.py /api/conv/win8-check · /api/conv/win8 — 결과는 work_dbf/<이름>/ 와 STC
|
|
*/
|
|
(function (global) {
|
|
"use strict";
|
|
|
|
const PLUG = (global.STMATE_PLUGINS = global.STMATE_PLUGINS || {
|
|
screens: {},
|
|
actions: {},
|
|
menus: [],
|
|
});
|
|
const app = () => global.STMATE_APP;
|
|
|
|
async function req(url, body) {
|
|
const res = await fetch(url, {
|
|
method: body === undefined ? "GET" : "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
});
|
|
if (!res.ok) throw new Error(await res.text());
|
|
return res.json();
|
|
}
|
|
|
|
// 구버전 폴더 고르기 → {이름: base64}
|
|
function pickFolder() {
|
|
return new Promise((resolve, reject) => {
|
|
const inp = document.createElement("input");
|
|
inp.type = "file";
|
|
inp.webkitdirectory = true;
|
|
inp.multiple = true;
|
|
inp.onchange = async () => {
|
|
const list = Array.from(inp.files || []).filter(
|
|
(f) => (f.webkitRelativePath || f.name).split("/").length <= 2,
|
|
);
|
|
if (!list.length) return reject(new Error("폴더를 고르지 않음"));
|
|
const out = {};
|
|
for (const f of list)
|
|
out[f.name] = await new Promise((ok, no) => {
|
|
const rd = new FileReader();
|
|
rd.onload = () => ok(String(rd.result));
|
|
rd.onerror = () => no(rd.error);
|
|
rd.readAsDataURL(f);
|
|
});
|
|
resolve(out);
|
|
};
|
|
inp.click();
|
|
});
|
|
}
|
|
|
|
async function openSaved(path) {
|
|
const a = app();
|
|
const src = await req("/api/sources");
|
|
if (src && src.projects) a.ctx.sourcesData = src;
|
|
const sel = document.getElementById("top-project-select");
|
|
if (sel && src && src.projects)
|
|
sel.innerHTML = src.projects
|
|
.map((p) => `<option value="${p.path}">${p.name}</option>`)
|
|
.join("");
|
|
await a.loadProjectFromServer(path, "wPrjList");
|
|
}
|
|
|
|
async function convert() {
|
|
const ctx = app().ctx;
|
|
if (!ctx.currentSourcePath)
|
|
throw new Error("틀로 쓸 Win8 프로젝트를 먼저 불러오세요(요율·서식·설정).");
|
|
const files = await pickFolder();
|
|
const chk = await req("/api/conv/win8-check", { files });
|
|
if (!/DOS|7\.x/.test(chk.kind)) {
|
|
alert(`[구버전 자료 변환] 판 ${chk.version} — ${chk.kind}`);
|
|
return;
|
|
}
|
|
if (!confirm(`${chk.kind} 자료(판 ${chk.version})를 Win8 자료로 변환할까요?`)) return;
|
|
const r = await req("/api/conv/win8", { files, template_path: ctx.currentSourcePath });
|
|
const rp = r.report;
|
|
const bx = Object.entries(rp.b_to_x || {});
|
|
alert(
|
|
`[구버전 자료 변환] ${rp.kind} → ${rp.pname}\n코드 ${rp.costn_count} · 구성 ${rp.bdqty_count} · ` +
|
|
`공사 ${rp.prj_count} · 내역표 ${rp.boq_tables.join(", ")}` +
|
|
(bx.length ? `\n중기 B→X: ${bx.map(([a, b]) => `${a}→${b}`).join(" ")}` : "") +
|
|
(rp.notes.length ? `\n\n[알림]\n${rp.notes.join("\n")}` : "") +
|
|
`\n\n[틀 값 유지 · 원본 규칙 미확인]\n${rp.unmapped.join("\n")}`,
|
|
);
|
|
await openSaved(r.saved_dir);
|
|
}
|
|
|
|
PLUG.actions.Act_ConvWin8 = async () => {
|
|
try {
|
|
await convert();
|
|
} catch (err) {
|
|
alert("변환 실패: " + err.message);
|
|
}
|
|
};
|
|
PLUG.menus.push({ menu: "m1", label: "구버전 자료 변환 (ST_ConvToWin8)", act: "Act_ConvWin8" });
|
|
})(window);
|