Skip to content

Commit 00ecd00

Browse files
alemarteatarix83
authored andcommitted
Merged in CSTPER-701-improveSuggestionNotifications (pull request #30)
Suggestions improvements picked from perucris Approved-by: Giuseppe Digilio
2 parents 54021da + 087899d commit 00ecd00

14 files changed

Lines changed: 228 additions & 35 deletions

src/app/openaire/reciter-suggestions/suggestion-actions/suggestion-actions.component.html

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
<div class="d-inline">
22
<div ngbDropdown class="d-inline">
3-
<button class="btn btn-success" id="dropdownSubmission" ngbDropdownToggle
4-
type="button">
3+
<button *ngIf="isCollectionFixed; else chooseCollection" class="btn btn-success" type="button" (click)="approveAndImportCollectionFixed()">
54
<i class="fa fa-check" aria-hidden="true"></i> {{ approveAndImportLabel() | translate}}
6-
<span class="caret"></span>
75
</button>
8-
<div ngbDropdownMenu
9-
class="dropdown-menu"
10-
id="entityControlsDropdownMenu"
11-
aria-labelledby="dropdownSubmission">
12-
<ds-entity-dropdown (selectionChange)="openDialog($event)"></ds-entity-dropdown>
13-
</div>
6+
<ng-template #chooseCollection>
7+
<button class="btn btn-success" id="dropdownSubmission" ngbDropdownToggle
8+
type="button">
9+
<i class="fa fa-check" aria-hidden="true"></i> {{ approveAndImportLabel() | translate}}
10+
<span class="caret"></span>
11+
</button>
12+
13+
<div ngbDropdownMenu
14+
class="dropdown-menu"
15+
id="entityControlsDropdownMenu"
16+
aria-labelledby="dropdownSubmission">
17+
<ds-entity-dropdown (selectionChange)="openDialog($event)"></ds-entity-dropdown>
18+
</div>
19+
</ng-template>
20+
1421
</div>
1522
<button (click)="notMine()" class="btn btn-danger ml-2"><i class="fa fa-ban"></i>
1623
{{ notMineLabel() | translate}}</button>

src/app/openaire/reciter-suggestions/suggestion-actions/suggestion-actions.component.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ export class SuggestionActionsComponent {
1818

1919
@Input() isBulk = false;
2020

21-
@Input() public hasEvidence = false;
21+
@Input() hasEvidence = false;
2222

23-
@Input() public seeEvidence = false;
23+
@Input() seeEvidence = false;
24+
25+
@Input() isCollectionFixed = false;
2426

2527
/**
2628
* The component is used to Delete suggestion
@@ -58,6 +60,14 @@ export class SuggestionActionsComponent {
5860
});
5961
}
6062

63+
approveAndImportCollectionFixed() {
64+
this.approveAndImport.emit({
65+
suggestion: this.isBulk ? undefined : this.object,
66+
collectionId: null
67+
});
68+
}
69+
70+
6171
/**
6272
* Delete the suggestion
6373
*/

src/app/openaire/reciter-suggestions/suggestion-list-element/suggestion-list-element.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<ds-suggestion-actions class="parent mt-2" [hasEvidence]="hasEvidences()"
2828
[seeEvidence]="seeEvidence"
2929
[object]="object"
30+
[isCollectionFixed]="isCollectionFixed"
3031
(approveAndImport)="onApproveAndImport($event)"
3132
(seeEvidences)="onSeeEvidences($event)"
3233
(notMineClicked)="onNotMine($event)"

src/app/openaire/reciter-suggestions/suggestion-list-element/suggestion-list-element.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export class SuggestionListElementComponent implements OnInit {
2424

2525
@Input() isSelected = false;
2626

27+
@Input() isCollectionFixed = false;
28+
2729
public listableObject: any;
2830

2931
public seeEvidence = false;

src/app/openaire/reciter-suggestions/suggestions-notification/suggestions-notification.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ng-container *ngIf="(suggestionsRD$ | async) as suggestions">
22
<ng-container *ngFor="let suggestion of suggestions" class="alert alert-info">
3-
<div class="alert alert-success" *ngIf="suggestion.total > 0">
3+
<div class="alert alert-success d-block" *ngIf="suggestion.total > 0">
44
<div [innerHTML]="'mydspace.notification.suggestion.page' | translate: getNotificationSuggestionInterpolation(suggestion)">
55
</div>
66
</div>

src/app/openaire/reciter-suggestions/suggestions.service.ts

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { OpenaireSuggestionTarget } from '../../core/openaire/reciter-suggestion
1212
import { ResearcherProfileService } from '../../core/profile/researcher-profile.service';
1313
import { AuthService } from '../../core/auth/auth.service';
1414
import { EPerson } from '../../core/eperson/models/eperson.model';
15-
import { isNotEmpty } from '../../shared/empty.util';
15+
import { hasValue, isNotEmpty } from '../../shared/empty.util';
1616
import { ResearcherProfile } from '../../core/profile/model/researcher-profile.model';
1717
import {
1818
getAllSucceededRemoteDataPayload,
@@ -24,6 +24,9 @@ import { OpenaireSuggestion } from '../../core/openaire/reciter-suggestions/mode
2424
import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-data.service';
2525
import { TranslateService } from '@ngx-translate/core';
2626
import { NoContent } from '../../core/shared/NoContent.model';
27+
import { environment } from '../../../environments/environment';
28+
import { SuggestionConfig } from '../../../config/layout-config.interfaces';
29+
import { WorkspaceItem } from '../../core/submission/models/workspaceitem.model';
2730

2831
export interface SuggestionBulkResult {
2932
success: number;
@@ -170,8 +173,10 @@ export class SuggestionsService {
170173
*/
171174
public approveAndImport(workspaceitemService: WorkspaceitemDataService,
172175
suggestion: OpenaireSuggestion,
173-
collectionId: string): Observable<string> {
174-
return workspaceitemService.importExternalSourceEntry(suggestion.externalSourceUri, collectionId)
176+
collectionId: string): Observable<WorkspaceItem> {
177+
178+
const resolvedCollectionId = this.resolveCollectionId(suggestion, collectionId);
179+
return workspaceitemService.importExternalSourceEntry(suggestion.externalSourceUri, resolvedCollectionId)
175180
.pipe(
176181
getFirstSucceededRemoteDataPayload(),
177182
catchError((error) => of(null))
@@ -200,7 +205,7 @@ export class SuggestionsService {
200205

201206
return forkJoin(suggestions.map((suggestion: OpenaireSuggestion) =>
202207
this.approveAndImport(workspaceitemService, suggestion, collectionId)))
203-
.pipe(map((results: string[]) => {
208+
.pipe(map((results: WorkspaceItem[]) => {
204209
return {
205210
success: results.filter((result) => result != null).length,
206211
fails: results.filter((result) => result == null).length
@@ -240,10 +245,52 @@ export class SuggestionsService {
240245
public getNotificationSuggestionInterpolation(suggestionTarget: OpenaireSuggestionTarget): any {
241246
return {
242247
count: suggestionTarget.total,
243-
source: this.translateService.instant('reciter.suggestion.source.' + suggestionTarget.source),
248+
source: this.translateService.instant(this.translateSuggestionSource(suggestionTarget.source)),
249+
type: this.translateService.instant(this.translateSuggestionType(suggestionTarget.source)),
244250
suggestionId: suggestionTarget.id,
245251
displayName: suggestionTarget.display
246252
};
247253
}
248254

255+
public translateSuggestionType(source: string): string {
256+
return 'reciter.suggestion.type.' + source;
257+
}
258+
259+
public translateSuggestionSource(source: string): string {
260+
return 'reciter.suggestion.source.' + source;
261+
}
262+
263+
/**
264+
* If the provided collectionId ha no value, tries to resolve it by suggestion source.
265+
* @param suggestion
266+
* @param collectionId
267+
*/
268+
public resolveCollectionId(suggestion: OpenaireSuggestion, collectionId): string {
269+
if (hasValue(collectionId)) {
270+
return collectionId;
271+
}
272+
return environment.suggestion
273+
.find((suggestionConf: SuggestionConfig) => suggestionConf.source === suggestion.source)
274+
.collectionId;
275+
}
276+
277+
/**
278+
* Return true if all the suggestion are configured with the same fixed collection
279+
* in the configuration.
280+
* @param suggestions
281+
*/
282+
public isCollectionFixed(suggestions: OpenaireSuggestion[]): boolean {
283+
return this.getFixedCollectionIds(suggestions).length === 1;
284+
}
285+
286+
private getFixedCollectionIds(suggestions: OpenaireSuggestion[]): string[] {
287+
const collectionIds = {};
288+
suggestions.forEach((suggestion: OpenaireSuggestion) => {
289+
const conf = environment.suggestion.find((suggestionConf: SuggestionConfig) => suggestionConf.source === suggestion.source);
290+
if (hasValue(conf)) {
291+
collectionIds[conf.collectionId] = true;
292+
}
293+
});
294+
return Object.keys(collectionIds);
295+
}
249296
}

src/app/profile-page/profile-page.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ <h3 class="mb-4">{{'profile.head' | translate}}</h3>
44
<div class="card mb-4">
55
<div class="card-header">{{'profile.card.researcher' | translate}}</div>
66
<div class="card-body">
7-
<ds-profile-page-researcher-form [user]="user"></ds-profile-page-researcher-form>
7+
<div class="mb-4">
8+
<ds-profile-page-researcher-form [user]="user"></ds-profile-page-researcher-form>
9+
</div>
10+
<ds-suggestions-notification></ds-suggestions-notification>
811
</div>
912
</div>
1013
<div class="card mb-4">

src/app/profile-page/profile-page.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { ProfilePageSecurityFormComponent } from './profile-page-security-form/p
88
import { ProfilePageResearcherFormComponent } from './profile-page-researcher-form/profile-page-researcher-form.component';
99
import { ThemedProfilePageComponent } from './themed-profile-page.component';
1010
import { UiSwitchModule } from 'ngx-ui-switch';
11+
import { OpenaireModule } from '../openaire/openaire.module';
1112

1213
@NgModule({
1314
imports: [
1415
ProfilePageRoutingModule,
1516
CommonModule,
1617
SharedModule,
17-
UiSwitchModule
18+
UiSwitchModule,
19+
OpenaireModule
1820
],
1921
exports: [
2022
ProfilePageSecurityFormComponent

src/app/suggestions-page/suggestions-page.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
<div *ngIf="suggestionsRD?.pageInfo?.totalElements > 0">
66

77
<h2>
8+
{{ translateSuggestionType() | translate }}
89
{{'reciter.suggestion.suggestionFor' | translate}}
910
<a target="_blank" [routerLink]="['/items', researcherUuid]">{{researcherName}}</a>
10-
{{'reciter.suggestion.from.source' | translate}} {{ getSuggestionSourceLabel() | translate}}
11+
{{'reciter.suggestion.from.source' | translate}} {{ translateSuggestionSource() | translate }}
1112
</h2>
1213

1314
<div class="mb-3 mt-3">
@@ -16,6 +17,7 @@ <h2>
1617
<ds-suggestion-actions *ngIf="getSelectedSuggestionsCount() > 0"
1718
class="mt-2 ml-2"
1819
[isBulk]="true"
20+
[isCollectionFixed]="isCollectionFixed(suggestionsRD.page)"
1921
(approveAndImport)="approveAndImportAllSelected($event)"
2022
(notMineClicked)="notMineAllSelected()"></ds-suggestion-actions>
2123
<i class='fas fa-circle-notch fa-spin' *ngIf="isBulkOperationPending"></i>
@@ -32,6 +34,7 @@ <h2>
3234
<ds-suggestion-list-item
3335
[object]="object"
3436
[isSelected]="selectedSuggestions[object.id]"
37+
[isCollectionFixed]="isCollectionFixed([object])"
3538
(notMineClicked)="notMine($event)"
3639
(selected)="onSelected(object, $event)"
3740
(approveAndImport)="approveAndImport($event)"></ds-suggestion-list-item>

src/app/suggestions-page/suggestions-page.component.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { SuggestionTargetsStateService } from '../openaire/reciter-suggestions/s
2020
import { WorkspaceitemDataService } from '../core/submission/workspaceitem-data.service';
2121
import { PaginationService } from '../core/pagination/pagination.service';
2222
import { FindListOptions } from '../core/data/request.models';
23+
import { WorkspaceItem } from '../core/submission/models/workspaceitem.model';
2324

2425
@Component({
2526
selector: 'ds-suggestion-page',
@@ -59,10 +60,11 @@ export class SuggestionsPageComponent implements OnInit {
5960
targetRD$: Observable<RemoteData<OpenaireSuggestionTarget>>;
6061
targetId$: Observable<string>;
6162

63+
suggestionTarget: OpenaireSuggestionTarget;
6264
suggestionId: any;
65+
suggestionSource: any;
6366
researcherName: any;
6467
researcherUuid: any;
65-
suggestionSource: any;
6668

6769
selectedSuggestions: { [id: string]: OpenaireSuggestion } = {};
6870
isBulkOperationPending = false;
@@ -93,6 +95,7 @@ export class SuggestionsPageComponent implements OnInit {
9395
this.targetRD$.pipe(
9496
getFirstSucceededRemoteDataPayload()
9597
).subscribe((suggestionTarget: OpenaireSuggestionTarget) => {
98+
this.suggestionTarget = suggestionTarget;
9699
this.suggestionId = suggestionTarget.id;
97100
this.researcherName = suggestionTarget.display;
98101
this.suggestionSource = suggestionTarget.source;
@@ -136,6 +139,15 @@ export class SuggestionsPageComponent implements OnInit {
136139
this.processing$.next(false);
137140
this.suggestionsRD$.next(results);
138141
this.suggestionService.clearSuggestionRequests();
142+
// navigate to the mydspace if no suggestions remains
143+
144+
// if (results.totalElements === 0) {
145+
// const content = this.translateService.instant('reciter.suggestion.empty',
146+
// this.suggestionService.getNotificationSuggestionInterpolation(this.suggestionTarget));
147+
// this.notificationService.success('', content, {timeOut:0}, true);
148+
// TODO if the target is not the current use route to the suggestion target page
149+
// this.router.navigate(['/mydspace']);
150+
// }
139151
});
140152
}
141153

@@ -181,9 +193,10 @@ export class SuggestionsPageComponent implements OnInit {
181193
*/
182194
approveAndImport(event: SuggestionApproveAndImport) {
183195
this.suggestionService.approveAndImport(this.workspaceItemService, event.suggestion, event.collectionId)
184-
.subscribe((response: any) => {
196+
.subscribe((workspaceitem: WorkspaceItem) => {
197+
const content = this.translateService.instant('reciter.suggestion.approveAndImport.success', { workspaceItemId: workspaceitem.id });
198+
this.notificationService.success('', content, {timeOut:0}, true);
185199
this.suggestionTargetsStateService.dispatchRefreshUserSuggestionsAction();
186-
this.notificationService.success(this.translateService.get('reciter.suggestion.approveAndImport.success'));
187200
this.updatePage();
188201
});
189202
}
@@ -248,8 +261,26 @@ export class SuggestionsPageComponent implements OnInit {
248261
return Object.keys(this.selectedSuggestions).length;
249262
}
250263

251-
getSuggestionSourceLabel(): string {
252-
return 'reciter.suggestion.source.' + this.suggestionSource;
264+
/**
265+
* Return true if all the suggestion are configured with the same fixed collection in the configuration.
266+
* @param suggestions
267+
*/
268+
isCollectionFixed(suggestions: OpenaireSuggestion[]): boolean {
269+
return this.suggestionService.isCollectionFixed(suggestions);
270+
}
271+
272+
/**
273+
* Label to be used to translate the suggestion source.
274+
*/
275+
translateSuggestionSource() {
276+
return this.suggestionService.translateSuggestionSource(this.suggestionSource);
277+
}
278+
279+
/**
280+
* Label to be used to translate the suggestion type.
281+
*/
282+
translateSuggestionType() {
283+
return this.suggestionService.translateSuggestionType(this.suggestionSource);
253284
}
254285

255286
}

0 commit comments

Comments
 (0)