-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd560bc
commit 56836e3
Showing
18 changed files
with
389 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/app/components/admin/navigation/side-nav/side-nav.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/app/components/admin/topic/csharp-interview-qa/csharp-interview-qa.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.question-list { | ||
float: left; | ||
width: 50%; | ||
} | ||
|
||
.question-details { | ||
float: right; | ||
width: 50%; | ||
} | ||
|
||
ul { | ||
list-style-type: none; | ||
padding: 0; | ||
} | ||
|
||
li { | ||
cursor: pointer; | ||
padding: 8px; | ||
border: 1px solid #ddd; | ||
margin-top: -1px; /* Prevent double borders */ | ||
background-color: #f6f6f6; | ||
text-align: left; | ||
} | ||
|
||
li:hover { | ||
background-color: #ddd; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/app/components/admin/topic/csharp-interview-qa/csharp-interview-qa.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<button mat-raised-button color="primary" (click)="openEditDialog()">Add Question</button> | ||
<div class="question-list"> | ||
<h2>Questions</h2> | ||
<ul> | ||
<li *ngFor="let question of questions" (click)="selectQuestion(question)" (keyup)="handleKeyUp($event)" | ||
tabindex="0"> | ||
{{ question.questionText }} | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="question-details" *ngIf="selectedQuestion"> | ||
<h2>{{ selectedQuestion.questionText }}</h2> | ||
<div [innerHTML]="selectedQuestion.answer"></div> | ||
<!-- Add form for editing the selected question here --> | ||
<button (click)="updateQuestion(selectedQuestion)">Update</button> | ||
<button mat-button (click)="openEditDialog(selectedQuestion)">Edit</button> | ||
<button (click)="deleteQuestion(selectedQuestion.questionId || '')">Delete</button> | ||
</div> |
21 changes: 21 additions & 0 deletions
21
src/app/components/admin/topic/csharp-interview-qa/csharp-interview-qa.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { CsharpInterviewQaComponent } from './csharp-interview-qa.component'; | ||
|
||
describe('CsharpInterviewQaComponent', () => { | ||
let component: CsharpInterviewQaComponent; | ||
let fixture: ComponentFixture<CsharpInterviewQaComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [CsharpInterviewQaComponent] | ||
}); | ||
fixture = TestBed.createComponent(CsharpInterviewQaComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
src/app/components/admin/topic/csharp-interview-qa/csharp-interview-qa.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { MatDialog } from '@angular/material/dialog'; | ||
import { MatSnackBar } from '@angular/material/snack-bar'; | ||
import { QuestionEditDialogComponent } from 'src/app/components/general/dialog/topic/question-edit-dialog/question-edit-dialog.component'; | ||
import { Question } from 'src/app/models/topic/question'; | ||
import { QaDataService } from 'src/app/services/general/qa-data/qa-data.service'; | ||
|
||
@Component({ | ||
selector: 'app-csharp-interview-qa', | ||
templateUrl: './csharp-interview-qa.component.html', | ||
styleUrls: ['./csharp-interview-qa.component.css'] | ||
}) | ||
export class CsharpInterviewQaComponent implements | ||
|
||
OnInit { | ||
questions: Question[] = []; | ||
selectedQuestion: Question | null = null; | ||
|
||
constructor(private questionService: QaDataService, | ||
public dialog: MatDialog, private snackBar: MatSnackBar) { } | ||
|
||
ngOnInit(): void { | ||
this.loadQuestions(); | ||
} | ||
|
||
loadQuestions(): void { | ||
this.questionService.getQuestions().subscribe(data => { | ||
this.questions = data; | ||
}); | ||
} | ||
|
||
selectQuestion(question: Question): void { | ||
this.selectedQuestion = question; | ||
} | ||
|
||
createQuestion(question: Question): void { | ||
this.questionService.createQuestion(question).subscribe(() => { | ||
this.loadQuestions(); | ||
}); | ||
} | ||
|
||
updateQuestion(question: Question): void { | ||
if (question.id) { | ||
this.questionService.updateQuestion(question).subscribe(() => { | ||
this.loadQuestions(); | ||
}); | ||
} | ||
} | ||
|
||
deleteQuestion(id: string): void { | ||
this.questionService.deleteQuestion(id).subscribe(() => { | ||
this.loadQuestions(); | ||
}); | ||
} | ||
|
||
handleKeyUp(event: KeyboardEvent): void { | ||
// Handle key up event here | ||
} | ||
|
||
openEditDialog(question?: Question): void { | ||
// Create copies of tags and references as comma-separated strings | ||
const editedQuestion = { | ||
...question, | ||
tags: question?.tags.join(', '), | ||
references: question?.references.join(', ') | ||
}; | ||
|
||
|
||
const dialogRef = this.dialog.open(QuestionEditDialogComponent, { | ||
width: '800px', // Set the desired width for the dialog | ||
data: editedQuestion // Pass the edited question to the dialog | ||
}); | ||
|
||
dialogRef.afterClosed().subscribe(result => { | ||
if (result) { | ||
// Check if the result has an id to determine if it's a new or existing question | ||
if (result.id) { | ||
console.log("result.id: " + result.id); | ||
// Split tags and references back into arrays before updating | ||
result.tags = result.tags.split(',').map((tag: string) => tag.trim()).filter((tag: string) => tag); | ||
result.references = result.references.split(',').map((ref: string) => ref.trim()).filter((ref: string) => ref); | ||
this.updateQuestion(result); // Update the question with the result from the dialog | ||
} | ||
else { | ||
this.createQuestion(result); | ||
} | ||
} | ||
}); | ||
} | ||
} |
Empty file.
31 changes: 31 additions & 0 deletions
31
.../components/general/dialog/topic/question-edit-dialog/question-edit-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h1 mat-dialog-title>Edit Question</h1> | ||
<div mat-dialog-content> | ||
<mat-form-field class="full-width"> | ||
<mat-label>Topic</mat-label> | ||
<input matInput [(ngModel)]="data.topic"> | ||
</mat-form-field> | ||
<mat-form-field class="full-width"> | ||
<mat-label>Subtopic</mat-label> | ||
<input matInput [(ngModel)]="data.subtopic"> | ||
</mat-form-field> | ||
<mat-form-field class="full-width"> | ||
<mat-label>Difficulty</mat-label> | ||
<input matInput [(ngModel)]="data.difficulty"> | ||
</mat-form-field> | ||
<mat-form-field class="full-width"> | ||
<mat-label>Tags</mat-label> | ||
<input matInput placeholder="Comma-separated (e.g., tag1, tag2)" [(ngModel)]="data.tags"> | ||
</mat-form-field> | ||
<mat-form-field class="full-width"> | ||
<mat-label>References</mat-label> | ||
<input matInput placeholder="Comma-separated (e.g., ref1, ref2)" [(ngModel)]="data.references"> | ||
</mat-form-field> | ||
<mat-form-field class="full-width"> | ||
<mat-label>Answer</mat-label> | ||
<textarea matInput placeholder="HTML allowed" [(ngModel)]="data.answer"></textarea> | ||
</mat-form-field> | ||
</div> | ||
<div mat-dialog-actions> | ||
<button mat-button (click)="onCancelClick()">Cancel</button> | ||
<button mat-button (click)="onSaveClick()">Save</button> | ||
</div> |
21 changes: 21 additions & 0 deletions
21
...mponents/general/dialog/topic/question-edit-dialog/question-edit-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { QuestionEditDialogComponent } from './question-edit-dialog.component'; | ||
|
||
describe('QuestionEditDialogComponent', () => { | ||
let component: QuestionEditDialogComponent; | ||
let fixture: ComponentFixture<QuestionEditDialogComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [QuestionEditDialogComponent] | ||
}); | ||
fixture = TestBed.createComponent(QuestionEditDialogComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
69 changes: 69 additions & 0 deletions
69
...pp/components/general/dialog/topic/question-edit-dialog/question-edit-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Component, Inject, OnInit } from '@angular/core'; | ||
import { MatChipInputEvent } from '@angular/material/chips'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { Question } from 'src/app/models/topic/question'; | ||
import { QaDataService } from 'src/app/services/general/qa-data/qa-data.service'; | ||
import { ENTER, COMMA } from '@angular/cdk/keycodes'; | ||
|
||
@Component({ | ||
selector: 'app-question-edit-dialog', | ||
templateUrl: './question-edit-dialog.component.html', | ||
styleUrls: ['./question-edit-dialog.component.css'] | ||
}) | ||
export class QuestionEditDialogComponent implements OnInit { | ||
readonly separatorKeysCodes = [ENTER, COMMA] as const; | ||
constructor( | ||
public dialogRef: MatDialogRef<QuestionEditDialogComponent>, | ||
@Inject(MAT_DIALOG_DATA) public data: Question, private questionService: QaDataService) { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
onCancelClick(): void { | ||
this.dialogRef.close(); | ||
} | ||
|
||
onSaveClick(): void { | ||
// Add the logic to save the question | ||
console.log(this.data); | ||
// this.questionService.updateQuestion(this.data.questionId ?? '', this.data).subscribe(); | ||
// Then close the dialog | ||
this.dialogRef.close(this.data); | ||
} | ||
|
||
addTag(event: MatChipInputEvent): void { | ||
const input = event.input; | ||
const value = (event.value || '').trim(); | ||
|
||
if (value) { | ||
this.data.tags.push(value); | ||
} | ||
|
||
if (input) { | ||
input.value = ''; | ||
} | ||
} | ||
|
||
removeTag(tag: string): void { | ||
const index = this.data.tags.indexOf(tag); | ||
if (index >= 0) { | ||
this.data.tags.splice(index, 1); | ||
} | ||
} | ||
|
||
addReference(event: MatChipInputEvent): void { | ||
const value = (event.value || '').trim(); | ||
if (value) { | ||
this.data.references.push(value); | ||
} | ||
// Clear the input value | ||
event.chipInput!.clear(); | ||
} | ||
|
||
removeReference(ref: string): void { | ||
const index = this.data.references.indexOf(ref); | ||
if (index >= 0) { | ||
this.data.references.splice(index, 1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.