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

Skip to content
Snippets Groups Projects
Commit 81c635aa authored by Daniel Rainer's avatar Daniel Rainer
Browse files

Integrate metadata selection

The search component receives notifications
when the selected repository changes.
Upon such changes, only display the pages to which
the new filter applies.
parent b0aec454
Branches
No related merge requests found
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subject, Subscription} from 'rxjs';
import {LoginModalService} from 'app/core/login/login-modal.service';
import {AccountService} from 'app/core/auth/account.service';
import {Account} from 'app/core/user/account.model';
import {HttpResponse} from '@angular/common/http';
import {ActivatedRoute, Router} from '@angular/router';
import {QueryParam, QueryParamBuilder, QueryParamGroup} from '@ngqp/core';
import {takeUntil} from 'rxjs/operators';
import {IFrequency} from 'app/shared/model/frequency.model';
import {IGitFilesPageDetails} from 'app/shared/model/git-files-page-details.model';
import {IGitFilesAggregation} from 'app/shared/model/git-files-aggregation';
import {IGitFiles} from 'app/shared/model/git-files.model';
import {SearchInput} from "app/shared/model/search-input.model";
import {SearchResultService} from "app/search/search/search-result.service";
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subject, Subscription } from 'rxjs';
import { LoginModalService } from 'app/core/login/login-modal.service';
import { AccountService } from 'app/core/auth/account.service';
import { Account } from 'app/core/user/account.model';
import { HttpResponse } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { QueryParam, QueryParamBuilder, QueryParamGroup } from '@ngqp/core';
import { takeUntil } from 'rxjs/operators';
import { IFrequency } from 'app/shared/model/frequency.model';
import { IGitFilesPageDetails, GitFilesPageDetails } from 'app/shared/model/git-files-page-details.model';
import { IGitFilesAggregation } from 'app/shared/model/git-files-aggregation';
import { IGitFiles } from 'app/shared/model/git-files.model';
import { SearchInput } from 'app/shared/model/search-input.model';
import { SearchResultService } from 'app/search/search/search-result.service';
import { MessageService } from 'app/search/metadata-message.service';
@Component({
selector: 'jhi-search',
......@@ -26,26 +27,30 @@ export class SearchComponent implements OnInit, OnDestroy {
account: Account | null = null;
authSubscription?: Subscription;
private gitFilesAllPages?: IGitFilesPageDetails;
gitFilesPageDetails?: IGitFilesPageDetails;
gitFilesAggregation?: IGitFilesAggregation;
private selectedFiltersSubscription: Subscription = new Subscription();
private selectedRepository: string | null = null;
private selectedUniversity: string | null = null;
private selectedFileFormat: string | null = null;
public paramGroup: QueryParamGroup;
private componentDestroyed$ = new Subject<void>();
public searchInput: SearchInput;
constructor(
protected searchResultService: SearchResultService,
private accountService: AccountService,
private loginModalService: LoginModalService,
protected activatedRoute: ActivatedRoute,
private router: Router,
private qpb: QueryParamBuilder
private qpb: QueryParamBuilder,
private filterSelectionService: MessageService
) {
this.searchInput = new SearchInput()
this.searchInput = new SearchInput();
this.paramGroup = qpb.group({
searchText: qpb.stringParam('q', {
......@@ -100,6 +105,9 @@ export class SearchComponent implements OnInit, OnDestroy {
this.loadAggregation();
this.loadPageDetails();
this.authSubscription = this.accountService.getAuthenticationState().subscribe(account => (this.account = account));
this.selectedFiltersSubscription.add(
this.filterSelectionService.filterSelection$.subscribe(filterSelection => this.updateSearchInfoFilter(filterSelection))
);
}
loadAggregation(): void {
......@@ -116,14 +124,44 @@ export class SearchComponent implements OnInit, OnDestroy {
loadPageDetails(): void {
if (this.searchInput.fulltextQuery) {
this.searchResultService
.searchPageDetails(this.searchInput, this.pageSize)
.subscribe((res: HttpResponse<IGitFilesPageDetails>) => {
this.gitFilesPageDetails = res.body || undefined;
});
this.searchResultService.searchPageDetails(this.searchInput, this.pageSize).subscribe((res: HttpResponse<IGitFilesPageDetails>) => {
if (res.body === null) {
this.gitFilesAllPages = undefined;
} else {
this.gitFilesAllPages = new GitFilesPageDetails(res.body.gitFiles, res.body.gitFiles.length);
this.updatePageDetails();
}
});
}
}
private updatePageDetails(): void {
if (this.gitFilesAllPages !== undefined) {
const matchingResults = this.gitFilesAllPages.gitFiles.filter(element => this.matchesSelection(element));
if (matchingResults.length > 0) {
this.gitFilesPageDetails = new GitFilesPageDetails(matchingResults, matchingResults.length);
} else {
this.gitFilesPageDetails = undefined;
}
}
}
public updateSearchInfoFilter(selectionUpdate: IFrequency<string>): void {
if (this.selectedRepository === selectionUpdate.key) {
this.selectedRepository = null;
} else {
this.selectedRepository = selectionUpdate.key;
}
this.updatePageDetails();
}
matchesSelection(file: IGitFiles): boolean {
if (this.selectedRepository) {
return file.repository === this.selectedRepository;
}
return true;
}
isAuthenticated(): boolean {
return this.accountService.isAuthenticated();
}
......@@ -136,6 +174,9 @@ export class SearchComponent implements OnInit, OnDestroy {
if (this.authSubscription) {
this.authSubscription.unsubscribe();
}
if (this.selectedFiltersSubscription) {
this.selectedFiltersSubscription.unsubscribe();
}
this.componentDestroyed$.next();
this.componentDestroyed$.complete();
}
......@@ -173,4 +214,3 @@ export class SearchComponent implements OnInit, OnDestroy {
return hits ? hits : 0;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment