-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
500 lines (463 loc) · 18.7 KB
/
Copy pathdashboard.html
File metadata and controls
500 lines (463 loc) · 18.7 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code AI Dashboard</title>
<style>
:root {
--primary: #6366f1;
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
--dark: #1f2937;
--light: #f3f4f6;
--gray: #6b7280;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #f9fafb;
color: var(--dark);
}
.container { display: flex; min-height: 100vh; }
/* Sidebar */
.sidebar {
width: 240px;
background: var(--dark);
color: white;
padding: 20px;
}
.logo {
display: flex;
align-items: center;
gap: 12px;
padding: 16px 0;
border-bottom: 1px solid rgba(255,255,255,0.1);
margin-bottom: 24px;
}
.logo h1 { font-size: 20px; }
.nav-link {
display: block;
padding: 12px 16px;
color: rgba(255,255,255,0.7);
text-decoration: none;
border-radius: 8px;
margin-bottom: 4px;
}
.nav-link:hover, .nav-link.active {
background: rgba(255,255,255,0.1);
color: white;
}
/* Main */
.main { flex: 1; padding: 24px; }
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
}
.header h2 { font-size: 24px; }
.badge {
padding: 6px 12px;
border-radius: 12px;
font-size: 12px;
background: rgba(16, 185, 129, 0.1);
color: var(--success);
}
/* Stats */
.stats {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
margin-bottom: 24px;
}
.stat-card {
background: white;
padding: 24px;
border-radius: 12px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.stat-value { font-size: 32px; font-weight: 700; }
.stat-label { color: var(--gray); font-size: 14px; margin-top: 4px; }
/* Grid */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.card {
background: white;
border-radius: 12px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
padding: 24px;
}
.card-title {
font-size: 16px;
font-weight: 600;
margin-bottom: 16px;
padding-bottom: 12px;
border-bottom: 1px solid var(--light);
}
/* Code Editor */
.code-editor {
width: 100%;
min-height: 300px;
padding: 16px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 14px;
background: #1e1e1e;
color: #d4d4d4;
border: none;
border-radius: 8px;
resize: vertical;
}
/* Score */
.score-circle {
width: 140px;
height: 140px;
border-radius: 50%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 0 auto 20px;
border: 6px solid var(--success);
background: rgba(16, 185, 129, 0.1);
}
.score-value { font-size: 42px; font-weight: 700; }
.score-grade { font-size: 20px; color: var(--gray); }
/* Progress */
.category { margin-bottom: 16px; }
.category-header {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
font-size: 14px;
}
.progress-bar {
height: 8px;
background: var(--light);
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: 4px;
transition: width 0.5s;
}
.progress-fill.high { background: var(--success); }
.progress-fill.medium { background: var(--warning); }
.progress-fill.low { background: var(--danger); }
/* Issues */
.issue {
display: flex;
gap: 12px;
padding: 12px 0;
border-bottom: 1px solid var(--light);
}
.issue:last-child { border-bottom: none; }
.issue-dot {
width: 8px;
height: 8px;
border-radius: 50%;
margin-top: 6px;
}
.issue-dot.critical { background: var(--danger); }
.issue-dot.warning { background: var(--warning); }
.issue-dot.info { background: var(--primary); }
.issue-title { font-weight: 500; margin-bottom: 4px; }
.issue-loc { font-size: 12px; color: var(--gray); }
.issue-fix {
margin-top: 8px;
padding: 8px 12px;
background: var(--light);
border-radius: 6px;
font-size: 13px;
}
/* Button */
.btn {
padding: 10px 20px;
border: none;
border-radius: 8px;
font-size: 14px;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 8px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #4f46e5; }
.btn-success { background: var(--success); color: white; }
.actions { display: flex; gap: 8px; margin-top: 16px; }
</style>
</head>
<body>
<div class="container">
<!-- Sidebar -->
<aside class="sidebar">
<div class="logo">
<svg width="28" height="28" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/>
</svg>
<h1>Code AI</h1>
</div>
<nav>
<a href="dashboard.html" class="nav-link active">Dashboard</a>
<a href="analyze.html" class="nav-link">Analyze</a>
<a href="history.html" class="nav-link">History</a>
<a href="settings.html" class="nav-link">Settings</a>
</nav>
</aside>
<!-- Main Content -->
<main class="main">
<header class="header">
<h2>Code AI Dashboard</h2>
<div style="display: flex; gap: 8px; align-items: center;">
<span class="badge" style="background: rgba(99,102,241,0.1); color: #6366f1;">N-gram Model</span>
<span class="badge">Ready</span>
</div>
</header>
<!-- Stats -->
<div class="stats">
<div class="stat-card">
<div class="stat-value" id="lines">0</div>
<div class="stat-label">Total Lines</div>
</div>
<div class="stat-card">
<div class="stat-value" id="methods">0</div>
<div class="stat-label">Methods</div>
</div>
<div class="stat-card">
<div class="stat-value" id="issues">0</div>
<div class="stat-label">Issues</div>
</div>
<div class="stat-card">
<div class="stat-value" id="complexity">0</div>
<div class="stat-label">Complexity</div>
</div>
</div>
<div class="grid">
<!-- Code Input -->
<div class="card">
<div class="card-title">Code Input</div>
<textarea id="code" class="code-editor" placeholder="// Paste your Java code here...">public class Example {
public static void main(String[] args) {
System.out.println("Hello World");
try {
int result = 100 / 0;
} catch (Exception e) {
// empty catch block
}
if (args.length > 0)
System.out.println(args[0]);
}
}</textarea>
<div style="margin-top: 16px; display: flex; align-items: center; gap: 16px;">
<label style="display: flex; align-items: center; gap: 8px; font-size: 14px;">
<span>Model:</span>
<select id="modelProvider" style="padding: 8px 12px; border-radius: 6px; border: 1px solid #e5e7eb;">
<option value="codeai" selected>Code AI (Our N-gram)</option>
<option value="claude">Claude API</option>
<option value="openai">OpenAI API</option>
<option value="ollama">Ollama (Local)</option>
</select>
</label>
</div>
<div class="actions">
<button class="btn btn-primary" onclick="analyzeCode()">
Analyze Code
</button>
<button class="btn btn-success" onclick="autoFix()">
Auto Fix
</button>
</div>
</div>
<!-- Score -->
<div class="card">
<div class="card-title">Code Quality Score</div>
<div class="score-circle" id="scoreCircle">
<span class="score-value" id="score">-</span>
<span class="score-grade" id="grade">-</span>
</div>
<div id="categories">
<div class="category">
<div class="category-header">
<span>Readability</span>
<span id="cat-read">-</span>
</div>
<div class="progress-bar">
<div class="progress-fill high" id="bar-read" style="width: 0%"></div>
</div>
</div>
<div class="category">
<div class="category-header">
<span>Maintainability</span>
<span id="cat-maint">-</span>
</div>
<div class="progress-bar">
<div class="progress-fill high" id="bar-maint" style="width: 0%"></div>
</div>
</div>
<div class="category">
<div class="category-header">
<span>Security</span>
<span id="cat-sec">-</span>
</div>
<div class="progress-bar">
<div class="progress-fill medium" id="bar-sec" style="width: 0%"></div>
</div>
</div>
<div class="category">
<div class="category-header">
<span>Performance</span>
<span id="cat-perf">-</span>
</div>
<div class="progress-bar">
<div class="progress-fill high" id="bar-perf" style="width: 0%"></div>
</div>
</div>
</div>
</div>
</div>
<!-- Issues -->
<div class="card" style="margin-top: 24px;">
<div class="card-title">Detected Issues</div>
<div id="issueList">
<div class="issue">
<div class="issue-dot warning"></div>
<div>
<div class="issue-title">Click "Analyze Code" to start</div>
<div class="issue-loc">Waiting for code analysis...</div>
</div>
</div>
</div>
</div>
</main>
</div>
<script>
function analyzeCode() {
const code = document.getElementById('code').value;
const lines = code.split('\n');
const issues = [];
let methodCount = 0;
let complexity = 1;
// Simple analysis
lines.forEach((line, i) => {
const lineNum = i + 1;
// Count methods
if (line.match(/\b(public|private|protected)?\s*(static)?\s*\w+\s+\w+\s*\(/)) {
methodCount++;
}
// Count complexity (if, for, while, switch, catch)
if (line.match(/\b(if|for|while|switch|catch)\s*\(/)) {
complexity++;
}
// Detect issues
if (line.includes('System.out.println')) {
issues.push({
type: 'warning',
title: 'System.out.println detected',
line: lineNum,
message: 'Use Logger instead of System.out',
fix: 'logger.info("message");'
});
}
if (line.match(/catch\s*\([^)]+\)\s*\{\s*$/)) {
const nextLine = lines[i + 1] || '';
if (nextLine.trim() === '' || nextLine.includes('//')) {
issues.push({
type: 'critical',
title: 'Empty catch block',
line: lineNum,
message: 'Empty catch blocks hide errors',
fix: 'logger.error("Error occurred", e);'
});
}
}
if (line.match(/\bif\s*\([^)]+\)\s*[^{]/)) {
issues.push({
type: 'info',
title: 'Missing braces in if statement',
line: lineNum,
message: 'Always use braces for better readability',
fix: 'if (condition) { ... }'
});
}
if (line.match(/\/\s*0\b/)) {
issues.push({
type: 'critical',
title: 'Potential division by zero',
line: lineNum,
message: 'This will throw ArithmeticException',
fix: 'Add null/zero check before division'
});
}
});
// Update stats
document.getElementById('lines').textContent = lines.length;
document.getElementById('methods').textContent = methodCount;
document.getElementById('issues').textContent = issues.length;
document.getElementById('complexity').textContent = complexity;
// Calculate score
const baseScore = 100;
const penalty = issues.reduce((sum, i) => {
return sum + (i.type === 'critical' ? 15 : i.type === 'warning' ? 8 : 3);
}, 0);
const score = Math.max(0, baseScore - penalty);
const grade = score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : score >= 60 ? 'D' : 'F';
// Update score display
document.getElementById('score').textContent = score;
document.getElementById('grade').textContent = grade;
const circle = document.getElementById('scoreCircle');
circle.style.borderColor = score >= 80 ? '#10b981' : score >= 60 ? '#f59e0b' : '#ef4444';
circle.style.background = score >= 80 ? 'rgba(16,185,129,0.1)' : score >= 60 ? 'rgba(245,158,11,0.1)' : 'rgba(239,68,68,0.1)';
// Update categories
const cats = {
'read': Math.min(100, score + 5),
'maint': score,
'sec': Math.max(0, score - (issues.filter(i => i.type === 'critical').length * 10)),
'perf': Math.min(100, score + 10)
};
Object.entries(cats).forEach(([key, val]) => {
document.getElementById(`cat-${key}`).textContent = val;
const bar = document.getElementById(`bar-${key}`);
bar.style.width = val + '%';
bar.className = 'progress-fill ' + (val >= 80 ? 'high' : val >= 60 ? 'medium' : 'low');
});
// Update issue list
const issueList = document.getElementById('issueList');
if (issues.length === 0) {
issueList.innerHTML = `
<div class="issue">
<div class="issue-dot" style="background: #10b981"></div>
<div>
<div class="issue-title">No issues found!</div>
<div class="issue-loc">Your code looks good.</div>
</div>
</div>
`;
} else {
issueList.innerHTML = issues.map(issue => `
<div class="issue">
<div class="issue-dot ${issue.type}"></div>
<div style="flex:1">
<div class="issue-title">${issue.title}</div>
<div class="issue-loc">Line ${issue.line} - ${issue.message}</div>
<div class="issue-fix">Fix: ${issue.fix}</div>
</div>
</div>
`).join('');
}
}
function autoFix() {
let code = document.getElementById('code').value;
// Apply fixes
code = code.replace(/System\.out\.println\((.*?)\);/g, 'logger.info($1);');
code = code.replace(/catch\s*\((\w+)\s+(\w+)\)\s*\{\s*\n\s*\/\/[^\n]*\n\s*\}/g,
'catch ($1 $2) {\n logger.error("Error occurred", $2);\n }');
code = code.replace(/if\s*\(([^)]+)\)\s*\n(\s*)(\S)/g, 'if ($1) {\n$2 $3');
document.getElementById('code').value = code;
analyzeCode();
}
// Initial analysis
analyzeCode();
</script>
</body>
</html>