Avnishjain commited on
Commit
1b39c74
·
verified ·
1 Parent(s): ea89440

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +131 -25
templates/index.html CHANGED
@@ -471,7 +471,7 @@
471
  <span id="file-name">filename.py</span>
472
  <span class="badge" id="task-difficulty">EASY</span>
473
  </div>
474
- <div class="code-container">
475
  <pre><code class="language-python" id="code-block"># Load a task to see code</code></pre>
476
  </div>
477
  </div>
@@ -494,11 +494,33 @@
494
  Add Comment
495
  </h2>
496
 
497
- <div class="form-row">
498
- <div class="form-group">
499
- <label>Line # (optional)</label>
500
- <input type="number" id="c-line" placeholder="e.g. 15" min="1">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  </div>
 
502
  <div class="form-group">
503
  <label>Category</label>
504
  <select id="c-category">
@@ -508,31 +530,38 @@
508
  <option value="style">Style</option>
509
  <option value="documentation">Documentation</option>
510
  </select>
 
 
 
 
511
  </div>
512
  <div class="form-group">
513
- <label>Severity</label>
514
- <select id="c-severity">
515
- <option value="low">Low</option>
516
- <option value="medium" selected>Medium</option>
517
- <option value="high">High</option>
518
- <option value="critical">Critical</option>
519
- </select>
 
 
 
 
 
 
 
 
520
  </div>
521
  </div>
522
 
523
- <div class="form-group">
524
- <label>Message</label>
525
- <textarea id="c-message" rows="2" placeholder="Describe the issue..."></textarea>
 
 
526
  </div>
527
 
528
- <div class="form-group">
529
- <label>Suggestion (optional)</label>
530
- <input type="text" id="c-suggestion" placeholder="Proposed fix code...">
531
- </div>
532
-
533
- <button class="btn-outline" style="width: 100%; justify-content: center;" onclick="stageComment()">
534
- + Add to Review
535
- </button>
536
 
537
  <div class="comments-list" id="staged-comments">
538
  <!-- Dynamic comments go here -->
@@ -543,7 +572,7 @@
543
  <textarea id="summary" placeholder="Provide an overall assessment of the code quality..."></textarea>
544
  </div>
545
 
546
- <div class="submit-section">
547
  <button class="btn-primary" onclick="submitReview()">
548
  <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
549
  Submit Review
@@ -594,6 +623,13 @@
594
  const tasks = await res.json();
595
  const select = document.getElementById('task-select');
596
  select.innerHTML = '';
 
 
 
 
 
 
 
597
 
