Skip to content

Commit

Permalink
Merge branch 'main' into fix/series-icon
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Jan 3, 2024
2 parents 93096ba + ffd59e3 commit d7f0a4c
Show file tree
Hide file tree
Showing 36 changed files with 568 additions and 327 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -48,4 +48,4 @@ jobs:
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
bundle exec rails test:system
- name: Upload screenshot artifacts
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: screenshots-failure
path: tmp/capybara
Expand Down
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ gem 'image_processing', '~> 1.12.2'
gem 'bootsnap', '~> 1.17.0', require: false

# used to validate container responses
gem 'json_schemer', '~> 2.1.0'
gem 'json_schemer', '~> 2.1.1'

# delayed jobs
gem 'delayed_job_active_record', '~> 4.1.8'
Expand Down Expand Up @@ -129,10 +129,10 @@ gem 'faker', '~> 3.2.2'
# Profiling
gem 'flamegraph', '~> 0.9.5'
gem 'memory_profiler', '~> 1.0.1'
gem 'rack-mini-profiler', '~> 3.1.1'
gem 'rack-mini-profiler', '~> 3.3.0'
gem 'stackprof', '~> 0.2.25'

gem 'ddtrace', '~> 1.17.0'
gem 'ddtrace', '~> 1.18.0'

# Make sure filesystem changes only happen at the end of a transaction
gem 'after_commit_everywhere', '~> 1.3.1'
Expand All @@ -154,15 +154,15 @@ group :development, :test do

# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 3.39.2'
gem 'selenium-webdriver', '~> 4.15.0'
gem 'selenium-webdriver', '~> 4.16.0'
end

group :test do
# For measuring coverage
gem 'minitest-ci', '~> 3.4.0'
gem 'simplecov', '~> 0.22.0', require: false
gem 'simplecov-cobertura', '~> 2.1.0', require: false
gem 'test-prof', '~> 1.3.0'
gem 'test-prof', '~> 1.3.1'

