Skip to content

Commit

Permalink
[CST-12145] get qa-sources by target for item-page & refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaismailati committed Nov 2, 2023
1 parent 8e0af9b commit d31dc4d
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PaginatedList } from '../../../data/paginated-list.model';
import { FindListOptions } from '../../../data/find-list-options.model';
import { IdentifiableDataService } from '../../../data/base/identifiable-data.service';
import { FindAllData, FindAllDataImpl } from '../../../data/base/find-all-data';
import { SearchData, SearchDataImpl } from 'src/app/core/data/base/search-data';

/**
* The service handling all Quality Assurance source REST requests.
Expand All @@ -25,6 +26,9 @@ import { FindAllData, FindAllDataImpl } from '../../../data/base/find-all-data';
export class QualityAssuranceSourceDataService extends IdentifiableDataService<QualityAssuranceSourceObject> {

private findAllData: FindAllData<QualityAssuranceSourceObject>;
private searchAllData: SearchData<QualityAssuranceSourceObject>;

private searchByTargetMethod = 'byTarget';

/**
* Initialize service variables
Expand All @@ -43,6 +47,7 @@ export class QualityAssuranceSourceDataService extends IdentifiableDataService<Q
) {
super('qualityassurancesources', requestService, rdbService, objectCache, halService);
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
this.searchAllData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
}

/**
Expand Down Expand Up @@ -84,4 +89,16 @@ export class QualityAssuranceSourceDataService extends IdentifiableDataService<Q
public getSource(id: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceSourceObject>[]): Observable<RemoteData<QualityAssuranceSourceObject>> {
return this.findById(id, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}

/**
* Retrieves a paginated list of QualityAssuranceSourceObject objects that are associated with a given target object.
* @param options The options for the search query.
* @param useCachedVersionIfAvailable Whether to use a cached version of the data if available.
* @param reRequestOnStale Whether to re-request the data if the cached version is stale.
* @param linksToFollow The links to follow to retrieve the data.
* @returns An observable that emits a RemoteData object containing the paginated list of QualityAssuranceSourceObject objects.
*/
public getSourcesByTarget(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceSourceObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceSourceObject>>> {
return this.searchAllData.searchBy(this.searchByTargetMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<ng-container *ngIf="(events$ | async)?.length > 0">
<div class="alert alert-info d-flex flex-row">
<img class="notify-logo" src="assets/images/notify-coar-icon.png" alt="Repository logo">
<div class="w-100 d-flex justify-content-between">
<div class="pl-4 align-self-center">{{'item.qa-event-notification.check.notification-info' | translate : {num: (events$ | async)?.length} }} </div>
<button [routerLink]="['/admin/notifications/quality-assurance', source, item.id]" class="btn btn-primary align-self-center">{{'item.qa-event-notification-info.check.button' | translate }}</button>
<ng-container *ngIf="(getQualityAssuranceSources$() | async)?.length > 0">
<ng-container *ngFor="let source of (getQualityAssuranceSources$() | async)">
<div class="alert alert-info d-flex flex-row" *ngIf="source.totalEvents > 0">
<img class="source-logo" src="assets/images/qa-{{(source.id | dsSplit: ':')[0]}}-logo.png" alt="{{source.id}} logo">
<div class="w-100 d-flex justify-content-between">
<div class="pl-4 align-self-center">{{'item.qa-event-notification.check.notification-info' | translate : {num:
source.totalEvents } }} </div>
<button [routerLink]="['/admin/notifications/quality-assurance', source, item.id]"
class="btn btn-primary align-self-center">{{'item.qa-event-notification-info.check.button' | translate
}}</button>
</div>
</div>
</div>
</ng-container>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

.notify-logo {
.source-logo {
max-height: var(--ds-header-logo-height);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,82 +1,50 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Item } from '../../../core/shared/item.model';
import { getFirstCompletedRemoteData, getPaginatedListPayload, getRemoteDataPayload } from '../../../core/shared/operators';
import { QualityAssuranceEventDataService } from '../../../core/suggestion-notifications/qa/events/quality-assurance-event-data.service';
import { QualityAssuranceTopicDataService } from '../../../core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service';
import { QualityAssuranceTopicObject } from '../../../core/suggestion-notifications/qa/models/quality-assurance-topic.model';
import { Observable, concatMap, from, mergeMap } from 'rxjs';
import { QualityAssuranceEventObject } from '../../../core/suggestion-notifications/qa/models/quality-assurance-event.model';
import { Observable, tap } from 'rxjs';
import { AlertType } from '../../../shared/alert/aletr-type';
import { FindListOptions } from '../../../core/data/find-list-options.model';
import { RequestParam } from '../../../core/cache/models/request-param.model';
import { QualityAssuranceSourceDataService } from '../../../core/suggestion-notifications/qa/source/quality-assurance-source-data.service';
import { QualityAssuranceSourceObject } from '../../../core/suggestion-notifications/qa/models/quality-assurance-source.model';

@Component({
selector: 'ds-qa-event-notification',
templateUrl: './qa-event-notification.component.html',
styleUrls: ['./qa-event-notification.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [QualityAssuranceTopicDataService, QualityAssuranceEventDataService]
providers: [QualityAssuranceSourceDataService]
})
/**
* Component for displaying quality assurance event notifications for an item.
*/
export class QaEventNotificationComponent implements OnInit {
export class QaEventNotificationComponent {

/**
* The item to display quality assurance event notifications for.
*/
@Input() item: Item;

/**
* An observable of quality assurance events for the item.
*/
events$: Observable<QualityAssuranceEventObject[]>;

/**
* The type of alert to display for the notification.
*/
AlertTypeInfo = AlertType.Info;

/**
* The source of the quality assurance events.
*/
source = 'coar-notify';

constructor(
private qualityAssuranceEventDataService: QualityAssuranceEventDataService,
private qualityAssuranceTopicDataService: QualityAssuranceTopicDataService,
private qualityAssuranceSourceDataService: QualityAssuranceSourceDataService,
) { }

ngOnInit() {
this.getEventsByTopicsAndTarget();
}

/**
* Retrieves quality assurance events by topics and target.
* First, it retrieves the topics by target and source.
* -> target: item.id
* -> source: 'coar-notify'
* Then, it retrieves the events by topic and target.
* Returns an Observable of QualityAssuranceSourceObject[] for the current item.
* @returns An Observable of QualityAssuranceSourceObject[] for the current item.
* Note: sourceId is composed as: id: "sourceName:<target>"
*/
getEventsByTopicsAndTarget() {
getQualityAssuranceSources$(): Observable<QualityAssuranceSourceObject[]> {
const findListTopicOptions: FindListOptions = {
searchParams: [new RequestParam('source', this.source), new RequestParam('target', this.item.id)]
searchParams: [new RequestParam('target', this.item.uuid)]
};

this.events$ = this.qualityAssuranceTopicDataService.searchTopics(findListTopicOptions).pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
getPaginatedListPayload(),
mergeMap((topics: QualityAssuranceTopicObject[]) => {
return from(topics).pipe(
concatMap((topic: QualityAssuranceTopicObject) => {
const findListEventOptions: FindListOptions = {
searchParams: [new RequestParam('topic', topic.name), new RequestParam('target', this.item.id)]
};
return this.qualityAssuranceEventDataService.searchEventsByTopic(findListEventOptions);
} )
);
}),
return this.qualityAssuranceSourceDataService.getSourcesByTarget(findListTopicOptions)
.pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
getPaginatedListPayload(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
<ng-container *ngIf="(sources$ | async)?.length > 0">
<ng-container *ngFor="let source of (sources$ | async)" >
<div class="alert alert-info d-flex flex-row" *ngIf="source.totalEvents > 0">
<img class="notify-logo" src="assets/images/notify-coar-icon.png" alt="Repository logo">
<ng-container *ngFor="let source of sources$ | async">
<div
class="alert alert-info d-flex flex-row"
*ngIf="source.totalEvents > 0"
>
<img
class="source-logo"
src="assets/images/qa-{{ source.id }}-logo.png"
alt="{{ source.id }} logo"
/>
<div class="w-100 d-flex justify-content-between">
<div class="pl-4 align-self-center">{{'item.qa-event-notification.check.notification-info' | translate : {num: source.totalEvents} }} </div>
<button [routerLink]="['/admin/notifications/quality-assurance', source.id]" class="btn btn-primary align-self-center">{{'item.qa-event-notification-info.check.button' | translate }}</button>
<div class="pl-4 align-self-center">
{{
"mydspace.qa-event-notification.check.notification-info"
| translate : { num: source.totalEvents }
}}
</div>
<button
[routerLink]="['/admin/notifications/quality-assurance', source.id]"
class="btn btn-primary align-self-center"
>
{{ "mydspace.qa-event-notification-info.check.button" | translate }}
</button>
</div>
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

.notify-logo {
.source-logo {
max-height: var(--ds-header-logo-height);
}

Expand Down
4 changes: 3 additions & 1 deletion src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ import {
} from '../item-page/simple/field-components/specific-field/title/themed-item-page-field.component';
import { BitstreamListItemComponent } from './object-list/bitstream-list-item/bitstream-list-item.component';
import { NgxPaginationModule } from 'ngx-pagination';
import { SplitPipe } from './utils/split.pipe';

const MODULES = [
CommonModule,
Expand Down Expand Up @@ -323,7 +324,8 @@ const PIPES = [
ObjNgFor,
BrowserOnlyPipe,
MarkdownPipe,
ShortNumberPipe
ShortNumberPipe,
SplitPipe,
];

const COMPONENTS = [
Expand Down
12 changes: 12 additions & 0 deletions src/app/shared/utils/split.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'dsSplit'
})
export class SplitPipe implements PipeTransform {

transform(value: string, separator: string): string[] {
return value.split(separator);
}

}
4 changes: 4 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,10 @@

"item.qa-event-notification-info.check.button": "Check",

"mydspace.qa-event-notification.check.notification-info": "There are {{num}} pending review to check",

"mydspace.qa-event-notification-info.check.button": "Check",

"workflow-item.search.result.delete-supervision.modal.header": "Delete Supervision Order",

"workflow-item.search.result.delete-supervision.modal.info": "Are you sure you want to delete Supervision Order",
Expand Down
8 changes: 8 additions & 0 deletions src/assets/i18n/it.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3731,6 +3731,14 @@
// TODO New key - Add a translation
"item.qa-event-notification-info.check.button": "Check",

// "mydspace.qa-event-notification.check.notification-info": "There are {{num}} pending review to check",
// TODO New key - Add a translation
"mydspace.qa-event-notification.check.notification-info": "There are {{num}} pending review to check",

// "mydspace.qa-event-notification-info.check.button": "Check",
// TODO New key - Add a translation
"mydspace.qa-event-notification-info.check.button": "Check",

// "workflow-item.search.result.delete-supervision.modal.header": "Delete Supervision Order",
// TODO New key - Add a translation
"workflow-item.search.result.delete-supervision.modal.header": "Delete Supervision Order",
Expand Down
Binary file added src/assets/images/qa-coar-notify-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/qa-openaire-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d31dc4d

Please sign in to comment.