Merge branch 'w2p-94390_replace-dso-page-edit-buttons-with-a-menu_7.2' into w2p-94390_replace-dso-page-edit-buttons-with-a-menu

This commit is contained in:
Yury Bondarenko
2022-09-28 18:50:06 +02:00
7 changed files with 43 additions and 16 deletions

View File

@@ -7,7 +7,7 @@
[attr.aria-labelledby]="'sidebarName-' + section.id" [attr.aria-labelledby]="'sidebarName-' + section.id"
[attr.aria-expanded]="expanded | async" [attr.aria-expanded]="expanded | async"
[title]="('menu.section.icon.' + section.id) | translate" [title]="('menu.section.icon.' + section.id) | translate"
[class.disabled]="section.model.disabled" [class.disabled]="section.model?.disabled"
(click)="toggleSection($event)" (click)="toggleSection($event)"
(keyup.space)="toggleSection($event)" (keyup.space)="toggleSection($event)"
(keyup.enter)="toggleSection($event)" (keyup.enter)="toggleSection($event)"

View File

@@ -16,6 +16,8 @@ import { Item } from '../../core/shared/item.model';
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../remote-data.utils'; import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
import { MenuID } from '../menu/menu-id.model'; import { MenuID } from '../menu/menu-id.model';
import { MenuItemType } from '../menu/menu-item-type.model'; import { MenuItemType } from '../menu/menu-item-type.model';
import { TextMenuItemModel } from '../menu/menu-item/models/text.model';
import { LinkMenuItemModel } from '../menu/menu-item/models/link.model';
describe('DSOEditMenuResolver', () => { describe('DSOEditMenuResolver', () => {
@@ -165,7 +167,7 @@ describe('DSOEditMenuResolver', () => {
expect(menuList[0].active).toEqual(false); expect(menuList[0].active).toEqual(false);
expect(menuList[0].visible).toEqual(true); expect(menuList[0].visible).toEqual(true);
expect(menuList[0].model.type).toEqual(MenuItemType.ONCLICK); expect(menuList[0].model.type).toEqual(MenuItemType.ONCLICK);
expect(menuList[0].model.text).toEqual('message'); expect((menuList[0].model as TextMenuItemModel).text).toEqual('message');
expect(menuList[0].model.disabled).toEqual(false); expect(menuList[0].model.disabled).toEqual(false);
expect(menuList[0].icon).toEqual('code-branch'); expect(menuList[0].icon).toEqual('code-branch');
done(); done();
@@ -180,8 +182,8 @@ describe('DSOEditMenuResolver', () => {
expect(menuList[0].active).toEqual(false); expect(menuList[0].active).toEqual(false);
expect(menuList[0].visible).toEqual(true); expect(menuList[0].visible).toEqual(true);
expect(menuList[0].model.type).toEqual(MenuItemType.LINK); expect(menuList[0].model.type).toEqual(MenuItemType.LINK);
expect(menuList[0].model.text).toEqual('item.page.edit'); expect((menuList[0].model as LinkMenuItemModel).text).toEqual('item.page.edit');
expect(menuList[0].model.link).toEqual('test-url/edit/metadata'); expect((menuList[0].model as LinkMenuItemModel).link).toEqual('test-url/edit/metadata');
expect(menuList[0].icon).toEqual('pencil-alt'); expect(menuList[0].icon).toEqual('pencil-alt');
done(); done();
}); });

View File

@@ -1,5 +1,5 @@
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router'; import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { combineLatest, Observable, of as observableOf } from 'rxjs'; import { combineLatest, Observable, of, of as observableOf } from 'rxjs';
import { FeatureID } from '../../core/data/feature-authorization/feature-id'; import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { MenuService } from '../menu/menu.service'; import { MenuService } from '../menu/menu.service';
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service'; import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
@@ -17,6 +17,7 @@ import { hasValue } from '../empty.util';
import { MenuID } from '../menu/menu-id.model'; import { MenuID } from '../menu/menu-id.model';
import { MenuItemType } from '../menu/menu-item-type.model'; import { MenuItemType } from '../menu/menu-item-type.model';
import { MenuSection } from '../menu/menu-section.model'; import { MenuSection } from '../menu/menu-section.model';
import { TextMenuItemModel } from '../menu/menu-item/models/text.model';
/** /**
* Creates the menus for the dspace object pages * Creates the menus for the dspace object pages
@@ -66,7 +67,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
/** /**
* Return all the menus for a dso based on the route and state * Return all the menus for a dso based on the route and state
*/ */
getDsoMenus(dso, route, state) { getDsoMenus(dso, route, state): Observable<MenuSection[]>[] {
return [ return [
this.getItemMenu(dso), this.getItemMenu(dso),
this.getCommonMenu(dso, state) this.getCommonMenu(dso, state)
@@ -76,7 +77,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
/** /**
* Get the common menus between all dspace objects * Get the common menus between all dspace objects
*/ */
protected getCommonMenu(dso, state): Observable<any[]> { protected getCommonMenu(dso, state): Observable<MenuSection[]> {
return combineLatest([ return combineLatest([
this.authorizationService.isAuthorized(FeatureID.CanEditMetadata, dso.self), this.authorizationService.isAuthorized(FeatureID.CanEditMetadata, dso.self),
]).pipe( ]).pipe(
@@ -95,7 +96,6 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
index: 1 index: 1
}, },
]; ];
}) })
); );
} }
@@ -103,7 +103,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
/** /**
* Get item sepcific menus * Get item sepcific menus
*/ */
protected getItemMenu(dso): Observable<any[]> { protected getItemMenu(dso): Observable<MenuSection[]> {
if (dso instanceof Item) { if (dso instanceof Item) {
return combineLatest([ return combineLatest([
this.authorizationService.isAuthorized(FeatureID.CanCreateVersion, dso.self), this.authorizationService.isAuthorized(FeatureID.CanCreateVersion, dso.self),

View File

@@ -1,14 +1,19 @@
<div class="dso-button-menu mb-1" ngbDropdown placement="bottom-right"> <div class="dso-button-menu mb-1" ngbDropdown container="body" placement="bottom-right">
<div class="d-flex flex-row flex-nowrap" <div class="d-flex flex-row flex-nowrap"
[ngbTooltip]="itemModel.text | translate"> [ngbTooltip]="itemModel.text | translate">
<button class="btn btn-dark btn-sm" ngbDropdownToggle [disabled]="section.model.disabled"> <button class="btn btn-dark btn-sm" ngbDropdownToggle [disabled]="section.model?.disabled">
<i class="fas fa-{{section.icon}} fa-fw"></i> <i class="fas fa-{{section.icon}} fa-fw"></i>
</button> </button>
<ul ngbDropdownMenu> <ul ngbDropdownMenu class="dso-edit-menu-dropdown">
<ng-container *ngFor="let subSection of (subSections$ | async)"> <li class="nav-item nav-link d-flex flex-row" *ngFor="let subSection of (subSections$ | async)">
<div *ngIf="renderIcons$ | async" class="mr-2">
<i *ngIf="subSection.icon; else spacer" class="fas fa-{{subSection.icon}} fa-fw"></i>
<ng-template #spacer><i class="fas fa-fw"></i></ng-template>
</div>
<ng-container <ng-container
*ngComponentOutlet="(sectionMap$ | async).get(subSection.id).component; injector: (sectionMap$ | async).get(subSection.id).injector;"></ng-container> *ngComponentOutlet="(sectionMap$ | async).get(subSection.id).component; injector: (sectionMap$ | async).get(subSection.id).injector;">
</ng-container> </ng-container>
</li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@@ -24,3 +24,7 @@ ul.dropdown-menu {
color: var(--bs-btn-link-disabled-color); color: var(--bs-btn-link-disabled-color);
} }
} }
.dso-edit-menu-dropdown {
max-width: calc(min(600px, 75vw));
}

View File

@@ -5,6 +5,9 @@ import { MenuService } from '../../../menu/menu.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { MenuID } from 'src/app/shared/menu/menu-id.model'; import { MenuID } from 'src/app/shared/menu/menu-id.model';
import { MenuSection } from 'src/app/shared/menu/menu-section.model'; import { MenuSection } from 'src/app/shared/menu/menu-section.model';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { hasValue } from '../../../empty.util';
/** /**
* Represents an expandable section in the dso edit menus * Represents an expandable section in the dso edit menus
@@ -21,6 +24,8 @@ export class DsoEditMenuExpandableSectionComponent extends MenuSectionComponent
menuID: MenuID = MenuID.DSO_EDIT; menuID: MenuID = MenuID.DSO_EDIT;
itemModel; itemModel;
renderIcons$: Observable<boolean>;
constructor( constructor(
@Inject('sectionDataProvider') menuSection: MenuSection, @Inject('sectionDataProvider') menuSection: MenuSection,
protected menuService: MenuService, protected menuService: MenuService,
@@ -34,6 +39,11 @@ export class DsoEditMenuExpandableSectionComponent extends MenuSectionComponent
ngOnInit(): void { ngOnInit(): void {
this.menuService.activateSection(this.menuID, this.section.id); this.menuService.activateSection(this.menuID, this.section.id);
super.ngOnInit(); super.ngOnInit();
}
this.renderIcons$ = this.subSections$.pipe(
map((sections: MenuSection[]) => {
return sections.some(section => hasValue(section.icon));
}),
);
}
} }

View File

@@ -186,3 +186,9 @@ ds-dynamic-form-control-container.d-none {
padding: 0.5rem; padding: 0.5rem;
} }
} }
ul.dso-edit-menu-dropdown > li .nav-item.nav-link {
// ensure that links in DSO edit menu dropdowns are unstyled (li elements are styled instead to support icons)
padding: 0;
display: inline;
}