[CST-12145] get qa-sources by target for item-page & refactor

This commit is contained in:
Alisa Ismailati
2023-11-02 17:49:19 +01:00
parent 8e0af9bcee
commit d31dc4d5fd
12 changed files with 94 additions and 61 deletions

View File

@@ -16,6 +16,7 @@ import { PaginatedList } from '../../../data/paginated-list.model';
import { FindListOptions } from '../../../data/find-list-options.model'; import { FindListOptions } from '../../../data/find-list-options.model';
import { IdentifiableDataService } from '../../../data/base/identifiable-data.service'; import { IdentifiableDataService } from '../../../data/base/identifiable-data.service';
import { FindAllData, FindAllDataImpl } from '../../../data/base/find-all-data'; 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. * The service handling all Quality Assurance source REST requests.
@@ -25,6 +26,9 @@ import { FindAllData, FindAllDataImpl } from '../../../data/base/find-all-data';
export class QualityAssuranceSourceDataService extends IdentifiableDataService<QualityAssuranceSourceObject> { export class QualityAssuranceSourceDataService extends IdentifiableDataService<QualityAssuranceSourceObject> {
private findAllData: FindAllData<QualityAssuranceSourceObject>; private findAllData: FindAllData<QualityAssuranceSourceObject>;
private searchAllData: SearchData<QualityAssuranceSourceObject>;
private searchByTargetMethod = 'byTarget';
/** /**
* Initialize service variables * Initialize service variables
@@ -43,6 +47,7 @@ export class QualityAssuranceSourceDataService extends IdentifiableDataService<Q
) { ) {
super('qualityassurancesources', requestService, rdbService, objectCache, halService); super('qualityassurancesources', requestService, rdbService, objectCache, halService);
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
this.searchAllData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
} }
/** /**
@@ -84,4 +89,16 @@ export class QualityAssuranceSourceDataService extends IdentifiableDataService<Q
public getSource(id: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceSourceObject>[]): Observable<RemoteData<QualityAssuranceSourceObject>> { public getSource(id: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceSourceObject>[]): Observable<RemoteData<QualityAssuranceSourceObject>> {
return this.findById(id, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); 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);
}
} }

View File

@@ -1,9 +1,14 @@
<ng-container *ngIf="(events$ | async)?.length > 0"> <ng-container *ngIf="(getQualityAssuranceSources$() | async)?.length > 0">
<div class="alert alert-info d-flex flex-row"> <ng-container *ngFor="let source of (getQualityAssuranceSources$() | async)">
<img class="notify-logo" src="assets/images/notify-coar-icon.png" alt="Repository logo"> <div class="alert alert-info d-flex flex-row" *ngIf="source.totalEvents > 0">
<div class="w-100 d-flex justify-content-between"> <img class="source-logo" src="assets/images/qa-{{(source.id | dsSplit: ':')[0]}}-logo.png" alt="{{source.id}} logo">
<div class="pl-4 align-self-center">{{'item.qa-event-notification.check.notification-info' | translate : {num: (events$ | async)?.length} }} </div> <div class="w-100 d-flex justify-content-between">
<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 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>
</div> </ng-container>
</ng-container> </ng-container>

View File

@@ -1,5 +1,5 @@
.notify-logo { .source-logo {
max-height: var(--ds-header-logo-height); max-height: var(--ds-header-logo-height);
} }

View File

@@ -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 { Item } from '../../../core/shared/item.model';
import { getFirstCompletedRemoteData, getPaginatedListPayload, getRemoteDataPayload } from '../../../core/shared/operators'; import { getFirstCompletedRemoteData, getPaginatedListPayload, getRemoteDataPayload } from '../../../core/shared/operators';
import { QualityAssuranceEventDataService } from '../../../core/suggestion-notifications/qa/events/quality-assurance-event-data.service'; import { Observable, tap } from 'rxjs';
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 { AlertType } from '../../../shared/alert/aletr-type'; import { AlertType } from '../../../shared/alert/aletr-type';
import { FindListOptions } from '../../../core/data/find-list-options.model'; import { FindListOptions } from '../../../core/data/find-list-options.model';
import { RequestParam } from '../../../core/cache/models/request-param.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({ @Component({
selector: 'ds-qa-event-notification', selector: 'ds-qa-event-notification',
templateUrl: './qa-event-notification.component.html', templateUrl: './qa-event-notification.component.html',
styleUrls: ['./qa-event-notification.component.scss'], styleUrls: ['./qa-event-notification.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
providers: [QualityAssuranceTopicDataService, QualityAssuranceEventDataService] providers: [QualityAssuranceSourceDataService]
}) })
/** /**
* Component for displaying quality assurance event notifications for an item. * 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. * The item to display quality assurance event notifications for.
*/ */
@Input() item: Item; @Input() item: Item;
/**
* An observable of quality assurance events for the item.
*/
events$: Observable<QualityAssuranceEventObject[]>;
/** /**
* The type of alert to display for the notification. * The type of alert to display for the notification.
*/ */
AlertTypeInfo = AlertType.Info; AlertTypeInfo = AlertType.Info;
/**
* The source of the quality assurance events.
*/
source = 'coar-notify';
constructor( constructor(
private qualityAssuranceEventDataService: QualityAssuranceEventDataService, private qualityAssuranceSourceDataService: QualityAssuranceSourceDataService,
private qualityAssuranceTopicDataService: QualityAssuranceTopicDataService,
) { } ) { }
ngOnInit() {
this.getEventsByTopicsAndTarget();
}
/** /**
* Retrieves quality assurance events by topics and target. * Returns an Observable of QualityAssuranceSourceObject[] for the current item.
* First, it retrieves the topics by target and source. * @returns An Observable of QualityAssuranceSourceObject[] for the current item.
* -> target: item.id * Note: sourceId is composed as: id: "sourceName:<target>"
* -> source: 'coar-notify'
* Then, it retrieves the events by topic and target.
*/ */
getEventsByTopicsAndTarget() { getQualityAssuranceSources$(): Observable<QualityAssuranceSourceObject[]> {
const findListTopicOptions: FindListOptions = { const findListTopicOptions: FindListOptions = {
searchParams: [new RequestParam('source', this.source), new RequestParam('target', this.item.id)] searchParams: [new RequestParam('target', this.item.uuid)]
}; };
return this.qualityAssuranceSourceDataService.getSourcesByTarget(findListTopicOptions)
this.events$ = this.qualityAssuranceTopicDataService.searchTopics(findListTopicOptions).pipe( .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);
} )
);
}),
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
getRemoteDataPayload(), getRemoteDataPayload(),
getPaginatedListPayload(), getPaginatedListPayload(),

