Skip to content

Commit

Permalink
Merge pull request #2527 from alexandrevryghem/add-display-none-to-hi…
Browse files Browse the repository at this point in the history
…dden-navbar-buttons_contribute-7.6

Minor header button improvements
  • Loading branch information
tdonohue authored Oct 23, 2023
2 parents a9d7ee3 + fa56d5d commit 7c0fdcb
Show file tree
Hide file tree
Showing 35 changed files with 178 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { Router } from '@angular/router';
* Represents a non-expandable section in the admin sidebar
*/
@Component({
/* eslint-disable @angular-eslint/component-selector */
selector: 'li[ds-admin-sidebar-section]',
selector: 'ds-admin-sidebar-section',
templateUrl: './admin-sidebar-section.component.html',
styleUrls: ['./admin-sidebar-section.component.scss'],

Expand Down
4 changes: 2 additions & 2 deletions src/app/admin/admin-sidebar/admin-sidebar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ <h4 class="section-header-text mb-0">{{ 'menu.header.admin' | translate }}</h4>
</div>
</li>

<ng-container *ngFor="let section of (sections | async)">
<li *ngFor="let section of (sections | async)">
<ng-container
*ngComponentOutlet="(sectionMap$ | async).get(section.id).component; injector: (sectionMap$ | async).get(section.id).injector;"></ng-container>
</ng-container>
</li>
</ul>
</div>
<div class="navbar-nav">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { Router } from '@angular/router';
* Represents a expandable section in the sidebar
*/
@Component({
/* eslint-disable @angular-eslint/component-selector */
selector: 'li[ds-expandable-admin-sidebar-section]',
selector: 'ds-expandable-admin-sidebar-section',
templateUrl: './expandable-admin-sidebar-section.component.html',
styleUrls: ['./expandable-admin-sidebar-section.component.scss'],
animations: [rotate, slide, bgColor]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ElementRef } from '@angular/core';
import { ContextHelpService } from '../../shared/context-help.service';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';

/**
Expand All @@ -15,12 +15,23 @@ import { map } from 'rxjs/operators';
export class ContextHelpToggleComponent implements OnInit {
buttonVisible$: Observable<boolean>;

subscriptions: Subscription[] = [];

constructor(
private contextHelpService: ContextHelpService,
) { }
protected elRef: ElementRef,
protected contextHelpService: ContextHelpService,
) {
}

ngOnInit(): void {
this.buttonVisible$ = this.contextHelpService.tooltipCount$().pipe(map(x => x > 0));
this.subscriptions.push(this.buttonVisible$.subscribe((showContextHelpToggle: boolean) => {
if (showContextHelpToggle) {
this.elRef.nativeElement.classList.remove('d-none');
} else {
this.elRef.nativeElement.classList.add('d-none');
}
}));
}

onClick() {
Expand Down
6 changes: 3 additions & 3 deletions src/app/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

<nav role="navigation" [attr.aria-label]="'nav.user.description' | translate" class="navbar navbar-light navbar-expand-md flex-shrink-0 px-0">
<ds-themed-search-navbar></ds-themed-search-navbar>
<ds-lang-switch></ds-lang-switch>
<ds-themed-lang-switch></ds-themed-lang-switch>
<ds-context-help-toggle></ds-context-help-toggle>
<ds-themed-auth-nav-menu></ds-themed-auth-nav-menu>
<ds-impersonate-navbar></ds-impersonate-navbar>
<div class="pl-2">
<button class="navbar-toggler" type="button" (click)="toggleNavbar()"
<div *ngIf="isXsOrSm$ | async" class="pl-2">
<button class="navbar-toggler px-0" type="button" (click)="toggleNavbar()"
aria-controls="collapsingNav"
aria-expanded="false" [attr.aria-label]="'nav.toggle' | translate">
<span class="navbar-toggler-icon fas fa-bars fa-fw" aria-hidden="true"></span>
Expand Down
5 changes: 5 additions & 0 deletions src/app/header/header.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@
}
}

.navbar {
display: flex;
gap: calc(var(--bs-spacer) / 3);
align-items: center;
}
5 changes: 4 additions & 1 deletion src/app/header/header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { MenuService } from '../shared/menu/menu.service';
import { MenuServiceStub } from '../shared/testing/menu-service.stub';
import { HostWindowService } from '../shared/host-window.service';
import { HostWindowServiceStub } from '../shared/testing/host-window-service.stub';

let comp: HeaderComponent;
let fixture: ComponentFixture<HeaderComponent>;
Expand All @@ -26,6 +28,7 @@ describe('HeaderComponent', () => {
ReactiveFormsModule],
declarations: [HeaderComponent],
providers: [
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
{ provide: MenuService, useValue: menuService }
],
schemas: [NO_ERRORS_SCHEMA]
Expand All @@ -40,7 +43,7 @@ describe('HeaderComponent', () => {
fixture = TestBed.createComponent(HeaderComponent);

comp = fixture.componentInstance;

fixture.detectChanges();
});

describe('when the toggle button is clicked', () => {
Expand Down
14 changes: 10 additions & 4 deletions src/app/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { MenuService } from '../shared/menu/menu.service';
import { MenuID } from '../shared/menu/menu-id.model';
import { HostWindowService } from '../shared/host-window.service';

/**
* Represents the header with the logo and simple navigation
Expand All @@ -11,20 +12,25 @@ import { MenuID } from '../shared/menu/menu-id.model';
styleUrls: ['header.component.scss'],
templateUrl: 'header.component.html',
})
export class HeaderComponent {
export class HeaderComponent implements OnInit {
/**
* Whether user is authenticated.
* @type {Observable<string>}
*/
public isAuthenticated: Observable<boolean>;
public showAuth = false;
public isXsOrSm$: Observable<boolean>;
menuID = MenuID.PUBLIC;

constructor(
private menuService: MenuService
protected menuService: MenuService,
protected windowService: HostWindowService,
) {
}

ngOnInit(): void {
this.isXsOrSm$ = this.windowService.isXsOrSm();
}

public toggleNavbar(): void {
this.menuService.toggleMenu(this.menuID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
</a>
<ul @slide *ngIf="(active | async)" (click)="deactivateSection($event)"
class="m-0 shadow-none border-top-0 dropdown-menu show">
<ng-container *ngFor="let subSection of (subSections$ | async)">
<li *ngFor="let subSection of (subSections$ | async)">
<ng-container
*ngComponentOutlet="(sectionMap$ | async).get(subSection.id).component; injector: (sectionMap$ | async).get(subSection.id).injector;"></ng-container>
</ng-container>
</li>
</ul>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { MenuService } from '../../shared/menu/menu.service';
import { slide } from '../../shared/animations/slide';
import { first } from 'rxjs/operators';
import { HostWindowService } from '../../shared/host-window.service';
import { rendersSectionForMenu } from '../../shared/menu/menu-section.decorator';
import { MenuID } from '../../shared/menu/menu-id.model';

/**
Expand All @@ -16,7 +15,6 @@ import { MenuID } from '../../shared/menu/menu-id.model';
styleUrls: ['./expandable-navbar-section.component.scss'],
animations: [slide]
})
@rendersSectionForMenu(MenuID.PUBLIC, true)
export class ExpandableNavbarSectionComponent extends NavbarSectionComponent implements OnInit {
/**
* This section resides in the Public Navbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { MenuID } from '../../shared/menu/menu-id.model';
* Themed wrapper for ExpandableNavbarSectionComponent
*/
@Component({
/* eslint-disable @angular-eslint/component-selector */
selector: 'li[ds-themed-expandable-navbar-section]',
selector: 'ds-themed-expandable-navbar-section',
styleUrls: [],
templateUrl: '../../shared/theme-support/themed.component.html',
})
Expand Down
3 changes: 1 addition & 2 deletions src/app/navbar/navbar-section/navbar-section.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { MenuID } from '../../shared/menu/menu-id.model';
* Represents a non-expandable section in the navbar
*/
@Component({
/* eslint-disable @angular-eslint/component-selector */
selector: 'li[ds-navbar-section]',
selector: 'ds-navbar-section',
templateUrl: './navbar-section.component.html',
styleUrls: ['./navbar-section.component.scss']
})
Expand Down
4 changes: 2 additions & 2 deletions src/app/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<li *ngIf="(isXsOrSm$ | async) && (isAuthenticated$ | async)">
<ds-user-menu [inExpandableNavbar]="true"></ds-user-menu>
</li>
<ng-container *ngFor="let section of (sections | async)">
<li *ngFor="let section of (sections | async)">
<ng-container *ngComponentOutlet="(sectionMap$ | async).get(section.id)?.component; injector: (sectionMap$ | async).get(section.id)?.injector;"></ng-container>
</ng-container>
</li>
</ul>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/app/search-navbar/search-navbar.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<div id="search-navbar-container" [title]="'nav.search' | translate" (dsClickOutside)="collapse()">
<div class="d-inline-block position-relative">
<form [formGroup]="searchForm" (ngSubmit)="onSubmit(searchForm.value)" autocomplete="on">
<form [formGroup]="searchForm" (ngSubmit)="onSubmit(searchForm.value)" autocomplete="on" class="d-flex">
<input #searchInput [@toggleAnimation]="isExpanded" [attr.aria-label]="('nav.search' | translate)" name="query"
formControlName="query" type="text" placeholder="{{searchExpanded ? ('nav.search' | translate) : ''}}"
class="d-inline-block bg-transparent position-absolute form-control dropdown-menu-right p-1" [attr.data-test]="'header-search-box' | dsBrowserOnly">
class="bg-transparent position-absolute form-control dropdown-menu-right pl-1 pr-4"
[class.display]="searchExpanded ? 'inline-block' : 'none'"
[tabIndex]="searchExpanded ? 0 : -1"
[attr.data-test]="'header-search-box' | dsBrowserOnly">
<button class="submit-icon btn btn-link btn-link-inline" [attr.aria-label]="'nav.search.button' | translate" type="button" (click)="searchExpanded ? onSubmit(searchForm.value) : expand()" [attr.data-test]="'header-search-icon' | dsBrowserOnly">
<em class="fas fa-search fa-lg fa-fw"></em>
</button>
Expand Down
1 change: 1 addition & 0 deletions src/app/search-navbar/search-navbar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ input[type="text"] {
cursor: pointer;
position: sticky;
top: 0;
border: 0 !important;

color: var(--ds-header-icon-color);
&:hover, &:focus {
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/animations/slide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const slideSidebarPadding = trigger('slideSidebarPadding', [

export const expandSearchInput = trigger('toggleAnimation', [
state('collapsed', style({
width: '30px',
width: '0',
opacity: '0'
})),
state('expanded', style({
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/auth-nav-menu/auth-nav-menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<li *ngIf="!(isAuthenticated | async) && !(isXsOrSm$ | async) && (showAuth | async)" class="nav-item"
(click)="$event.stopPropagation();">
<div ngbDropdown #loginDrop display="dynamic" placement="bottom-right" class="d-inline-block" @fadeInOut>
<a href="javascript:void(0);" class="dropdownLogin px-1" [attr.aria-label]="'nav.login' |translate"
<a href="javascript:void(0);" class="dropdownLogin px-0.5" [attr.aria-label]="'nav.login' |translate"
(click)="$event.preventDefault()" [attr.data-test]="'login-menu' | dsBrowserOnly"
ngbDropdownToggle>{{ 'nav.login' | translate }}</a>
<div class="loginDropdownMenu" [ngClass]="{'pl-3 pr-3': (loading | async)}" ngbDropdownMenu
Expand All @@ -13,7 +13,7 @@
</div>
</li>
<li *ngIf="!(isAuthenticated | async) && (isXsOrSm$ | async)" class="nav-item">
<a routerLink="/login" routerLinkActive="active" class="loginLink px-1">
<a routerLink="/login" routerLinkActive="active" class="loginLink px-0.5">
{{ 'nav.login' | translate }}<span class="sr-only">(current)</span>
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { hasValue } from '../../../empty.util';
* Represents an expandable section in the dso edit menus
*/
@Component({
/* tslint:disable:component-selector */
selector: 'ds-dso-edit-menu-expandable-section',
templateUrl: './dso-edit-menu-expandable-section.component.html',
styleUrls: ['./dso-edit-menu-expandable-section.component.scss'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { MenuSection } from '../../../menu/menu-section.model';
* Represents a non-expandable section in the dso edit menus
*/
@Component({
/* tslint:disable:component-selector */
selector: 'ds-dso-edit-menu-section',
templateUrl: './dso-edit-menu-section.component.html',
styleUrls: ['./dso-edit-menu-section.component.scss']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul class="navbar-nav" *ngIf="(isAuthenticated$ | async) && isImpersonating">
<ul class="navbar-nav" *ngIf="isImpersonating$ | async">
<li class="nav-item">
<button class="btn btn-sm btn-dark" ngbTooltip="{{'nav.stop-impersonating' | translate}}" (click)="stopImpersonating()">
<i class="fa fa-user-secret"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { authReducer } from '../../core/auth/auth.reducer';
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
import { EPersonMock } from '../testing/eperson.mock';
import { AppState, storeModuleConfig } from '../../app.reducer';
import { of as observableOf } from 'rxjs';

describe('ImpersonateNavbarComponent', () => {
let component: ImpersonateNavbarComponent;
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('ImpersonateNavbarComponent', () => {

describe('when the user is impersonating another user', () => {
beforeEach(() => {
component.isImpersonating = true;
component.isImpersonating$ = observableOf(true);
fixture.detectChanges();
});

Expand Down
33 changes: 21 additions & 12 deletions src/app/shared/impersonate-navbar/impersonate-navbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ElementRef } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { AppState } from '../../app.reducer';
import { AuthService } from '../../core/auth/auth.service';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { isAuthenticated } from '../../core/auth/selectors';

@Component({
Expand All @@ -13,24 +14,32 @@ import { isAuthenticated } from '../../core/auth/selectors';
* Navbar component for actions to take concerning impersonating users
*/
export class ImpersonateNavbarComponent implements OnInit {
/**
* Whether or not the user is authenticated.
* @type {Observable<string>}
*/
isAuthenticated$: Observable<boolean>;

/**
* Is the user currently impersonating another user?
*/
isImpersonating: boolean;
isImpersonating$: Observable<boolean>;

subscriptions: Subscription[] = [];

constructor(private store: Store<AppState>,
private authService: AuthService) {
constructor(
protected elRef: ElementRef,
protected store: Store<AppState>,
protected authService: AuthService,
) {
}

ngOnInit(): void {
this.isAuthenticated$ = this.store.pipe(select(isAuthenticated));
this.isImpersonating = this.authService.isImpersonating();
this.isImpersonating$ = this.store.pipe(select(isAuthenticated)).pipe(
map((isUserAuthenticated: boolean) => isUserAuthenticated && this.authService.isImpersonating()),
);
this.subscriptions.push(this.isImpersonating$.subscribe((isImpersonating: boolean) => {
if (isImpersonating) {
this.elRef.nativeElement.classList.remove('d-none');
} else {
this.elRef.nativeElement.classList.add('d-none');
}
}));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/lang-switch/lang-switch.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div ngbDropdown class="navbar-nav" *ngIf="moreThanOneLanguage" display="dynamic" placement="bottom-right">
<a href="javascript:void(0);" role="button"
[attr.aria-label]="'nav.language' |translate"
[title]="'nav.language' | translate" class="px-1"
[title]="'nav.language' | translate"
(click)="$event.preventDefault()" data-toggle="dropdown" ngbDropdownToggle
tabindex="0">
<i class="fas fa-globe-asia fa-lg fa-fw"></i>
Expand Down
8 changes: 5 additions & 3 deletions src/app/shared/lang-switch/lang-switch.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Component, OnInit } from '@angular/core';

import { Component, OnInit, ElementRef } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

import { LangConfig } from '../../../config/lang-config.interface';
import { environment } from '../../../environments/environment';
import { LocaleService } from '../../core/locale/locale.service';
Expand All @@ -25,6 +23,7 @@ export class LangSwitchComponent implements OnInit {
moreThanOneLanguage: boolean;

constructor(
public el: ElementRef,
public translate: TranslateService,
private localeService: LocaleService
) {
Expand All @@ -33,6 +32,9 @@ export class LangSwitchComponent implements OnInit {
ngOnInit(): void {
this.activeLangs = environment.languages.filter((MyLangConfig) => MyLangConfig.active === true);
this.moreThanOneLanguage = (this.activeLangs.length > 1);
if (!this.moreThanOneLanguage) {
this.el.nativeElement.parentElement.classList.add('d-none');
}
}

/**
Expand Down
Loading

0 comments on commit 7c0fdcb

Please sign in to comment.