598
  for (const [id, spec] of Object.entries(tasks)) {
599
  const option = document.createElement('option');
@@ -634,6 +670,35 @@
634
  document.getElementById('c-suggestion').value = '';
635
  document.getElementById('c-line').value = '';
636
  document.getElementById('summary').value = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637
 
638
  try {
639
  const res = await fetch('/reset', {
@@ -668,7 +733,48 @@
668
  setTimeout(() => document.getElementById('loader').style.display = 'none', 500);
669
  }
670
  }
671
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
672
  function stageComment() {
673
  const line = document.getElementById('c-line').value;
674
  const category = document.getElementById('c-category').value;
 
471
  <span id="file-name">filename.py</span>
472
  <span class="badge" id="task-difficulty">EASY</span>
473
  </div>
474
+ <div class="code-container" id="code-container-inner">
475
  <pre><code class="language-python" id="code-block"># Load a task to see code</code></pre>
476
  </div>
477
  </div>
 
494
  Add Comment
495
  </h2>
496
 
497
+ <div id="manual-review-forms">
498
+ <div class="form-row">
499
+ <div class="form-group">
500
+ <label>Line # (optional)</label>
501
+ <input type="number" id="c-line" placeholder="e.g. 15" min="1">
502
+ </div>
503
+ <div class="form-group">
504
+ <label>Category</label>
505
+ <select id="c-category">
506
+ <option value="bug">Bug</option>
507
+ <option value="security">Security</option>
508
+ <option value="performance">Performance</option>
509
+ <option value="style">Style</option>
510
+ <option value="documentation">Documentation</option>
511
+ </select>
512
+ </div>
513
+ <div class="form-group">
514
+ <label>Severity</label>
515
+ <select id="c-severity">
516
+ <option value="low">Low</option>
517
+ <option value="medium" selected>Medium</option>
518
+ <option value="high">High</option>
519
+ <option value="critical">Critical</option>
520
+ </select>
521
+ </div>
522
  </div>
523
+
524
  <div class="form-group">
525
  <label>Category</label>
526
  <select id="c-category">
 
530
  <option value="style">Style</option>
531
  <option value="documentation">Documentation</option>
532
  </select>
533
+ <label>Message</label>
534
+ <textarea id="c-message" rows="2" placeholder="Describe the issue..."></textarea>
535
+ </div>
536
+
537
  </div>
538
  <div class="form-group">
539
+ <label>Message</label>
540
+ <textarea id="c-message" rows="2" placeholder="Describe the issue..."></textarea>
541
+ </div>
542
+ <div class="form-group">
543
+ <label>Suggestion (optional)</label>
544
+ <input type="text" id="c-suggestion" placeholder="Proposed fix code...">
545
+ </div>
546
+
547
+ <button class="btn-outline" style="width: 100%; justify-content: center;" onclick="stageComment()">
548
+ + Add to Review
549
+ </button>
550
+
551
+ <div class="form-group" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--surface-border);">
552
+ <label>Overall Summary (required for Hard tasks)</label>
553
+ <textarea id="summary" placeholder="Provide an overall assessment of the code quality..."></textarea>
554
  </div>
555
  </div>
556
 
557
+ <div class="submit-section" style="border-top: none; padding-top: 0; margin-top: 10px;">
558
+ <button class="btn-primary" id="auto-review-btn" onclick="autoReview()" style="display: none; width: 100%; justify-content: center; background: linear-gradient(135deg, #ec4899, #8b5cf6);">
559
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2v20 M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg>
560
+ Run AI Auto-Review
561
+ </button>
562
  </div>
563
 
564
+ <div id="summary-output" style="display:none; font-style:italic; border-bottom: 1px solid var(--surface-border); padding-bottom: 10px; margin-bottom: 10px; color: var(--text-secondary);"></div>
 
 
 
 
 
 
 
565
 
566
  <div class="comments-list" id="staged-comments">
567
  <!-- Dynamic comments go here -->
 
572
  <textarea id="summary" placeholder="Provide an overall assessment of the code quality..."></textarea>
573
  </div>
574
 
575
+ <div class="submit-section" id="submit-review-btn">
576
  <button class="btn-primary" onclick="submitReview()">
577
  <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
578
  Submit Review
 
623
  const tasks = await res.json();
624
  const select = document.getElementById('task-select');
625
  select.innerHTML = '';
626
+ // Add the custom option first
627
+ const customOpt = document.createElement('option');
628
+ customOpt.value = 'custom';
629
+ customOpt.textContent = '✨ Auto-Review Custom Code';
630
+ customOpt.style.fontWeight = 'bold';
631
+ select.appendChild(customOpt);
632
+
633
 
634
  for (const [id, spec] of Object.entries(tasks)) {
635
  const option = document.createElement('option');
 
670
  document.getElementById('c-suggestion').value = '';
671
  document.getElementById('c-line').value = '';
672
  document.getElementById('summary').value = '';
673
+ document.getElementById('summary-output').style.display = 'none';
674
+
675
+ if (taskId === 'custom') {
676
+ document.getElementById('instructions').textContent = "Paste any Python code snippet into the editor on the left, then click 'Run AI Auto-Review' to see what the LLM finds! Note: Ensure you have your HF_TOKEN set.";
677
+ document.getElementById('file-name').textContent = "custom_code.py";
678
+
679
+ let diffBadge = document.getElementById('task-difficulty');
680
+ diffBadge.className = 'badge medium';
681
+ diffBadge.textContent = "AI REVIEW";
682
+
683
+ const codeBox = document.getElementById('code-container-inner');
684
+ codeBox.innerHTML = '<textarea id="custom-code-input" placeholder="def your_code_here():\\n pass" style="width:100%; height:100%; font-family: \'Fira Code\', monospace; font-size: 0.95rem; background:transparent; border:none; outline:none; padding:20px; color:var(--text-primary); resize:none;"></textarea>';
685
+
686
+ document.getElementById('manual-review-forms').style.display = 'none';
687
+ document.getElementById('submit-review-btn').style.display = 'none';
688
+ document.getElementById('auto-review-btn').style.display = 'flex';
689
+
690
+ document.getElementById('review-panel').style.display = 'block';
691
+
692
+ document.getElementById('loader').style.opacity = '0';
693
+ setTimeout(() => document.getElementById('loader').style.display = 'none', 500);
694
+ return;
695
+ }
696
+
697
+ // Restore normal mode
698
+ document.getElementById('code-container-inner').innerHTML = '<pre><code class="language-python" id="code-block"></code></pre>';
699
+ document.getElementById('manual-review-forms').style.display = 'block';
700
+ document.getElementById('submit-review-btn').style.display = 'flex';
701
+ document.getElementById('auto-review-btn').style.display = 'none';
702
 
703
  try {
704
  const res = await fetch('/reset', {
 
733
  setTimeout(() => document.getElementById('loader').style.display = 'none', 500);
734
  }
735
  }
736
+ async function autoReview() {
737
+ const input = document.getElementById('custom-code-input');
738
+ const code = input ? input.value : "";
739
+ if (!code.trim()) {
740
+ alert("Please paste some code first!");
741
+ return;
742
+ }
743
+
744
+ document.getElementById('loader').style.display = 'flex';
745
+ document.getElementById('loader').style.opacity = '1';
746
+ document.getElementById('summary-output').style.display = 'none';
747
+
748
+ try {
749
+ const res = await fetch('/auto-review', {
750
+ method: 'POST',
751
+ headers: {'Content-Type': 'application/json'},
752
+ body: JSON.stringify({source_code: code})
753
+ });
754
+
755
+ if (!res.ok) {
756
+ const err = await res.json();
757
+ alert("Error: " + err.detail);
758
+ return;
759
+ }
760
+
761
+ const data = await res.json();
762
+
763
+ stagedComments = data.comments || [];
764
+ renderComments();
765
+
766
+ if(data.summary) {
767
+ document.getElementById('summary-output').style.display = 'block';
768
+ document.getElementById('summary-output').textContent = "AI Summary: " + data.summary;
769
+ }
770
+
771
+ } catch(e) {
772
+ alert("Failed to hit the auto-review API endpoint.");
773
+ } finally {
774
+ document.getElementById('loader').style.opacity = '0';
775
+ setTimeout(() => document.getElementById('loader').style.display = 'none', 500);
776
+ }
777
+ }
778
  function stageComment() {
779
  const line = document.getElementById('c-line').value;
780
  const category = document.getElementById('c-category').value;