Merged in CST-11045 (pull request #978)

CST-11045

Approved-by: Andrea Bollini
This commit is contained in:
Alisa Ismailati
2023-11-03 18:28:59 +00:00
committed by Andrea Bollini
18 changed files with 761 additions and 28 deletions

View File

@@ -26,11 +26,13 @@ import { LdnService } from '../ldn-services-model/ldn-services.model';
import { PatchData, PatchDataImpl } from '../../../core/data/base/patch-data'; import { PatchData, PatchDataImpl } from '../../../core/data/base/patch-data';
import { ChangeAnalyzer } from '../../../core/data/change-analyzer'; import { ChangeAnalyzer } from '../../../core/data/change-analyzer';
import { Operation } from 'fast-json-patch'; import { Operation } from 'fast-json-patch';
import { RestRequestMethod } from 'src/app/core/data/rest-request-method'; import { RestRequestMethod } from '../../../core/data/rest-request-method';
import { CreateData, CreateDataImpl } from '../../../core/data/base/create-data'; import { CreateData, CreateDataImpl } from '../../../core/data/base/create-data';
import { ldnServiceConstrain } from '../ldn-services-model/ldn-service.constrain.model'; import { LdnServiceConstrain } from '../ldn-services-model/ldn-service.constrain.model';
import { getFirstCompletedRemoteData } from 'src/app/core/shared/operators'; import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { hasValue } from 'src/app/shared/empty.util'; import { hasValue } from '../../../shared/empty.util';
import { SearchDataImpl } from '../../../core/data/base/search-data';
import { RequestParam } from '../../../core/cache/models/request-param.model';
/** /**
* A service responsible for fetching/sending data from/to the REST API on the ldnservices endpoint * A service responsible for fetching/sending data from/to the REST API on the ldnservices endpoint
@@ -43,6 +45,9 @@ export class LdnServicesService extends IdentifiableDataService<LdnService> impl
private deleteData: DeleteDataImpl<LdnService>; private deleteData: DeleteDataImpl<LdnService>;
private patchData: PatchDataImpl<LdnService>; private patchData: PatchDataImpl<LdnService>;
private comparator: ChangeAnalyzer<LdnService>; private comparator: ChangeAnalyzer<LdnService>;
private searchData: SearchDataImpl<LdnService>;
private findByPatternEndpoint = 'byInboundPattern';
constructor( constructor(
protected requestService: RequestService, protected requestService: RequestService,
@@ -54,6 +59,7 @@ export class LdnServicesService extends IdentifiableDataService<LdnService> impl
super('ldnservices', requestService, rdbService, objectCache, halService); super('ldnservices', 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.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint);
this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint); this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint);
this.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive); this.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive);
@@ -84,6 +90,12 @@ export class LdnServicesService extends IdentifiableDataService<LdnService> impl
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
findByInboundPattern(pattern: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {
const params = [new RequestParam('pattern', pattern)];
const findListOptions = Object.assign(new FindListOptions(), options, { searchParams: params });
return this.searchData.searchBy(this.findByPatternEndpoint, findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> { public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.delete(objectId, copyVirtualMetadata); return this.deleteData.delete(objectId, copyVirtualMetadata);
} }
@@ -92,7 +104,7 @@ export class LdnServicesService extends IdentifiableDataService<LdnService> impl
return this.deleteData.deleteByHref(href, copyVirtualMetadata); return this.deleteData.deleteByHref(href, copyVirtualMetadata);
} }
public invoke(serviceName: string, serviceId: string, parameters: ldnServiceConstrain[], files: File[]): Observable<RemoteData<LdnService>> { public invoke(serviceName: string, serviceId: string, parameters: LdnServiceConstrain[], files: File[]): Observable<RemoteData<LdnService>> {
const requestId = this.requestService.generateRequestId(); const requestId = this.requestService.generateRequestId();
this.getBrowseEndpoint().pipe( this.getBrowseEndpoint().pipe(
take(1), take(1),
@@ -115,7 +127,7 @@ export class LdnServicesService extends IdentifiableDataService<LdnService> impl
); );
} }
private getInvocationFormData(constrain: ldnServiceConstrain[], files: File[]): FormData { private getInvocationFormData(constrain: LdnServiceConstrain[], files: File[]): FormData {
const form: FormData = new FormData(); const form: FormData = new FormData();
form.set('properties', JSON.stringify(constrain)); form.set('properties', JSON.stringify(constrain));
files.forEach((file: File) => { files.forEach((file: File) => {

View File

@@ -1,3 +1,3 @@
export class ldnServiceConstrain { export class LdnServiceConstrain {
void: any; void: any;
} }

View File

@@ -190,7 +190,11 @@ import { SuggestionSource } from './suggestion-notifications/reciter-suggestions
import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service'; import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service';
import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model'; import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model';
import { LdnItemfiltersService } from '../admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service'; import { LdnItemfiltersService } from '../admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service';
import { Itemfilter } from "../admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters"; import { Itemfilter } from '../admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters';
import {
CoarNotifyConfigDataService
} from '../submission/sections/section-coar-notify/coar-notify-config-data.service';
import { SubmissionCoarNotifyConfig } from '../submission/sections/section-coar-notify/submission-coar-notify.config';
/** /**
* When not in production, endpoint responses can be mocked for testing purposes * When not in production, endpoint responses can be mocked for testing purposes
@@ -315,7 +319,8 @@ const PROVIDERS = [
OrcidHistoryDataService, OrcidHistoryDataService,
SupervisionOrderDataService, SupervisionOrderDataService,
LdnServicesService, LdnServicesService,
LdnItemfiltersService LdnItemfiltersService,
CoarNotifyConfigDataService
]; ];
/** /**
@@ -398,7 +403,8 @@ export const models =
SuggestionTarget, SuggestionTarget,
SuggestionSource, SuggestionSource,
LdnService, LdnService,
Itemfilter Itemfilter,
SubmissionCoarNotifyConfig
]; ];

View File

@@ -26,3 +26,5 @@ export type WorkspaceitemSectionDataType
| WorkspaceitemSectionSherpaPoliciesObject | WorkspaceitemSectionSherpaPoliciesObject
| WorkspaceitemSectionIdentifiersObject | WorkspaceitemSectionIdentifiersObject
| string; | string;

View File

@@ -9,7 +9,8 @@
<div class="submission-form-header-item mb-3 mb-sm-0 flex-sm-grow-1 flex-md-grow-0"> <div class="submission-form-header-item mb-3 mb-sm-0 flex-sm-grow-1 flex-md-grow-0">
<ng-container *ngIf="!isSectionHidden"> <ng-container *ngIf="!isSectionHidden">
<ds-submission-form-collection [currentCollectionId]="collectionId" <ds-submission-form-collection
[currentCollectionId]="collectionId"
[currentDefinition]="definitionId" [currentDefinition]="definitionId"
[submissionId]="submissionId" [submissionId]="submissionId"
[collectionModifiable]="collectionModifiable" [collectionModifiable]="collectionModifiable"
@@ -30,10 +31,12 @@
<ng-container *ngFor="let object of (submissionSections | async)"> <ng-container *ngFor="let object of (submissionSections | async)">
<ds-submission-section-container [collectionId]="collectionId" <ds-submission-section-container [collectionId]="collectionId"
[submissionId]="submissionId" [submissionId]="submissionId"
[sectionData]="object"></ds-submission-section-container> [sectionData]="object">
</ds-submission-section-container>
</ng-container> </ng-container>
</div> </div>
<div *ngIf="!(isLoading() | async)" class="submission-form-footer mt-3 mb-3 position-sticky"> <div *ngIf="!(isLoading() | async)" class="submission-form-footer mt-3 mb-3 position-sticky">
<ds-submission-form-footer [submissionId]="submissionId"></ds-submission-form-footer> <ds-submission-form-footer [submissionId]="submissionId"></ds-submission-form-footer>
</div> </div>
</div> </div>

View File

@@ -48,4 +48,4 @@
</ng-template> </ng-template>
</ngb-panel> </ngb-panel>
</ngb-accordion> </ngb-accordion>
</div> </div>

View File

@@ -0,0 +1,122 @@
import { Injectable } from '@angular/core';
import { dataService } from '../../../core/data/base/data-service.decorator';
import { IdentifiableDataService } from '../../../core/data/base/identifiable-data.service';
import { FindAllData, FindAllDataImpl } from '../../../core/data/base/find-all-data';
import { DeleteData, DeleteDataImpl } from '../../../core/data/base/delete-data';
import { RequestService } from '../../../core/data/request.service';
import { RemoteDataBuildService } from '../../../core/cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
import { HALEndpointService } from '../../../core/shared/hal-endpoint.service';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { FindListOptions } from '../../../core/data/find-list-options.model';
import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
import { Observable } from 'rxjs';
import { RemoteData } from '../../../core/data/remote-data';
import { PaginatedList } from '../../../core/data/paginated-list.model';
import { NoContent } from '../../../core/shared/NoContent.model';
import { map, take } from 'rxjs/operators';
import { URLCombiner } from '../../../core/url-combiner/url-combiner';
import { MultipartPostRequest } from '../../../core/data/request.models';
import { RestRequest } from '../../../core/data/rest-request.model';
import { SUBMISSION_COAR_NOTIFY_CONFIG } from './section-coar-notify-service.resource-type';
import { SubmissionCoarNotifyConfig } from './submission-coar-notify.config';
import { CreateData, CreateDataImpl } from '../../../core/data/base/create-data';
import { PatchData, PatchDataImpl } from '../../../core/data/base/patch-data';
import { ChangeAnalyzer } from '../../../core/data/change-analyzer';
import { Operation } from 'fast-json-patch';
import { RestRequestMethod } from '../../../core/data/rest-request-method';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { hasValue } from '../../../shared/empty.util';
/**
* A service responsible for fetching/sending data from/to the REST API on the CoarNotifyConfig endpoint
*/
@Injectable()
@dataService(SUBMISSION_COAR_NOTIFY_CONFIG)
export class CoarNotifyConfigDataService extends IdentifiableDataService<SubmissionCoarNotifyConfig> implements FindAllData<SubmissionCoarNotifyConfig>, DeleteData<SubmissionCoarNotifyConfig>, PatchData<SubmissionCoarNotifyConfig>, CreateData<SubmissionCoarNotifyConfig> {
createData: CreateDataImpl<SubmissionCoarNotifyConfig>;
private findAllData: FindAllDataImpl<SubmissionCoarNotifyConfig>;
private deleteData: DeleteDataImpl<SubmissionCoarNotifyConfig>;
private patchData: PatchDataImpl<SubmissionCoarNotifyConfig>;
private comparator: ChangeAnalyzer<SubmissionCoarNotifyConfig>;
constructor(
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected notificationsService: NotificationsService,
) {
super('submissioncoarnotifyconfigs', requestService, rdbService, objectCache, halService);
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint);
this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint);
this.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive);
}
create(object: SubmissionCoarNotifyConfig): Observable<RemoteData<SubmissionCoarNotifyConfig>> {
return this.createData.create(object);
}
patch(object: SubmissionCoarNotifyConfig, operations: Operation[]): Observable<RemoteData<SubmissionCoarNotifyConfig>> {
return this.patchData.patch(object, operations);
}
update(object: SubmissionCoarNotifyConfig): Observable<RemoteData<SubmissionCoarNotifyConfig>> {
return this.patchData.update(object);
}
commitUpdates(method?: RestRequestMethod): void {
return this.patchData.commitUpdates(method);
}
createPatchFromCache(object: SubmissionCoarNotifyConfig): Observable<Operation[]> {
return this.patchData.createPatchFromCache(object);
}
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<SubmissionCoarNotifyConfig>[]): Observable<RemoteData<PaginatedList<SubmissionCoarNotifyConfig>>> {
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.delete(objectId, copyVirtualMetadata);
}
public deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
}
public invoke(serviceName: string, serviceId: string, files: File[]): Observable<RemoteData<SubmissionCoarNotifyConfig>> {
const requestId = this.requestService.generateRequestId();
this.getBrowseEndpoint().pipe(
take(1),
map((endpoint: string) => new URLCombiner(endpoint, serviceName, 'submissioncoarnotifyconfigmodel', serviceId).toString()),
map((endpoint: string) => {
const body = this.getInvocationFormData(files);
return new MultipartPostRequest(requestId, endpoint, body);
})
).subscribe((request: RestRequest) => this.requestService.send(request));
return this.rdbService.buildFromRequestUUID<SubmissionCoarNotifyConfig>(requestId);
}
public SubmissionCoarNotifyConfigModelWithNameExistsAndCanExecute(scriptName: string): Observable<boolean> {
return this.findById(scriptName).pipe(
getFirstCompletedRemoteData(),
map((rd: RemoteData<SubmissionCoarNotifyConfig>) => {
return hasValue(rd.payload);
}),
);
}
private getInvocationFormData(files: File[]): FormData {
const form: FormData = new FormData();
files.forEach((file: File) => {
form.append('file', file);
});
return form;
}
}

