This commit is contained in:
2026-03-20 15:45:24 +07:00
parent 1ee888e929
commit d969ac594e
2 changed files with 72 additions and 18 deletions

View File

@@ -335,6 +335,14 @@
<textarea id="sqlEditor" class="flex-1 bg-slate-900 text-slate-300 p-4 font-mono text-sm resize-none outline-none" placeholder="-- Введите SQL запрос здесь
SELECT * FROM users LIMIT 10;"></textarea>
</div>
<div class="flex flex-wrap gap-2">
<button onclick="app.applySQLTemplate('select')" class="px-3 py-2 bg-slate-800 text-slate-200 rounded-lg text-xs">SELECT *</button>
<button onclick="app.applySQLTemplate('count')" class="px-3 py-2 bg-slate-800 text-slate-200 rounded-lg text-xs">COUNT rows</button>
<button onclick="app.applySQLTemplate('insert')" class="px-3 py-2 bg-slate-800 text-slate-200 rounded-lg text-xs">INSERT row</button>
<button onclick="app.applySQLTemplate('update')" class="px-3 py-2 bg-slate-800 text-slate-200 rounded-lg text-xs">UPDATE row</button>
<button onclick="app.applySQLTemplate('delete')" class="px-3 py-2 bg-slate-800 text-slate-200 rounded-lg text-xs">DELETE row</button>
<button onclick="app.applySQLTemplate('schema')" class="px-3 py-2 bg-slate-800 text-slate-200 rounded-lg text-xs">Describe table</button>
</div>
<div class="flex justify-end">
<button onclick="app.executeSQL()" class="flex items-center gap-2 px-6 py-2.5 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-medium transition-all shadow-lg shadow-blue-600/20">
<i data-lucide="play" class="w-4 h-4"></i>
@@ -1532,7 +1540,7 @@ SELECT * FROM users LIMIT 10;"></textarea>
fetch('/api/query', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', 'X-Request-Source': 'WEB' },
body: JSON.stringify({ sql })
})
.then(response => response.json())
@@ -1587,6 +1595,20 @@ SELECT * FROM users LIMIT 10;"></textarea>
editor.value = sql.trim();
}
applySQLTemplate(type) {
const table = this.currentTable || 'your_table';
const templates = {
select: `SELECT *\nFROM "${table}"\nLIMIT 50;`,
count: `SELECT COUNT(*) AS total\nFROM "${table}";`,
insert: `INSERT INTO "${table}" ("column_name")\nVALUES ('value')\nRETURNING *;`,
update: `UPDATE "${table}"\nSET "column_name" = 'value'\nWHERE "id" = 'your-id'\nRETURNING *;`,
delete: `DELETE FROM "${table}"\nWHERE "id" = 'your-id'\nRETURNING *;`,
schema: `SELECT column_name, data_type, is_nullable, column_default\nFROM information_schema.columns\nWHERE table_schema = 'public' AND table_name = '${table}'\nORDER BY ordinal_position;`,
};
document.getElementById('sqlEditor').value = templates[type] || '';
}
clearSQL() {
document.getElementById('sqlEditor').value = '';
document.getElementById('sqlResults').classList.add('hidden');
@@ -1801,7 +1823,7 @@ SELECT * FROM users LIMIT 10;"></textarea>
disabled: document.getElementById('userDisabled').checked,
access: {
view: { folders: this.getCheckedValues('userViewFoldersList'), tables: [] },
create: { folders: [], tables: [] },
create: { folders: this.getCheckedValues('userViewFoldersList'), tables: [] },
edit: { folders: [], tables: this.getCheckedValues('userEditTablesList') },
delete: { folders: this.getCheckedValues('userDeleteFoldersList'), tables: [] },
},
@@ -1897,10 +1919,11 @@ SELECT * FROM users LIMIT 10;"></textarea>
? entries.map(entry => `
<div class="border border-slate-200 rounded-xl p-4">
<div class="flex items-center justify-between gap-4">
<div class="font-medium text-slate-800">${entry.event}</div>
<div class="font-medium text-slate-800">${entry.summary || entry.event}</div>
<div class="text-xs text-slate-500">${entry.timestamp}</div>
</div>
<div class="text-sm text-slate-600 mt-1">Actor: ${entry.actor}</div>
<div class="text-sm text-slate-600 mt-1">Who: ${entry.actor} · Source: ${entry.source || 'WEB'}</div>
<div class="text-xs text-slate-500 mt-2">${entry.event}</div>
<pre class="mt-3 text-xs bg-slate-50 rounded-lg p-3 overflow-auto">${JSON.stringify(entry.details, null, 2)}</pre>
</div>
`).join('')