Skip to content

Commit 75f5462

Browse files
[CST-5249] fix ssr rendering
1 parent f475a4f commit 75f5462

6 files changed

Lines changed: 63 additions & 31 deletions

File tree

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<ng-container *ngIf="(suggestionsRD$ | async) as suggestions">
22
<ng-container *ngFor="let suggestion of suggestions" class="alert alert-info">
33
<div class="alert alert-success d-block" *ngIf="suggestion.total > 0">
4-
<div [innerHTML]="'notification.suggestion' | translate: getNotificationSuggestionInterpolation(suggestion)">
5-
</div>
4+
<div [innerHTML]="'notification.suggestion' | translate: getNotificationSuggestionInterpolation(suggestion)"></div>
5+
{{ 'notification.suggestion.please' | translate }}
6+
<a [routerLink]="getNotificationSuggestionInterpolation(suggestion).url"> {{ 'notification.suggestion.review' | translate}} </a>
67
</div>
78
</ng-container>
89
</ng-container>

src/app/suggestion-notifications/suggestions-notification/suggestions-notification.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Component, OnInit } from '@angular/core';
22
import { SuggestionTarget } from '../../core/suggestion-notifications/models/suggestion-target.model';
3-
import { TranslateService } from '@ngx-translate/core';
43
import { SuggestionTargetsStateService } from '../suggestion-targets/suggestion-targets.state.service';
5-
import { NotificationsService } from '../../shared/notifications/notifications.service';
64
import { SuggestionsService } from '../suggestions.service';
75
import { Observable } from 'rxjs';
86

