This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
peer-reviewing.component.ts 2.2 KiB
Newer Older
import { Component, OnInit } from '@angular/core';
import { UserManagementService } from 'app/admin/user-management/service/user-management.service';
import { User } from 'app/admin/user-management/user-management.model';
import { Account } from 'app/core/auth/account.model';
import { AccountService } from 'app/core/auth/account.service';
import { SearchService } from 'app/search/service/search-service';
import { Exercise, searchResultToExercise } from 'app/shared/model/exercise.model';
import { SearchResultsDTO } from 'app/shared/model/search/search-results-dto.model';

@Component({
  selector: 'jhi-peer-reviewing',
  templateUrl: './peer-reviewing.component.html',
  styleUrls: ['./peer-reviewing.component.scss'],
})
export class PeerReviewingComponent implements OnInit {
  isChecked = false;
  currentAccount: Account | null = null;
  user: User | null = null;
  results: Exercise[] = [];

  constructor(private userService: UserManagementService, private accountService: AccountService, private searchService: SearchService) {}

  ngOnInit(): void {
    this.accountService.identity().subscribe(account => (this.currentAccount = account));
    this.getUserFromLogin();
    this.searchForExercises();
  }

  getUserFromLogin(): void {
    if (this.currentAccount != null && this.currentAccount.login != null) {
      this.userService.find(this.currentAccount?.login).subscribe(val => (this.user = val));
    }
  }

  setReviewerStatusForLogin(): void {
    if (this.user != null && this.currentAccount != null && this.user.login == this.currentAccount.login) {
      this.user.reviewingEnabled = !this.user.reviewingEnabled;
      this.userService.update(this.user).subscribe();
    }
  }

  searchForExercises(): void {
    if (this.currentAccount) {
      this.searchService.getResultsForAuthor('michael.breu@uibk.ac.at').subscribe(
        (data: SearchResultsDTO) => {
          const searchResults = data.searchResult.map(searchResultToExercise);
          this.results = this.results.concat(searchResults);
        },
        () => alert('Search failed')
      );
    }
  }

  requestReview(exercise: Exercise): void {
    if (this.currentAccount) {
      this.searchService.requestReview(exercise.identifier).subscribe();
    }
  }