Newer
Older
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
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';
import { UserManagementService } from '../user-management/service/user-management.service';
import { User } from '../user-management/user-management.model';
import { ReviewRequest } from './reviewRequest.model';
@Component({
selector: 'jhi-review-management',
templateUrl: './review-management.component.html',
styleUrls: ['./review-management.component.scss'],
})
export class ReviewManagementComponent implements OnInit {
currentAccount: Account | null = null;
users: User[] | undefined;
results: Exercise[] = [];
selectedUsers: User[] | undefined;
selectedExercise: Exercise | undefined;
constructor(
private http: HttpClient,
private userService: UserManagementService,
private accountService: AccountService,
private searchService: SearchService
) {
this.loadAll();
}
ngOnInit(): void {
this.accountService.identity().subscribe(account => (this.currentAccount = account));
this.loadAll();
}
loadAll(): void {
this.userService.loadAll().subscribe(users => {
this.users = users;
});
this.searchService.getAllResources().subscribe(
(data: SearchResultsDTO) => {
const searchResults = data.searchResult.map(searchResultToExercise);
this.results = this.results.concat(searchResults);
},
() => (this.results = [])
);
}
shareCheckedUserList(users: User[]) {
this.selectedUsers = users;
shareExercise(exercise: Exercise) {
this.selectedExercise = exercise;
}
submitReview() {
this.http
.post<ReviewRequest>(
'api/review/create',
new ReviewRequest(
this.selectedExercise!.title,
this.selectedUsers!.map(u => u.email!)
)
)
.subscribe();