@@ -22,9 +20,7 @@ export class SuggestionsNotificationComponent implements OnInit {
2220
suggestionsRD$: Observable<SuggestionTarget[]>;
2321

2422
constructor(
25-
private translateService: TranslateService,
2623
private suggestionTargetsStateService: SuggestionTargetsStateService,
27-
private notificationsService: NotificationsService,
2824
private suggestionsService: SuggestionsService
2925
) { }
3026

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1+
<div class="notifications-wrapper position-fixed top right" *ngIf="suggestionsRD$ | async">
2+
<div class="notification alert alert-success alert-dismissible m-3 shadow" role="alert">
3+
<button (click)="removePopup()"
4+
type="button" class="close pt-0 pr-1 pl-0 pb-0" data-dismiss="alert" aria-label="Close">
5+
<span aria-hidden="true">&times;</span>
6+
</button>
7+
8+
<div class="d-flex flex-row">
9+
<div class="d-flex flex-column justify-content-center align-items-center">
10+
<div class="notification-icon d-flex justify-content-center"><i class="fas fa-2x fa-check-circle"></i></div>
11+
</div>
12+
<div class="d-flex flex-column justify-content-center align-content-stretch text-left p-2">
13+
<ng-container *ngIf="(suggestionsRD$ | async) as suggestions">
14+
<ng-container *ngFor="let suggestion of suggestions" class="alert alert-info">
15+
<div *ngIf="suggestion.total > 0">
16+
<div [innerHTML]="'notification.suggestion' | translate: getNotificationSuggestionInterpolation(suggestion)"></div>
17+
{{ 'notification.suggestion.please' | translate }}
18+
<a [routerLink]="getNotificationSuggestionInterpolation(suggestion).url"> {{ 'notification.suggestion.review' | translate}} </a>
19+
</div>
20+
</ng-container>
21+
</ng-container>
22+
</div>
23+
</div>
24+
</div>
25+
</div>
26+
127

src/app/suggestion-notifications/suggestions-popup/suggestions-popup.component.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
33
import { SuggestionsPopupComponent } from './suggestions-popup.component';
44
import { TranslateModule } from '@ngx-translate/core';
55
import { SuggestionTargetsStateService } from '../suggestion-targets/suggestion-targets.state.service';
6-
import { NotificationsService } from '../../shared/notifications/notifications.service';
7-
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
86
import { NO_ERRORS_SCHEMA } from '@angular/core';
97
import { of as observableOf } from 'rxjs';
108
import { mockSuggestionTargetsObjectOne } from '../../shared/mocks/publication-claim-targets.mock';
@@ -13,7 +11,6 @@ import { SuggestionsService } from '../suggestions.service';
1311
describe('SuggestionsPopupComponent', () => {
1412
let component: SuggestionsPopupComponent;
1513
let fixture: ComponentFixture<SuggestionsPopupComponent>;
16-
let notificationsService: NotificationsService;
1714

1815
const suggestionStateService = jasmine.createSpyObj('SuggestionTargetsStateService', {
1916
hasUserVisitedSuggestions: jasmine.createSpy('hasUserVisitedSuggestions'),
@@ -35,7 +32,6 @@ describe('SuggestionsPopupComponent', () => {
3532
providers: [
3633
{ provide: SuggestionTargetsStateService, useValue: suggestionStateService },
3734
{ provide: SuggestionsService, useValue: suggestionService },
38-
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
3935
],
4036
schemas: [NO_ERRORS_SCHEMA]
4137

@@ -69,12 +65,10 @@ describe('SuggestionsPopupComponent', () => {
6965

7066
fixture = TestBed.createComponent(SuggestionsPopupComponent);
7167
component = fixture.componentInstance;
72-
notificationsService = (component as any).notificationsService;
7368
fixture.detectChanges();
7469
});
7570

7671
it('should show a notification when new publication suggestions are available', () => {
77-
expect(notificationsService.success).toHaveBeenCalled();
7872
expect(suggestionStateService.dispatchRefreshUserSuggestionsAction).toHaveBeenCalled();
7973
expect(suggestionStateService.dispatchMarkUserSuggestionsAsVisitedAction).toHaveBeenCalled();
8074
});
Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
import { Component, OnDestroy, OnInit } from '@angular/core';
2-
import { TranslateService } from '@ngx-translate/core';
32
import { SuggestionTargetsStateService } from '../suggestion-targets/suggestion-targets.state.service';
4-
import { NotificationsService } from '../../shared/notifications/notifications.service';
53
import { SuggestionsService } from '../suggestions.service';
64
import { take, takeUntil } from 'rxjs/operators';
75
import { SuggestionTarget } from '../../core/suggestion-notifications/models/suggestion-target.model';
86
import { isNotEmpty } from '../../shared/empty.util';
9-
import { combineLatest, Subject } from 'rxjs';
7+
import { combineLatest, Observable, of, Subject } from 'rxjs';
8+
import { trigger } from '@angular/animations';
9+
10+
11+
import { fromTopEnter } from '../../shared/animations/fromTop';
1012

1113
/**
1214
* Show suggestions on a popover window, used on the homepage
1315
*/
1416
@Component({
1517
selector: 'ds-suggestions-popup',
1618
templateUrl: './suggestions-popup.component.html',
17-
styleUrls: ['./suggestions-popup.component.scss']
19+
styleUrls: ['./suggestions-popup.component.scss'],
20+
animations: [
21+
trigger('enterLeave', [
22+
fromTopEnter
23+
])
24+
],
1825
})
1926
export class SuggestionsPopupComponent implements OnInit, OnDestroy {
2027

2128
labelPrefix = 'notification.';
2229

2330
subscription;
2431

32+
suggestionsRD$: Observable<SuggestionTarget[]>;
33+
34+
2535
constructor(
26-
private translateService: TranslateService,
2736
private suggestionTargetsStateService: SuggestionTargetsStateService,
28-
private notificationsService: NotificationsService,
2937
private suggestionsService: SuggestionsService
3038
) { }
3139

@@ -42,7 +50,7 @@ export class SuggestionsPopupComponent implements OnInit, OnDestroy {
4250
this.suggestionTargetsStateService.dispatchRefreshUserSuggestionsAction();
4351
if (isNotEmpty(suggestions)) {
4452
if (!visited) {
45-
suggestions.forEach((suggestionTarget: SuggestionTarget) => this.showNotificationForNewSuggestions(suggestionTarget));
53+
this.suggestionsRD$ = of(suggestions);
4654
this.suggestionTargetsStateService.dispatchMarkUserSuggestionsAsVisitedAction();
4755
notifier.next(null);
4856
notifier.complete();
@@ -51,21 +59,24 @@ export class SuggestionsPopupComponent implements OnInit, OnDestroy {
5159
});
5260
}
5361

54-
/**
55-
* Show a notification to user for a new suggestions detected
56-
* @param suggestionTarget
57-
* @private
58-
*/
59-
private showNotificationForNewSuggestions(suggestionTarget: SuggestionTarget): void {
60-
const content = this.translateService.instant(this.labelPrefix + 'suggestion',
61-
this.suggestionsService.getNotificationSuggestionInterpolation(suggestionTarget));
62-
this.notificationsService.success('', content, {timeOut:0}, true);
63-
}
64-
6562
ngOnDestroy() {
6663
if (this.subscription) {
6764
this.subscription.unsubscribe();
6865
}
6966
}
7067

68+
/**
69+
* Interpolated params to build the notification suggestions notification.
70+
* @param suggestionTarget
71+
*/
72+
public getNotificationSuggestionInterpolation(suggestionTarget: SuggestionTarget): any {
73+
return this.suggestionsService.getNotificationSuggestionInterpolation(suggestionTarget);
74+
}
75+
76+
/**
77+
* Hide popup from view
78+
*/
79+
public removePopup() {
80+
this.suggestionsRD$ = null;
81+
}
7182
}

src/assets/i18n/en.json5

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3120,7 +3120,11 @@
31203120

31213121
"mydspace.import": "Import",
31223122

3123-
"notification.suggestion": "We found <b>{{count}} publications</b> in the {{source}} that seems to be related to your profile.<br> Please <a href='{{ url }}'>review the suggestions</a>",
3123+
"notification.suggestion": "We found <b>{{count}} publications</b> in the {{source}} that seems to be related to your profile.<br>",
3124+
3125+
"notification.suggestion.review": "review the suggestions",
3126+
3127+
"notification.suggestion.please": "Please",
31243128

31253129
"nav.browse.header": "All of DSpace",
31263130

0 commit comments

Comments
 (0)