View File

@@ -0,0 +1,13 @@
/**
* The resource type for Ldn-Services
*
* Needs to be in a separate file to prevent circular
* dependencies in webpack.
*/
import { ResourceType } from '../../../core/shared/resource-type';
export const SUBMISSION_COAR_NOTIFY_CONFIG = new ResourceType('submissioncoarnotifyconfig');
export const COAR_NOTIFY_WORKSPACEITEM = new ResourceType('workspaceitem');

View File

@@ -0,0 +1,124 @@
<div class="container-fluid">
<ng-container *ngIf="patterns.length > 0">
<div *ngFor="let pattern of patterns; let i = index" class="col">
<label class="row col-form-label"
>
{{'submission.section.section-coar-notify.control.label' | translate : {pattern : pattern} }}
</label
>
<div
*ngFor="
let service of ldnServiceByPattern[pattern];
let serviceIndex = index
"
>
<div class="row">
<div ngbDropdown #myDropdown="ngbDropdown" class="w-100">
<div class="position-relative right-addon" role="combobox">
<i ngbDropdownToggle class="position-absolute scrollable-dropdown-toggle"
aria-hidden="true"></i>
<input
type="text"
[readonly]="true"
ngbDropdownAnchor
[ngClass]="{'border-danger': (getShownSectionErrors$(pattern, serviceIndex) | async)?.length > 0}"
class="form-control w-100 scrollable-dropdown-input"
[value]="ldnServiceByPattern[pattern][serviceIndex]?.name"
(click)="myDropdown.open()"
/>
</div>
<div
ngbDropdownMenu
class="dropdown-menu scrollable-dropdown-menu w-100"
aria-haspopup="true"
aria-expanded="false"
>
<div
class="scrollable-menu"
role="listbox"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="50"
[scrollWindow]="false"
>
<button
*ngIf="(filterServices(pattern) | async)?.length == 0"
class="dropdown-item collection-item text-truncate w-100"
>
{{'submission.section.section-coar-notify.dropdown.no-data' | translate}}
</button>
<button
*ngIf="(filterServices(pattern) | async)?.length > 0"
class="dropdown-item collection-item text-truncate w-100"
(click)="onChange(pattern, serviceIndex, null)"
>
{{'submission.section.section-coar-notify.dropdown.select-none' | translate}}
</button>
<button
*ngFor="let serviceOption of filterServices(pattern) | async"
[ngClass]="{'bg-light': ldnServiceByPattern[pattern][serviceIndex]?.id == serviceOption.id}"
class="dropdown-item collection-item text-truncate w-100"
(click)="onChange(pattern, serviceIndex, serviceOption)"
>
<b>
{{ serviceOption.name }}
</b>
<br />
{{ serviceOption.description }}
</button>
</div>
</div>
</div>
</div>
<small
class="row text-muted"
*ngIf="!ldnServiceByPattern[pattern][serviceIndex]"
>
{{'submission.section.section-coar-notify.small.notification' | translate : {pattern : pattern} }}
</small>
<ng-container *ngIf="(getShownSectionErrors$(pattern, serviceIndex) | async)?.length > 0">
<small class="row text-danger" *ngFor="let error of (getShownSectionErrors$(pattern, serviceIndex) | async)">
{{ error.message | translate}}
</small>
</ng-container>
<div
class="row mt-1"
*ngIf="ldnServiceByPattern[pattern][serviceIndex]"
>
<div
class="alert alert-info w-100 d-flex align-items-center flex-row"
>
<i class="fa-solid fa-circle-info fa-xl ml-2"></i>
<div class="ml-4">
<div>{{ 'submission.section.section-coar-notify.selection.description' | translate }}</div>
<div *ngIf="ldnServiceByPattern[pattern][serviceIndex]?.description; else noDesc">
{{ ldnServiceByPattern[pattern][serviceIndex].description }}
</div>
<ng-template #noDesc>
<span class="text-muted">
{{ 'submission.section.section-coar-notify.selection.no-description' | translate }}
</span>
</ng-template>
</div>
</div>
</div>
<div class="row" *ngIf="(getShownSectionErrors$(pattern, serviceIndex) | async)?.length > 0">
<div
class="alert alert-danger w-100 d-flex align-items-center flex-row"
>
<div class="ml-4">
<span>
{{ 'submission.section.section-coar-notify.notification.error' | translate }}
</span>
</div>
</div>
</div>
</div>
</div>
</ng-container>
<ng-container *ngIf="patterns.length === 0">
<p>
{{'submission.section.section-coar-notify.info.no-pattern' | translate }}
</p>
</ng-container>
</div>

View File

@@ -0,0 +1,4 @@
// Getting styles for NgbDropdown
@import '../../../shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.scss';
@import '../../../shared/form/form.component.scss';

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SubmissionSectionCoarNotifyComponent } from './section-coar-notify.component';
describe('LdnServiceComponent', () => {
let component: SubmissionSectionCoarNotifyComponent;
let fixture: ComponentFixture<SubmissionSectionCoarNotifyComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [SubmissionSectionCoarNotifyComponent]
})
.compileComponents();
fixture = TestBed.createComponent(SubmissionSectionCoarNotifyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,294 @@
import { ChangeDetectorRef, Component, Inject } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
import { SectionModelComponent } from '../models/section.model';
import { renderSectionFor } from '../sections-decorator';
import { SectionsType } from '../sections-type';
import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner';
import { SectionFormOperationsService } from '../form/section-form-operations.service';
import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder';
import { SectionsService } from '../sections.service';
import { SectionDataObject } from '../models/section-data.model';
import { hasNoValue, hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
import { getFirstCompletedRemoteData, getPaginatedListPayload, getRemoteDataPayload } from '../../../core/shared/operators';
import { LdnServicesService } from '../../../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service';
import { LdnService } from '../../../admin/admin-ldn-services/ldn-services-model/ldn-services.model';
import { CoarNotifyConfigDataService } from './coar-notify-config-data.service';
import { filter, map, take, tap } from 'rxjs/operators';
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap';
import { SubmissionSectionError } from '../../objects/submission-section-error.model';
/**
* This component represents a section that contains the submission section-coar-notify form.
*/
@Component({
selector: 'ds-submission-section-coar-notify',
templateUrl: './section-coar-notify.component.html',
styleUrls: ['./section-coar-notify.component.scss'],
providers: [NgbDropdown]
})
@renderSectionFor(SectionsType.CoarNotify)
export class SubmissionSectionCoarNotifyComponent extends SectionModelComponent {
/**
* Contains an array of string patterns.
*/
patterns: string[] = [];
/**
* An object that maps string keys to arrays of LdnService objects.
* Used to store LdnService objects by pattern.
*/
ldnServiceByPattern: { [key: string]: LdnService[] } = {};
/**
* A map representing all services for each pattern
* {
* 'pattern': {
* 'index': 'service.id'
* }
* }
*
* @type {{ [key: string]: {[key: number]: number} }}
* @memberof SubmissionSectionCoarNotifyComponent
*/
previousServices: { [key: string]: {[key: number]: number} } = {};
/**
* The [[JsonPatchOperationPathCombiner]] object
* @type {JsonPatchOperationPathCombiner}
*/
protected pathCombiner: JsonPatchOperationPathCombiner;
/**
* A map representing all field on their way to be removed
* @type {Map}
*/
protected fieldsOnTheirWayToBeRemoved: Map<string, number[]> = new Map();
/**
* Array to track all subscriptions and unsubscribe them onDestroy
* @type {Array}
*/
protected subs: Subscription[] = [];
constructor(protected ldnServicesService: LdnServicesService,
protected formOperationsService: SectionFormOperationsService,
protected operationsBuilder: JsonPatchOperationsBuilder,
protected sectionService: SectionsService,
protected coarNotifyConfigDataService: CoarNotifyConfigDataService,
protected chd: ChangeDetectorRef,
@Inject('collectionIdProvider') public injectedCollectionId: string,
@Inject('sectionDataProvider') public injectedSectionData: SectionDataObject,
@Inject('submissionIdProvider') public injectedSubmissionId: string) {
super(injectedCollectionId, injectedSectionData, injectedSubmissionId);
}
/**
* Initialize all instance variables
*/
onSectionInit() {
this.setCoarNotifyConfig();
this.getSectionServerErrorsAndSetErrorsToDisplay();
this.pathCombiner = new JsonPatchOperationPathCombiner('sections', this.sectionData.id);
}
/**
* Method called when section is initialized
* Retriev available NotifyConfigs
*/
setCoarNotifyConfig() {
this.subs.push(
this.coarNotifyConfigDataService.findAll().pipe(
getFirstCompletedRemoteData()
).subscribe((data) => {
if (data.hasSucceeded) {
this.patterns = data.payload.page[0].patterns;
this.initSelectedServicesByPattern();
}
}));
}
/**
* Handles the change event of a select element.
* @param pattern - The pattern of the select element.
* @param index - The index of the select element.
*/
onChange(pattern: string, index: number, selectedService: LdnService | null) {
// do nothing if the selected value is the same as the previous one
if (this.ldnServiceByPattern[pattern][index]?.id === selectedService?.id) {
return;
}
// initialize the previousServices object for the pattern if it does not exist
if (!this.previousServices[pattern]) {
this.previousServices[pattern] = {};
}
if (hasNoValue(selectedService)) {
// on value change, remove the path when the selected value is null
// and remove the previous value stored for the same index and pattern
this.operationsBuilder.remove(this.pathCombiner.getPath([pattern, index.toString()]));
this.sectionService.dispatchRemoveSectionErrors(this.submissionId, this.sectionData.id);
this.ldnServiceByPattern[pattern][index] = null;
this.previousServices[pattern][index] = null;
return;
}
// store the previous value
this.previousServices[pattern][index] = this.ldnServiceByPattern[pattern][index]?.id;
// set the new value
this.ldnServiceByPattern[pattern][index] = selectedService;
const hasPrevValueStored = hasValue(this.previousServices[pattern][index]) && this.previousServices[pattern][index] !== selectedService.id;
if (hasPrevValueStored) {
// replace the path
// when there is a previous value stored and it is different from the new one
this.operationsBuilder.replace(this.pathCombiner.getPath([pattern, index.toString()]), selectedService.id, true);
} else {
// add the path when there is no previous value stored
this.operationsBuilder.add(this.pathCombiner.getPath([pattern, '-']), [selectedService.id], false, true);
}
// set the previous value to the new value
this.previousServices[pattern][index] = this.ldnServiceByPattern[pattern][index].id;
this.sectionService.dispatchRemoveSectionErrors(this.submissionId, this.sectionData.id);
this.chd.detectChanges();
}
/**
* Initializes the selected services by pattern.
* Loops through each pattern and filters the services based on the pattern.
* If the section data has a value for the pattern, it adds the service to the selected services by pattern.
* If the section data does not have a value for the pattern, it adds a null service to the selected services by pattern,
* so that the select element is initialized with a null value and to display the default select input.
*/
initSelectedServicesByPattern(): void {
this.patterns.forEach((pattern) => {
if (hasValue(this.sectionData.data[pattern])) {
this.subs.push(
this.filterServices(pattern)
.subscribe((services: LdnService[]) => {
const selectedServices = services.filter((service) => {
const selection = (this.sectionData.data[pattern] as LdnService[]).find((s: LdnService) => s.id === service.id);
this.addService(pattern, selection);
return this.sectionData.data[pattern].includes(service.id);
});
this.ldnServiceByPattern[pattern] = selectedServices;
})
);
} else {
this.ldnServiceByPattern[pattern] = [];
this.addService(pattern, null);
}
});
}
/**
* Adds a new service to the selected services for the given pattern.
* @param pattern - The pattern to add the new service to.
* @param newService - The new service to add.
*/
addService(pattern: string, newService: LdnService) {
// Your logic to add a new service to the selected services for the pattern
// Example: Push the newService to the array corresponding to the pattern
if (!this.ldnServiceByPattern[pattern]) {
this.ldnServiceByPattern[pattern] = [];
}
this.ldnServiceByPattern[pattern].push(newService);
}
/**
* Removes the service at the specified index from the array corresponding to the pattern.
* (part of next phase of implementation)
*/
removeService(pattern: string, serviceIndex: number) {
if (this.ldnServiceByPattern[pattern]) {
// Remove the service at the specified index from the array
this.ldnServiceByPattern[pattern].splice(serviceIndex, 1);
}
}
/**
* Method called when dropdowns for the section are initialized
* Retrieve services with corresponding patterns to the dropdowns.
*/
filterServices(pattern: string): Observable<LdnService[]> {
return this.ldnServicesService.findByInboundPattern(pattern).pipe(
getFirstCompletedRemoteData(),
tap((rd) => {
if (rd.hasFailed) {
throw new Error(`Failed to retrieve services for pattern ${pattern}`);
}
}),
filter((rd) => rd.hasSucceeded),
getRemoteDataPayload(),
getPaginatedListPayload(),
map((res: LdnService[]) => res.filter((service) =>
this.hasInboundPattern(service, pattern)))
);
}
/**
* Checks if the given service has the specified inbound pattern type.
* @param service - The service to check.
* @param patternType - The inbound pattern type to look for.
* @returns True if the service has the specified inbound pattern type, false otherwise.
*/
hasInboundPattern(service: any, patternType: string): boolean {
return service.notifyServiceInboundPatterns.some((pattern: { pattern: string }) => {
return pattern.pattern === patternType;
});
}
/**
* Retrieves server errors for the current section and sets them to display.
* @returns An Observable that emits the validation errors for the current section.
*/
private getSectionServerErrorsAndSetErrorsToDisplay() {
this.subs.push(
this.sectionService.getSectionServerErrors(this.submissionId, this.sectionData.id).pipe(
take(1),
filter((validationErrors) => isNotEmpty(validationErrors)),
).subscribe((validationErrors: SubmissionSectionError[]) => {
if (isNotEmpty(validationErrors)) {
validationErrors.forEach((error) => {
this.sectionService.setSectionError(this.submissionId, this.sectionData.id, error);
});
}
}));
}
/**
* Returns an observable of the errors for the current section that match the given pattern and index.
* @param pattern - The pattern to match against the error paths.
* @param index - The index to match against the error paths.
* @returns An observable of the errors for the current section that match the given pattern and index.
*/
public getShownSectionErrors$(pattern: string, index: number): Observable<SubmissionSectionError[]> {
return this.sectionService.getShownSectionErrors(this.submissionId, this.sectionData.id, this.sectionData.sectionType)
.pipe(
take(1),
filter((validationErrors) => isNotEmpty(validationErrors)),
map((validationErrors: SubmissionSectionError[]) => {
return validationErrors.filter((error) => {
const path = `${pattern}/${index}`;
return error.path.includes(path);
});
})
);
}
/**
* @returns An observable that emits a boolean indicating whether the section has any server errors or not.
*/
protected getSectionStatus(): Observable<boolean> {
return this.sectionService.getSectionServerErrors(this.submissionId, this.sectionData.id).pipe(
map((validationErrors) => isEmpty(validationErrors)
));
}
/**
* Unsubscribe from all subscriptions
*/
onSectionDestroy() {
this.subs
.filter((subscription) => hasValue(subscription))
.forEach((subscription) => subscription.unsubscribe());
}
}

View File

@@ -0,0 +1,35 @@
import { CacheableObject } from '../../../core/cache/cacheable-object.model';
import { autoserialize, deserialize, deserializeAs, inheritSerialization } from 'cerialize';
import { excludeFromEquals } from '../../../core/utilities/equals.decorators';
import { typedObject } from '../../../core/cache/builders/build-decorators';
import { COAR_NOTIFY_WORKSPACEITEM } from './section-coar-notify-service.resource-type';
/** An CoarNotify and its properties. */
@typedObject
@inheritSerialization(CacheableObject)
export class SubmissionCoarNotifyWorkspaceitemModel extends CacheableObject {
static type = COAR_NOTIFY_WORKSPACEITEM;
@excludeFromEquals
@autoserialize
endorsement?: number[];
@deserializeAs('id')
review?: number[];
@autoserialize
ingest?: number[];
@deserialize
_links: {
self: {
href: string;
};
};
get self(): string {
return this._links.self.href;
}
}

View File

@@ -0,0 +1,39 @@
import { ResourceType } from '../../../core/shared/resource-type';
import { CacheableObject } from '../../../core/cache/cacheable-object.model';
import { autoserialize, deserialize, deserializeAs, inheritSerialization } from 'cerialize';
import { excludeFromEquals } from '../../../core/utilities/equals.decorators';
import { typedObject } from '../../../core/cache/builders/build-decorators';
import { SUBMISSION_COAR_NOTIFY_CONFIG } from './section-coar-notify-service.resource-type';
/** A SubmissionCoarNotifyConfig and its properties. */
@typedObject
@inheritSerialization(CacheableObject)
export class SubmissionCoarNotifyConfig extends CacheableObject {
static type = SUBMISSION_COAR_NOTIFY_CONFIG;
@excludeFromEquals
@autoserialize
type: ResourceType;
@autoserialize
id: string;
@deserializeAs('id')
uuid: string;
@autoserialize
patterns: string[];
@deserialize
_links: {
self: {
href: string;
};
};
get self(): string {
return this._links.self.href;
}
}

View File

@@ -9,4 +9,5 @@ export enum SectionsType {
SherpaPolicies = 'sherpaPolicy', SherpaPolicies = 'sherpaPolicy',
Identifiers = 'identifiers', Identifiers = 'identifiers',
Collection = 'collection', Collection = 'collection',
CoarNotify = 'coarnotify'
} }

View File

@@ -10,7 +10,7 @@ import { SubmissionFormFooterComponent } from './form/footer/submission-form-foo
import { SubmissionFormComponent } from './form/submission-form.component'; import { SubmissionFormComponent } from './form/submission-form.component';
import { SubmissionFormSectionAddComponent } from './form/section-add/submission-form-section-add.component'; import { SubmissionFormSectionAddComponent } from './form/section-add/submission-form-section-add.component';
import { SubmissionSectionContainerComponent } from './sections/container/section-container.component'; import { SubmissionSectionContainerComponent } from './sections/container/section-container.component';
import { CommonModule } from '@angular/common'; import { CommonModule, NgOptimizedImage } from '@angular/common';
import { Action, StoreConfig, StoreModule } from '@ngrx/store'; import { Action, StoreConfig, StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects'; import { EffectsModule } from '@ngrx/effects';
import { submissionReducers, SubmissionState } from './submission.reducers'; import { submissionReducers, SubmissionState } from './submission.reducers';
@@ -67,6 +67,11 @@ import {
} from './sections/sherpa-policies/metadata-information/metadata-information.component'; } from './sections/sherpa-policies/metadata-information/metadata-information.component';
import { SectionFormOperationsService } from './sections/form/section-form-operations.service'; import { SectionFormOperationsService } from './sections/form/section-form-operations.service';
import {SubmissionSectionIdentifiersComponent} from './sections/identifiers/section-identifiers.component'; import {SubmissionSectionIdentifiersComponent} from './sections/identifiers/section-identifiers.component';
import { SubmissionSectionCoarNotifyComponent } from './sections/section-coar-notify/section-coar-notify.component';
import {
CoarNotifyConfigDataService
} from './sections/section-coar-notify/coar-notify-config-data.service';
import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service';
const ENTRY_COMPONENTS = [ const ENTRY_COMPONENTS = [
// put only entry components that use custom decorator // put only entry components that use custom decorator
@@ -76,6 +81,7 @@ const ENTRY_COMPONENTS = [
SubmissionSectionCcLicensesComponent, SubmissionSectionCcLicensesComponent,
SubmissionSectionAccessesComponent, SubmissionSectionAccessesComponent,
SubmissionSectionSherpaPoliciesComponent, SubmissionSectionSherpaPoliciesComponent,
SubmissionSectionCoarNotifyComponent
]; ];
const DECLARATIONS = [ const DECLARATIONS = [
@@ -109,20 +115,22 @@ const DECLARATIONS = [
]; ];
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
CoreModule.forRoot(), CoreModule.forRoot(),
SharedModule, SharedModule,
StoreModule.forFeature('submission', submissionReducers, storeModuleConfig as StoreConfig<SubmissionState, Action>), StoreModule.forFeature('submission', submissionReducers, storeModuleConfig as StoreConfig<SubmissionState, Action>),
EffectsModule.forFeature(submissionEffects), EffectsModule.forFeature(),
JournalEntitiesModule.withEntryComponents(), EffectsModule.forFeature(submissionEffects),
ResearchEntitiesModule.withEntryComponents(), JournalEntitiesModule.withEntryComponents(),
FormModule, ResearchEntitiesModule.withEntryComponents(),
NgbModalModule, FormModule,
NgbCollapseModule, NgbModalModule,
NgbAccordionModule, NgbCollapseModule,
UploadModule, NgbAccordionModule,
], UploadModule,
NgOptimizedImage,
],
declarations: DECLARATIONS, declarations: DECLARATIONS,
exports: [ exports: [
...DECLARATIONS, ...DECLARATIONS,
@@ -135,6 +143,8 @@ const DECLARATIONS = [
SubmissionAccessesConfigDataService, SubmissionAccessesConfigDataService,
SectionAccessesService, SectionAccessesService,
SectionFormOperationsService, SectionFormOperationsService,
CoarNotifyConfigDataService,
LdnServicesService
] ]
}) })

