Skip to content

Commit bcdd773

Browse files
Fatima-Tahirihalaij1
authored andcommitted
Add a button from student view to deadline deviations
Fixes #1458
1 parent 45e35b1 commit bcdd773

4 files changed

Lines changed: 66 additions & 9 deletions

File tree

assets/js/table.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ $(function() {
242242
});
243243
}
244244
});
245+
246+
// Emit an event when the table is rendered
247+
self.element.trigger('aplusTable:rendered');
245248
},
246249

247250
filterGetType: function(query) {
@@ -326,21 +329,30 @@ $(function() {
326329
+ " If you are using regex, make sure it is correct.");
327330
this.filters[column] = this.filterGetType(query.trim());
328331
if (this.filters[column][1] === undefined) {
329-
input.popover("destroy")
330-
.popover({
331-
trigger: "manual",
332-
title: popoverTitle,
333-
placement: "top"
334-
})
335-
.popover("toggle");
332+
// Dispose existing popover first
333+
const existingPopover = bootstrap.Popover.getInstance(input[0]);
334+
if (existingPopover) {
335+
existingPopover.dispose();
336+
}
337+
338+
// Create new popover
339+
const popover = new bootstrap.Popover(input[0], {
340+
trigger: "manual",
341+
title: popoverTitle,
342+
placement: "top"
343+
});
344+
popover.show();
336345

337346
input.on('hide.bs.popover', function(event) {
338347
event.preventDefault();
339348
});
340349
} else {
341350
input.off('hide.bs.popover');
342-
input.popover("destroy")
343-
.removeAttr("title data-original-title");
351+
const existingPopover = bootstrap.Popover.getInstance(input[0]);
352+
if (existingPopover) {
353+
existingPopover.dispose();
354+
}
355+
input.removeAttr("title data-bs-original-title");
344356
}
345357
this.filterTable();
346358
},
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
function filterBySubmitter(submitterLabel) {
3+
const params = new URLSearchParams(window.location.search);
4+
const submitterName = params.get("submitter");
5+
if (!submitterName) return;
6+
7+
const table = $(".filtered-table");
8+
if (!table.length) return;
9+
10+
// Find the submitter column index (case-insensitive)
11+
let submitterIndex = -1;
12+
table.find("thead > tr:first-child > th").each(function (index) {
13+
const text = $(this).text().trim().toUpperCase();
14+
if (text === submitterLabel) {
15+
submitterIndex = index;
16+
}
17+
});
18+
19+
if (submitterIndex === -1) return;
20+
21+
// Fill the input in the second row (filter row)
22+
const filterInput = table.find(`thead > tr:eq(1) > td:eq(${submitterIndex}) input`);
23+
if (filterInput.length) {
24+
filterInput.val(submitterName).trigger("keyup");
25+
}
26+
}

deviations/templates/deviations/list_dl.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,14 @@ <h5 class="card-title text-white">{% translate "DEADLINE_DEVIATIONS" %}</h5>
158158
</form>
159159
</div>
160160
{% endblock %}
161+
162+
{% block scripts %}
163+
{{ block.super }}
164+
<script src="{% static 'deviations/filter_deviations_by_submitter.js' %}"></script>
165+
<script>
166+
const submitterLabel = "{% trans 'SUBMITTER'|upper %}";
167+
$(document).on('aplusTable:rendered', '.filtered-table', function() {
168+
filterBySubmitter(submitterLabel);
169+
});
170+
</script>
171+
{% endblock %}

exercise/templates/exercise/staff/user_results.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
</tr>
6161
</table>
6262

63+
<div class="float-start">
64+
<a class="btn aplus-button--default aplus-button--sm d-flex gap-2" role="button"
65+
href="{{ instance|url:'deviations-list-dl' }}?submitter={{ student.get_full_name|urlencode }}">
66+
<span class="bi bi-clock" aria-hidden="true"></span>
67+
{% translate "DEADLINE_DEVIATIONS" %}
68+
</a>
69+
</div>
70+
6371
<p id="enrollment-and-tags" class="usertags-container" data-user-id="{{ student.id }}">
6472
{% for submission in enrollment_submissions %}
6573
<a href="{{ submission|url }}" class="page-modal">

0 commit comments

Comments
 (0)