diff --git a/frontend/src/app/admin/admin.component.html b/frontend/src/app/admin/admin.component.html index 707a9731a815a569893ca6290dac6c2d47863711..ac032df87e75ead76aa124c959083734d8a04d3c 100644 --- a/frontend/src/app/admin/admin.component.html +++ b/frontend/src/app/admin/admin.component.html @@ -43,7 +43,7 @@ <tr *ngFor="let answer of answers" class="border-b dark:border-neutral-500"> <td class="whitespace-nowrap px-6 py-4">{{answer.text_answer}}</td> <td class="whitespace-nowrap px-6 py-4">{{answer.correct}}</td> - <td><button class="bg-teal-200 w-fit border-2 border-teal-600 rounded-lg px-2 hover:bg-teal-400 mt-2">UPDATE</button></td> + <td><button class="bg-teal-200 w-fit border-2 border-teal-600 rounded-lg px-2 hover:bg-teal-400 mt-2" (click)="showAnswerUpdateModal(answer)">UPDATE</button></td> <td><button class="bg-red-400 w-fit border-2 border-red-600 rounded-lg px-2 hover:bg-red-300 mt-2" (click)="deleteAnswer(answer)">DELETE</button></td> </tr> </tbody> @@ -73,5 +73,7 @@ <div *ngIf="modalQuestionUpdate"> <app-update-question [question]="questionToEdit" (closeModal)="modalQuestionUpdate=false;"></app-update-question> </div> - + <div *ngIf="modalAnswerUpdate"> + <app-update-answer [answer]="answerToEdit" (closeModal)="modalAnswerUpdate=false" ></app-update-answer> + </div> </div> diff --git a/frontend/src/app/admin/admin.component.ts b/frontend/src/app/admin/admin.component.ts index 6638a40c163bd943669b5f63976c2f2e7c44a241..60bcd6ab194264867a0d6f326d45228dbd4410eb 100644 --- a/frontend/src/app/admin/admin.component.ts +++ b/frontend/src/app/admin/admin.component.ts @@ -20,6 +20,7 @@ export class AdminComponent implements OnInit { selectedQuestionID!: number; userToEdit!: User; questionToEdit!: Question; + answerToEdit!: Answer; buttonCreateAnswer!: boolean; @@ -28,6 +29,7 @@ export class AdminComponent implements OnInit { modalQuestionCreate: boolean = false; modalQuestionUpdate: boolean = false; modalAnswerCreate: boolean = false; + modalAnswerUpdate: boolean = false; constructor( private router: Router, @@ -87,4 +89,10 @@ export class AdminComponent implements OnInit { this.questionToEdit = question; this.modalQuestionUpdate = true; } + + showAnswerUpdateModal(answer: Answer) { + this.answerToEdit = answer; + this.modalAnswerUpdate = true; + } + } diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index e1ac6e8315bf26eeac17860c51bb81629878f64b..a0b83ffad67d066ec281453da3f1d69d0d914b36 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -14,6 +14,7 @@ import { UpdateUserComponent } from './user-shit/update-user/update-user.compone import { CreateQuestionComponent } from './question-shit/create-question/create-question.component'; import { CreateAnswerComponent } from './question-shit/create-answer/create-answer.component'; import { UpdateQuestionComponent } from './question-shit/update-question/update-question.component'; +import { UpdateAnswerComponent } from './question-shit/update-answer/update-answer.component'; @NgModule({ declarations: [ @@ -25,7 +26,8 @@ import { UpdateQuestionComponent } from './question-shit/update-question/update- UpdateUserComponent, CreateQuestionComponent, CreateAnswerComponent, - UpdateQuestionComponent + UpdateQuestionComponent, + UpdateAnswerComponent ], imports: [ BrowserModule, diff --git a/frontend/src/app/question-shit/update-answer/update-answer.component.css b/frontend/src/app/question-shit/update-answer/update-answer.component.css new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/frontend/src/app/question-shit/update-answer/update-answer.component.html b/frontend/src/app/question-shit/update-answer/update-answer.component.html new file mode 100644 index 0000000000000000000000000000000000000000..102dd70b0a09b9adeef25d2170199be80a7ad936 --- /dev/null +++ b/frontend/src/app/question-shit/update-answer/update-answer.component.html @@ -0,0 +1,22 @@ +<div class="z-10 relative"> + <div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"></div> + <div class="fixed inset-0 z-10 overflow-y-auto"> + <div class="flex flex-col min-h-full justify-center p-4 text-center items-center sm:p-0"> + <div class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all sm:my-8 "> + <h1 class="mt-2 mx-2 font-bold">Update Answer</h1> + + <form [formGroup]="updateAnswer" (ngSubmit)="onSubmit()" class="flex flex-col pb-2 mx-2"> + <input class="border-b-4 mt-2 w-full" type="text" placeholder="Text" formControlName="answer"> + <div class="my-2 border-b-4"> + <label class="mt-2 w-fit">Correct</label><input class="ml-6" type="checkbox" formControlName="correct"> + </div> + <div class="flex flex-row justify-between"> + <button class="border-2 border-black rounded-lg px-2 hover:bg-gray-300 mt-2" type="submit">Update</button> + <button class="border-2 border-black rounded-lg px-2 hover:bg-gray-300 mt-2" (click)="closeModal.emit()">Close</button> + </div> + </form> + + </div> + </div> + </div> +</div> \ No newline at end of file diff --git a/frontend/src/app/question-shit/update-answer/update-answer.component.spec.ts b/frontend/src/app/question-shit/update-answer/update-answer.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..7b44b636d99dad2c92aa995d73d9b65e1e0952e0 --- /dev/null +++ b/frontend/src/app/question-shit/update-answer/update-answer.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { UpdateAnswerComponent } from './update-answer.component'; + +describe('UpdateAnswerComponent', () => { + let component: UpdateAnswerComponent; + let fixture: ComponentFixture<UpdateAnswerComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [UpdateAnswerComponent] + }); + fixture = TestBed.createComponent(UpdateAnswerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/question-shit/update-answer/update-answer.component.ts b/frontend/src/app/question-shit/update-answer/update-answer.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..d44594b85478aba24e126c2122739cdd9b5c347e --- /dev/null +++ b/frontend/src/app/question-shit/update-answer/update-answer.component.ts @@ -0,0 +1,40 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Answer } from 'src/app/Types/types'; +import { QuestionsService } from 'src/app/services/questions.service'; + +@Component({ + selector: 'app-update-answer', + templateUrl: './update-answer.component.html', + styleUrls: ['./update-answer.component.css'] +}) +export class UpdateAnswerComponent { + updateAnswer: FormGroup; + + @Input() answer: Answer; + @Output() closeModal: EventEmitter<string> = new EventEmitter<string>(); + + constructor(private questionsController: QuestionsService) { } + + ngOnInit(): void { + this.updateAnswer = new FormGroup({ + answer: new FormControl(this.answer.text_answer, Validators.required), + correct: new FormControl(this.answer.correct, Validators.required) + }); + } + + onSubmit() { + const answer = this.updateAnswer.get("answer")!.value; + const correct = this.updateAnswer.get("correct")!.value; + + const newAnswer: Answer = { + id: this.answer.id, + text_answer: answer, + correct: correct, + id_question: this.answer.id_question + } + + this.questionsController.updateAnswer(newAnswer); + this.closeModal.emit(); + } +} diff --git a/frontend/src/app/services/questions.service.ts b/frontend/src/app/services/questions.service.ts index 516ef8d9a6cdd2421ff2c7b73917d6a591179ce3..1e1517657dd88eba10c884757d52dafb6524d2de 100644 --- a/frontend/src/app/services/questions.service.ts +++ b/frontend/src/app/services/questions.service.ts @@ -78,9 +78,10 @@ export class QuestionsService { }) } - // addUser(user: User) { - // this.http.post<User>(ROUTE, user).subscribe(res => { - // this.auth.login(user.username, user.password); - // }); - // } - } + updateAnswer(answer: Answer) { + this.http.patch(ROUTE + "/answer/" + answer.id.toString(), answer).subscribe(() => { + this.fetchAnswers(answer.id_question); + }) + } + + }