View File

@@ -1982,6 +1982,8 @@
"info.coar-notify.breadcrumbs": "Notify Support", "info.coar-notify.breadcrumbs": "Notify Support",
"submission.sections.notify.info": "The selected service is compatible with the item according to its current status. {{ service.name }}: {{ service.description }}",
"info.feedback.head": "Feedback", "info.feedback.head": "Feedback",
"info.feedback.title": "Feedback", "info.feedback.title": "Feedback",
@@ -4766,6 +4768,8 @@
"submission.sections.submit.progressbar.sherpaPolicies": "Publisher open access policy information", "submission.sections.submit.progressbar.sherpaPolicies": "Publisher open access policy information",
"submission.sections.submit.progressbar.coarnotify": "COAR Notify",
"submission.sections.sherpa-policy.title-empty": "No publisher policy information available. If your work has an associated ISSN, please enter it above to see any related publisher open access policies.", "submission.sections.sherpa-policy.title-empty": "No publisher policy information available. If your work has an associated ISSN, please enter it above to see any related publisher open access policies.",
"submission.sections.status.errors.title": "Errors", "submission.sections.status.errors.title": "Errors",
@@ -5012,6 +5016,24 @@
"submission.workspace.generic.view-help": "Select this option to view the item's metadata.", "submission.workspace.generic.view-help": "Select this option to view the item's metadata.",
"submission.section.section-coar-notify.control.label": "Request {{ pattern }} at the following services",
"submission.section.section-coar-notify.dropdown.no-data": "No data available",
"submission.section.section-coar-notify.dropdown.select-none": "Select none",
"submission.section.section-coar-notify.small.notification": "Select a service for {{ pattern }} of this item",
"submission.section.section-coar-notify.selection.description": "Selected service's description:",
"submission.section.section-coar-notify.selection.no-description": "No further information is available",
"submission.section.section-coar-notify.notification.error": "The selected service is not suitable for the current item. Please check the description for details about which record can be managed by this service.",
"submission.section.section-coar-notify.info.no-pattern": "No patterns found in the submission.",
"error.validation.coarnotify.invalidfilter": "Invalid filter, try to select another service or none.",
"submitter.empty": "N/A", "submitter.empty": "N/A",
"subscriptions.title": "Subscriptions", "subscriptions.title": "Subscriptions",

