mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Move subscription button to DSO edit menu
(cherry picked from commit c9558167b2
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
506579cd23
commit
578a427f46
@@ -34,9 +34,6 @@
|
||||
</ds-comcol-page-content>
|
||||
</header>
|
||||
<ds-dso-edit-menu></ds-dso-edit-menu>
|
||||
<div class="pl-2 space-children-mr">
|
||||
<ds-dso-page-subscription-button [dso]="collection"></ds-dso-page-subscription-button>
|
||||
</div>
|
||||
</div>
|
||||
<section class="comcol-page-browse-section">
|
||||
<!-- Browse-By Links -->
|
||||
|
@@ -21,9 +21,6 @@
|
||||
</ds-comcol-page-content>
|
||||
</header>
|
||||
<ds-dso-edit-menu></ds-dso-edit-menu>
|
||||
<div class="pl-2 space-children-mr">
|
||||
<ds-dso-page-subscription-button [dso]="communityPayload"></ds-dso-page-subscription-button>
|
||||
</div>
|
||||
</div>
|
||||
<section class="comcol-page-browse-section">
|
||||
|
||||
|
@@ -21,6 +21,9 @@ import { getDSORoute } from '../../app-routing-paths';
|
||||
import { ResearcherProfileDataService } from '../../core/profile/researcher-profile-data.service';
|
||||
import { NotificationsService } from '../notifications/notifications.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { SubscriptionModalComponent } from '../subscriptions/subscription-modal/subscription-modal.component';
|
||||
import { Community } from '../../core/shared/community.model';
|
||||
import { Collection } from '../../core/shared/collection.model';
|
||||
|
||||
/**
|
||||
* Creates the menus for the dspace object pages
|
||||
@@ -84,6 +87,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
|
||||
getDsoMenus(dso, route, state): Observable<MenuSection[]>[] {
|
||||
return [
|
||||
this.getItemMenu(dso),
|
||||
this.getComColMenu(dso),
|
||||
this.getCommonMenu(dso, state)
|
||||
];
|
||||
}
|
||||
@@ -178,6 +182,39 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Community/Collection-specific menus
|
||||
*/
|
||||
protected getComColMenu(dso): Observable<MenuSection[]> {
|
||||
if (dso instanceof Community || dso instanceof Collection) {
|
||||
return combineLatest([
|
||||
this.authorizationService.isAuthorized(FeatureID.CanSubscribe, dso.self),
|
||||
]).pipe(
|
||||
map(([canSubscribe]) => {
|
||||
return [
|
||||
{
|
||||
id: 'subscribe',
|
||||
active: false,
|
||||
visible: canSubscribe,
|
||||
model: {
|
||||
type: MenuItemType.ONCLICK,
|
||||
text: 'subscriptions.tooltip',
|
||||
function: () => {
|
||||
const modalRef = this.modalService.open(SubscriptionModalComponent);
|
||||
modalRef.componentInstance.dso = dso;
|
||||
}
|
||||
} as OnClickMenuItemModel,
|
||||
icon: 'bell',
|
||||
index: 4
|
||||
},
|
||||
];
|
||||
})
|
||||
);
|
||||
} else {
|
||||
return observableOf([]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim a researcher by creating a profile
|
||||
* Shows notifications and/or hides the menu section on success/error
|
||||
|
@@ -1,8 +0,0 @@
|
||||
<button *ngIf="isAuthorized$ | async" data-test="subscription-button"
|
||||
(click)="openSubscriptionModal()"
|
||||
[ngbTooltip]="'subscriptions.tooltip' | translate"
|
||||
[title]="'subscriptions.tooltip' | translate"
|
||||
[attr.aria-label]="'subscriptions.tooltip' | translate"
|
||||
class="subscription-button btn btn-dark btn-sm">
|
||||
<i class="fas fa-bell fa-fw"></i>
|
||||
</button>
|
@@ -1,83 +0,0 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DsoPageSubscriptionButtonComponent } from './dso-page-subscription-button.component';
|
||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { ITEM } from '../../../core/shared/item.resource-type';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { TranslateLoaderMock } from '../../mocks/translate-loader.mock';
|
||||
|
||||
describe('DsoPageSubscriptionButtonComponent', () => {
|
||||
let component: DsoPageSubscriptionButtonComponent;
|
||||
let fixture: ComponentFixture<DsoPageSubscriptionButtonComponent>;
|
||||
let de: DebugElement;
|
||||
|
||||
const authorizationService = jasmine.createSpyObj('authorizationService', {
|
||||
isAuthorized: jasmine.createSpy('isAuthorized') // observableOf(true)
|
||||
});
|
||||
|
||||
const mockItem = Object.assign(new Item(), {
|
||||
id: 'fake-id',
|
||||
uuid: 'fake-id',
|
||||
handle: 'fake/handle',
|
||||
lastModified: '2018',
|
||||
type: ITEM,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://localhost:8000/items/fake-id'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [
|
||||
NgbModalModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useClass: TranslateLoaderMock
|
||||
}
|
||||
})
|
||||
],
|
||||
declarations: [ DsoPageSubscriptionButtonComponent ],
|
||||
providers: [
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DsoPageSubscriptionButtonComponent);
|
||||
component = fixture.componentInstance;
|
||||
de = fixture.debugElement;
|
||||
component.dso = mockItem;
|
||||
});
|
||||
|
||||
describe('when is authorized', () => {
|
||||
beforeEach(() => {
|
||||
authorizationService.isAuthorized.and.returnValue(observableOf(true));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should display subscription button', () => {
|
||||
expect(de.query(By.css(' [data-test="subscription-button"]'))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when is not authorized', () => {
|
||||
beforeEach(() => {
|
||||
authorizationService.isAuthorized.and.returnValue(observableOf(false));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should not display subscription button', () => {
|
||||
expect(de.query(By.css(' [data-test="subscription-button"]'))).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,57 +0,0 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||
import { SubscriptionModalComponent } from '../../subscriptions/subscription-modal/subscription-modal.component';
|
||||
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-dso-page-subscription-button',
|
||||
templateUrl: './dso-page-subscription-button.component.html',
|
||||
styleUrls: ['./dso-page-subscription-button.component.scss']
|
||||
})
|
||||
/**
|
||||
* Display a button that opens the modal to manage subscriptions
|
||||
*/
|
||||
export class DsoPageSubscriptionButtonComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* Whether the current user is authorized to edit the DSpaceObject
|
||||
*/
|
||||
isAuthorized$: Observable<boolean> = of(false);
|
||||
|
||||
/**
|
||||
* Reference to NgbModal
|
||||
*/
|
||||
public modalRef: NgbModalRef;
|
||||
|
||||
/**
|
||||
* DSpaceObject that is being viewed
|
||||
*/
|
||||
@Input() dso: DSpaceObject;
|
||||
|
||||
constructor(
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
private modalService: NgbModal,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the current DSpaceObject can be subscribed by the user
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.isAuthorized$ = this.authorizationService.isAuthorized(FeatureID.CanSubscribe, this.dso.self);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the modal to subscribe to the related DSpaceObject
|
||||
*/
|
||||
public openSubscriptionModal() {
|
||||
this.modalRef = this.modalService.open(SubscriptionModalComponent);
|
||||
this.modalRef.componentInstance.dso = this.dso;
|
||||
}
|
||||
|
||||
}
|
@@ -273,9 +273,6 @@ import {
|
||||
AdvancedClaimedTaskActionRatingComponent
|
||||
} from './mydspace-actions/claimed-task/rating/advanced-claimed-task-action-rating.component';
|
||||
import { ClaimedTaskActionsDeclineTaskComponent } from './mydspace-actions/claimed-task/decline-task/claimed-task-actions-decline-task.component';
|
||||
import {
|
||||
DsoPageSubscriptionButtonComponent
|
||||
} from './dso-page/dso-page-subscription-button/dso-page-subscription-button.component';
|
||||
import { EpersonGroupListComponent } from './eperson-group-list/eperson-group-list.component';
|
||||
import { EpersonSearchBoxComponent } from './eperson-group-list/eperson-search-box/eperson-search-box.component';
|
||||
import { GroupSearchBoxComponent } from './eperson-group-list/group-search-box/group-search-box.component';
|
||||
@@ -395,7 +392,6 @@ const COMPONENTS = [
|
||||
ItemPageTitleFieldComponent,
|
||||
ThemedSearchNavbarComponent,
|
||||
ListableNotificationObjectComponent,
|
||||
DsoPageSubscriptionButtonComponent,
|
||||
MetadataFieldWrapperComponent,
|
||||
ContextHelpWrapperComponent,
|
||||
EpersonGroupListComponent,
|
||||
|
Reference in New Issue
Block a user