Changeset 32cd040


Ignore:
Timestamp:
10/27/21 21:37:43 (3 years ago)
Author:
Стојков Марко <mst@…>
Branches:
dev
Children:
15a34a3
Parents:
c205cc4
Message:

Added generic component for asking questions

Location:
src/Clients/Angular/finki-chattery/src/app
Files:
4 added
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/Clients/Angular/finki-chattery/src/app/core/guards/authorized-student.guard.ts

    rc205cc4 r32cd040  
    11import { Injectable } from '@angular/core';
    22import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
    3 import { ApplicationUserType } from 'src/app/shared-app/models';
    43import { AuthService } from '../services';
    54
     
    1110
    1211  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    13     return this.auth.user?.userType === ApplicationUserType.Student;
     12    return this.auth.isStudent();
    1413  }
    1514}
  • src/Clients/Angular/finki-chattery/src/app/modules/questioning/components/ask-question/ask-question.component.html

    rc205cc4 r32cd040  
    1 <form class="example-container" [formGroup]="questionFormGroup">
    2   <mat-form-field class="full-width margin-bottom-sm" appearance="fill" appHandleInputFormErrors>
    3     <mat-label>{{ 'ask-question-question-title' | translate }}</mat-label>
    4     <input matInput [formControl]="titleForm" />
    5   </mat-form-field>
    6 
    7   <editor
    8     matInput
    9     class="margin-bottom-sm"
    10     [formControl]="textForm"
    11     [init]="{
    12       apiKey: 'fx28x0d64jeufa35u7mcd80fgveayg5c4ap9gnr6posehzny',
    13       menubar: false,
    14       plugins: [
    15         'advlist autolink lists link image charmap print preview anchor',
    16         'searchreplace visualblocks code fullscreen',
    17         'insertdatetime media table paste code help wordcount'
    18       ],
    19       toolbar:
    20         'undo redo | formatselect | bold italic backcolor | code | \
    21         alignleft aligncenter alignright alignjustify | \
    22         bullist numlist outdent indent | removeformat | help'
    23     }"
    24   ></editor>
    25   <mat-error *ngIf="textForm?.touched && textForm?.errors?.required">{{ 'not-found' | translate }}</mat-error>
    26   <mat-error *ngIf="textForm?.touched && textForm?.errors?.maxlength">{{
    27     'error-message-max-length' | translate: { maxlength: textForm?.errors?.maxlength?.requiredLength }
    28   }}</mat-error>
    29 
    30   <mat-form-field class="full-width margin-bottom-sm" appearance="fill" appHandleInputFormErrors>
    31     <mat-label>{{ 'ask-question-categories' | translate }}</mat-label>
    32     <mat-select [formControl]="categoriesForm" multiple>
    33       <mat-option *ngFor="let category of categoriesList$ | async" [value]="category.uid">{{ category.translatedName }}</mat-option>
    34     </mat-select>
    35   </mat-form-field>
    36 
    37   <app-button [disabled]="questionFormGroup.invalid" [buttonType]="ButtonType.CallToAction" (action)="askQuestion()">
    38     {{ 'ask-question-ask-button' | translate }}
    39   </app-button>
    40 </form>
     1<app-ask-question-shared (askQuestion)="askQuestionAsStudent($event)"></app-ask-question-shared>
  • src/Clients/Angular/finki-chattery/src/app/modules/questioning/components/ask-question/ask-question.component.ts

    rc205cc4 r32cd040  
    11import { Component, OnInit } from '@angular/core';
    2 import { FormControl, FormGroup, Validators } from '@angular/forms';
    32import { Router } from '@angular/router';
    43
    5 import { CategoryFacadeService } from 'src/app/core/state/category-facade.service';
    6 import { ButtonType } from 'src/app/shared-app/components/generic/button/button.models';
    7 import { AskQuestionRequest } from '../../models/questioning-request.models';
     4import { AskQuestionRequest } from 'src/app/shared-app/models';
    85import { QuestioningApiService } from '../../services/questioning-api.service';
    96
     
    1411})
    1512export class AskQuestionComponent implements OnInit {
    16   public titleForm = new FormControl('', [Validators.required, Validators.maxLength(500)]);
    17   public textForm = new FormControl('', [Validators.required, Validators.maxLength(4000)]);
    18   public categoriesForm = new FormControl([]);
    19   public questionFormGroup: FormGroup;
    20   public ButtonType = ButtonType;
    21   public categoriesList$ = this.categoriesFacade.getCategories();
    22 
    23   constructor(private api: QuestioningApiService, private categoriesFacade: CategoryFacadeService, private router: Router) {
    24     this.questionFormGroup = new FormGroup({
    25       title: this.titleForm,
    26       text: this.textForm,
    27       categories: this.categoriesForm
    28     });
    29   }
     13  constructor(private api: QuestioningApiService, private router: Router) {}
    3014
    3115  ngOnInit(): void {}
    3216
    33   public askQuestion(): void {
    34     const body = new AskQuestionRequest(this.titleForm.value, this.textForm.value, this.categoriesForm.value);
     17  public askQuestionAsStudent(body: AskQuestionRequest): void {
    3518    this.api.askQuestion(body).subscribe((questionUid) => {
    3619      this.router.navigateByUrl(`questioning/${questionUid}`);
  • src/Clients/Angular/finki-chattery/src/app/shared-app/components/components.ts

    rc205cc4 r32cd040  
    44import { HeaderComponent } from './generic/header/header.component';
    55import { VoteComponent } from './generic/vote/vote.component';
     6import { AskQuestionSharedComponent } from './question/ask-question-shared/ask-question-shared.component';
    67import { PreviewQuestionDisplayComponent } from './question/preview-question-display/preview-question-display.component';
    78import { QuestionPreviewComponent } from './question/question-preview/question-preview.component';
     
    1819  HeaderComponent,
    1920  SearchQuestionComponent,
    20   PreviewQuestionDisplayComponent
     21  PreviewQuestionDisplayComponent,
     22  AskQuestionSharedComponent
    2123];
  • src/Clients/Angular/finki-chattery/src/app/shared-app/models/index.ts

    rc205cc4 r32cd040  
    44export * from './category-state-view-models.models';
    55export * from './question-state-enums.models';
     6export * from './questioning-request.models';
Note: See TracChangeset for help on using the changeset viewer.