Skip to content

Commit d8429f7

Browse files
nikunj59atarix83
authored andcommitted
Merged in DSC-673 (pull request DSpace#263)
DSC-673 changes for Context menu should not display "view item full" when already in same view Approved-by: Giuseppe Digilio
2 parents bedcb85 + 16b8dc2 commit d8429f7

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<button class="dropdown-item" [routerLink]="getItemFullPageRoute(contextMenuObject)"
1+
<button *ngIf="!isSameView(contextMenuObject)" class="dropdown-item" [routerLink]="getItemFullPageRoute(contextMenuObject)"
22
[innerHTML]="'context-menu.actions.show-all-metadata' | translate">
33
</button>

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { TranslateLoaderMock } from '../../mocks/translate-loader.mock';
99
import { Item } from '../../../core/shared/item.model';
1010
import { FullItemMenuComponent } from './full-item-menu.component';
1111
import { AuthService } from '../../../core/auth/auth.service';
12+
import { Router } from '@angular/router';
1213
import { By } from '@angular/platform-browser';
1314

1415
describe('FullItemMenuComponent', () => {
@@ -17,6 +18,7 @@ describe('FullItemMenuComponent', () => {
1718
let fixture: ComponentFixture<FullItemMenuComponent>;
1819
let scheduler: TestScheduler;
1920
let dso: DSpaceObject;
21+
let router: Router;
2022

2123
const authServiceStub = jasmine.createSpyObj('authorizationService', {
2224
getAuthenticatedUserFromStore: jasmine.createSpy('getAuthenticatedUserFromStore'),
@@ -25,9 +27,21 @@ describe('FullItemMenuComponent', () => {
2527

2628
beforeEach(waitForAsync(() => {
2729
dso = Object.assign(new Item(), {
28-
id: 'test-item',
29-
_links: {
30-
self: { href: 'test-item-selflink' }
30+
'entityType': 'Publication',
31+
'id': '12345',
32+
'uuid': '12345',
33+
'type': 'item',
34+
'metadata': {
35+
'dspace.entity.type': [
36+
{
37+
'uuid': '1234567890',
38+
'language': null,
39+
'value': 'Publication',
40+
'place': 0,
41+
'authority': null,
42+
'confidence': -1
43+
}
44+
]
3145
}
3246
});
3347

@@ -48,6 +62,7 @@ describe('FullItemMenuComponent', () => {
4862
{ provide: AuthService, useValue: authServiceStub },
4963
]
5064
}).compileComponents();
65+
router = TestBed.inject(Router);
5166
}));
5267

5368
beforeEach(() => {
@@ -63,8 +78,16 @@ describe('FullItemMenuComponent', () => {
6378
});
6479

6580
it('should render a button', () => {
81+
fixture.detectChanges();
6682
const link = fixture.debugElement.query(By.css('button'));
6783
expect(link).not.toBeNull();
6884
});
6985

86+
it('should not render a button', () => {
87+
spyOnProperty(router, 'url', 'get').and.returnValue('/entities/publication/12345/full');
88+
fixture.detectChanges();
89+
const link = fixture.debugElement.query(By.css('button'));
90+
expect(link).toBeNull();
91+
});
92+
7093
});

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ContextMenuEntryComponent } from '../context-menu-entry.component';
77
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
88
import { ContextMenuEntryType } from '../context-menu-entry-type';
99
import { Item } from '../../../core/shared/item.model';
10+
import { Router } from '@angular/router';
1011

1112
/**
1213
* This component renders a context menu option that provides to export an item.
@@ -21,6 +22,7 @@ export class FullItemMenuComponent extends ContextMenuEntryComponent {
2122
constructor(
2223
@Inject('contextMenuObjectProvider') protected injectedContextMenuObject: DSpaceObject,
2324
@Inject('contextMenuObjectTypeProvider') protected injectedContextMenuObjectType: DSpaceObjectType,
25+
private router: Router
2426
) {
2527
super(injectedContextMenuObject, injectedContextMenuObjectType, ContextMenuEntryType.FullItem);
2628
}
@@ -29,4 +31,8 @@ export class FullItemMenuComponent extends ContextMenuEntryComponent {
2931
return getItemFullPageRoute(object as Item);
3032
}
3133

34+
isSameView(object: DSpaceObject): boolean {
35+
return this.router.url === getItemFullPageRoute(object as Item);
36+
}
37+
3238
}

0 commit comments

Comments
 (0)