Skip to content

Commit

Permalink
Merge remote-tracking branch '4Science-github/CST-5337' into CST-5249…
Browse files Browse the repository at this point in the history
…_suggestion
  • Loading branch information
LucaGiamminonni committed Jul 7, 2022
2 parents 63bba67 + 0942a1e commit de6b533
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h3 class="border-bottom pb-2">
<hr>
<div>
{{(eventElement.hasProject ? 'quality-assurance.event.project.found' : 'quality-assurance.event.project.notFound') | translate}}
<a target="_blank" *ngIf="eventElement.hasProject" title="{{eventElement.projectTitle}}" [routerLink]="['/items', eventElement.projectId]">{{eventElement.handle}}</a>
<a target="_blank" *ngIf="eventElement.hasProject" title="{{eventElement.projectTitle}}" [routerLink]="['/items', eventElement.projectId]">{{eventElement.handle}} </a>
<div class="btn-group">
<button class="btn btn-outline-primary btn-sm"
[disabled]="eventElement.isRunning"
Expand All @@ -108,25 +108,36 @@ <h3 class="border-bottom pb-2">
</div>
</td>
<td>
<div class="btn-group-vertical button-width">
<div class="btn-group button-width">
<button *ngIf="showTopic.indexOf('/PROJECT') !== -1"
class="btn btn-outline-success btn-sm button-width"
ngbTooltip="{{'quality-assurance.event.action.import' | translate}}"
container="body"
[disabled]="eventElement.isRunning"
(click)="modalChoice('ACCEPTED', eventElement, acceptModal)">
<i class="fas fa-check"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.import' | translate}}</span>
</button>
<button *ngIf="showTopic.indexOf('/PROJECT') == -1" class="btn btn-outline-success btn-sm button-width" [disabled]="eventElement.isRunning" (click)="executeAction('ACCEPTED', eventElement)">
<button *ngIf="showTopic.indexOf('/PROJECT') == -1"
class="btn btn-outline-success btn-sm button-width"
ngbTooltip="{{'quality-assurance.event.action.accept' | translate}}"
container="body"
[disabled]="eventElement.isRunning"
(click)="executeAction('ACCEPTED', eventElement)">
<i class="fas fa-check"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.accept' | translate}}</span>
</button>
<button class="btn btn-outline-dark btn-sm button-width" [disabled]="eventElement.isRunning" (click)="openModal('DISCARDED', eventElement, ignoreModal)">
<i class="fas fa-trash-alt"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.ignore' | translate}}</span>
<button class="btn btn-outline-dark btn-sm button-width"
ngbTooltip="{{'quality-assurance.event.action.ignore' | translate}}"
container="body"
[disabled]="eventElement.isRunning"
(click)="openModal('DISCARDED', eventElement, ignoreModal)">
<i class="fas fa-ban"></i>
</button>
<button class="btn btn-outline-danger btn-sm button-width" [disabled]="eventElement.isRunning" (click)="openModal('REJECTED', eventElement, rejectModal)">
<button class="btn btn-outline-danger btn-sm button-width"
ngbTooltip="{{'quality-assurance.event.action.reject' | translate}}"
container="body"
[disabled]="eventElement.isRunning"
(click)="openModal('REJECTED', eventElement, rejectModal)">
<i class="fas fa-trash-alt"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.reject' | translate}}</span>
</button>
</div>
</td>
Expand Down Expand Up @@ -155,13 +166,13 @@ <h4 class="modal-title" id="acceptModal">{{'quality-assurance.event.sure' | tran
<div class="modal-body">
<p>{{'quality-assurance.event.accept.description' | translate}}</p>

<button class="btn btn-outline-success float-left" (click)="modal.close('do')">
<button class="btn btn-outline-success float-right" (click)="modal.close('do')">
<i class="fas fa-check"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.import' | translate}}</span>
<span class="d-none d-sm-inline"> {{'quality-assurance.event.action.import' | translate}}</span>
</button>
<button class="btn btn-outline-secondary float-right" (click)="modal.close('cancel')">
<button class="btn btn-outline-secondary" (click)="modal.close('cancel')">
<i class="fas fa-close"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.cancel' | translate}}</span>
<span class="d-none d-sm-inline"> {{'quality-assurance.event.action.cancel' | translate}}</span>
</button>
</div>
</ng-template>
Expand All @@ -172,16 +183,13 @@ <h4 class="modal-title" id="ignoreModal">{{'quality-assurance.event.sure' | tran
</div>
<div class="modal-body">
<p>{{'quality-assurance.event.ignore.description' | translate}}</p>

<!-- textarea class="form-control mb-2" [(ngModel)]="selectedReason" placeholder="{{'quality-assurance.event.reason' |translate}}"></textarea -->

<button class="btn btn-outline-danger float-left" (click)="modal.close('do')">
<button class="btn btn-outline-danger float-right" (click)="modal.close('do')">
<i class="fas fa-trash-alt"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.ignore' | translate}}</span>
<span class="d-none d-sm-inline"> {{'quality-assurance.event.action.ignore' | translate}}</span>
</button>
<button class="btn btn-outline-secondary float-right" (click)="modal.close('cancel')">
<button class="btn btn-outline-secondary" (click)="modal.close('cancel')">
<i class="fas fa-close"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.cancel' | translate}}</span>
<span class="d-none d-sm-inline"> {{'quality-assurance.event.action.cancel' | translate}}</span>
</button>
</div>
</ng-template>
Expand All @@ -192,16 +200,13 @@ <h4 class="modal-title" id="rejectModal">{{'quality-assurance.event.sure' | tran
</div>
<div class="modal-body">
<p>{{'quality-assurance.event.reject.description' | translate}}</p>

<!-- textarea class="form-control mb-2" [(ngModel)]="selectedReason" placeholder="{{'quality-assurance.event.reason' |translate}}"></textarea -->

<button class="btn btn-outline-danger float-left" (click)="modal.close('do')">
<button class="btn btn-outline-danger float-right" (click)="modal.close('do')">
<i class="fas fa-trash-alt"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.reject' | translate}}</span>
<span class="d-none d-sm-inline"> {{'quality-assurance.event.action.reject' | translate}}</span>
</button>
<button class="btn btn-outline-secondary float-right" (click)="modal.close('cancel')">
<button class="btn btn-outline-secondary" (click)="modal.close('cancel')">
<i class="fas fa-close"></i>
<span class="d-none d-sm-inline">{{'quality-assurance.event.action.cancel' | translate}}</span>
<span class="d-none d-sm-inline"> {{'quality-assurance.event.action.cancel' | translate}}</span>
</button>
</div>
</ng-template>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
Expand All @@ -10,25 +10,27 @@ import { SortDirection, SortOptions } from '../../../core/cache/models/sort-opti
import { PaginatedList } from '../../../core/data/paginated-list.model';
import { RemoteData } from '../../../core/data/remote-data';
import {
QualityAssuranceEventObject,
OpenaireQualityAssuranceEventMessageObject
OpenaireQualityAssuranceEventMessageObject,
QualityAssuranceEventObject
} from '../../../core/suggestion-notifications/qa/models/quality-assurance-event.model';
import { QualityAssuranceEventRestService } from '../../../core/suggestion-notifications/qa/events/quality-assurance-event-rest.service';
import {
QualityAssuranceEventRestService
} from '../../../core/suggestion-notifications/qa/events/quality-assurance-event-rest.service';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
import { Metadata } from '../../../core/shared/metadata.utils';
import { followLink } from '../../../shared/utils/follow-link-config.model';
import { hasValue } from '../../../shared/empty.util';
import { hasValue, isEmpty } from '../../../shared/empty.util';
import { ItemSearchResult } from '../../../shared/object-collection/shared/item-search-result.model';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import {
QualityAssuranceEventData,
ProjectEntryImportModalComponent
ProjectEntryImportModalComponent,
QualityAssuranceEventData
} from '../project-entry-import-modal/project-entry-import-modal.component';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { combineLatest } from 'rxjs/internal/observable/combineLatest';
import { Item } from '../../../core/shared/item.model';
import {FindListOptions} from '../../../core/data/find-list-options.model';
import { FindListOptions } from '../../../core/data/find-list-options.model';

/**
* Component to display the Quality Assurance event list.
Expand All @@ -38,7 +40,7 @@ import {FindListOptions} from '../../../core/data/find-list-options.model';
templateUrl: './quality-assurance-events.component.html',
styleUrls: ['./quality-assurance-events.scomponent.scss'],
})
export class QualityAssuranceEventsComponent implements OnInit {
export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
/**
* The pagination system configuration for HTML listing.
* @type {PaginationComponentOptions}
Expand Down Expand Up @@ -376,47 +378,50 @@ export class QualityAssuranceEventsComponent implements OnInit {
* the Quality Assurance event item
*/
protected setEventUpdated(events: QualityAssuranceEventObject[]): void {
this.subs.push(
from(events).pipe(
mergeMap((event: QualityAssuranceEventObject) => {
const related$ = event.related.pipe(
getFirstCompletedRemoteData(),
);
const target$ = event.target.pipe(
getFirstCompletedRemoteData()
);
return combineLatest([related$, target$]).pipe(
map(([relatedItemRD, targetItemRD]: [RemoteData<Item>, RemoteData<Item>]) => {
const data: QualityAssuranceEventData = {
event: event,
id: event.id,
title: event.title,
hasProject: false,
projectTitle: null,
projectId: null,
handle: null,
reason: null,
isRunning: false,
target: (targetItemRD?.hasSucceeded) ? targetItemRD.payload : null,
};
if (relatedItemRD?.hasSucceeded && relatedItemRD?.payload?.id) {
data.hasProject = true;
data.projectTitle = event.message.title;
data.projectId = relatedItemRD?.payload?.id;
data.handle = relatedItemRD?.payload?.handle;
}
return data;
})
);
}),
scan((acc: any, value: any) => [...acc, value], []),
take(events.length)
).subscribe(
(eventsReduced) => {
this.eventsUpdated$.next(eventsReduced);
}
)
);
if (isEmpty(events)) {
this.eventsUpdated$.next([]);
} else {
this.subs.push(
from(events).pipe(
mergeMap((event: QualityAssuranceEventObject) => {
const related$ = event.related.pipe(
getFirstCompletedRemoteData(),
);
const target$ = event.target.pipe(
getFirstCompletedRemoteData()
);
return combineLatest([related$, target$]).pipe(
map(([relatedItemRD, targetItemRD]: [RemoteData<Item>, RemoteData<Item>]) => {
const data: QualityAssuranceEventData = {
event: event,
id: event.id,
title: event.title,
hasProject: false,
projectTitle: null,
projectId: null,
handle: null,
reason: null,
isRunning: false,
target: (targetItemRD?.hasSucceeded) ? targetItemRD.payload : null,
};
if (relatedItemRD?.hasSucceeded && relatedItemRD?.payload?.id) {
data.hasProject = true;
data.projectTitle = event.message.title;
data.projectId = relatedItemRD?.payload?.id;
data.handle = relatedItemRD?.payload?.handle;
}
return data;
})
);
}),
scan((acc: any, value: any) => [...acc, value], []),
take(events.length)
).subscribe((eventsReduced) => {
this.eventsUpdated$.next(eventsReduced);
}
)
);
}
}

protected computePIDHref(event: OpenaireQualityAssuranceEventMessageObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {subStateSelector} from '../../submission/selectors';
* @param {AppState} state Top level state.
* @return {SuggestionNotificationsState}
*/
const _getReciterSuggestionTargetState = createFeatureSelector<SuggestionNotificationsState>('suggestion-notifications');
const _getReciterSuggestionTargetState = createFeatureSelector<SuggestionNotificationsState>('suggestionNotifications');

// Reciter Suggestion Targets
// ----------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions src/app/suggestion-notifications/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { suggestionNotificationsSelector, SuggestionNotificationsState } from '.
import { QualityAssuranceTopicObject } from '../core/suggestion-notifications/qa/models/quality-assurance-topic.model';
import { QualityAssuranceTopicState } from './qa/topics/quality-assurance-topics.reducer';
import { QualityAssuranceSourceState } from './qa/source/quality-assurance-source.reducer';
import { QualityAssuranceSourceObject } from '../core/suggestion-notifications/qa/models/quality-assurance-source.model';
import {
QualityAssuranceSourceObject
} from '../core/suggestion-notifications/qa/models/quality-assurance-source.model';

/**
* Returns the Notifications state.
* @function _getNotificationsState
* @param {AppState} state Top level state.
* @return {SuggestionNotificationsState}
*/
const _getNotificationsState = createFeatureSelector<SuggestionNotificationsState>('suggestion-notifications');
const _getNotificationsState = createFeatureSelector<SuggestionNotificationsState>('suggestionNotifications');

// Quality Assurance topics
// ----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('NotificationsStateService', () => {
function init(mode: string) {
if (mode === 'empty') {
initialState = {
notifications: {
suggestionNotifications: {
qaTopic: {
topics: [],
processing: false,
Expand All @@ -39,7 +39,7 @@ describe('NotificationsStateService', () => {
};
} else {
initialState = {
notifications: {
suggestionNotifications: {
qaTopic: {
topics: [
qualityAssuranceTopicObjectMorePid,
Expand All @@ -63,7 +63,7 @@ describe('NotificationsStateService', () => {
init('empty');
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any),
StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any),
],
providers: [
provideMockStore({ initialState }),
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('NotificationsStateService', () => {
init('full');
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any),
StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any),
],
providers: [
provideMockStore({ initialState }),
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('NotificationsStateService', () => {
init('full');
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any),
StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any),
],
providers: [
provideMockStore({ initialState }),
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('NotificationsStateService', () => {
function init(mode: string) {
if (mode === 'empty') {
initialState = {
notifications: {
suggestionNotifications: {
qaSource: {
source: [],
processing: false,
Expand All @@ -297,7 +297,7 @@ describe('NotificationsStateService', () => {
};
} else {
initialState = {
notifications: {
suggestionNotifications: {
qaSource: {
source: [
qualityAssuranceSourceObjectMorePid,
Expand All @@ -321,7 +321,7 @@ describe('NotificationsStateService', () => {
init('empty');
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any),
StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any),
],
providers: [
provideMockStore({ initialState }),
Expand Down Expand Up @@ -413,7 +413,7 @@ describe('NotificationsStateService', () => {
init('full');
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any),
StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any),
],
providers: [
provideMockStore({ initialState }),
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('NotificationsStateService', () => {
init('full');
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any),
StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any),
],
providers: [
provideMockStore({ initialState }),
Expand Down
Loading

0 comments on commit de6b533

Please sign in to comment.