thadillo commited on
Commit
634e667
·
1 Parent(s): 316fc26

Phase 4: UI updates for sentence-level categorization

Browse files

- Add collapsible sentence breakdown to submissions page
- Show category distribution per submission
- Add updateSentenceCategory() JavaScript function
- Display confidence scores for each sentence
- Editable sentence categories with inline feedback

app/templates/admin/submissions.html CHANGED
@@ -66,6 +66,55 @@
66
 
67
  <p class="mb-3">{{ sub.message }}</p>
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  {% if sub.latitude and sub.longitude %}
70
  <p class="text-muted small mb-3">
71
  <i class="bi bi-geo-alt-fill"></i>
@@ -147,6 +196,35 @@ function updateCategory(submissionId, category, selectElement) {
147
  });
148
  }
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  function toggleFlag(submissionId) {
151
  fetch(`{{ url_for("admin.toggle_flag", submission_id=0) }}`.replace('/0', `/${submissionId}`), {
152
  method: 'POST'
 
66
 
67
  <p class="mb-3">{{ sub.message }}</p>
68
 
69
+ {% if sub.sentence_analysis_done and sub.sentences %}
70
+ <!-- NEW: Category Distribution -->
71
+ <div class="mb-2">
72
+ <strong>Category Distribution:</strong>
73
+ {% for category, percentage in sub.get_category_distribution().items() %}
74
+ <span class="badge bg-secondary">{{ category }}: {{ percentage }}%</span>
75
+ {% endfor %}
76
+ </div>
77
+
78
+ <!-- NEW: Collapsible Sentence Breakdown -->
79
+ <button class="btn btn-sm btn-outline-primary mb-2"
80
+ type="button"
81
+ data-bs-toggle="collapse"
82
+ data-bs-target="#sentences-{{ sub.id }}">
83
+ <i class="bi bi-list-nested"></i> View Sentences ({{ sub.sentences|length }})
84
+ </button>
85
+
86
+ <div class="collapse" id="sentences-{{ sub.id }}">
87
+ <div class="border-start border-primary ps-3 mt-2">
88
+ {% for sentence in sub.sentences %}
89
+ <div class="mb-2 p-2 bg-light rounded">
90
+ <div class="d-flex justify-content-between align-items-start">
91
+ <div class="flex-grow-1">
92
+ <small class="text-muted">Sentence {{ sentence.sentence_index + 1 }}:</small>
93
+ <p class="mb-1">{{ sentence.text }}</p>
94
+ </div>
95
+ <div class="ms-2">
96
+ <select class="form-select form-select-sm"
97
+ style="width: 150px;"
98
+ onchange="updateSentenceCategory({{ sentence.id }}, this.value, this)">
99
+ <option value="">Uncategorized</option>
100
+ {% for cat in categories %}
101
+ <option value="{{ cat }}"
102
+ {% if sentence.category == cat %}selected{% endif %}>
103
+ {{ cat }}
104
+ </option>
105
+ {% endfor %}
106
+ </select>
107
+ </div>
108
+ </div>
109
+ {% if sentence.confidence %}
110
+ <small class="text-muted">Confidence: {{ "%.0f"|format(sentence.confidence * 100) }}%</small>
111
+ {% endif %}
112
+ </div>
113
+ {% endfor %}
114
+ </div>
115
+ </div>
116
+ {% endif %}
117
+
118
  {% if sub.latitude and sub.longitude %}
119
  <p class="text-muted small mb-3">
120
  <i class="bi bi-geo-alt-fill"></i>
 
196
  });
197
  }
198
 
199
+ function updateSentenceCategory(sentenceId, category, selectElement) {
200
+ fetch(`{{ url_for("admin.update_sentence_category", sentence_id=0) }}`.replace('/0', `/${sentenceId}`), {
201
+ method: 'POST',
202
+ headers: {
203
+ 'Content-Type': 'application/json'
204
+ },
205
+ body: JSON.stringify({ category: category || null })
206
+ })
207
+ .then(response => response.json())
208
+ .then(data => {
209
+ if (data.success) {
210
+ // Show success feedback
211
+ const originalBg = selectElement.style.backgroundColor;
212
+ selectElement.style.backgroundColor = '#d1fae5';
213
+ setTimeout(() => {
214
+ selectElement.style.backgroundColor = originalBg;
215
+ }, 500);
216
+ } else {
217
+ alert('Failed to update sentence category: ' + (data.error || 'Unknown error'));
218
+ location.reload();
219
+ }
220
+ })
221
+ .catch(err => {
222
+ console.error('Sentence category update error:', err);
223
+ alert('Error updating sentence category: ' + err.message);
224
+ location.reload();
225
+ });
226
+ }
227
+
228
  function toggleFlag(submissionId) {
229
  fetch(`{{ url_for("admin.toggle_flag", submission_id=0) }}`.replace('/0', `/${submissionId}`), {
230
  method: 'POST'