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

Development: Refactor Markdown editor actions with the adapter pattern #9260

Merged
merged 33 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d3eb39b
Add type aliases
pzdr7 Aug 30, 2024
be49c3b
Add more type aliases
pzdr7 Aug 30, 2024
db328a4
Refactor test-case-action
pzdr7 Aug 30, 2024
62226bf
Rename type aliases
pzdr7 Aug 30, 2024
a7469e3
More renaming
pzdr7 Aug 30, 2024
d386562
More renaming
pzdr7 Aug 30, 2024
40f8d4a
Basic models for Adapter pattern
pzdr7 Aug 31, 2024
607ca83
Basic models for Adapter pattern
pzdr7 Aug 31, 2024
512384e
Use TextEditor in Actions
pzdr7 Aug 31, 2024
605bcd1
Move TextEditor interface
pzdr7 Aug 31, 2024
bbd0fa2
Add more methods to TextEditor interface
pzdr7 Aug 31, 2024
0ef7086
Remove Model
pzdr7 Aug 31, 2024
29c83a8
Fix addAction
pzdr7 Aug 31, 2024
891fc52
Fix compile
pzdr7 Aug 31, 2024
e188a36
Fix tests
pzdr7 Aug 31, 2024
e78dbee
Remove unused types/functions
pzdr7 Aug 31, 2024
2be3d2d
Remove more type definitions
pzdr7 Aug 31, 2024
726db04
Add Model for keybindings
pzdr7 Aug 31, 2024
49f1168
Delete text-editor-model.model.ts
pzdr7 Aug 31, 2024
249e6b2
Remove unused monaco import
pzdr7 Aug 31, 2024
2606f9a
Remove resolved TODO
pzdr7 Aug 31, 2024
81bf417
MonacoEditorAction -> TextEditorAction
pzdr7 Aug 31, 2024
a7c2e46
Rename action files
pzdr7 Aug 31, 2024
eb3a288
Rename the remaining MonacoEditorAction files
pzdr7 Aug 31, 2024
edd7c9c
Rename action classes
pzdr7 Aug 31, 2024
d401416
Rename action IDs
pzdr7 Aug 31, 2024
9b18e28
Rename another action class
pzdr7 Aug 31, 2024
e8cfa1f
Merge branch 'develop' into chore/development/refactor-monaco-types
pzdr7 Sep 3, 2024
ec0659e
Merge branch 'develop' into chore/development/refactor-monaco-types
pzdr7 Sep 4, 2024
ae2243b
Merge branch 'develop' into chore/development/refactor-monaco-types
pzdr7 Sep 6, 2024
9e3f49e
Merge branch 'develop' into chore/development/refactor-monaco-types
pzdr7 Sep 6, 2024
53fba0d
Merge branch 'develop' into chore/development/refactor-monaco-types
pzdr7 Sep 9, 2024
104f0e5
Merge branch 'develop' into chore/development/refactor-monaco-types
pzdr7 Sep 10, 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 @@ -6,28 +6,20 @@ import { ExamLiveEventType, ExamWideAnnouncementEvent } from 'app/exam/participa
import { faCheckCircle, faSpinner } from '@fortawesome/free-solid-svg-icons';
import { AccountService } from 'app/core/auth/account.service';
import dayjs from 'dayjs/esm';
import { MonacoBoldAction } from 'app/shared/monaco-editor/model/actions/monaco-bold.action';
import { MonacoItalicAction } from 'app/shared/monaco-editor/model/actions/monaco-italic.action';
import { MonacoUnderlineAction } from 'app/shared/monaco-editor/model/actions/monaco-underline.action';
import { MonacoCodeAction } from 'app/shared/monaco-editor/model/actions/monaco-code.action';
import { MonacoCodeBlockAction } from 'app/shared/monaco-editor/model/actions/monaco-code-block.action';
import { MonacoOrderedListAction } from 'app/shared/monaco-editor/model/actions/monaco-ordered-list.action';
import { BoldAction } from 'app/shared/monaco-editor/model/actions/bold.action';
import { ItalicAction } from 'app/shared/monaco-editor/model/actions/italic.action';
import { UnderlineAction } from 'app/shared/monaco-editor/model/actions/underline.action';
import { CodeAction } from 'app/shared/monaco-editor/model/actions/code.action';
import { CodeBlockAction } from 'app/shared/monaco-editor/model/actions/code-block.action';
import { OrderedListAction } from 'app/shared/monaco-editor/model/actions/ordered-list.action';

