Skip to content

Commit 8dba15c

Browse files
Sufiyan Shaikhatarix83
authored andcommitted
Merged in DSC-472 (pull request DSpace#141)
DSC-472 Approved-by: Giuseppe Digilio
2 parents 4e345a9 + 87c9d46 commit 8dba15c

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

src/app/shared/context-menu/context-menu.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<ng-container *ngFor="let entry of (getStandAloneMenuEntries() | async)">
33
<ng-container *ngComponentOutlet="entry; injector: objectInjector;"></ng-container>
44
</ng-container>
5-
<div ngbDropdown #itemOptions="ngbDropdown" placement="bottom-right" class="d-inline-block float-right ml-1">
5+
<div ngbDropdown #itemOptions="ngbDropdown" placement="bottom-right"
6+
class="float-right ml-1" [ngClass]="optionCount === 0 ? 'd-none' : 'd-inline-block'">
67
<button class="btn btn-outline-primary" id="context-menu" ngbDropdownToggle>
78
<i class="fas fa-ellipsis-h" aria-hidden="true"></i>
89
</button>

src/app/shared/context-menu/context-menu.component.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ describe('ContextMenuComponent', () => {
146146
done();
147147
});
148148

149+
it('should display d-none', (done) => {
150+
const menu = fixture.debugElement.query(By.css('div.d-none'));
151+
expect(menu).not.toBeNull();
152+
done();
153+
});
154+
155+
it('should not display d-inline-block', (done) => {
156+
const menu = fixture.debugElement.query(By.css('div.d-inline-block'));
157+
expect(menu).toBeNull();
158+
done();
159+
});
160+
149161
it('should display stand alone buttons', (done) => {
150162
const menu = fixture.debugElement.query(By.css('button.btn-primary'));
151163
expect(menu).not.toBeNull();
@@ -203,6 +215,18 @@ describe('ContextMenuComponent', () => {
203215
done();
204216
});
205217

218+
it('should display d-none', (done) => {
219+
const menu = fixture.debugElement.query(By.css('div.d-none'));
220+
expect(menu).not.toBeNull();
221+
done();
222+
});
223+
224+
it('should not display d-inline-block', (done) => {
225+
const menu = fixture.debugElement.query(By.css('div.d-inline-block'));
226+
expect(menu).toBeNull();
227+
done();
228+
});
229+
206230
it('should not display stand alone buttons', (done) => {
207231
const menu = fixture.debugElement.query(By.css('button.btn-primary'));
208232
expect(menu).not.toBeNull();
@@ -232,6 +256,18 @@ describe('ContextMenuComponent', () => {
232256
done();
233257
});
234258

259+
it('should display d-inline-block', (done) => {
260+
const menu = fixture.debugElement.query(By.css('div.d-inline-block'));
261+
expect(menu).toBeNull();
262+
done();
263+
});
264+
265+
it('should not display d-none', (done) => {
266+
const menu = fixture.debugElement.query(By.css('div.d-none'));
267+
expect(menu).toBeNull();
268+
done();
269+
});
270+
235271
it('should check the authorization of the current user', (done) => {
236272
expect(component.isAuthenticated).toBeObservable(cold('a', { a: false }));
237273
done();

src/app/shared/context-menu/context-menu.component.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Injector, Input, OnInit } from '@angular/core';
1+
import { Component, Inject, Injector, Input, OnInit } from '@angular/core';
22

33
import { select, Store } from '@ngrx/store';
44
import { from, Observable } from 'rxjs';
@@ -17,6 +17,7 @@ import { ContextMenuEntryType } from './context-menu-entry-type';
1717
import { isNotEmpty } from '../empty.util';
1818
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
1919
import { GenericConstructor } from '../../core/shared/generic-constructor';
20+
import { DOCUMENT } from '@angular/common';
2021

2122
/**
2223
* This component renders a context menu for a given DSO.
@@ -50,14 +51,22 @@ export class ContextMenuComponent implements OnInit {
5051
*/
5152
public objectInjector: Injector;
5253

54+
/**
55+
* context menu options count.
56+
* @type {number}
57+
*/
58+
public optionCount = 0;
59+
5360
/**
5461
* Initialize instance variables
5562
*
63+
* @param {Document} _document
5664
* @param {ConfigurationDataService} configurationService
5765
* @param {Injector} injector
5866
* @param {Store<CoreState>} store
5967
*/
6068
constructor(
69+
@Inject(DOCUMENT) private _document: Document,
6170
private configurationService: ConfigurationDataService,
6271
private injector: Injector,
6372
private store: Store<CoreState>
@@ -124,4 +133,17 @@ export class ContextMenuComponent implements OnInit {
124133
isItem(): boolean {
125134
return this.contextMenuObjectType === DSpaceObjectType.ITEM;
126135
}
136+
137+
ngAfterViewChecked() {
138+
// To check that Context-menu contains options or not
139+
if (this._document.getElementById('itemOptionsDropdownMenu')) {
140+
const el = Array.from(this._document.getElementById('itemOptionsDropdownMenu')?.getElementsByClassName('ng-star-inserted'));
141+
this.optionCount = 0;
142+
if (el) {
143+
el.forEach(element => {
144+
this.optionCount += element.childElementCount;
145+
});
146+
}
147+
}
148+
}
127149
}

0 commit comments

Comments
 (0)