mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
97732 Context help button now disabled when there are no tooltips available on the page
This commit is contained in:
@@ -9,15 +9,17 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<ng-template #editheader>
|
<ng-template #editheader>
|
||||||
<h2 class="border-bottom pb-2"
|
<h2 class="border-bottom pb-2">
|
||||||
|
<span
|
||||||
*dsContextHelp="{
|
*dsContextHelp="{
|
||||||
content: 'admin.access-control.groups.form.tooltip.editGroupPage',
|
content: 'admin.access-control.groups.form.tooltip.editGroupPage',
|
||||||
id: 'edit-group-page',
|
id: 'edit-group-page',
|
||||||
iconPlacement: 'left',
|
iconPlacement: 'right',
|
||||||
tooltipPlacement: ['left', 'bottom']
|
tooltipPlacement: ['right', 'bottom']
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
{{messagePrefix + '.head.edit' | translate}}
|
{{messagePrefix + '.head.edit' | translate}}
|
||||||
|
</span>
|
||||||
</h2>
|
</h2>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
|
@@ -1,15 +1,17 @@
|
|||||||
<ng-container>
|
<ng-container>
|
||||||
<h3 class="border-bottom pb-2">{{messagePrefix + '.head' | translate}}</h3>
|
<h3 class="border-bottom pb-2">{{messagePrefix + '.head' | translate}}</h3>
|
||||||
|
|
||||||
<h4 id="search" class="border-bottom pb-2"
|
<h4 id="search" class="border-bottom pb-2">
|
||||||
|
<span
|
||||||
*dsContextHelp="{
|
*dsContextHelp="{
|
||||||
content: 'admin.access-control.groups.form.tooltip.editGroup.addEpeople',
|
content: 'admin.access-control.groups.form.tooltip.editGroup.addEpeople',
|
||||||
id: 'edit-group-add-epeople',
|
id: 'edit-group-add-epeople',
|
||||||
iconPlacement: 'left',
|
iconPlacement: 'right',
|
||||||
tooltipPlacement: ['left', 'top', 'bottom']
|
tooltipPlacement: ['top', 'right', 'bottom']
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
{{messagePrefix + '.search.head' | translate}}
|
{{messagePrefix + '.search.head' | translate}}
|
||||||
|
</span>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)" class="d-flex justify-content-between">
|
<form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)" class="d-flex justify-content-between">
|
||||||
|
@@ -1,15 +1,17 @@
|
|||||||
<ng-container>
|
<ng-container>
|
||||||
<h3 class="border-bottom pb-2">{{messagePrefix + '.head' | translate}}</h3>
|
<h3 class="border-bottom pb-2">{{messagePrefix + '.head' | translate}}</h3>
|
||||||
|
|
||||||
<h4 id="search" class="border-bottom pb-2"
|
<h4 id="search" class="border-bottom pb-2">
|
||||||
*dsContextHelp="{
|
<span *dsContextHelp="{
|
||||||
content: 'admin.access-control.groups.form.tooltip.editGroup.addSubgroups',
|
content: 'admin.access-control.groups.form.tooltip.editGroup.addSubgroups',
|
||||||
id: 'edit-group-add-subgroups',
|
id: 'edit-group-add-subgroups',
|
||||||
iconPlacement: 'left',
|
iconPlacement: 'right',
|
||||||
tooltipPlacement: ['left', 'top', 'bottom']
|
tooltipPlacement: ['top', 'right', 'bottom']
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
{{messagePrefix + '.search.head' | translate}}
|
{{messagePrefix + '.search.head' | translate}}
|
||||||
|
</span>
|
||||||
|
|
||||||
</h4>
|
</h4>
|
||||||
<form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)" class="d-flex justify-content-between">
|
<form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)" class="d-flex justify-content-between">
|
||||||
<div class="flex-grow-1 mr-3">
|
<div class="flex-grow-1 mr-3">
|
||||||
|
@@ -2,9 +2,11 @@
|
|||||||
<a href="javascript:void(0);"
|
<a href="javascript:void(0);"
|
||||||
role="button"
|
role="button"
|
||||||
(click)="onClick()"
|
(click)="onClick()"
|
||||||
[attr.aria-label]="'nav.context-help-toggle' | translate"
|
[attr.aria-label]="((buttonDisabled$ | async) ? 'nav.context-help-toggle-disabled' : 'nav.context-help-toggle') | translate"
|
||||||
[title]="'nav.context-help-toggle' | translate"
|
[title]="((buttonDisabled$ | async) ? 'nav.context-help-toggle-disabled' : 'nav.context-help-toggle') | translate"
|
||||||
>
|
>
|
||||||
<i class="fas fa-lg fa-fw fa-question-circle ds-context-help-toggle"></i>
|
<i class="fas fa-lg fa-fw fa-question-circle"
|
||||||
|
[class]="(buttonDisabled$ | async) ? 'ds-context-help-toggle-disabled' : 'ds-context-help-toggle-enabled'"
|
||||||
|
></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
.ds-context-help-toggle {
|
.ds-context-help-toggle-enabled {
|
||||||
color: var(--ds-header-icon-color);
|
color: var(--ds-header-icon-color);
|
||||||
background-color: var(--ds-header-bg);
|
background-color: var(--ds-header-bg);
|
||||||
|
|
||||||
@@ -6,3 +6,8 @@
|
|||||||
color: var(--ds-header-icon-color-hover);
|
color: var(--ds-header-icon-color-hover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ds-context-help-toggle-disabled {
|
||||||
|
color: grey;
|
||||||
|
background-color: var(--ds-header-bg);
|
||||||
|
}
|
||||||
|
@@ -3,17 +3,19 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { ContextHelpToggleComponent } from './context-help-toggle.component';
|
import { ContextHelpToggleComponent } from './context-help-toggle.component';
|
||||||
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
||||||
import { ContextHelpService } from '../../shared/context-help.service';
|
import { ContextHelpService } from '../../shared/context-help.service';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf, BehaviorSubject } from 'rxjs';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
describe('ContextHelpToggleComponent', () => {
|
describe('ContextHelpToggleComponent', () => {
|
||||||
let component: ContextHelpToggleComponent;
|
let component: ContextHelpToggleComponent;
|
||||||
let fixture: ComponentFixture<ContextHelpToggleComponent>;
|
let fixture: ComponentFixture<ContextHelpToggleComponent>;
|
||||||
let contextHelpService;
|
let contextHelpService;
|
||||||
|
let contextHelpEmpty$ = new BehaviorSubject(true);
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
contextHelpService = jasmine.createSpyObj('contextHelpService',
|
contextHelpService = jasmine.createSpyObj('contextHelpService',
|
||||||
['toggleIcons']);
|
['toggleIcons', 'contextHelpEmpty$']);
|
||||||
|
contextHelpService.contextHelpEmpty$.and.returnValue(contextHelpEmpty$);
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
declarations: [ ContextHelpToggleComponent ],
|
declarations: [ ContextHelpToggleComponent ],
|
||||||
providers: [
|
providers: [
|
||||||
@@ -34,8 +36,28 @@ describe('ContextHelpToggleComponent', () => {
|
|||||||
expect(component).toBeTruthy();
|
expect(component).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('clicking the button should toggle context help icon visibility', () => {
|
describe('if there are elements on the page with a tooltip', () => {
|
||||||
fixture.debugElement.query(By.css('a')).nativeElement.click();
|
beforeEach(() => {
|
||||||
expect(contextHelpService.toggleIcons).toHaveBeenCalled();
|
contextHelpEmpty$.next(false);
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clicking the button should toggle context help icon visibility', () => {
|
||||||
|
fixture.whenStable().then((done) => {
|
||||||
|
fixture.debugElement.query(By.css('a')).nativeElement.click();
|
||||||
|
expect(contextHelpService.toggleIcons).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('if there are no elements on the page with a tooltip', () => {
|
||||||
|
it('clicking the button does not toggle context help icon visibility', () => {
|
||||||
|
fixture.whenStable().then((done) => {
|
||||||
|
fixture.debugElement.query(By.css('a')).nativeElement.click();
|
||||||
|
expect(contextHelpService.toggleIcons).toHaveBeenCalledTimes(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,23 +1,40 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { ContextHelpService } from '../../shared/context-help.service';
|
import { ContextHelpService } from '../../shared/context-help.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { Observable, Subscription, BehaviorSubject } from 'rxjs';
|
||||||
|
import { combineLatest } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-context-help-toggle',
|
selector: 'ds-context-help-toggle',
|
||||||
templateUrl: './context-help-toggle.component.html',
|
templateUrl: './context-help-toggle.component.html',
|
||||||
styleUrls: ['./context-help-toggle.component.scss']
|
styleUrls: ['./context-help-toggle.component.scss']
|
||||||
})
|
})
|
||||||
export class ContextHelpToggleComponent implements OnInit {
|
export class ContextHelpToggleComponent implements OnInit, OnDestroy {
|
||||||
|
buttonDisabled$: Observable<boolean>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private contextHelpService: ContextHelpService,
|
private contextHelpService: ContextHelpService,
|
||||||
private translateService: TranslateService
|
private translateService: TranslateService
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
private clickEvents: BehaviorSubject<null> = new BehaviorSubject(null);
|
||||||
|
private subs: Subscription[];
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.buttonDisabled$ = this.contextHelpService.contextHelpEmpty$();
|
||||||
|
this.subs = [
|
||||||
|
this.buttonDisabled$.subscribe(),
|
||||||
|
combineLatest([this.clickEvents, this.buttonDisabled$])
|
||||||
|
.subscribe(([_, disabled]) =>
|
||||||
|
disabled ? null : this.contextHelpService.toggleIcons())
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.subs.forEach(sub => sub.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
onClick() {
|
onClick() {
|
||||||
this.contextHelpService.toggleIcons();
|
this.clickEvents.next(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ContextHelp } from './context-help.model';
|
import { ContextHelp } from './context-help.model';
|
||||||
import { Store, createFeatureSelector, createSelector, select, MemoizedSelector } from '@ngrx/store';
|
import { Store, createFeatureSelector, createSelector, select, MemoizedSelector } from '@ngrx/store';
|
||||||
import { ContextHelpState } from './context-help.reducer';
|
import { ContextHelpState, ContextHelpModels } from './context-help.reducer';
|
||||||
import {
|
import {
|
||||||
ContextHelpToggleIconsAction,
|
ContextHelpToggleIconsAction,
|
||||||
ContextHelpAddAction,
|
ContextHelpAddAction,
|
||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
ContextHelpToggleTooltipAction
|
ContextHelpToggleTooltipAction
|
||||||
} from './context-help.actions';
|
} from './context-help.actions';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
const contextHelpStateSelector =
|
const contextHelpStateSelector =
|
||||||
createFeatureSelector<ContextHelpState>('contextHelp');
|
createFeatureSelector<ContextHelpState>('contextHelp');
|
||||||
@@ -23,6 +24,10 @@ const contextHelpSelector =
|
|||||||
contextHelpStateSelector,
|
contextHelpStateSelector,
|
||||||
(state: ContextHelpState) => state.models[id]
|
(state: ContextHelpState) => state.models[id]
|
||||||
);
|
);
|
||||||
|
const allContextHelpSelector = createSelector(
|
||||||
|
contextHelpStateSelector,
|
||||||
|
((state: ContextHelpState) => state.models)
|
||||||
|
);
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -46,6 +51,14 @@ export class ContextHelpService {
|
|||||||
return this.store.pipe(select(contextHelpSelector(id)));
|
return this.store.pipe(select(contextHelpSelector(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observable that yields true iff there are currently no context help entries in the store.
|
||||||
|
*/
|
||||||
|
contextHelpEmpty$(): Observable<boolean> {
|
||||||
|
return this.store.pipe(select(allContextHelpSelector))
|
||||||
|
.pipe(map((models: ContextHelpModels) => Object.keys(models).length === 0));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggles the visibility of all context help icons.
|
* Toggles the visibility of all context help icons.
|
||||||
*/
|
*/
|
||||||
|
@@ -2680,6 +2680,8 @@
|
|||||||
|
|
||||||
"nav.context-help-toggle": "Toggle context help",
|
"nav.context-help-toggle": "Toggle context help",
|
||||||
|
|
||||||
|
"nav.context-help-toggle-disabled": "No context help available on this page",
|
||||||
|
|
||||||
"nav.language": "Language switch",
|
"nav.language": "Language switch",
|
||||||
|
|
||||||
"nav.login": "Log In",
|
"nav.login": "Log In",
|
||||||
|
Reference in New Issue
Block a user