View File

@@ -7461,6 +7461,29 @@
// "submission.workspace.generic.view-help": "Select this option to view the item's metadata.", // "submission.workspace.generic.view-help": "Select this option to view the item's metadata.",
"submission.workspace.generic.view-help": "Seleziona questa opzione per vedere i metadata dell'item.", "submission.workspace.generic.view-help": "Seleziona questa opzione per vedere i metadata dell'item.",
// "submission.section.section-coar-notify.control.label": "Request {{ pattern }} at the following services",
// TODO New key - a translation
"submission.section.section-coar-notify.control.label": "Request {{ pattern }} at the following services",
// "submission.section.section-coar-notify.dropdown.no-data": "No data available",
// TODO New key - a translation
"submission.section.section-coar-notify.dropdown.no-data": "No data available",
// "submission.section.section-coar-notify.dropdown.select-none": "Select none",
// TODO New key - a translation
"submission.section.section-coar-notify.dropdown.select-none": "Select none",
// "submission.section.section-coar-notify.small.notification": "Select a service for {{ pattern }} of this item",
// TODO New key - a translation
"submission.section.section-coar-notify.small.notification": "Select a service for {{ pattern }} of this item",
// "submission.section.section-coar-notify.selection.description": "Selected service's description:",
// TODO New key - a translation
"submission.section.section-coar-notify.selection.description": "Selected service's description:",
// "submission.section.section-coar-notify.notification.error": "The selected service is not suitable for the current item.Please check the description for details about which record can be managed by this service.",
// TODO New key - a translation
"submission.section.section-coar-notify.notification.error": "The selected service is not suitable for the current item.Please check the description for details about which record can be managed by this service.",
// "subscriptions.title": "Subscriptions", // "subscriptions.title": "Subscriptions",
"subscriptions.title": "Sottoscrizioni", "subscriptions.title": "Sottoscrizioni",