-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
236 lines (197 loc) · 8.55 KB
/
app.js
File metadata and controls
236 lines (197 loc) · 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* --- DATOS DE PRUEBA (MOCK DATA) --- */
// Esto simula lo que tu Python devolverá en formato JSON
const MOCK_DATA = [
{
id: 1,
title: "Fundamentos de Python: De Cero a Héroe",
level: "beginner",
rating: 4.8,
reviews: 12500,
duration: "10h 30m",
image: "https://placehold.co/600x400/dcfce7/15803d?text=Python+Basics",
description: "Aprende las bases de la programación: variables, bucles y funciones con ejercicios prácticos."
},
{
id: 2,
title: "Estructuras de Datos y Algoritmos en Python",
level: "intermediate",
rating: 4.6,
reviews: 8200,
duration: "18h 15m",
image: "https://placehold.co/600x400/fef9c3/a16207?text=Algoritmos",
description: "Domina listas enlazadas, árboles binarios y optimización de código."
},
{
id: 3,
title: "Machine Learning y Data Science Avanzado",
level: "expert",
rating: 4.9,
reviews: 21000,
duration: "32h 00m",
image: "https://placehold.co/600x400/fee2e2/b91c1c?text=AI+Expert",
description: "Implementa redes neuronales, TensorFlow y modelos predictivos complejos."
}
];
/* --- VARIABLES DE ESTADO --- */
let currentTopic = "";
/* --- FUNCIONES DE NAVEGACIÓN --- */
function handleEnter(e) {
if (e.key === 'Enter') {
startSearch();
}
}
function quickSearch(term) {
document.getElementById('search-input').value = term;
startSearch();
}
function resetApp() {
// Volver a la vista inicial
hideElement('view-loading');
hideElement('view-results');
showElement('view-home');
hideElement('view-tabs');
// Limpiar input
document.getElementById('search-input').value = '';
}
function startSearch() {
const input = document.getElementById('search-input');
const term = input.value.trim();
if (!term) return;
currentTopic = term;
// 1. Cambiar UI a Loading
hideElement('view-home');
showElement('view-loading');
// 2. Simular llamada al Backend (Aquí conectarás tu Python)
fetchDataFromPython(term);
}
function switchTab(tabName) {
// Manejar clases de botones
const btnRoadmap = document.getElementById('btn-roadmap');
const btnGraph = document.getElementById('btn-graph');
if (tabName === 'roadmap') {
btnRoadmap.classList.add('active');
btnGraph.classList.remove('active');
showElement('tab-roadmap');
hideElement('tab-graph');
} else {
btnGraph.classList.add('active');
btnRoadmap.classList.remove('active');
hideElement('tab-roadmap');
showElement('tab-graph');
// Renderizar grafo si es la primera vez
renderGraph(MOCK_DATA);
}
}
/* --- LÓGICA DE DATOS --- */
function fetchDataFromPython(term) {
console.log("Buscando ruta para:", term);
// SIMULACIÓN DE RETARDO DE RED (1.5 segundos)
setTimeout(() => {
// AQUÍ ES DONDE HARÁS: fetch('http://localhost:5000/api/ruta?tema=' + term)
// Por ahora usamos MOCK_DATA
const data = MOCK_DATA;
renderRoadmap(data, term);
// Cambiar vista
hideElement('view-loading');
showElement('view-results');
document.getElementById('view-tabs').classList.remove('hidden'); // Mostrar tabs
document.getElementById('view-tabs').style.display = 'flex'; // Forzar flex
}, 1500);
}
/* --- RENDERIZADO (GENERACIÓN DE HTML) --- */
function renderRoadmap(courses, topic) {
const container = document.getElementById('roadmap-container');
document.getElementById('result-title').innerHTML = `Ruta para: <span class="highlight">${topic}</span>`;
container.innerHTML = ''; // Limpiar anterior
courses.forEach((course, index) => {
// Determinar etiquetas y colores
let badgeClass = course.level; // beginner, intermediate, expert
let badgeText = course.level === 'beginner' ? 'Principiante' :
course.level === 'intermediate' ? 'Intermedio' : 'Experto';
let stepColor = badgeClass === 'beginner' ? 'var(--color-beginner)' :
badgeClass === 'intermediate' ? 'var(--color-intermediate)' : 'var(--color-expert)';
// Crear HTML de la tarjeta
const cardHTML = `
<div class="course-card-wrapper" style="animation-delay: ${index * 0.2}s">
<!-- Número del paso -->
<div class="step-number" style="border-color: ${stepColor}; color: ${stepColor}">
${index + 1}
</div>
<!-- Tarjeta -->
<div class="course-card">
<div class="card-image">
<img src="${course.image}" alt="${course.title}">
</div>
<div class="card-content">
<div>
<div class="card-badges">
<span class="badge ${badgeClass}">${badgeText}</span>
<div class="rating">
<!-- Icono Estrella SVG -->
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>
${course.rating}
</div>
</div>
<h3 class="card-title">${course.title}</h3>
<p class="card-desc">${course.description}</p>
</div>
<div class="card-footer">
<span>⏳ ${course.duration}</span>
<span>👥 ${course.reviews.toLocaleString()} reviews</span>
</div>
</div>
</div>
</div>
${index < courses.length - 1 ? `
<div class="arrow-connector">
<!-- Flecha hacia abajo SVG -->
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="19 12 12 19 5 12"/></svg>
</div>
` : ''}
`;
container.innerHTML += cardHTML;
});
}
function renderGraph(courses) {
const container = document.getElementById('graph-svg-container');
// Construimos un SVG simple dinámicamente
// Coordenadas fijas para demostración (X aumenta, Y fijo)
// En un caso real, calcularías esto con lógica de grafos
let svgContent = `<svg width="100%" height="100%" viewBox="0 0 600 200">`;
// Dibujar Aristas (Líneas) primero para que queden detrás
courses.forEach((c, i) => {
if (i < courses.length - 1) {
let x1 = 100 + (i * 200);
let x2 = 100 + ((i + 1) * 200);
svgContent += `
<line x1="${x1}" y1="100" x2="${x2}" y2="100" stroke="#cbd5e1" stroke-width="2" stroke-dasharray="5,5" />
<circle cx="${(x1+x2)/2}" cy="100" r="12" fill="white" stroke="#cbd5e1" />
<text x="${(x1+x2)/2}" y="104" text-anchor="middle" font-size="10" fill="#64748b" font-family="sans-serif">Peso</text>
`;
}
});
// Dibujar Nodos
courses.forEach((c, i) => {
let x = 100 + (i * 200);
let color = c.level === 'beginner' ? '#22c55e' : c.level === 'intermediate' ? '#eab308' : '#ef4444';
let label = c.level === 'beginner' ? 'INI' : c.level === 'intermediate' ? 'PRO' : 'FIN';
svgContent += `
<g class="node-group" style="cursor: pointer">
<circle cx="${x}" cy="100" r="30" fill="${color}20" stroke="${color}" stroke-width="3" />
<text x="${x}" y="105" text-anchor="middle" font-family="sans-serif" font-weight="bold" fill="#334155" font-size="12">${label}</text>
<text x="${x}" y="150" text-anchor="middle" font-family="sans-serif" fill="#64748b" font-size="10">${c.title.substring(0, 12)}...</text>
</g>
`;
});
svgContent += `</svg>`;
container.innerHTML = svgContent;
}
/* --- UTILIDADES DOM --- */
function showElement(id) {
const el = document.getElementById(id);
if (el) el.classList.remove('hidden');
}
function hideElement(id) {
const el = document.getElementById(id);
if (el) el.classList.add('hidden');
}