Skip to content

Commit

Permalink
Merge pull request #416 from correctexam/379-reduce-the-number-of-htt…
Browse files Browse the repository at this point in the history
…p-queries-when-switching-from-one-page-to-another-one-in-the-correction-view

close #406
  • Loading branch information
barais authored Nov 28, 2023
2 parents fe0c5f2 + 9aa4f24 commit 78f5da4
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div *ngFor="let comment of currentTextComment4Question | sort: 'checked'" class="sm:col-3 md:col-3 lg:col-12 xl:col-12">
<div class="card">
<div class="card-body">
<span class="float-end" (click)="removeTextComment(comment)">
<span *ngIf="couldDelete" class="float-end" (click)="removeTextComment(comment)">
<fa-icon icon="times"></fa-icon>
</span>
<div>
Expand Down Expand Up @@ -45,7 +45,7 @@ <h5 class="card-title">{{ comment.text }}</h5>
<div *ngFor="let comment of currentGradedComment4Question | sort: 'checked'" class="sm:col-3 md:col-3 lg:col-12 xl:col-12">
<div class="card">
<div class="card-body">
<span *ngIf="_q?.typeAlgoName !== 'QCM'" class="float-end clickable" (click)="removeGradedComment(comment)"
<span *ngIf="_q?.typeAlgoName !== 'QCM' && couldDelete" class="float-end clickable" (click)="removeGradedComment(comment)"
><fa-icon icon="times"></fa-icon
></span>
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/restrict-plus-operands */
/* eslint-disable @typescript-eslint/no-empty-function */
import { Component, Input, OnInit } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { GradeType } from 'app/entities/enumerations/grade-type.model';
import { IGradedComment } from 'app/entities/graded-comment/graded-comment.model';
Expand All @@ -20,6 +20,18 @@ export class CreateCommentsComponent implements OnInit {
currentTextComment4Question: ITextComment[] | undefined;
currentGradedComment4Question: IGradedComment[] | undefined;

@Output()
addTextComment: EventEmitter<ITextComment> = new EventEmitter<ITextComment>();
@Output()
addGradedComment: EventEmitter<IGradedComment> = new EventEmitter<IGradedComment>();
@Output()
updateTextComment: EventEmitter<ITextComment> = new EventEmitter<ITextComment>();
@Output()
updateGradedComment: EventEmitter<IGradedComment> = new EventEmitter<IGradedComment>();

@Input()
couldDelete = true;

questionStep = 0;
titreCommentaire = '';
descCommentaire = '';
Expand Down Expand Up @@ -51,7 +63,7 @@ export class CreateCommentsComponent implements OnInit {
constructor(
public gradedCommentService: GradedCommentService,
public textCommentService: TextCommentService,
public translate: TranslateService
public translate: TranslateService,
) {}
// eslint-disable-next-line @angular-eslint/no-empty-lifecycle-method
ngOnInit(): void {}
Expand Down Expand Up @@ -80,6 +92,7 @@ export class CreateCommentsComponent implements OnInit {
this.textCommentService.create(t).subscribe(e => {
const currentComment = e.body!;
this.currentTextComment4Question?.push(currentComment);
this.addTextComment.emit(currentComment);
this.titreCommentaire = '';
this.descCommentaire = '';
this.blocked = false;
Expand All @@ -96,6 +109,8 @@ export class CreateCommentsComponent implements OnInit {
this.gradedCommentService.create(t).subscribe(e => {
const currentComment = e.body!;
this.currentGradedComment4Question?.push(currentComment);
this.addGradedComment.emit(currentComment);

this.titreCommentaire = '';
this.descCommentaire = '';
this.noteCommentaire = 0;
Expand All @@ -110,21 +125,24 @@ export class CreateCommentsComponent implements OnInit {
(l as IGradedComment).grade = 0;
}
this.gradedCommentService.update(l).subscribe(() => {
this.updateGradedComment.emit(l);
const coms = this.currentGradedComment4Question?.filter(c => c.id === l.id!);
if (coms !== undefined && coms.length > 0) {
coms[0].grade = (l as any).grade;
}
});
} else {
this.textCommentService.update(l).subscribe(() => {});
this.textCommentService.update(l).subscribe(() => {
this.updateTextComment.emit(l);
});
}
}

removeTextComment(comment: ITextComment): void {
this.currentTextComment4Question = this.currentTextComment4Question!.filter(e => e.id !== comment.id);
this.textCommentService.delete(comment.id!).subscribe(() =>
// eslint-disable-next-line no-console
console.log('delete')
console.log('delete'),
);
}

Expand Down Expand Up @@ -169,6 +187,7 @@ export class CreateCommentsComponent implements OnInit {
this.textCommentService.create(t).subscribe(e => {
const currentComment = e.body!;
this.currentTextComment4Question?.push(currentComment);
this.addTextComment.emit(currentComment);
this.titreCommentaire = '';
this.descCommentaire = '';
this.blocked = false;
Expand All @@ -188,6 +207,7 @@ export class CreateCommentsComponent implements OnInit {
this.gradedCommentService.create(t).subscribe(e => {
const currentComment = e.body!;
this.currentGradedComment4Question?.push(currentComment);
this.addGradedComment.emit(currentComment);
this.titreCommentaire = '';
this.descCommentaire = '';
this.noteCommentaire = 0;
Expand Down Expand Up @@ -223,6 +243,8 @@ export class CreateCommentsComponent implements OnInit {
this.textCommentService.create(t).subscribe(e => {
const currentComment = e.body!;
this.currentTextComment4Question?.push(currentComment);
this.addTextComment.emit(currentComment);

this.titreCommentaire = '';
this.descCommentaire = '';
this.blocked = false;
Expand Down Expand Up @@ -255,6 +277,8 @@ export class CreateCommentsComponent implements OnInit {
this.gradedCommentService.create(t).subscribe(e => {
const currentComment = e.body!;
this.currentGradedComment4Question?.push(currentComment);
this.addGradedComment.emit(currentComment);

this.titreCommentaire = '';
this.descCommentaire = '';
this.noteCommentaire = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<h3>Palette</h3>
<hr />
<jhi-graphical-toolbar></jhi-graphical-toolbar>
<jhi-questionpropertiesview (updatenumero)="updateNumero($event)"></jhi-questionpropertiesview>
<jhi-questionpropertiesview [eventHandler]="eventHandlerService" (updatenumero)="updateNumero($event)"></jhi-questionpropertiesview>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Input } from '@angular/core';
import { IExam } from '../../../entities/exam/exam.model';
import { Subject } from 'rxjs';
import { EventHandlerService } from './event-handler.service';

@Component({
selector: 'jhi-paint',
Expand All @@ -15,6 +16,8 @@ export class PaintComponent {

numero = new Subject<string>();

constructor(public eventHandlerService: EventHandlerService) {}

previousState(): void {
window.history.back();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
styleClass="p-0"
appendTo="body"
>
<jhi-create-comments [question]="questions[0]"></jhi-create-comments>
<jhi-create-comments
[question]="questions[0]"
(addTextComment)="addTextCommentM($event)"
(addGradedComment)="addGradedCommentM($event)"
(updateGradedComment)="updateGradedCommentM($event)"
(updateTextComment)="updateTextCommentM($event)"
[couldDelete]="couldDelete"
></jhi-create-comments>
</p-sidebar>

<hr *ngIf="questions.length > 0" />
Expand All @@ -16,7 +23,7 @@
<div>
<jhi-alert-error></jhi-alert-error>

<div class="row">
<div class="row" *ngIf="canUpdateNumero">
<label class="form-label" jhiTranslate="gradeScopeIsticApp.question.numero" for="field_numero">Numero</label>
<input
type="number"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/member-ordering */
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
import { HttpResponse } from '@angular/common/http';
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
import { Component, OnInit, EventEmitter, Output, Input } from '@angular/core';
import { UntypedFormBuilder, Validators, UntypedFormGroup } from '@angular/forms';
import { IQuestionType } from 'app/entities/question-type/question-type.model';
import { QuestionTypeService } from 'app/entities/question-type/service/question-type.service';
Expand All @@ -13,6 +13,8 @@ import { GradeType } from 'app/entities/enumerations/grade-type.model';
import { animate, state, style, transition, trigger } from '@angular/animations';
import { PreferenceService } from '../../../preference-page/preference.service';
import { OnDestroy } from '@angular/core';
import { ITextComment } from 'app/entities/text-comment/text-comment.model';
import { IGradedComment } from 'app/entities/graded-comment/graded-comment.model';

type SelectableEntity = IQuestionType;
export type EntityResponseType = HttpResponse<IQuestion>;
Expand Down Expand Up @@ -44,6 +46,13 @@ export class QuestionpropertiesviewComponent implements OnInit, OnDestroy {
/** The selected questions. This is an array since a same question can be divided into several parts.
* The first question of the array, if not empty, is the truely selected question. An empty array means no selection. */
public questions: Array<IQuestion> = [];

@Input()
public questionsInput: Array<IQuestion> = [];

@Input()
public canUpdateNumero = true;

public layoutsidebarVisible = false;
public manualid = 2;
public qcmid = 3;
Expand Down Expand Up @@ -79,13 +88,44 @@ export class QuestionpropertiesviewComponent implements OnInit, OnDestroy {
@Output()
public updatenumero: EventEmitter<string> = new EventEmitter<string>();

@Output()
public updatedQuestions: EventEmitter<Array<IQuestion>> = new EventEmitter<Array<IQuestion>>();

@Output()
addTextComment: EventEmitter<ITextComment> = new EventEmitter<ITextComment>();
@Output()
addGradedComment: EventEmitter<IGradedComment> = new EventEmitter<IGradedComment>();
@Output()
updateTextComment: EventEmitter<ITextComment> = new EventEmitter<ITextComment>();
@Output()
updateGradedComment: EventEmitter<IGradedComment> = new EventEmitter<IGradedComment>();

@Input()
couldDelete = true;

addTextCommentM($event: ITextComment): void {
this.addTextComment.emit($event);
}
updateTextCommentM($event: ITextComment): void {
this.updateTextComment.emit($event);
}
addGradedCommentM($event: IGradedComment): void {
this.addGradedComment.emit($event);
}
updateGradedCommentM($event: IGradedComment): void {
this.updateGradedComment.emit($event);
}

private selectionSubscription: Subscription | undefined = undefined;

@Input()
eventHandler?: EventHandlerService;

constructor(
private questionService: QuestionService,
private questionTypeService: QuestionTypeService,
private fb: UntypedFormBuilder,
private eventHandler: EventHandlerService,
// private eventHandler: EventHandlerService,
private preferenceService: PreferenceService,
) {}

Expand Down Expand Up @@ -115,13 +155,18 @@ export class QuestionpropertiesviewComponent implements OnInit, OnDestroy {
});
});

this.selectionSubscription = this.eventHandler.getSelectedQuestion().subscribe(selectedQ => {
this.selectionSubscription = this.eventHandler?.getSelectedQuestion().subscribe(selectedQ => {
if (selectedQ === undefined) {
this.questions = [];
} else {
this.updateQuestions(selectedQ.id!, selectedQ.examId!, selectedQ.numero!);
}
});

if (this.questionsInput.length > 0) {
this.questions = this.questionsInput;
this.updateForm();
}
}

private async updateQuestions(qid: number, examId: number, numero: number): Promise<void> {
Expand Down Expand Up @@ -203,9 +248,10 @@ export class QuestionpropertiesviewComponent implements OnInit, OnDestroy {
private onSaveSuccess(updatedQuestions: Array<IQuestion>): void {
this.questions = updatedQuestions;
this.questions.forEach(q => {
this.eventHandler.updateQuestion(q);
this.eventHandler?.updateQuestion(q);
});
this.isSaving = false;
this.updatedQuestions.emit(updatedQuestions);
}

private onSaveError(): void {
Expand Down Expand Up @@ -260,7 +306,7 @@ export class QuestionpropertiesviewComponent implements OnInit, OnDestroy {
return Promise.resolve(new HttpResponse<IQuestion>());
})
.then(() => {
this.eventHandler.setCurrentQuestionNumber(number);
this.eventHandler?.setCurrentQuestionNumber(number);
this.updatenumero.next(number);
this.updateForm();
this.isSaving = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ <h3 jhiTranslate="scanexam.confirmation"></h3>
[gradedcomments]="currentGradedComment4Question"
></jhi-keyboardshortcut>
</ng-container>
<p-sidebar [(visible)]="questionpropertiesviewVisible" [modal]="true" position="right">
<div *ngIf="questionpropertiesviewVisible">
<jhi-questionpropertiesview
[canUpdateNumero]="false"
[questionsInput]="questions!"
(updatedQuestions)="updateQuestion($event)"
[couldDelete]="false"
(addGradedComment)="addGradedComment($event)"
(addTextComment)="addTextComment($event)"
(updateGradedComment)="updateGradedComment($event)"
(updateTextComment)="updateTextComment($event)"
></jhi-questionpropertiesview>
</div>
</p-sidebar>

<p-sidebar [(visible)]="layoutsidebarVisible">
<h3 jhiTranslate="scanexam.layoutoptions">Layout options</h3>
Expand Down Expand Up @@ -441,6 +455,17 @@ <h2 id="jhi-course-heading" data-cy="CourseCreateUpdateHeading" jhiTranslate="sc
>
<fa-icon icon="code-compare"></fa-icon>
</span>
<span *ngIf="resp?.id" class="float-end"> &nbsp; &nbsp; </span>

<span
class="float-end"
[tooltipPosition]="'left'"
[tooltipZIndex]="'3000'"
[pTooltip]="'scanexam.editquestionTooltip' | translate"
(click)="editQuestion()"
>
<fa-icon icon="edit"></fa-icon>
</span>
</div>
<div *ngIf="resp" style="padding-bottom: 0.4rem" class="col-3 sm:col-3 md:col-3 lg:col-12 xl:col-12">
<label jhiTranslate="scanexam.excellente">Excellente réponse: </label>
Expand Down
Loading

0 comments on commit 78f5da4

Please sign in to comment.