Skip to content

Commit

Permalink
Add tutorlink in default renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Oct 19, 2023
1 parent ceb6b93 commit 95c31e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
13 changes: 7 additions & 6 deletions app/assets/javascripts/pythia_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ function initPythiaSubmissionShow(submissionCode: string, activityPath: string):

function initTutorLinks(): void {
document.querySelectorAll(".tutorlink").forEach(l => {
const group = l.closest(".group") as HTMLElement;
if (!(group.dataset.statements || group.dataset.stdin)) {
const tutorLink = l as HTMLLinkElement;
if (!(tutorLink.dataset.statements || tutorLink.dataset.stdin)) {
l.remove();
}
});

document.querySelectorAll(".tutorlink").forEach(l => l.addEventListener("click", e => {
const exerciseId = (document.querySelector(".feedback-table") as HTMLElement).dataset.exercise_id;
const group = e.currentTarget.closest(".group");
const stdin = group.dataset.stdin.slice(0, -1);
const statements = group.dataset.statements;
const tutorLink = e.currentTarget as HTMLLinkElement;
const group = tutorLink.closest(".group");
const stdin = tutorLink.dataset.stdin.slice(0, -1);
const statements = tutorLink.dataset.statements;
const files = { inline: {}, href: {} };

group.querySelectorAll(".contains-file").forEach(g => {
const content = JSON.parse(g.dataset.files);
const content = JSON.parse((g as HTMLElement).dataset.files);

Object.values(content).forEach(value => {
files[value["location"]][value["name"]] = value["content"];
Expand Down
13 changes: 13 additions & 0 deletions app/helpers/renderers/feedback_table_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ def tab_content(t)

def group(g)
@builder.div(class: "group #{g[:accepted] ? 'correct' : 'wrong'}") do
# Add a link to the debugger if there is data
if g[:data] && (g[:data][:statements] || g[:data][:stdin])
@builder.div(class: 'tutor-strip tutorlink',
title: 'Start debugger',
'data-statements': (g[:data][:statements]).to_s,
'data-stdin': (g[:data][:stdin]).to_s
) do
@builder.div(class: 'tutor-strip-icon') do
@builder.i('', class: 'mdi mdi-launch mdi-18')
end
end
end

if g[:description]
@builder.div(class: 'row') do
@builder.div(class: 'col-12 description') do
Expand Down
23 changes: 0 additions & 23 deletions app/helpers/renderers/pythia_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,6 @@ def output_message(m)
end
end

def group(g)
if g.key?(:data)
@builder.div(class: "group #{g[:accepted] ? 'correct' : 'wrong'}",
'data-statements': (g[:data][:statements]).to_s,
'data-stdin': (g[:data][:stdin]).to_s) do
@builder.div(class: 'tutor-strip tutorlink', title: 'Start debugger') do
@builder.div(class: 'tutor-strip-icon') do
@builder.i('', class: 'mdi mdi-launch mdi-18')
end
end
if g[:description]
@builder.div(class: 'col-12 description') do
message(g[:description])
end
end
messages(g[:messages])
g[:groups]&.each { |tc| testcase(tc) }
end
else
super(g)
end
end

def testcase(tc)
return super(tc) unless tc[:data] && tc[:data][:files]

Expand Down

0 comments on commit 95c31e7

Please sign in to comment.