Skip to content

Commit

Permalink
111731: Used yml config to configure the visibility advanced search c…
Browse files Browse the repository at this point in the history
…omponent & its filters
  • Loading branch information
alexandrevryghem committed May 2, 2024
1 parent e251c2c commit 561ccc3
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
import { Router } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';

import { APP_CONFIG } from '../../../../config/app-config.interface';
import { environment } from '../../../../environments/environment.test';
import { SearchService } from '../../../core/shared/search/search.service';
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
Expand Down Expand Up @@ -39,6 +41,7 @@ describe('AdvancedSearchComponent', () => {
{ provide: SearchService, useValue: searchService },
{ provide: SearchConfigurationService, useValue: searchConfigurationService },
{ provide: SearchFilterService, useValue: searchFilterService },
{ provide: APP_CONFIG, useValue: environment },
],
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@angular/common';
import {
Component,
Inject,
Input,
OnDestroy,
OnInit,
Expand All @@ -23,6 +24,10 @@ import {
} from 'rxjs';
import { take } from 'rxjs/operators';

import {
APP_CONFIG,
AppConfig,
} from '../../../../config/app-config.interface';
import { SearchService } from '../../../core/shared/search/search.service';
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
Expand Down Expand Up @@ -84,12 +89,17 @@ export class AdvancedSearchComponent implements OnInit, OnDestroy {
protected searchService: SearchService,
protected searchConfigurationService: SearchConfigurationService,
protected searchFilterService: SearchFilterService,
@Inject(APP_CONFIG) protected appConfig: AppConfig,
) {
}

ngOnInit(): void {
this.advancedFilters$ = this.searchConfigurationService.getConfigurationSearchConfig(this.configuration).pipe(
map((searchConfiguration: SearchConfig) => searchConfiguration.filters.filter((filter: FilterConfig) => filter.type !== FilterType.range)),
map((searchConfiguration: SearchConfig) => {
return searchConfiguration.filters
.filter((filter: FilterConfig) => this.appConfig.search.advancedFilters.filter.includes(filter.filter))
.filter((filter: FilterConfig) => filter.type !== FilterType.range);
}),
);
this.subs.push(this.advancedFilters$.subscribe((filters: FilterConfig[]) => {
const filterMap: Map<string, FilterConfig> = new Map();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
import {
ChangeDetectionStrategy,
NO_ERRORS_SCHEMA,
CUSTOM_ELEMENTS_SCHEMA,
} from '@angular/core';
import {
ComponentFixture,
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { RouterModule } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { APP_CONFIG } from 'src/config/app-config.interface';
import { environment } from 'src/environments/environment';

import { SearchService } from '../../../core/shared/search/search.service';
import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-configuration.service';
import { SearchConfigurationServiceStub } from '../../testing/search-configuration-service.stub';
import { SearchFilterServiceStub } from '../../testing/search-filter-service.stub';
import { SearchServiceStub } from '../../testing/search-service.stub';
import { SearchFiltersComponent } from './search-filters.component';

describe('SearchFiltersComponent', () => {
let comp: SearchFiltersComponent;
let fixture: ComponentFixture<SearchFiltersComponent>;
let searchService: SearchService;

const searchServiceStub = {
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
getClearFiltersQueryParams: () => {
},
getSearchLink: () => {
},
getConfigurationSearchConfig: () => { },
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
};

const searchFiltersStub = {
getSelectedValuesForFilter: (filter) =>
[],
};
let searchService: SearchServiceStub;
let searchFilters: SearchFilterServiceStub;

beforeEach(waitForAsync(() => {
searchService = new SearchServiceStub();
searchFilters = new SearchFilterServiceStub();

TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, SearchFiltersComponent],
imports: [
TranslateModule.forRoot(),
RouterModule.forRoot([]),
NoopAnimationsModule,
SearchFiltersComponent,
],
providers: [
{ provide: SearchService, useValue: searchServiceStub },
{ provide: SearchService, useValue: searchService },
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
{ provide: SearchFilterService, useValue: searchFiltersStub },
{ provide: APP_CONFIG, useValue: environment },

{ provide: SearchFilterService, useValue: searchFilters },
],
schemas: [NO_ERRORS_SCHEMA],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
}).overrideComponent(SearchFiltersComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default },
}).compileComponents();
Expand All @@ -59,13 +52,12 @@ describe('SearchFiltersComponent', () => {
fixture = TestBed.createComponent(SearchFiltersComponent);
comp = fixture.componentInstance; // SearchFiltersComponent test instance
fixture.detectChanges();
searchService = (comp as any).searchService;
});

describe('when the getSearchLink method is called', () => {
beforeEach(() => {
spyOn(searchService, 'getSearchLink');
(comp as any).getSearchLink();
comp.getSearchLink();
});

it('should call getSearchLink on the searchService', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import {
Observable,
} from 'rxjs';
import { map } from 'rxjs/operators';
import {
APP_CONFIG,
AppConfig,
} from 'src/config/app-config.interface';

import { RemoteData } from '../../../core/data/remote-data';
import { SearchService } from '../../../core/shared/search/search.service';
Expand All @@ -32,7 +28,6 @@ import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-configu
import { currentPath } from '../../utils/route.utils';
import { AdvancedSearchComponent } from '../advanced-search/advanced-search.component';
import { AppliedFilter } from '../models/applied-filter.model';
import { PaginatedSearchOptions } from '../models/paginated-search-options.model';
import { SearchFilterConfig } from '../models/search-filter-config.model';
import { SearchFilterComponent } from './search-filter/search-filter.component';

Expand All @@ -52,7 +47,7 @@ export class SearchFiltersComponent implements OnInit {
* An observable containing configuration about which filters are shown and how they are shown
*/
@Input() filters: Observable<RemoteData<SearchFilterConfig[]>>;
@Input() searchOptions: PaginatedSearchOptions;

/**
* List of all filters that are currently active with their value set to null.
* Used to reset all filters at once
Expand Down Expand Up @@ -90,7 +85,6 @@ export class SearchFiltersComponent implements OnInit {
filterLabel = 'search';

constructor(
@Inject(APP_CONFIG) protected appConfig: AppConfig,
protected searchService: SearchService,
protected searchFilterService: SearchFilterService,
protected router: Router,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[queryParams]="(removeParameters$ | async)"
(click)="searchFilterService.minimizeAll()">
<span class="d-flex">
<span class="flex-grow-1 text-left">{{ ('search.filters.applied.f.' + appliedFilter.filter) | translate}}: {{'search.filters.' + appliedFilter.filter + '.' + appliedFilter.label | translate: { default: appliedFilter.label } }}</span>
<span class="flex-grow-1 text-left">{{ ('search.filters.applied.f.' + appliedFilter.filter) | translate}}{{'search.filters.applied.operator.' + appliedFilter.operator | translate}}: {{'search.filters.' + appliedFilter.filter + '.' + appliedFilter.label | translate: { default: appliedFilter.label } }}</span>
<span class="pl-1" aria-hidden="true">×</span>
</span>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
[refreshFilters]="refreshFilters"
[inPlaceSearch]="inPlaceSearch">
</ds-themed-search-filters>
<ds-advanced-search [configuration]="configuration"
<ds-advanced-search *ngIf="appConfig.search.advancedFilters.enabled"
[configuration]="configuration"
[filtersConfig]="(filters | async)?.payload">
</ds-advanced-search>
<ds-themed-search-settings *ngIf="inPlaceSearch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { By } from '@angular/platform-browser';
import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';

import { APP_CONFIG } from '../../../../config/app-config.interface';
import { environment } from '../../../../environments/environment.test';
import { AdvancedSearchComponent } from '../advanced-search/advanced-search.component';
import { ThemedSearchFiltersComponent } from '../search-filters/themed-search-filters.component';
import { ThemedSearchSettingsComponent } from '../search-settings/themed-search-settings.component';
Expand All @@ -27,6 +29,9 @@ describe('SearchSidebarComponent', () => {
NgbCollapseModule,
SearchSidebarComponent,
],
providers: [
{ provide: APP_CONFIG, useValue: environment },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
.overrideComponent(SearchSidebarComponent, {
Expand Down
10 changes: 10 additions & 0 deletions src/app/shared/search/search-sidebar/search-sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import {
Component,
EventEmitter,
Inject,
Input,
Output,
} from '@angular/core';
Expand All @@ -14,6 +15,10 @@ import {
Observable,
} from 'rxjs';

import {
APP_CONFIG,
AppConfig,
} from '../../../../config/app-config.interface';
import { SortOptions } from '../../../core/cache/models/sort-options.model';
import { RemoteData } from '../../../core/data/remote-data';
import { ViewMode } from '../../../core/shared/view-mode.model';
Expand Down Expand Up @@ -120,4 +125,9 @@ export class SearchSidebarComponent {
*/
@Output() changeViewMode: EventEmitter<ViewMode> = new EventEmitter<ViewMode>();

constructor(
@Inject(APP_CONFIG) protected appConfig: AppConfig,
) {
}

}
26 changes: 0 additions & 26 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6058,24 +6058,6 @@

"admin.notifications.publicationclaim.page.title": "Publication Claim",

"filter.search.operator.placeholder": "Operator",

"search.filters.filter.entityType.text": "Item Type",

"search.filters.operator.equals.text": "Equals",

"search.filters.operator.notequals.text": "Not Equals",

"search.filters.operator.notcontains.text": "Not Contains",

"search.filters.operator.contains.text": "Contains",

"search.filters.filter.title.text": "Title",

"search.filters.applied.f.title": "Title",

"search.filters.filter.author.text": "Author",

"coar-notify-support.title": "COAR Notify Protocol",

"coar-notify-support-title.content": "Here, we fully support the COAR Notify protocol, which is designed to enhance the communication between repositories. To learn more about the COAR Notify protocol, visit the <a href=\\\"https://notify.coar-repositories.org/\\\">COAR Notify website</a>.",
Expand Down Expand Up @@ -6370,14 +6352,6 @@

"type-equals-journal-article_condition.label": "Type equals Journal Article",

"search.filters.filter.subject.text": "Subject",

"search.advanced.filters.head": "Advanced Search",

"filter.search.text.placeholder": "Search text",

"advancesearch.form.submit": "Add",

"ldn.no-filter.label": "None",

"admin.notify.dashboard": "Dashboard",
Expand Down

0 comments on commit 561ccc3

Please sign in to comment.