@Component({
selector: 'jhi-exam-live-announcement-create-modal',
templateUrl: './exam-live-announcement-create-modal.component.html',
styleUrls: ['./exam-live-announcement-create-modal.component.scss'],
})
export class ExamLiveAnnouncementCreateModalComponent {
actions = [
new MonacoBoldAction(),
new MonacoItalicAction(),
new MonacoUnderlineAction(),
new MonacoCodeAction(),
new MonacoCodeBlockAction(),
new MonacoOrderedListAction(),
new MonacoOrderedListAction(),
];
actions = [new BoldAction(), new ItalicAction(), new UnderlineAction(), new CodeAction(), new CodeBlockAction(), new OrderedListAction(), new OrderedListAction()];

courseId: number;
examId: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { TeamConfigFormGroupComponent } from 'app/exercises/shared/team-config-f
import { NgModel } from '@angular/forms';
import { Subscription } from 'rxjs';
import { FormSectionStatus } from 'app/forms/form-status-bar/form-status-bar.component';
import { MonacoFormulaAction } from 'app/shared/monaco-editor/model/actions/monaco-formula.action';
import { FormulaAction } from 'app/shared/monaco-editor/model/actions/formula.action';

@Component({
selector: 'jhi-file-upload-exercise-update',
Expand Down Expand Up @@ -54,8 +54,8 @@ export class FileUploadExerciseUpdateComponent implements AfterViewInit, OnDestr
exerciseCategories: ExerciseCategory[];
existingCategories: ExerciseCategory[];
notificationText?: string;
domainActionsProblemStatement = [new MonacoFormulaAction()];
domainActionsExampleSolution = [new MonacoFormulaAction()];
domainActionsProblemStatement = [new FormulaAction()];
domainActionsExampleSolution = [new FormulaAction()];
isImport: boolean;
examCourseId?: number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { NgModel } from '@angular/forms';
import { ExerciseUpdatePlagiarismComponent } from 'app/exercises/shared/plagiarism/exercise-update-plagiarism/exercise-update-plagiarism.component';
import { TeamConfigFormGroupComponent } from 'app/exercises/shared/team-config-form-group/team-config-form-group.component';
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';
import { MonacoFormulaAction } from 'app/shared/monaco-editor/model/actions/monaco-formula.action';
import { FormulaAction } from 'app/shared/monaco-editor/model/actions/formula.action';

@Component({
selector: 'jhi-modeling-exercise-update',
Expand Down Expand Up @@ -64,8 +64,8 @@ export class ModelingExerciseUpdateComponent implements AfterViewInit, OnDestroy
exerciseCategories: ExerciseCategory[];
existingCategories: ExerciseCategory[];
notificationText?: string;
domainActionsProblemStatement = [new MonacoFormulaAction()];
domainActionsExampleSolution = [new MonacoFormulaAction()];
domainActionsProblemStatement = [new FormulaAction()];
domainActionsExampleSolution = [new FormulaAction()];
examCourseId?: number;
isImport: boolean;
isExamMode: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { Result } from 'app/entities/result.model';
import { faCheckCircle, faCircleNotch, faExclamationTriangle, faGripLines, faSave } from '@fortawesome/free-solid-svg-icons';
import { MarkdownEditorHeight, MarkdownEditorMonacoComponent } from 'app/shared/markdown-editor/monaco/markdown-editor-monaco.component';
import { Annotation } from 'app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component';
import { MonacoFormulaAction } from 'app/shared/monaco-editor/model/actions/monaco-formula.action';
import { MonacoTaskAction } from 'app/shared/monaco-editor/model/actions/monaco-task.action';
import { MonacoTestCaseAction } from 'app/shared/monaco-editor/model/actions/monaco-test-case.action';
import { MonacoEditorDomainAction } from 'app/shared/monaco-editor/model/actions/monaco-editor-domain-action.model';
import { FormulaAction } from 'app/shared/monaco-editor/model/actions/formula.action';
import { TaskAction } from 'app/shared/monaco-editor/model/actions/task.action';
import { TestCaseAction } from 'app/shared/monaco-editor/model/actions/test-case.action';
import { TextEditorDomainAction } from 'app/shared/monaco-editor/model/actions/text-editor-domain-action.model';

@Component({
selector: 'jhi-programming-exercise-editable-instructions',
Expand All @@ -31,9 +31,9 @@ export class ProgrammingExerciseEditableInstructionComponent implements AfterVie

exerciseTestCases: string[] = [];

taskRegex = MonacoTaskAction.GLOBAL_TASK_REGEX;
testCaseAction = new MonacoTestCaseAction();
domainActions: MonacoEditorDomainAction[] = [new MonacoFormulaAction(), new MonacoTaskAction(), this.testCaseAction];
taskRegex = TaskAction.GLOBAL_TASK_REGEX;
testCaseAction = new TestCaseAction();
domainActions: TextEditorDomainAction[] = [new FormulaAction(), new TaskAction(), this.testCaseAction];

savingInstructions = false;
unsavedChangesValue = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RepositoryFileService } from 'app/exercises/shared/result/repository.se
import { CodeEditorRepositoryFileService, ConnectionError } from 'app/exercises/programming/shared/code-editor/service/code-editor-repository.service';
import { CodeEditorFileService } from 'app/exercises/programming/shared/code-editor/service/code-editor-file.service';
import { LocalStorageService } from 'ngx-webstorage';
import { EditorPosition, MonacoEditorComponent } from 'app/shared/monaco-editor/monaco-editor.component';
import { MonacoEditorComponent } from 'app/shared/monaco-editor/monaco-editor.component';
import { firstValueFrom, timeout } from 'rxjs';
import { FEEDBACK_SUGGESTION_ACCEPTED_IDENTIFIER, FEEDBACK_SUGGESTION_IDENTIFIER, Feedback } from 'app/entities/feedback.model';
import { Course } from 'app/entities/course.model';
Expand All @@ -21,6 +21,7 @@ import { fromPairs, pickBy } from 'lodash-es';
import { CodeEditorTutorAssessmentInlineFeedbackSuggestionComponent } from 'app/exercises/programming/assess/code-editor-tutor-assessment-inline-feedback-suggestion.component';
import { MonacoEditorLineHighlight } from 'app/shared/monaco-editor/model/monaco-editor-line-highlight.model';
import { FileTypeService } from 'app/exercises/programming/shared/service/file-type.service';
import { EditorPosition } from 'app/shared/monaco-editor/model/actions/monaco-editor.util';

type FileSession = { [fileName: string]: { code: string; cursor: EditorPosition; loadingError: boolean } };
export type Annotation = { fileName: string; row: number; column: number; text: string; type: string; timestamp: number; hash?: string };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ import { faFileImage } from '@fortawesome/free-regular-svg-icons';
import { CdkDragDrop } from '@angular/cdk/drag-drop';
import { MAX_QUIZ_QUESTION_POINTS } from 'app/shared/constants/input.constants';
import { FileService } from 'app/shared/http/file.service';
import { MonacoQuizHintAction } from 'app/shared/monaco-editor/model/actions/quiz/monaco-quiz-hint.action';
import { MonacoQuizExplanationAction } from 'app/shared/monaco-editor/model/actions/quiz/monaco-quiz-explanation.action';
import { QuizHintAction } from 'app/shared/monaco-editor/model/actions/quiz/quiz-hint.action';
import { QuizExplanationAction } from 'app/shared/monaco-editor/model/actions/quiz/quiz-explanation.action';
import { MarkdownEditorMonacoComponent, TextWithDomainAction } from 'app/shared/markdown-editor/monaco/markdown-editor-monaco.component';

@Component({
Expand Down Expand Up @@ -105,8 +105,8 @@ export class DragAndDropQuestionEditComponent implements OnInit, OnChanges, Afte
*/
mouse: DragAndDropMouseEvent;

hintAction = new MonacoQuizHintAction();
explanationAction = new MonacoQuizExplanationAction();
hintAction = new QuizHintAction();
explanationAction = new QuizExplanationAction();

dragAndDropDomainActions = [this.explanationAction, this.hintAction];

Expand Down Expand Up @@ -855,9 +855,9 @@ export class DragAndDropQuestionEditComponent implements OnInit, OnChanges, Afte
if (action === undefined && text.length > 0) {
this.question.text = text;
}
if (action instanceof MonacoQuizExplanationAction) {
if (action instanceof QuizExplanationAction) {
this.question.explanation = text;
} else if (action instanceof MonacoQuizHintAction) {
} else if (action instanceof QuizHintAction) {
this.question.hint = text;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { generateExerciseHintExplanation } from 'app/shared/util/markdown.util';
import { faAngleDown, faAngleRight, faQuestionCircle, faTrash } from '@fortawesome/free-solid-svg-icons';
import { ScoringType } from 'app/entities/quiz/quiz-question.model';
import { MAX_QUIZ_QUESTION_POINTS } from 'app/shared/constants/input.constants';
import { MonacoQuizHintAction } from 'app/shared/monaco-editor/model/actions/quiz/monaco-quiz-hint.action';
import { MonacoWrongMultipleChoiceAnswerAction } from 'app/shared/monaco-editor/model/actions/quiz/monaco-wrong-multiple-choice-answer.action';
import { MonacoCorrectMultipleChoiceAnswerAction } from 'app/shared/monaco-editor/model/actions/quiz/monaco-correct-multiple-choice-answer.action';
import { MonacoQuizExplanationAction } from 'app/shared/monaco-editor/model/actions/quiz/monaco-quiz-explanation.action';
import { QuizHintAction } from 'app/shared/monaco-editor/model/actions/quiz/quiz-hint.action';
import { WrongMultipleChoiceAnswerAction } from 'app/shared/monaco-editor/model/actions/quiz/wrong-multiple-choice-answer.action';
import { CorrectMultipleChoiceAnswerAction } from 'app/shared/monaco-editor/model/actions/quiz/correct-multiple-choice-answer.action';
import { QuizExplanationAction } from 'app/shared/monaco-editor/model/actions/quiz/quiz-explanation.action';
import { MarkdownEditorMonacoComponent, TextWithDomainAction } from 'app/shared/markdown-editor/monaco/markdown-editor-monaco.component';
import { MultipleChoiceVisualQuestionComponent } from 'app/exercises/quiz/shared/questions/multiple-choice-question/multiple-choice-visual-question.component';

Expand Down Expand Up @@ -49,10 +49,10 @@ export class MultipleChoiceQuestionEditComponent implements OnInit, QuizQuestion
showMultipleChoiceQuestionPreview = true;
showMultipleChoiceQuestionVisual = true;

correctAction = new MonacoCorrectMultipleChoiceAnswerAction();
wrongAction = new MonacoWrongMultipleChoiceAnswerAction();
explanationAction = new MonacoQuizExplanationAction();
hintAction = new MonacoQuizHintAction();
correctAction = new CorrectMultipleChoiceAnswerAction();
wrongAction = new WrongMultipleChoiceAnswerAction();
explanationAction = new QuizExplanationAction();
hintAction = new QuizHintAction();
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved

multipleChoiceActions = [this.correctAction, this.wrongAction, this.explanationAction, this.hintAction];

Expand Down Expand Up @@ -170,18 +170,18 @@ export class MultipleChoiceQuestionEditComponent implements OnInit, QuizQuestion
if (action === undefined && text.length > 0) {
this.question.text = text;
}
if (action instanceof MonacoCorrectMultipleChoiceAnswerAction || action instanceof MonacoWrongMultipleChoiceAnswerAction) {
if (action instanceof CorrectMultipleChoiceAnswerAction || action instanceof WrongMultipleChoiceAnswerAction) {
currentAnswerOption = new AnswerOption();
currentAnswerOption.isCorrect = action instanceof MonacoCorrectMultipleChoiceAnswerAction;
currentAnswerOption.isCorrect = action instanceof CorrectMultipleChoiceAnswerAction;
currentAnswerOption.text = text;
this.question.answerOptions!.push(currentAnswerOption);
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
} else if (action instanceof MonacoQuizExplanationAction) {
} else if (action instanceof QuizExplanationAction) {
if (currentAnswerOption) {
currentAnswerOption.explanation = text;
} else {
this.question.explanation = text;
}
} else if (action instanceof MonacoQuizHintAction) {
} else if (action instanceof QuizHintAction) {
if (currentAnswerOption) {
currentAnswerOption.hint = text;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { cloneDeep } from 'lodash-es';
import { generateExerciseHintExplanation, parseExerciseHintExplanation } from 'app/shared/util/markdown.util';
import { faAngleDown, faAngleRight, faArrowsAltV, faChevronDown, faChevronUp, faTrash, faUndo } from '@fortawesome/free-solid-svg-icons';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { MonacoCorrectMultipleChoiceAnswerAction } from 'app/shared/monaco-editor/model/actions/quiz/monaco-correct-multiple-choice-answer.action';
import { MonacoWrongMultipleChoiceAnswerAction } from 'app/shared/monaco-editor/model/actions/quiz/monaco-wrong-multiple-choice-answer.action';
import { CorrectMultipleChoiceAnswerAction } from 'app/shared/monaco-editor/model/actions/quiz/correct-multiple-choice-answer.action';
import { WrongMultipleChoiceAnswerAction } from 'app/shared/monaco-editor/model/actions/quiz/wrong-multiple-choice-answer.action';

@Component({
selector: 'jhi-re-evaluate-multiple-choice-question',
Expand Down Expand Up @@ -45,9 +45,7 @@ export class ReEvaluateMultipleChoiceQuestionComponent implements OnInit {
for (const answer of this.question.answerOptions!) {
this.markdownMap.set(
answer.id!,
(answer.isCorrect ? MonacoCorrectMultipleChoiceAnswerAction.IDENTIFIER : MonacoWrongMultipleChoiceAnswerAction.IDENTIFIER) +
' ' +
generateExerciseHintExplanation(answer),
(answer.isCorrect ? CorrectMultipleChoiceAnswerAction.IDENTIFIER : WrongMultipleChoiceAnswerAction.IDENTIFIER) + ' ' + generateExerciseHintExplanation(answer),
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
);
}
this.questionText = this.getQuestionText(this.question);
Expand Down Expand Up @@ -104,9 +102,9 @@ export class ReEvaluateMultipleChoiceQuestionComponent implements OnInit {
const startOfThisPart = text.indexOf(answerOptionText);
const box = text.substring(0, startOfThisPart);
// Check if box says this answer option is correct or not
if (box === MonacoCorrectMultipleChoiceAnswerAction.IDENTIFIER) {
if (box === CorrectMultipleChoiceAnswerAction.IDENTIFIER) {
answer.isCorrect = true;
} else if (box === MonacoWrongMultipleChoiceAnswerAction.IDENTIFIER) {
} else if (box === WrongMultipleChoiceAnswerAction.IDENTIFIER) {
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
answer.isCorrect = false;
} else {
answer.isCorrect = undefined;
Expand All @@ -120,9 +118,7 @@ export class ReEvaluateMultipleChoiceQuestionComponent implements OnInit {
*/
private static splitByCorrectIncorrectTag(text: string): string[] {
const stringForSplit =
escapeStringForUseInRegex(`${MonacoCorrectMultipleChoiceAnswerAction.IDENTIFIER}`) +
'|' +
escapeStringForUseInRegex(`${MonacoWrongMultipleChoiceAnswerAction.IDENTIFIER}`);
escapeStringForUseInRegex(`${CorrectMultipleChoiceAnswerAction.IDENTIFIER}`) + '|' + escapeStringForUseInRegex(`${WrongMultipleChoiceAnswerAction.IDENTIFIER}`);
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
const splitRegExp = new RegExp(stringForSplit, 'g');
return text.split(splitRegExp);
}
Expand Down
Loading
Loading