mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
[CST-4633] Fix issue with detail view mode
This commit is contained in:
@@ -8,7 +8,9 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="search-sidebar-content">
|
<div id="search-sidebar-content">
|
||||||
<ds-view-mode-switch *ngIf="showViewModes" [viewModeList]="viewModeList" class="d-none d-md-block"></ds-view-mode-switch>
|
<ds-view-mode-switch *ngIf="showViewModes" class="d-none d-md-block"
|
||||||
|
[viewModeList]="viewModeList"
|
||||||
|
(changeViewMode)="changeViewMode.emit($event)"></ds-view-mode-switch>
|
||||||
<div class="sidebar-content">
|
<div class="sidebar-content">
|
||||||
<ds-search-switch-configuration *ngIf="configurationList"
|
<ds-search-switch-configuration *ngIf="configurationList"
|
||||||
[configurationList]="configurationList"
|
[configurationList]="configurationList"
|
||||||
|
@@ -88,4 +88,9 @@ export class SearchSidebarComponent {
|
|||||||
*/
|
*/
|
||||||
@Output() changeConfiguration: EventEmitter<SearchConfigurationOption> = new EventEmitter<SearchConfigurationOption>();
|
@Output() changeConfiguration: EventEmitter<SearchConfigurationOption> = new EventEmitter<SearchConfigurationOption>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits event when the user select a new view mode
|
||||||
|
*/
|
||||||
|
@Output() changeViewMode: EventEmitter<ViewMode> = new EventEmitter<ViewMode>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,8 @@
|
|||||||
[currentSortOption]="(currentSortOptions$ | async)"
|
[currentSortOption]="(currentSortOptions$ | async)"
|
||||||
[inPlaceSearch]="inPlaceSearch"
|
[inPlaceSearch]="inPlaceSearch"
|
||||||
[viewModeList]="viewModeList"
|
[viewModeList]="viewModeList"
|
||||||
(changeConfiguration)="changeContext($event.context)"></ds-search-sidebar>
|
(changeConfiguration)="changeContext($event.context)"
|
||||||
|
(changeViewMode)="changeViewMode()"></ds-search-sidebar>
|
||||||
<ds-search-sidebar id="search-sidebar-sm" *ngIf="(isXsOrSm$ | async)"
|
<ds-search-sidebar id="search-sidebar-sm" *ngIf="(isXsOrSm$ | async)"
|
||||||
[configurationList]="configurationList"
|
[configurationList]="configurationList"
|
||||||
[configuration]="(currentConfiguration$ | async)"
|
[configuration]="(currentConfiguration$ | async)"
|
||||||
@@ -59,7 +60,8 @@
|
|||||||
[currentSortOption]="(currentSortOptions$ | async)"
|
[currentSortOption]="(currentSortOptions$ | async)"
|
||||||
[viewModeList]="viewModeList"
|
[viewModeList]="viewModeList"
|
||||||
(toggleSidebar)="closeSidebar()"
|
(toggleSidebar)="closeSidebar()"
|
||||||
(changeConfiguration)="changeContext($event.context)">
|
(changeConfiguration)="changeContext($event.context)"
|
||||||
|
(changeViewMode)="changeViewMode()">
|
||||||
</ds-search-sidebar>
|
</ds-search-sidebar>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
|
@@ -256,6 +256,13 @@ export class SearchComponent implements OnInit {
|
|||||||
this.sidebarService.collapse();
|
this.sidebarService.collapse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset result list on view mode change
|
||||||
|
*/
|
||||||
|
public changeViewMode() {
|
||||||
|
this.resultsRD$.next(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the sidebar to an expanded state
|
* Set the sidebar to an expanded state
|
||||||
*/
|
*/
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
</a>
|
</a>
|
||||||
<a *ngIf="isToShow(viewModeEnum.DetailedListElement)"
|
<a *ngIf="isToShow(viewModeEnum.DetailedListElement)"
|
||||||
routerLink="."
|
routerLink="."
|
||||||
[queryParams]="{view: 'detail'}"
|
[queryParams]="{view: 'detailed'}"
|
||||||
queryParamsHandling="merge"
|
queryParamsHandling="merge"
|
||||||
(click)="switchViewTo(viewModeEnum.DetailedListElement)"
|
(click)="switchViewTo(viewModeEnum.DetailedListElement)"
|
||||||
routerLinkActive="active"
|
routerLinkActive="active"
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
|
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { TranslateLoaderMock } from '../mocks/translate-loader.mock';
|
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
|
||||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||||
|
|
||||||
|
import { TranslateLoaderMock } from '../mocks/translate-loader.mock';
|
||||||
import { SearchService } from '../../core/shared/search/search.service';
|
import { SearchService } from '../../core/shared/search/search.service';
|
||||||
import { ViewModeSwitchComponent } from './view-mode-switch.component';
|
import { ViewModeSwitchComponent } from './view-mode-switch.component';
|
||||||
import { SearchServiceStub } from '../testing/search-service.stub';
|
import { SearchServiceStub } from '../testing/search-service.stub';
|
||||||
@@ -21,6 +20,7 @@ describe('ViewModeSwitchComponent', () => {
|
|||||||
const searchService = new SearchServiceStub();
|
const searchService = new SearchServiceStub();
|
||||||
let listButton: HTMLElement;
|
let listButton: HTMLElement;
|
||||||
let gridButton: HTMLElement;
|
let gridButton: HTMLElement;
|
||||||
|
let detailButton: HTMLElement;
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -49,27 +49,76 @@ describe('ViewModeSwitchComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(ViewModeSwitchComponent);
|
fixture = TestBed.createComponent(ViewModeSwitchComponent);
|
||||||
comp = fixture.componentInstance; // ViewModeSwitchComponent test instance
|
comp = fixture.componentInstance; // ViewModeSwitchComponent test instance
|
||||||
|
spyOn(comp.changeViewMode, 'emit');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('', () => {
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
comp.viewModeList = [ViewMode.ListElement, ViewMode.GridElement];
|
||||||
|
comp.currentMode = ViewMode.ListElement;
|
||||||
|
searchService.setViewMode(ViewMode.ListElement);
|
||||||
|
tick();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const debugElements = fixture.debugElement.queryAll(By.css('a'));
|
const debugElements = fixture.debugElement.queryAll(By.css('a'));
|
||||||
listButton = debugElements[0].nativeElement;
|
listButton = debugElements[0].nativeElement;
|
||||||
gridButton = debugElements[1].nativeElement;
|
gridButton = debugElements[1].nativeElement;
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should set list button as active when on list mode', fakeAsync(() => {
|
it('should set list button as active when on list mode', fakeAsync(() => {
|
||||||
searchService.setViewMode(ViewMode.ListElement);
|
comp.switchViewTo(ViewMode.ListElement);
|
||||||
|
expect(comp.changeViewMode.emit).not.toHaveBeenCalled();
|
||||||
tick();
|
tick();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(comp.currentMode).toBe(ViewMode.ListElement);
|
expect(comp.currentMode).toBe(ViewMode.ListElement);
|
||||||
expect(listButton.classList).toContain('active');
|
expect(listButton.classList).toContain('active');
|
||||||
expect(gridButton.classList).not.toContain('active');
|
expect(gridButton.classList).not.toContain('active');
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should set grid button as active when on grid mode', fakeAsync(() => {
|
it('should set grid button as active when on grid mode', fakeAsync(() => {
|
||||||
searchService.setViewMode(ViewMode.GridElement);
|
comp.switchViewTo(ViewMode.GridElement);
|
||||||
|
expect(comp.changeViewMode.emit).toHaveBeenCalledWith(ViewMode.GridElement);
|
||||||
tick();
|
tick();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(comp.currentMode).toBe(ViewMode.GridElement);
|
expect(comp.currentMode).toBe(ViewMode.GridElement);
|
||||||
expect(listButton.classList).not.toContain('active');
|
expect(listButton.classList).not.toContain('active');
|
||||||
expect(gridButton.classList).toContain('active');
|
expect(gridButton.classList).toContain('active');
|
||||||
}));
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('', () => {
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
comp.viewModeList = [ViewMode.ListElement, ViewMode.DetailedListElement];
|
||||||
|
comp.currentMode = ViewMode.ListElement;
|
||||||
|
searchService.setViewMode(ViewMode.ListElement);
|
||||||
|
tick();
|
||||||
|
fixture.detectChanges();
|
||||||
|
const debugElements = fixture.debugElement.queryAll(By.css('a'));
|
||||||
|
listButton = debugElements[0].nativeElement;
|
||||||
|
detailButton = debugElements[1].nativeElement;
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should set list button as active when on list mode', fakeAsync(() => {
|
||||||
|
comp.switchViewTo(ViewMode.ListElement);
|
||||||
|
expect(comp.changeViewMode.emit).not.toHaveBeenCalled();
|
||||||
|
tick();
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(comp.currentMode).toBe(ViewMode.ListElement);
|
||||||
|
expect(listButton.classList).toContain('active');
|
||||||
|
expect(detailButton.classList).not.toContain('active');
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should set detail button as active when on detailed mode', fakeAsync(() => {
|
||||||
|
comp.switchViewTo(ViewMode.DetailedListElement);
|
||||||
|
expect(comp.changeViewMode.emit).toHaveBeenCalledWith(ViewMode.DetailedListElement);
|
||||||
|
tick();
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(comp.currentMode).toBe(ViewMode.DetailedListElement);
|
||||||
|
expect(listButton.classList).not.toContain('active');
|
||||||
|
expect(detailButton.classList).toContain('active');
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -1,12 +1,13 @@
|
|||||||
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
|
||||||
|
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
import { SearchService } from '../../core/shared/search/search.service';
|
import { SearchService } from '../../core/shared/search/search.service';
|
||||||
import { ViewMode } from '../../core/shared/view-mode.model';
|
import { ViewMode } from '../../core/shared/view-mode.model';
|
||||||
import { isEmpty } from '../empty.util';
|
import { isEmpty, isNotEmpty } from '../empty.util';
|
||||||
import { currentPath } from '../utils/route.utils';
|
import { currentPath } from '../utils/route.utils';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { filter } from 'rxjs/operators';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to switch between list and grid views.
|
* Component to switch between list and grid views.
|
||||||
@@ -37,8 +38,18 @@ export class ViewModeSwitchComponent implements OnInit, OnDestroy {
|
|||||||
* All available view modes
|
* All available view modes
|
||||||
*/
|
*/
|
||||||
viewModeEnum = ViewMode;
|
viewModeEnum = ViewMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscription to unsubscribe OnDestroy
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
private sub: Subscription;
|
private sub: Subscription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits event when the user select a new view mode
|
||||||
|
*/
|
||||||
|
@Output() changeViewMode: EventEmitter<ViewMode> = new EventEmitter<ViewMode>();
|
||||||
|
|
||||||
constructor(private searchService: SearchService, private router: Router) {
|
constructor(private searchService: SearchService, private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +61,9 @@ export class ViewModeSwitchComponent implements OnInit, OnDestroy {
|
|||||||
this.viewModeList = [ViewMode.ListElement, ViewMode.GridElement];
|
this.viewModeList = [ViewMode.ListElement, ViewMode.GridElement];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sub = this.searchService.getViewMode().subscribe((viewMode: ViewMode) => {
|
this.sub = this.searchService.getViewMode().pipe(
|
||||||
|
filter((viewMode: ViewMode) => isNotEmpty(viewMode))
|
||||||
|
).subscribe((viewMode: ViewMode) => {
|
||||||
this.currentMode = viewMode;
|
this.currentMode = viewMode;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -60,6 +73,9 @@ export class ViewModeSwitchComponent implements OnInit, OnDestroy {
|
|||||||
* @param viewMode The new view mode
|
* @param viewMode The new view mode
|
||||||
*/
|
*/
|
||||||
switchViewTo(viewMode: ViewMode) {
|
switchViewTo(viewMode: ViewMode) {
|
||||||
|
if (viewMode !== this.currentMode) {
|
||||||
|
this.changeViewMode.emit(viewMode);
|
||||||
|
}
|
||||||
this.searchService.setViewMode(viewMode, this.getSearchLinkParts());
|
this.searchService.setViewMode(viewMode, this.getSearchLinkParts());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user