[8423429] | 1 | import {Component} from '@angular/core';
|
---|
| 2 | import {QuestionInterface} from "../QuestionInterface";
|
---|
| 3 | import {CourseInterface} from "../courseInterface";
|
---|
| 4 | import {ActiveUserInterface} from "../ActiveUserInterface";
|
---|
| 5 | import {LoginService} from "../login.service";
|
---|
| 6 | import {ActivatedRoute, Router} from "@angular/router";
|
---|
| 7 | import {AddQuestionService} from "../add-question.service";
|
---|
| 8 | import {CategoryInterface} from "../categoryInterface";
|
---|
| 9 | import {CategoryService} from "../category.service";
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | @Component({
|
---|
| 13 | selector: 'app-add-question',
|
---|
| 14 | templateUrl: './add-question.component.html',
|
---|
| 15 | styleUrls: ['./add-question.component.css']
|
---|
| 16 | })
|
---|
| 17 | export class AddQuestionComponent {
|
---|
| 18 | title: string | undefined;
|
---|
| 19 | content: string | undefined;
|
---|
| 20 | courseId: number | undefined;
|
---|
| 21 | question: QuestionInterface | undefined;
|
---|
| 22 | course: CourseInterface | undefined;
|
---|
| 23 | activeUser: ActiveUserInterface | undefined;
|
---|
| 24 | categories : CategoryInterface[] =[]
|
---|
| 25 | dropdownList = [];
|
---|
| 26 | selectedItems = [];
|
---|
| 27 | dropdownSettings = {};
|
---|
| 28 |
|
---|
| 29 | constructor(private addQuestionService: AddQuestionService,
|
---|
| 30 | private categoryService: CategoryService,
|
---|
| 31 | private loginService: LoginService,
|
---|
| 32 | private route: ActivatedRoute,
|
---|
| 33 | private router: Router) {
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | ngOnInit(): void {
|
---|
| 37 | this.courseId = Number(this.route.snapshot.paramMap.get('id'));
|
---|
| 38 | this.activeUser = this.loginService.activeUser;
|
---|
| 39 | this.categoryService.getAllCategories().subscribe(response => this.categories=response);
|
---|
| 40 | this.dropdownSettings = {
|
---|
| 41 | singleSelection: false,
|
---|
| 42 | idField: 'id',
|
---|
| 43 | textField: 'name',
|
---|
| 44 | selectAllText: 'Select All',
|
---|
| 45 | unSelectAllText: 'UnSelect All',
|
---|
| 46 | itemsShowLimit: 6,
|
---|
| 47 | allowSearchFilter: false
|
---|
| 48 | };
|
---|
| 49 | if (!this.activeUser) {
|
---|
| 50 | this.router.navigate(['/'])
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | submit() {
|
---|
| 55 | this.addQuestionService.add(this.title!!, this.content!!, this.activeUser!!.username, this.courseId!!,this.selectedItems!!.map(cat => cat.id))
|
---|
| 56 | }
|
---|
| 57 | }
|
---|