@@ -10,21 +10,13 @@ import { AuthorizationDataService } from '@dspace/core/data/feature-authorizatio
1010import { FeatureID } from '@dspace/core/data/feature-authorization/feature-id' ;
1111import { DSpaceObject } from '@dspace/core/shared/dspace-object.model' ;
1212import { NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
13- import { TranslateService } from '@ngx-translate/core' ;
1413import {
1514 combineLatest ,
1615 Observable ,
17- Subject ,
1816} from 'rxjs' ;
19- import {
20- map ,
21- startWith ,
22- switchMap ,
23- } from 'rxjs/operators' ;
24- import { AuthService } from 'src/app/core/auth/auth.service' ;
17+ import { map } from 'rxjs/operators' ;
2518
2619import { SubscriptionModalComponent } from '../../subscriptions/subscription-modal/subscription-modal.component' ;
27- import { SubscriptionsDataService } from '../../subscriptions/subscriptions-data.service' ;
2820import { OnClickMenuItemModel } from '../menu-item/models/onclick.model' ;
2921import { MenuItemType } from '../menu-item-type.model' ;
3022import { PartialMenuSection } from '../menu-provider.model' ;
@@ -35,57 +27,33 @@ import { DSpaceObjectPageMenuProvider } from './helper-providers/dso.menu';
3527 */
3628@Injectable ( )
3729export class SubscribeMenuProvider extends DSpaceObjectPageMenuProvider {
38- private refresh$ = new Subject < void > ( ) ;
39-
4030 constructor (
41- protected authService : AuthService ,
4231 protected authorizationService : AuthorizationDataService ,
43- protected subscriptionService : SubscriptionsDataService ,
4432 protected modalService : NgbModal ,
45- protected translateService : TranslateService ,
4633 ) {
4734 super ( ) ;
4835 }
4936
5037 public getSectionsForContext ( dso : DSpaceObject ) : Observable < PartialMenuSection [ ] > {
51- return this . refresh$ . pipe (
52- startWith ( undefined ) , // Disparamos siempre al inicio
53- switchMap ( ( ) =>
54- combineLatest ( [
55- this . authorizationService . isAuthorized ( FeatureID . CanSubscribe , dso . self ) ,
56- this . authService . getAuthenticatedUserFromStore ( ) ,
57- ] ) ,
58- ) ,
59- switchMap ( ( [ canSubscribe , user ] ) =>
60- this . subscriptionService . getSubscriptionsByPersonDSO ( user . id , dso . uuid ) . pipe (
61- map ( ( subscriptionRD ) => {
62- const subscription = subscriptionRD . payload ?. page [ 0 ] ;
63- const isSubscribed = subscription != null ;
64- const key = isSubscribed
65- ? 'subscriptions.manage'
66- : 'subscriptions.tooltip' ;
67- return [
68- {
69- visible : canSubscribe ,
70- model : {
71- type : MenuItemType . ONCLICK ,
72- text : key ,
73- function : ( ) => {
74- const modalRef = this . modalService . open ( SubscriptionModalComponent ) ;
75- modalRef . componentInstance . dso = dso ;
76- modalRef . componentInstance . updated . subscribe ( ( ) => {
77- this . refresh$ . next ( ) ;
78- } ) ;
79- modalRef . closed . subscribe ( ( ) => {
80- } ) ;
81- } ,
82- } as OnClickMenuItemModel ,
83- icon : 'bell' ,
38+ return combineLatest ( [
39+ this . authorizationService . isAuthorized ( FeatureID . CanSubscribe , dso . self ) ,
40+ ] ) . pipe (
41+ map ( ( [ canSubscribe ] ) => {
42+ return [
43+ {
44+ visible : canSubscribe ,
45+ model : {
46+ type : MenuItemType . ONCLICK ,
47+ text : 'subscriptions.tooltip' ,
48+ function : ( ) => {
49+ const modalRef = this . modalService . open ( SubscriptionModalComponent ) ;
50+ modalRef . componentInstance . dso = dso ;
8451 } ,
85- ] as PartialMenuSection [ ] ;
86- } ) ,
87- ) ,
88- ) ,
52+ } as OnClickMenuItemModel ,
53+ icon : 'bell' ,
54+ } ,
55+ ] as PartialMenuSection [ ] ;
56+ } ) ,
8957 ) ;
9058 }
9159}
0 commit comments