forked from cms-dev/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor training program UI: CSS improvements and centralized JS #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ronryv
merged 9 commits into
training_program
from
devin/1769876720-refactor-training-program-js
Jan 31, 2026
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c8c528
Refactor training program UI: CSS improvements and centralized JS
devin-ai-integration[bot] f0a7599
Fix duplicate HTML IDs and split aws_utils.js into modules
devin-ai-integration[bot] 04df717
Fix Add Student dialog size to accommodate dropdown
devin-ai-integration[bot] 1be9fd7
Remove extracted functions from aws_utils.js (cleanup)
devin-ai-integration[bot] c93d204
cleanup css
ronryv a02c37a
Remove unused histogram_js.html fragment
devin-ai-integration[bot] 6d58503
nits
ronryv b39ea0c
nits
ronryv dc7d0d8
Update cms/server/admin/static/aws_table_utils.js
ronryv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| /* Contest Management System | ||
| * Copyright © 2012-2014 Stefano Maggiolo <[email protected]> | ||
| * Copyright © 2012-2014 Luca Wehrstedt <[email protected]> | ||
| * | ||
| * Table sorting and filtering utilities for AWS. | ||
| * Extracted from aws_utils.js for better code organization. | ||
| */ | ||
|
|
||
| "use strict"; | ||
|
|
||
| var CMS = CMS || {}; | ||
| CMS.AWSTableUtils = CMS.AWSTableUtils || {}; | ||
|
|
||
|
|
||
| /** | ||
| * Provides table row comparator for specified column and order. | ||
| * | ||
| * column_idx (int): Index of the column to sort by. | ||
| * numeric (boolean): Whether to sort numerically. | ||
| * ascending (boolean): Whether to sort in ascending order. | ||
| * return (function): Comparator function for Array.sort(). | ||
| */ | ||
| CMS.AWSTableUtils.getRowComparator = function(column_idx, numeric, ascending) { | ||
| return function(a, b) { | ||
| var cellA = $(a).children("td").eq(column_idx); | ||
| var cellB = $(b).children("td").eq(column_idx); | ||
|
|
||
| // Use data-value if present, otherwise fallback to text | ||
| var valA = cellA.attr("data-value"); | ||
| if (typeof valA === "undefined" || valA === "") valA = cellA.text().trim(); | ||
|
|
||
| var valB = cellB.attr("data-value"); | ||
| if (typeof valB === "undefined" || valB === "") valB = cellB.text().trim(); | ||
|
|
||
| var result; | ||
| if (numeric) { | ||
| var numA = parseFloat(valA); | ||
| var numB = parseFloat(valB); | ||
|
|
||
| // Treat non-numeric/empty values so they always sink to bottom regardless of sort direction | ||
| if (isNaN(numA)) numA = ascending ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; | ||
| if (isNaN(numB)) numB = ascending ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY; | ||
|
|
||
| result = numA - numB; | ||
| return ascending ? result : -result; | ||
| } else { | ||
| result = valA.localeCompare(valB); | ||
| return ascending ? result : -result; | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * Sorts specified table by specified column in specified order. | ||
| * | ||
| * table (jQuery): The table element to sort. | ||
| * column_idx (int): Index of the column to sort by. | ||
| * ascending (boolean): Whether to sort in ascending order. | ||
| * header_element (Element): Optional header element for the column. | ||
| */ | ||
| CMS.AWSTableUtils.sortTable = function(table, column_idx, ascending, header_element) { | ||
| var initial_column_idx = table.data("initial_sort_column_idx"); | ||
| var ranks_column = table.data("ranks_column"); | ||
| var data_column_idx = column_idx + (ranks_column ? 1 : 0); | ||
| var table_rows = table | ||
| .children("tbody") | ||
| .children("tr"); | ||
|
|
||
| // Use provided header element if available, otherwise find by index | ||
| var column_header; | ||
| if (header_element) { | ||
| column_header = $(header_element); | ||
| } else { | ||
| column_header = table | ||
| .children("thead") | ||
| .children("tr") | ||
| .children("th") | ||
| .eq(data_column_idx); | ||
| } | ||
| var settings = (column_header.attr("data-sort-settings") || "").split(" "); | ||
|
|
||
| var numeric = settings.indexOf("numeric") >= 0; | ||
|
|
||
| // If specified, flip column's natural order, e.g. due to meaning of values. | ||
| if (settings.indexOf("reversed") >= 0) { | ||
| ascending = !ascending; | ||
| } | ||
|
|
||
| // Normalize column index for data access, converting negative to positive from the end. | ||
| if (data_column_idx < 0) { | ||
| // For negative indices, calculate from the number of columns in data rows | ||
| var first_data_row = table_rows.first(); | ||
| var num_cols = first_data_row.children("td,th").length; | ||
| data_column_idx = num_cols + data_column_idx; | ||
| } | ||
|
|
||
| // Reassign arrows to headers | ||
| table.find(".column-sort").html("↕"); | ||
| column_header.find(".column-sort").html(ascending ? "↑" : "↓"); | ||
|
|
||
| // Do the sorting, by initial column and then by selected column. | ||
| table_rows | ||
| .sort(CMS.AWSTableUtils.getRowComparator(initial_column_idx, numeric, ascending)) | ||
| .sort(CMS.AWSTableUtils.getRowComparator(data_column_idx, numeric, ascending)) | ||
| .each(function(idx, row) { | ||
| table.children("tbody").append(row); | ||
| }); | ||
|
|
||
| if (ranks_column) { | ||
| table_rows.each(function(idx, row) { | ||
| $(row).children("td").first().text(idx + 1); | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * Makes table sortable, adding ranks column and sorting buttons in header. | ||
| * | ||
| * table (jQuery): The table element to make sortable. | ||
| * ranks_column (boolean): Whether to add a ranks column. | ||
| * initial_column_idx (int): Index of the column to initially sort by. | ||
| * initial_ascending (boolean): Whether to initially sort in ascending order. | ||
| */ | ||
| CMS.AWSTableUtils.initTableSort = function(table, ranks_column, initial_column_idx, initial_ascending) { | ||
| table.addClass("sortable"); | ||
| var table_column_headers = table | ||
| .children("thead") | ||
| .children("tr"); | ||
| var table_rows = table | ||
| .children("tbody") | ||
| .children("tr"); | ||
|
|
||
| // Normalize column index, converting negative to positive from the end. | ||
| initial_column_idx = table_column_headers | ||
| .children("th") | ||
| .eq(initial_column_idx) | ||
| .index(); | ||
|
|
||
| table.data("ranks_column", ranks_column); | ||
| table.data("initial_sort_column_idx", initial_column_idx); | ||
|
|
||
| // Declaring sort settings. | ||
| var previous_column_idx = initial_column_idx; | ||
| var ascending = initial_ascending; | ||
|
|
||
| // Add sorting indicators to column headers | ||
| // Skip headers with the "no-sort" class | ||
| // Use data-sort-column attribute if present for correct column index | ||
| table_column_headers | ||
| .children("th") | ||
| .not(".no-sort") | ||
| .each(function(idx, header) { | ||
| var $header = $(header); | ||
| // Use data-sort-column if specified, otherwise use the header's index | ||
| var sortColumn = $header.data("sort-column"); | ||
| if (sortColumn === undefined) { | ||
| sortColumn = $header.index(); | ||
| } | ||
| $("<a/>", { | ||
| href: "#", | ||
| class: "column-sort", | ||
| click: function(e) { | ||
| e.preventDefault(); | ||
| ascending = !ascending && previous_column_idx == sortColumn; | ||
| previous_column_idx = sortColumn; | ||
| CMS.AWSTableUtils.sortTable(table, sortColumn, ascending, header); | ||
| } | ||
| }).appendTo(header); | ||
| }); | ||
|
|
||
| // Add ranks column | ||
| if (ranks_column) { | ||
| table_column_headers.prepend("<th>#</th>"); | ||
| table_rows.prepend("<td></td>"); | ||
| } | ||
|
|
||
| // Do initial sorting | ||
| CMS.AWSTableUtils.sortTable(table, initial_column_idx, initial_ascending); | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * Filters table rows based on search text. | ||
| * | ||
| * table_id (string): The id of the table to filter. | ||
| * search_text (string): The text to search for in table rows. | ||
| */ | ||
| CMS.AWSTableUtils.filterTable = function(table_id, search_text) { | ||
| var table = document.getElementById(table_id); | ||
| if (!table) { | ||
| return; | ||
| } | ||
| var rows = table.querySelectorAll("tbody tr"); | ||
| var search_lower = search_text.toLowerCase().trim(); | ||
|
|
||
| rows.forEach(function(row) { | ||
| if (search_lower === "") { | ||
| row.style.display = ""; | ||
| return; | ||
| } | ||
| var text = row.textContent.toLowerCase(); | ||
| if (text.indexOf(search_lower) !== -1) { | ||
| row.style.display = ""; | ||
| } else { | ||
| row.style.display = "none"; | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| // Backward compatibility aliases on CMS.AWSUtils | ||
| // These will be set up after aws_utils.js loads | ||
| $(document).ready(function() { | ||
| if (typeof CMS.AWSUtils !== 'undefined') { | ||
| // Alias the new functions to the old names for backward compatibility | ||
| CMS.AWSUtils.sort_table = CMS.AWSTableUtils.sortTable; | ||
| CMS.AWSUtils.init_table_sort = CMS.AWSTableUtils.initTableSort; | ||
| CMS.AWSUtils.filter_table = CMS.AWSTableUtils.filterTable; | ||
| } | ||
| }); | ||
ronryv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.