# Mocking HTTP requests to third parties.
gem 'webmock'
Expand Down
30 changes: 15 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,16 @@ GEM
railties (>= 6.0.0)
daemons (1.4.1)
dalli (3.2.6)
datadog-ci (0.4.1)
datadog-ci (0.5.1)
msgpack
date (3.3.4)
ddtrace (1.17.0)
datadog-ci (~> 0.4.0)
debase-ruby_core_source (= 3.2.2)
ddtrace (1.18.0)
datadog-ci (~> 0.5.0)
debase-ruby_core_source (= 3.2.3)
libdatadog (~> 5.0.0.1.0)
libddwaf (~> 1.14.0.0.0)
msgpack
debase-ruby_core_source (3.2.2)
debase-ruby_core_source (3.2.3)
delayed_job (4.1.11)
activesupport (>= 3.0, < 8.0)
delayed_job_active_record (4.1.8)
Expand Down Expand Up @@ -218,7 +218,7 @@ GEM
i18n-js (4.2.3)
glob (>= 0.4.0)
i18n
icalendar (2.10.0)
icalendar (2.10.1)
ice_cube (~> 0.16)
ice_cube (0.16.4)
image_processing (1.12.2)
Expand All @@ -240,7 +240,7 @@ GEM
bindata
faraday (~> 2.0)
faraday-follow_redirects
json_schemer (2.1.0)
json_schemer (2.1.1)
hana (~> 1.3)
regexp_parser (~> 2.0)
simpleidn (~> 0.2)
Expand Down Expand Up @@ -367,7 +367,7 @@ GEM
activesupport (>= 3.0.0)
racc (1.7.3)
rack (2.2.8)
rack-mini-profiler (3.1.1)
rack-mini-profiler (3.3.0)
rack (>= 1.2.0)
rack-oauth2 (2.2.0)
activesupport
Expand Down Expand Up @@ -469,7 +469,7 @@ GEM
ffi (~> 1.12)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
selenium-webdriver (4.15.0)
selenium-webdriver (4.16.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand Down Expand Up @@ -510,7 +510,7 @@ GEM
attr_required (>= 0.0.5)
faraday (~> 2.0)
faraday-follow_redirects
test-prof (1.3.0)
test-prof (1.3.1)
thor (1.3.0)
tilt (2.0.11)
timeout (0.4.1)
Expand Down Expand Up @@ -572,7 +572,7 @@ DEPENDENCIES
counter_culture (~> 3.5)
cssbundling-rails (~> 1.3.3)
dalli (~> 3.2.6)
ddtrace (~> 1.17.0)
ddtrace (~> 1.18.0)
delayed_job_active_record (~> 4.1.8)
delayed_job_web (~> 1.4.4)
devise (~> 4.9.3)
Expand All @@ -591,7 +591,7 @@ DEPENDENCIES
image_processing (~> 1.12.2)
jbuilder (~> 2.11.5)
jsbundling-rails (~> 1.2.1)
json_schemer (~> 2.1.0)
json_schemer (~> 2.1.1)
jwt (~> 2.7.1)
kramdown (~> 2.4.0)
kramdown-parser-gfm (~> 1.1.0)
Expand All @@ -613,7 +613,7 @@ DEPENDENCIES
pretender (~> 0.5.0)
puma (~> 6.4.0)
pundit (~> 2.3.1)
rack-mini-profiler (~> 3.1.1)
rack-mini-profiler (~> 3.3.0)
rails (~> 7.1.2)
rails-controller-testing (~> 1.0.5)
rails-i18n (~> 7.0.8)
Expand All @@ -625,13 +625,13 @@ DEPENDENCIES
rubocop-rails (~> 2.22.2)
ruby-saml (~> 1.16.0)
rubyzip (~> 2.3.2)
selenium-webdriver (~> 4.15.0)
selenium-webdriver (~> 4.16.0)
simplecov (~> 0.22.0)
simplecov-cobertura (~> 2.1.0)
slack-notifier (~> 2.4.0)
sprockets-rails (~> 3.4.2)
stackprof (~> 0.2.25)
test-prof (~> 1.3.0)
test-prof (~> 1.3.1)
tzinfo-data
web-console (~> 4.2.1)
webmock
Expand Down
8 changes: 6 additions & 2 deletions app/assets/javascripts/code_listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ import {

const MARKING_CLASS = "marked";

function initAnnotations(submissionId: number, courseId: number, exerciseId: number, userId: number, code: string, questionMode = false): void {
function initAnnotations(submissionId: number, courseId: number, exerciseId: number, userId: number, code: string, userIsStudent: boolean, canSubmitAsOwn: boolean): void {
userAnnotationState.reset();
submissionState.code = code;
courseState.id = courseId;
exerciseState.id = exerciseId;
userState.id = userId;
submissionState.id = submissionId;
annotationState.isQuestionMode = questionMode;
annotationState.isQuestionMode = userIsStudent;

if (canSubmitAsOwn) {
userState.addPermission("submission.submit_as_own");
}

const table = document.querySelector<HTMLTableElement>("table.code-listing");
const rows = table.querySelectorAll("tr");
Expand Down
22 changes: 18 additions & 4 deletions app/assets/javascripts/coding_scratchpad.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Papyros } from "@dodona/papyros";
import { InputMode } from "@dodona/papyros";
import { ProgrammingLanguage } from "@dodona/papyros";
import { CodeEditor, InputMode, Papyros, ProgrammingLanguage } from "@dodona/papyros";
import { themeState } from "state/Theme";
import { EditorView } from "@codemirror/view";
import { setCode } from "editor";
import { rougeStyle, setCode } from "editor";
import { syntaxHighlighting } from "@codemirror/language";

/** Identifiers used in HTML for relevant elements */
const CODE_EDITOR_PARENT_ID = "scratchpad-editor-wrapper";
Expand All @@ -28,6 +27,17 @@ function initCodingScratchpad(programmingLanguage: ProgrammingLanguage): void {
showButton.classList.remove("hidden");
showButton.addEventListener("click", async function () {
if (!papyros) { // Only create Papyros once per session, but only when required
// Papyros registers a service worker on a specific path
// We used to do this on a different path
// So we need to unregister old serviceworkers manually as these won't get overwritten
navigator.serviceWorker.getRegistrations().then(function (registrations) {
for (const registration of registrations) {
if (registration.scope !== document.location.origin + "/") {
registration.unregister();
}
}
});

papyros = new Papyros(
{
programmingLanguage: Papyros.toProgrammingLanguage(programmingLanguage),
Expand Down Expand Up @@ -76,6 +86,10 @@ function initCodingScratchpad(programmingLanguage: ProgrammingLanguage): void {
darkMode: themeState.theme === "dark"
});
await papyros.launch();

papyros.codeRunner.editor.reconfigure([CodeEditor.STYLE, syntaxHighlighting(rougeStyle, {
fallback: true
})]);
}
});
// Ask user to choose after offcanvas is shown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "components/annotations/hidden_annotations_dot";
import { i18nMixin } from "components/meta/i18n_mixin";
import { userState } from "state/Users";
import { annotationState } from "state/Annotations";
import { submissionState } from "state/Submissions";


/**
Expand Down Expand Up @@ -38,6 +39,11 @@ export class AnnotationOptions extends i18nMixin(ShadowlessLitElement) {
${this.addAnnotationTitle}
</button>
` : html``}
${submissionState.canResubmitSubmission ? html`
<a class="btn btn-text resubmit-btn" href="${submissionState.resubmitPath}" target="_blank">
${I18n.t("js.feedbacks.submission.submit")}
</a>
` : html``}
<span class="flex-spacer"></span>
<d-annotations-toggles></d-annotations-toggles>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ declare type EditorEventHandler = (event: FocusEvent, view: EditorView) => boole

// A custom theme for CodeMirror that applies the same CSS as Rouge does,
// meaning we can use our existing themes.
const rougeStyle = HighlightStyle.define([
export const rougeStyle = HighlightStyle.define([
{ tag: tags.comment, class: "c" },
{ tag: tags.lineComment, class: "c" },
{ tag: tags.blockComment, class: "cm" },
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/i18n/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@
"favorite-course-do": "Favorite",
"favorite-course-failed": "Favoriting course failed",
"favorite-course-succeeded": "Favorited course",
"feedbacks": {
"submission": {
"submit": "Submit this solution"
}
},
"institutions": "Institutions",
"judges": "Judges",
"label-undeletable": "This label can't be deleted because it was set in the dirconfig file of a parent directory of the learning activity.",
Expand Down Expand Up @@ -753,6 +758,11 @@
"favorite-course-do": "Voeg toe aan favorieten",
"favorite-course-failed": "Cursus aan favorieten toevoegen mislukt",
"favorite-course-succeeded": "Cursus toegevoegd aan favorieten",
"feedbacks": {
"submission": {
"submit": "Deze oplossing indienen"
}
},
"institutions": "Onderwijsinstellingen",
"judges": "Judges",
"label-undeletable": "Dit label kan niet verwijderd worden omdat het werd ingesteld in het dirconfig bestand van een bovenliggende map.",
Expand Down
11 changes: 11 additions & 0 deletions app/assets/javascripts/state/Submissions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { State } from "state/state_system/State";
import { stateProperty } from "state/state_system/StateProperty";
import { userState } from "state/Users";
import { courseState } from "state/Courses";
import { exerciseState } from "state/Exercises";

class SubmissionState extends State {
@stateProperty id: number;
Expand All @@ -14,6 +17,14 @@ class SubmissionState extends State {
get code(): string {
return this._code;
}

get canResubmitSubmission(): boolean {
return userState.hasPermission("submission.submit_as_own");
}

get resubmitPath(): string {
return `/courses/${courseState.id}/exercises/${exerciseState.id}/?edit_submission=${submissionState.id}`;
}
}

export const submissionState = new SubmissionState();
2 changes: 1 addition & 1 deletion app/assets/javascripts/state/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { stateProperty } from "state/state_system/StateProperty";
import { ThemeOption } from "state/Theme";
import { fetch } from "utilities";

export type Permission = "annotation.create"
export type Permission = "annotation.create" | "submission.submit_as_own";

class UserState extends State {
@stateProperty id: number;
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/base.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@

// 6. Seasonal css sheets
@import "seasonal/christmas.css.scss";
@import "seasonal/december.css.scss";
@import "seasonal/valentine.css.scss";
@import "seasonal/mario-day.css.scss";
@import "seasonal/pi-day.css.scss";

// 8. Papyros css
@import "../../../node_modules/@dodona/papyros/dist/Papyros";

/* stylelint-disable-next-line selector-class-pattern */
.field_with_errors input {
border-color: var(--d-danger);
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/components/card.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,8 @@ a.card-title-link:hover {
flex-direction: column;
justify-content: space-evenly;
}

.card-title .btn-icon {
margin-top: -6px;
margin-bottom: -6px;
}
32 changes: 31 additions & 1 deletion app/assets/stylesheets/components/scratchpad.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
color: var(--d-on-surface-muted);

// Header has absolute position, simulate its height using margin-top
margin-top: var(--d-navbar-height) + 5;
margin-top: calc(var(--d-navbar-height) + 5px);
}

#scratchpad-code-copy-btn {
Expand All @@ -57,6 +57,10 @@
// Wrapper around editor provides margin
#scratchpad-editor-wrapper {
margin-bottom: 20px;

:focus-visible {
outline: none;
}
}

// Wrapper and its child should take up as much space as possible
Expand Down Expand Up @@ -86,3 +90,29 @@
#scratchpad-offcanvas.show {
@include shadow-z3;
}

/* stylelint-disable selector-class-pattern */
.tailwind ._tw-border-gray-200 {
border-color: var(--d-divider) !important;
}

.tailwind :is(._tw-dark .dark\:_tw-border-dark-mode-content) {
border-color: var(--d-divider) !important;
}

.tailwind * {
border-color: var(--d-divider) !important;
}
/* stylelint-enable selector-class-pattern */

/* stylelint-disable selector-id-pattern */
#__papyros-code-input-area {
background-color: var(--d-code-bg) !important;
color: var(--d-on-background);
caret-color: var(--d-secondary);
}
/* stylelint-enable selector-id-pattern */

#scratchpad-panel-wrapper {
border-bottom: 0 !important;
}
Loading

0 comments on commit d7f0a4c

Please sign in to comment.