200 lines
9.2 KiB
HTML
200 lines
9.2 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Тест интеграции истории AI Drawer</title>
|
||
<style>
|
||
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
|
||
.container { max-width: 1000px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; }
|
||
.test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
|
||
.button { background: #007bff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin: 5px; }
|
||
.button:hover { background: #0056b3; }
|
||
.button.secondary { background: #6c757d; }
|
||
.log { background: #f8f9fa; padding: 15px; border-radius: 5px; margin: 10px 0; font-family: monospace; max-height: 300px; overflow-y: auto; }
|
||
.status { padding: 10px; border-radius: 5px; margin: 10px 0; font-weight: bold; }
|
||
.success { background: #d4edda; color: #155724; }
|
||
.error { background: #f8d7da; color: #721c24; }
|
||
.info { background: #d1ecf1; color: #0c5460; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<h1>🧪 Тест интеграции истории AI Drawer</h1>
|
||
|
||
<div class="test-section">
|
||
<h3>1. Тест с реальными данными (есть история)</h3>
|
||
<button class="button" onclick="testRealData()">Тест с projectId: 82823</button>
|
||
<div id="real-result" class="log"></div>
|
||
</div>
|
||
|
||
<div class="test-section">
|
||
<h3>2. Тест с фейковыми данными (нет истории)</h3>
|
||
<button class="button" onclick="testFakeData()">Тест с projectId: 999999</button>
|
||
<div id="fake-result" class="log"></div>
|
||
</div>
|
||
|
||
<div class="test-section">
|
||
<h3>3. Тест AI Drawer с историей</h3>
|
||
<button class="button" onclick="openAIDrawerReal()">Открыть AI Drawer (реальные данные)</button>
|
||
<button class="button secondary" onclick="openAIDrawerFake()">Открыть AI Drawer (фейковые данные)</button>
|
||
<button class="button secondary" onclick="closeAIDrawer()">Закрыть AI Drawer</button>
|
||
</div>
|
||
|
||
<div class="test-section">
|
||
<h3>4. Логи</h3>
|
||
<button class="button secondary" onclick="clearLogs()">Очистить логи</button>
|
||
<div id="logs" class="log"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Подключаем AI Drawer -->
|
||
<link rel="stylesheet" href="layouts/v7/resources/css/ai-drawer.css">
|
||
<script src="layouts/v7/resources/js/ai-drawer.js"></script>
|
||
|
||
<script>
|
||
let aiDrawerInstance;
|
||
|
||
function log(message, type = 'info') {
|
||
const timestamp = new Date().toLocaleTimeString();
|
||
const logDiv = document.getElementById('logs');
|
||
const entry = document.createElement('div');
|
||
entry.className = `status ${type}`;
|
||
entry.textContent = `[${timestamp}] ${message}`;
|
||
logDiv.appendChild(entry);
|
||
logDiv.scrollTop = logDiv.scrollHeight;
|
||
console.log(`[${type.toUpperCase()}] ${message}`);
|
||
}
|
||
|
||
function clearLogs() {
|
||
document.getElementById('logs').innerHTML = '';
|
||
document.getElementById('real-result').innerHTML = '';
|
||
document.getElementById('fake-result').innerHTML = '';
|
||
}
|
||
|
||
async function testRealData() {
|
||
log('Тестирование с реальными данными (projectId: 82823)', 'info');
|
||
|
||
try {
|
||
const response = await fetch('/get_chat_history.php', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({
|
||
context: {
|
||
projectId: "82823",
|
||
currentModule: "Contacts",
|
||
currentView: "Detail",
|
||
userId: "8",
|
||
userName: "",
|
||
userEmail: "",
|
||
projectName: "Ирина Сабурова",
|
||
pageTitle: "Контакты - Ирина Сабурова",
|
||
currentDate: "18.09.2025",
|
||
url: "https://crm.clientright.ru//index.php?module=Contacts&view=Detail&record=82823",
|
||
timestamp: 1758180782558
|
||
},
|
||
sessionId: "test-real-" + Date.now()
|
||
})
|
||
});
|
||
|
||
const data = await response.json();
|
||
document.getElementById('real-result').textContent = JSON.stringify(data, null, 2);
|
||
|
||
if (data.success) {
|
||
log(`Реальные данные: получено ${data.count} сообщений`, 'success');
|
||
} else {
|
||
log(`Ошибка с реальными данными: ${data.error}`, 'error');
|
||
}
|
||
|
||
} catch (error) {
|
||
log(`Ошибка запроса реальных данных: ${error.message}`, 'error');
|
||
}
|
||
}
|
||
|
||
async function testFakeData() {
|
||
log('Тестирование с фейковыми данными (projectId: 999999)', 'info');
|
||
|
||
try {
|
||
const response = await fetch('/get_chat_history.php', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({
|
||
context: {
|
||
projectId: "999999",
|
||
currentModule: "Contacts",
|
||
currentView: "Detail",
|
||
userId: "999",
|
||
userName: "Тестовый пользователь",
|
||
userEmail: "test@test.com",
|
||
projectName: "Несуществующий проект",
|
||
pageTitle: "Тест - Несуществующий проект",
|
||
currentDate: "19.09.2025",
|
||
url: "https://crm.clientright.ru/test",
|
||
timestamp: Date.now()
|
||
},
|
||
sessionId: "test-fake-" + Date.now()
|
||
})
|
||
});
|
||
|
||
const data = await response.json();
|
||
document.getElementById('fake-result').textContent = JSON.stringify(data, null, 2);
|
||
|
||
if (data.success) {
|
||
log(`Фейковые данные: получено ${data.count} сообщений`, 'success');
|
||
} else {
|
||
log(`Ошибка с фейковыми данными: ${data.error}`, 'error');
|
||
}
|
||
|
||
} catch (error) {
|
||
log(`Ошибка запроса фейковых данных: ${error.message}`, 'error');
|
||
}
|
||
}
|
||
|
||
function openAIDrawerReal() {
|
||
// Симулируем реальный контекст
|
||
window._USERMETA = { id: '8', name: '', email: '' };
|
||
window.location.search = '?module=Contacts&view=Detail&record=82823';
|
||
|
||
if (aiDrawerInstance) {
|
||
aiDrawerInstance.open();
|
||
log('AI Drawer открыт с реальными данными', 'info');
|
||
} else {
|
||
log('AI Drawer не инициализирован', 'error');
|
||
}
|
||
}
|
||
|
||
function openAIDrawerFake() {
|
||
// Симулируем фейковый контекст
|
||
window._USERMETA = { id: '999', name: 'Тестовый пользователь', email: 'test@test.com' };
|
||
window.location.search = '?module=Contacts&view=Detail&record=999999';
|
||
|
||
if (aiDrawerInstance) {
|
||
aiDrawerInstance.open();
|
||
log('AI Drawer открыт с фейковыми данными', 'info');
|
||
} else {
|
||
log('AI Drawer не инициализирован', 'error');
|
||
}
|
||
}
|
||
|
||
function closeAIDrawer() {
|
||
if (aiDrawerInstance) {
|
||
aiDrawerInstance.close();
|
||
log('AI Drawer закрыт', 'info');
|
||
}
|
||
}
|
||
|
||
// Инициализация
|
||
document.addEventListener('DOMContentLoaded', function() {
|
||
try {
|
||
aiDrawerInstance = new AIDrawer();
|
||
log('AI Drawer инициализирован', 'success');
|
||
} catch (error) {
|
||
log(`Ошибка инициализации AI Drawer: ${error.message}`, 'error');
|
||
}
|
||
});
|
||
|
||
log('Страница загружена', 'info');
|
||
</script>
|
||
</body>
|
||
</html>
|