Skip to content

Commit

Permalink
Add copy button to exam questions tab (#1014)
Browse files Browse the repository at this point in the history
Co-authored-by: Matti Lupari <[email protected]>
  • Loading branch information
VirmasaloA and lupari authored Dec 1, 2023
1 parent 68fd1f9 commit 62ec1a7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
</button>
<div ngbDropdownMenu>
<button ngbDropdownItem (click)="editQuestion()">{{ 'sitnet_edit' | translate }}</button>
<button ngbDropdownItem (click)="copyQuestion()">{{ 'sitnet_copy' | translate }}</button>
<button ngbDropdownItem (click)="removeQuestion()">{{ 'sitnet_remove' | translate }}</button>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions ui/src/app/exam/editor/sections/section-question.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class SectionQuestionComponent {
@Input() examId = 0;
@Output() removed = new EventEmitter<ExamSectionQuestion>();
@Output() updated = new EventEmitter<ExamSectionQuestion>();
@Output() copied = new EventEmitter<ExamSectionQuestion>();

constructor(
private http: HttpClient,
Expand Down Expand Up @@ -73,6 +74,12 @@ export class SectionQuestionComponent {
this.translate.instant('sitnet_remove_question'),
).subscribe({ next: () => this.removed.emit(this.sectionQuestion), error: (err) => this.toast.error(err) });

copyQuestion = () =>
this.Confirmation.open$(
this.translate.instant('sitnet_confirm'),
this.translate.instant('sitnet_copy_question'),
).subscribe({ next: () => this.copied.emit(this.sectionQuestion), error: (err) => this.toast.error(err) });

determineClaimOptionType(examOption: ExamSectionQuestionOption) {
return this.Question.determineClaimOptionTypeForExamQuestionOption(examOption);
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/exam/editor/sections/section.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
[lotteryOn]="section.lotteryOn"
(removed)="removeQuestion($event)"
(updated)="updateQuestion($event)"
(copied)="copyQuestion($event)"
>
</xm-section-question>
</div>
Expand Down
9 changes: 9 additions & 0 deletions ui/src/app/exam/editor/sections/section.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ export class SectionComponent {
});
};

copyQuestion = (sq: ExamSectionQuestion) =>
this.http.post<Question>(`/app/question/${sq.question.id}`, {}).subscribe({
next: (copy) => {
this.insertExamQuestion(copy, sq.sequenceNumber);
this.toast.info(this.translate.instant('sitnet_question_copied'));
},
error: (err) => this.toast.error(err),
});

updateQuestion = (sq: ExamSectionQuestion) => {
const index = this.section.sectionQuestions.findIndex((q) => q.id == sq.id);
this.section.sectionQuestions[index] = sq;
Expand Down

0 comments on commit 62ec1a7

Please sign in to comment.