Skip to content

Commit

Permalink
Selection by a dedicated class instead of elements and removed unused…
Browse files Browse the repository at this point in the history
… logs
  • Loading branch information
mengyewgau authored and huyuxin0429 committed Sep 19, 2023
1 parent d39164f commit d041556
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 42 deletions.
54 changes: 20 additions & 34 deletions app/assets/javascripts/submission_obfuscation.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
(function() {
(function () {
let SubmissionObfuscation = {};

// Retrieve the "obfuscate" parameter from the URL
let urlParams = new URLSearchParams(window.location.search);
window.shouldNotObfuscate = (urlParams.get('obfuscate') === 'false');

// Store the original student2 name
SubmissionObfuscation.originalStudent2Name = null;
SubmissionObfuscation.maskStudentName = function () {

SubmissionObfuscation.maskStudentName = function() {
// console.log("JS Script here onwards");
// console.log(window.shouldNotObfuscate)

// Check if the global flag for obfuscation is false; if so, return without obfuscating
if (window.shouldNotObfuscate) {
// console.log("Names are not obfuscated")
return;
}

// console.log("Masking student name now");
// Masking inside all h4 elements to get the student pairings
let h4Elements = document.querySelectorAll('h4');
h4Elements.forEach(h4Element => {

// Masking inside all h4 elements with id "submission_similarities_for_students" to get the student pairings
let h4Element = document.querySelector('h4[class="submission_similarities_for_students"]');
if (h4Element) {
let match = h4Element.innerHTML.match(/for Students .*? and (.*?) \(\d+\.\d+%\)/);
if (match && match[1] && match[1] !== '******') {
let student2Name = match[1];
h4Element.innerHTML = h4Element.innerHTML.replace(new RegExp("and\\s" + student2Name, "g"), "and ******");
}
});

// Masking the second h5 for each pair of submissions
let h5Elements = document.querySelectorAll('h5');
}

for (let i = 1; i < h5Elements.length; i += 2) {
// Masking h5 elements with the class 'submission2_by_student2'
let h5Elements = document.querySelectorAll('h5.submission2_by_student2');

h5Elements.forEach(h5Element => {
// Adjusted regex to capture student names like Student-02 or x-v6551_q1
h5Elements[i].innerHTML = h5Elements[i].innerHTML.replace(/Submission by [\w-]+[_\w]*/, 'Submission by ******');
}


// Masking inside all table headers in every table
h5Element.innerHTML = h5Element.innerHTML.replace(/Submission by [\w-]+[_\w]*/, 'Submission by ******');
});



// Masking inside table header with class "student2_submission" in every table
let tables = document.querySelectorAll('table');
tables.forEach(table => {
let thirdColumnHeader = table.querySelector('th.lines_col:nth-child(3)');
let thirdColumnHeader = table.querySelector('th.student2_submission');
if (thirdColumnHeader) {
// Adjusted regex to capture student names like Student-02 or x-v6551_q1
let match = thirdColumnHeader.innerHTML.match(/Submission by ([\w-]+[_\w]*)/);
Expand All @@ -51,18 +46,9 @@
}
}
});

};


/*
SubmissionObfuscation.onLoad = function() {
if (!window.shouldNotObfuscate) {
console.log("On Load called")
SubmissionObfuscation.maskStudentName();
}

};
*/

// Expose SubmissionObfuscation to the global context
window.SubmissionObfuscation = SubmissionObfuscation;
Expand Down
3 changes: 0 additions & 3 deletions app/views/layouts/pdf_report.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ along with SSID. If not, see <http://www.gnu.org/licenses/>.
var shouldNotObfuscate = localStorage.getItem('shouldNotObfuscate') === 'true';
window.shouldNotObfuscate = shouldNotObfuscate
if (window.SubmissionObfuscation && typeof window.SubmissionObfuscation.maskStudentName === 'function') {
// console.log("Report Fn Hit")
// console.log(window.shouldNotObfuscate)
// console.log("Local Storage", shouldNotObfuscate)
window.SubmissionObfuscation.maskStudentName();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
</style>

<h4>Submission Similarities for Students <%= @submission_similarity.student1.name %> and <%= @submission_similarity.student2.name %> (<%= @submission_similarity.similarity %>%)</h4>
<h4 class="submission_similarities_for_students">Submission Similarities for Students <%= @submission_similarity.student1.name %> and <%= @submission_similarity.student2.name %> (<%= @submission_similarity.similarity %>%)</h4>
<%= render partial: "side_by_side_view", locals: { submission_similarity: @submission_similarity }%>

<script type="text/javascript">
Expand Down
8 changes: 4 additions & 4 deletions app/views/submission_similarities/_side_by_side_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<thead>
<tr>
<th>Key</th>
<th class="lines_col">Submission by <%= @student1.name %></th>
<th class="lines_col">Submission by <%= @student2.name %></th>
<th class="lines_col student1_submission">Submission by <%= @student1.name %></th>
<th class="lines_col student2_submission">Submission by <%= @student2.name %></th>
<th>Num of Matching Statements</th>
</tr>
</thead>
Expand Down Expand Up @@ -64,8 +64,8 @@
<% current_line_num = 1 %>
<% current_mapping = sorted_mappings.shift %>

<h5 style="float:left; width: 50%;">Submission by <%= @student1.name %></h5>
<h5 style="float:right; width: 50%;">Submission by <%= @student2.name %></h5>
<h5 class="submission1_by_student1" style="float:left; width: 50%;">Submission by <%= @student1.name %></h5>
<h5 class="submission2_by_student2" style="float:right; width: 50%;">Submission by <%= @student2.name %></h5>

<% while current_line_num <= @submission1.lines.size %>
<div class="submissions">
Expand Down

0 comments on commit d041556

Please sign in to comment.