View File

@@ -1,10 +1,27 @@
<ng-container *ngIf="(sources$ | async)?.length > 0"> <ng-container *ngIf="(sources$ | async)?.length > 0">
<ng-container *ngFor="let source of (sources$ | async)" > <ng-container *ngFor="let source of sources$ | async">
<div class="alert alert-info d-flex flex-row" *ngIf="source.totalEvents > 0"> <div
<img class="notify-logo" src="assets/images/notify-coar-icon.png" alt="Repository logo"> 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="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> <div class="pl-4 align-self-center">
<button [routerLink]="['/admin/notifications/quality-assurance', source.id]" class="btn btn-primary align-self-center">{{'item.qa-event-notification-info.check.button' | translate }}</button> {{
"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>
</div> </div>
</ng-container> </ng-container>

View File

@@ -1,5 +1,5 @@
.notify-logo { .source-logo {
max-height: var(--ds-header-logo-height); max-height: var(--ds-header-logo-height);
} }

View File

@@ -284,6 +284,7 @@ import {
} from '../item-page/simple/field-components/specific-field/title/themed-item-page-field.component'; } 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 { BitstreamListItemComponent } from './object-list/bitstream-list-item/bitstream-list-item.component';
import { NgxPaginationModule } from 'ngx-pagination'; import { NgxPaginationModule } from 'ngx-pagination';
import { SplitPipe } from './utils/split.pipe';
const MODULES = [ const MODULES = [
CommonModule, CommonModule,
@@ -323,7 +324,8 @@ const PIPES = [
ObjNgFor, ObjNgFor,
BrowserOnlyPipe, BrowserOnlyPipe,
MarkdownPipe, MarkdownPipe,
ShortNumberPipe ShortNumberPipe,
SplitPipe,
]; ];
const COMPONENTS = [ const COMPONENTS = [

View File

@@ -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);
}
}

View File

@@ -2452,6 +2452,10 @@
"item.qa-event-notification-info.check.button": "Check", "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.header": "Delete Supervision Order",
"workflow-item.search.result.delete-supervision.modal.info": "Are you sure you want to delete Supervision Order", "workflow-item.search.result.delete-supervision.modal.info": "Are you sure you want to delete Supervision Order",

View File

@@ -3731,6 +3731,14 @@
// TODO New key - Add a translation // TODO New key - Add a translation
"item.qa-event-notification-info.check.button": "Check", "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", // "workflow-item.search.result.delete-supervision.modal.header": "Delete Supervision Order",
// TODO New key - Add a translation // TODO New key - Add a translation
"workflow-item.search.result.delete-supervision.modal.header": "Delete Supervision Order", "workflow-item.search.result.delete-supervision.modal.header": "Delete Supervision Order",

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB