Commit 159099af authored by Vũ Hoàng Anh's avatar Vũ Hoàng Anh

fix(sqlite): backfill description_data_full & fix manage_prompt UI

parent 981784ff
...@@ -740,8 +740,8 @@ body { ...@@ -740,8 +740,8 @@ body {
.diff-output-side { .diff-output-side {
display: grid; display: grid;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
height: 100%; min-height: 300px;
min-height: 0; height: 55vh;
} }
.diff-pane { .diff-pane {
display: flex; display: flex;
...@@ -773,7 +773,8 @@ body { ...@@ -773,7 +773,8 @@ body {
.diff-output-unified { .diff-output-unified {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%; min-height: 300px;
height: 55vh;
} }
.diff-unified-header { .diff-unified-header {
padding: 10px 16px; padding: 10px 16px;
......
...@@ -354,34 +354,74 @@ let diffViewMode = 'side'; // 'side' | 'unified' ...@@ -354,34 +354,74 @@ let diffViewMode = 'side'; // 'side' | 'unified'
let lastDiffData = null; // cache for view toggle let lastDiffData = null; // cache for view toggle
async function openDiffModal(moduleName) { async function openDiffModal(moduleName) {
const mod = modules.find(m => m.module_name === moduleName); try {
if (!mod || !mod.dev || !mod.production) return; const mod = modules.find(m => m.module_name === moduleName);
if (!mod || !mod.dev || !mod.production) {
toast('Module không có cả DEV và PRODUCTION để so sánh', 'error');
return;
}
document.getElementById('diff-title').textContent = `So sánh: ${moduleName}`; document.getElementById('diff-title').textContent = `So sánh: ${moduleName}`;
document.getElementById('btn-promote-modal').onclick = () => { document.getElementById('btn-promote-modal').onclick = () => {
closeDiffModal(); closeDiffModal();
promoteVersion(mod.dev.id, moduleName); promoteVersion(mod.dev.id, moduleName);
}; };
const [devC, prodC] = await Promise.all([ const [devC, prodC] = await Promise.all([
fetchContent(mod.dev.id), fetchContent(mod.dev.id),
fetchContent(mod.production.id), fetchContent(mod.production.id),
]); ]);
const devText = devC || ''; const devText = devC || '';
const prodText = prodC || ''; const prodText = prodC || '';
// Compute diff using jsdiff // Compute diff — use jsdiff if available, else fallback
const changes = Diff.diffLines(devText, prodText); let changes;
lastDiffData = { changes, devText, prodText, devV: mod.dev.version, prodV: mod.production.version }; if (typeof Diff !== 'undefined' && Diff.diffLines) {
changes = Diff.diffLines(devText, prodText);
} else {
console.warn('jsdiff not loaded, using fallback diff');
changes = fallbackDiff(devText, prodText);
}
// Update char counts lastDiffData = { changes, devText, prodText, devV: mod.dev.version, prodV: mod.production.version };
document.getElementById('ds-dev-chars').textContent = devText.length.toLocaleString();
document.getElementById('ds-prod-chars').textContent = prodText.length.toLocaleString();
renderDiff(); // Update char counts
document.getElementById('diff-modal').classList.add('open'); document.getElementById('ds-dev-chars').textContent = devText.length.toLocaleString();
lucide.createIcons(); document.getElementById('ds-prod-chars').textContent = prodText.length.toLocaleString();
renderDiff();
document.getElementById('diff-modal').classList.add('open');
lucide.createIcons();
} catch (err) {
console.error('Diff modal error:', err);
toast('❌ Lỗi mở Compare: ' + err.message, 'error');
}
}
// Fallback diff when jsdiff CDN fails
function fallbackDiff(oldText, newText) {
const oldLines = oldText.split('\n');
const newLines = newText.split('\n');
const result = [];
const maxLen = Math.max(oldLines.length, newLines.length);
for (let i = 0; i < maxLen; i++) {
const ol = oldLines[i];
const nl = newLines[i];
if (ol === nl) {
result.push({ value: ol + '\n', added: false, removed: false });
} else {
if (ol !== undefined) {
result.push({ value: ol + '\n', added: false, removed: true });
}
if (nl !== undefined) {
result.push({ value: nl + '\n', added: true, removed: false });
}
}
}
return result;
} }
function setDiffView(mode) { function setDiffView(mode) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment