Skip to content
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

Programming exercises: Allow tutors to assess submissions in the new code editor #8437

Merged
merged 69 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
268463d
Enable monaco editor for instructors
pzdr7 Apr 9, 2024
2a33ffe
Only reset if editor available
pzdr7 Apr 9, 2024
9e6a1ec
Experimental: Initialize monaco in constructor; remove template
pzdr7 Apr 9, 2024
9c82511
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 12, 2024
c72496c
Fix integration tests
pzdr7 Apr 12, 2024
f95e270
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 13, 2024
ce8b18a
New widget: Hovering button for glyph margin
pzdr7 Apr 13, 2024
fe94da5
Add margin hover button to code editor; add feedback when clicked
pzdr7 Apr 13, 2024
4d99769
Limit to one feedback node per line
pzdr7 Apr 13, 2024
54bc401
Add support for update / cancel / delete feedback
pzdr7 Apr 13, 2024
ee9302b
Use monaco in manual assessment, onFileLoad support
pzdr7 Apr 13, 2024
71b2e37
New editor element: line highlight
pzdr7 Apr 13, 2024
fc3a0cf
Add line highlights to code-editor-monaco
pzdr7 Apr 13, 2024
153be44
Add line highlights to monaco editor from tutor assessment
pzdr7 Apr 13, 2024
a77d7ae
Allow editing of feedback
pzdr7 Apr 13, 2024
778d02f
Refresh feedback on changes
pzdr7 Apr 13, 2024
c1eb886
Fix positioning of new (unsaved) feedback
pzdr7 Apr 13, 2024
ad854f3
Add support for feedback suggestions and add remaining input parameters
pzdr7 Apr 13, 2024
c2992e8
Disable editing when readOnlyManualFeedback === true
pzdr7 Apr 13, 2024
25d4fe5
Add explanatory comment
pzdr7 Apr 14, 2024
14dd262
Merge branch 'feature/programming-exercises/monaco-instructors' into …
pzdr7 Apr 14, 2024
da03f70
Try to fix E2E tests
pzdr7 Apr 14, 2024
67dbc94
Try to fix playwright assessment test
pzdr7 Apr 14, 2024
3bd4419
Store line highlights; fix test case
pzdr7 Apr 14, 2024
277c7ff
Refactor move highlight method to container
pzdr7 Apr 14, 2024
5164b80
Fix client test using fakeAsync
pzdr7 Apr 14, 2024
5654681
Add client test for line highlights
pzdr7 Apr 14, 2024
8a30765
Always init margin button on tutor assessment
pzdr7 Apr 14, 2024
a33b623
Add test for hover button
pzdr7 Apr 14, 2024
d2ed715
Revert cypress fix
pzdr7 Apr 15, 2024
2361642
Skip cypress test for ProgrammingExerciseAssessment
pzdr7 Apr 15, 2024
a31e3af
Add tests for feedbacks and feedback suggestions
pzdr7 Apr 15, 2024
3e2a6d1
Remove jest import
pzdr7 Apr 15, 2024
ff141b3
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 15, 2024
730143c
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 16, 2024
55740f7
Merge branch 'feature/programming-exercises/monaco-instructors' into …
pzdr7 Apr 17, 2024
f09d203
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 17, 2024
f532dbe
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 18, 2024
3320c10
Merge branch 'feature/programming-exercises/monaco-instructors' into …
pzdr7 Apr 18, 2024
2cc369b
Unify methods for highlighting lines (ace is deprecated)
pzdr7 Apr 19, 2024
c4ad0e5
Dispose line highlights as well
pzdr7 Apr 19, 2024
e35096c
Docs for glyph margin hover button
pzdr7 Apr 19, 2024
2b003f9
Docs for line highlights
pzdr7 Apr 19, 2024
bc13d75
Docs for monaco editor methods
pzdr7 Apr 19, 2024
4b665db
Define color scheme for diff highlight
pzdr7 Apr 19, 2024
0b5c9ba
Adjust styling of margin button
pzdr7 Apr 19, 2024
3d1041d
Adjust colors
pzdr7 Apr 19, 2024
b77b0ec
Center hover button
pzdr7 Apr 19, 2024
705df0e
Docs for code-editor-monaco.component
pzdr7 Apr 19, 2024
6cc5692
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 19, 2024
3713a32
Merge branch 'feature/programming-exercises/monaco-instructors' into …
pzdr7 Apr 19, 2024
0eb0d2b
Quickfix line number of highlights
pzdr7 Apr 19, 2024
8d3377d
Fix one-line file bug
pzdr7 Apr 19, 2024
56e102b
Fix saving of feedback on 0-th line
pzdr7 Apr 19, 2024
4da4256
Test behavior of button when line unavailable
pzdr7 Apr 19, 2024
9cf30a8
Render build annotations and the hover button in separate lanes
pzdr7 Apr 19, 2024
5a2df18
Add typing for node retrieval; auto-focus text area on feedback creation
pzdr7 Apr 20, 2024
e872eca
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 21, 2024
4c2b776
Merge branch 'feature/programming-exercises/monaco-instructors' into …
pzdr7 Apr 21, 2024
ca68eb5
Merge branch 'develop' into feature/programming-exercises/monaco-inst…
pzdr7 Apr 22, 2024
60c18dc
Merge branch 'feature/programming-exercises/monaco-instructors' into …
pzdr7 Apr 22, 2024
b7a4649
Insert newline
pzdr7 Apr 22, 2024
6139177
Insert newline
pzdr7 Apr 22, 2024
badde51
Adjust hover class: move to front
pzdr7 Apr 22, 2024
6f970bc
Merge branch 'develop' into feature/programming-exercises/monaco-tuto…
pzdr7 Apr 22, 2024
37a5553
Merge branch 'develop' into feature/programming-exercises/monaco-tuto…
pzdr7 Apr 23, 2024
0f4b7d5
Decrease lastLine by 1
pzdr7 Apr 24, 2024
ed22bbc
Merge branch 'develop' into feature/programming-exercises/monaco-tuto…
pzdr7 Apr 25, 2024
602c902
Merge branch 'develop' into feature/programming-exercises/monaco-tuto…
pzdr7 Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
>
@if (!loadingParticipation && !participationCouldNotBeFetched) {
<jhi-code-editor-container
[useMonacoEditor]="true"
[editable]="false"
[participation]="participation"
[feedbackSuggestions]="feedbackSuggestions"
Expand All @@ -72,7 +73,7 @@
(onUpdateFeedback)="onUpdateFeedback($event)"
(onAcceptSuggestion)="removeSuggestion($event)"
(onDiscardSuggestion)="removeSuggestion($event)"
(onFileLoad)="onFileLoad($event)"
(onFileLoad)="highlightChangedLines($event)"
>
<div editorTitle *ngTemplateOutlet="editorTitle"></div>
<div editorToolbar *ngTemplateOutlet="editorToolbar"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,18 @@ export class CodeEditorTutorAssessmentContainerComponent implements OnInit, OnDe
}

/**
* Triggers when a new file was selected in the code editor. Compares the content of the file with the template (if available), calculates the diff
* and highlights the changed/added lines or all lines if the file is not in the template.
*
* @param selectedFile name of the file which is currently displayed
* For a file, computes the diff between the template and the submission currently being viewed, then highlights changed or edited lines in the editor.
* If the file did not exist in the template, all lines will be highlighted.
* @param selectedFile The file that has been selected in the editor.
*/
onFileLoad(selectedFile: string): void {
if (selectedFile && this.codeEditorContainer?.selectedFile && this.codeEditorContainer.aceEditor) {
// When the selectedFile is not part of the template, then this is a new file and all lines in code editor are highlighted
highlightChangedLines(selectedFile: string) {
if (selectedFile && this.codeEditorContainer?.selectedFile) {
if (!this.templateFileSession[selectedFile]) {
const lastLine = this.codeEditorContainer.aceEditor.editorSession.getLength() - 1;
const lastLine = this.codeEditorContainer.getNumberOfLines();
this.highlightLines(0, lastLine);
} else {
// Calculation of the diff, see: https://github.com/google/diff-match-patch/wiki/Line-or-Word-Diffs
const diffArray = this.diffMatchPatch.diff_linesToChars(this.templateFileSession[selectedFile], this.codeEditorContainer.aceEditor.editorSession.getValue());
const diffArray = this.diffMatchPatch.diff_linesToChars(this.templateFileSession[selectedFile], this.codeEditorContainer.getText());
const lineText1 = diffArray.chars1;
const lineText2 = diffArray.chars2;
const lineArray = diffArray.lineArray;
Expand Down Expand Up @@ -337,9 +335,7 @@ export class CodeEditorTutorAssessmentContainerComponent implements OnInit, OnDe
}

private highlightLines(firstLine: number, lastLine: number) {
if (this.codeEditorContainer?.aceEditor) {
this.codeEditorContainer.aceEditor.highlightLines(firstLine, lastLine, 'diff-newLine', 'gutter-diff-newLine');
}
this.codeEditorContainer.highlightLines(firstLine, lastLine);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,24 @@ <h4 class="editor-title"><ng-content select="[editorTitle]" /></h4>
/>
} @else {
<jhi-code-editor-monaco
#codeEditorMonaco
[commitState]="commitState"
[editorState]="editorState"
[course]="course"
[feedbacks]="participation?.results?.[0]?.feedbacks ?? []"
[feedbackSuggestions]="feedbackSuggestions"
[readOnlyManualFeedback]="readOnlyManualFeedback"
[disableActions]="!editable"
[isTutorAssessment]="isTutorAssessment"
[highlightDifferences]="highlightDifferences"
[selectedFile]="selectedFile"
[buildAnnotations]="annotations"
[sessionId]="participation?.id ?? 'test'"
(onFileContentChange)="onFileContentChange($event)"
(onUpdateFeedback)="onUpdateFeedback.emit($event)"
(onAcceptSuggestion)="onAcceptSuggestion.emit($event)"
(onDiscardSuggestion)="onDiscardSuggestion.emit($event)"
(onError)="onError($event)"
(onFileLoad)="fileLoad($event)"
/>
}
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class CodeEditorContainerComponent implements OnChanges, ComponentCanDeac
@ViewChild(CodeEditorActionsComponent, { static: false }) actions: CodeEditorActionsComponent;
@ViewChild(CodeEditorBuildOutputComponent, { static: false }) buildOutput: CodeEditorBuildOutputComponent;
@ViewChild(CodeEditorAceComponent, { static: false }) aceEditor?: CodeEditorAceComponent;
@ViewChild('codeEditorMonaco', { static: false }) monacoEditor?: CodeEditorMonacoComponent;
@ViewChild(CodeEditorMonacoComponent, { static: false }) monacoEditor?: CodeEditorMonacoComponent;
@ViewChild(CodeEditorInstructionsComponent, { static: false }) instructions: CodeEditorInstructionsComponent;

@Input()
Expand Down Expand Up @@ -272,6 +272,24 @@ export class CodeEditorContainerComponent implements OnChanges, ComponentCanDeac
return _isEmpty(this.unsavedFiles);
}

getText(): string {
return this.monacoEditor?.getText() ?? '';
}

getNumberOfLines(): number {
if (this.aceEditor) {
return this.aceEditor.editorSession.getLength();
}
return this.monacoEditor?.getNumberOfLines() ?? 0;
}

highlightLines(startLine: number, endLine: number): void {
// Workaround: increase line number by 1 for monaco
// Will be removed once ace is gone from every instance of this component
this.monacoEditor?.highlightLines(startLine + 1, endLine + 1);
this.aceEditor?.highlightLines(startLine, endLine, 'diff-newLine', 'gutter-diff-newLine');
}

// displays the alert for confirming refreshing or closing the page if there are unsaved changes
@HostListener('window:beforeunload', ['$event'])
unloadNotification(event: any) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
<div class="card">
<div [hidden]="true">
<div #addFeedbackButton>
<div class="monaco-add-feedback-button">
<fa-icon [icon]="faPlusSquare" />
</div>
</div>
</div>
<jhi-code-editor-header [showTabSizeSelector]="false" [filename]="selectedFile!" [isLoading]="isLoading" />
<div class="card-body card-body-monaco">
@if (selectedFile) {
@for (feedback of filterFeedbackForSelectedFile(feedbacks); track feedback) {
<!-- actual, stored feedback -->
<jhi-code-editor-tutor-assessment-inline-feedback
class="monaco-hidden-element"
[selectedFile]="selectedFile"
[codeLine]="Feedback.getReferenceLine(feedback)!"
[feedback]="feedback"
[readOnly]="true"
[highlightDifferences]="false"
[readOnly]="readOnlyManualFeedback"
[highlightDifferences]="highlightDifferences"
[course]="course"
(onUpdateFeedback)="updateFeedback($event)"
(onDeleteFeedback)="deleteFeedback($event)"
(onCancelFeedback)="cancelFeedback($event)"
/>
}
<!-- new, unsaved feedback -->
@for (line of newFeedbackLines; track line) {
<jhi-code-editor-tutor-assessment-inline-feedback
class="monaco-hidden-element"
[selectedFile]="selectedFile"
[codeLine]="line"
[feedback]="undefined"
[highlightDifferences]="highlightDifferences"
[readOnly]="readOnlyManualFeedback"
[course]="course"
(onUpdateFeedback)="updateFeedback($event)"
(onDeleteFeedback)="deleteFeedback($event)"
(onCancelFeedback)="cancelFeedback($event)"
/>
}
<!-- feedback suggestions -->
@for (suggestion of filterFeedbackForSelectedFile(feedbackSuggestions); track suggestion) {
<jhi-code-editor-tutor-assessment-inline-feedback-suggestion
[codeLine]="Feedback.getReferenceLine(suggestion)!"
[feedback]="suggestion"
[course]="course"
(onAcceptSuggestion)="acceptSuggestion($event)"
(onDiscardSuggestion)="discardSuggestion($event)"
/>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,30 @@
.card-body-monaco {
padding: unset;
}

/* Applied e.g. to hover messages of build annotations. Makes them visible even when there are line widgets. */
.monaco-hover {
z-index: 1;
}

.monaco-add-feedback-button {
cursor: pointer;

/*
* Below are cosmetic adjustments that center the button and prevent the icon from breaking out of its row.
*/
display: flex;
width: 19px;
height: 19px;
font-size: 18px;
align-items: center;
padding-left: 1px;
}

.monaco-diff-line-highlight {
background-color: var(--monaco-editor-diff-line-highlight);
}

.monaco-diff-margin-highlight {
background-color: var(--monaco-editor-diff-margin-highlight);
}
Loading
Loading