mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge branch 'DSpace:main' into main
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { LdnServicesOverviewComponent } from './ldn-services-directory/ldn-services-directory.component';
|
||||
import { NavigationBreadcrumbResolver } from '../../core/breadcrumbs/navigation-breadcrumb.resolver';
|
||||
import { I18nBreadcrumbResolver } from '../../core/breadcrumbs/i18n-breadcrumb.resolver';
|
||||
import { LdnServiceFormComponent } from './ldn-service-form/ldn-service-form.component';
|
||||
|
||||
|
||||
const moduleRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
pathMatch: 'full',
|
||||
component: LdnServicesOverviewComponent,
|
||||
resolve: {breadcrumb: I18nBreadcrumbResolver},
|
||||
data: {title: 'ldn-registered-services.title', breadcrumbKey: 'ldn-registered-services.new'},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
resolve: {breadcrumb: NavigationBreadcrumbResolver},
|
||||
component: LdnServiceFormComponent,
|
||||
data: {title: 'ldn-register-new-service.title', breadcrumbKey: 'ldn-register-new-service'}
|
||||
},
|
||||
{
|
||||
path: 'edit/:serviceId',
|
||||
resolve: {breadcrumb: NavigationBreadcrumbResolver},
|
||||
component: LdnServiceFormComponent,
|
||||
data: {title: 'ldn-edit-service.title', breadcrumbKey: 'ldn-edit-service'}
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild(moduleRoutes.map(route => {
|
||||
return {...route, data: {
|
||||
...route.data,
|
||||
relatedRoutes: moduleRoutes.filter(relatedRoute => relatedRoute.path !== route.path)
|
||||
.map((relatedRoute) => {
|
||||
return {path: relatedRoute.path, data: relatedRoute.data};
|
||||
})
|
||||
}};
|
||||
}))
|
||||
]
|
||||
})
|
||||
export class AdminLdnServicesRoutingModule {
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { AdminLdnServicesRoutingModule } from './admin-ldn-services-routing.module';
|
||||
import { LdnServicesOverviewComponent } from './ldn-services-directory/ldn-services-directory.component';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { LdnServiceFormComponent } from './ldn-service-form/ldn-service-form.component';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { LdnItemfiltersService } from './ldn-services-data/ldn-itemfilters-data.service';
|
||||
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
SharedModule,
|
||||
AdminLdnServicesRoutingModule,
|
||||
FormsModule
|
||||
],
|
||||
declarations: [
|
||||
LdnServicesOverviewComponent,
|
||||
LdnServiceFormComponent,
|
||||
],
|
||||
providers: [LdnItemfiltersService]
|
||||
})
|
||||
export class AdminLdnServicesModule {
|
||||
}
|
@@ -0,0 +1,310 @@
|
||||
<div class="container">
|
||||
<form (ngSubmit)="onSubmit()" [formGroup]="formModel">
|
||||
<div class="d-flex">
|
||||
<h1 class="flex-grow-1">{{ isNewService ? ('ldn-create-service.title' | translate) : ('ldn-edit-registered-service.title' | translate) }}</h1>
|
||||
</div>
|
||||
<!-- In the toggle section -->
|
||||
<div class="toggle-switch-container" *ngIf="!isNewService">
|
||||
<label class="status-label font-weight-bold" for="enabled">{{ 'ldn-service-status' | translate }}</label>
|
||||
<div>
|
||||
<input formControlName="enabled" hidden id="enabled" name="enabled" type="checkbox">
|
||||
<div (click)="toggleEnabled()" [class.checked]="formModel.get('enabled').value" class="toggle-switch">
|
||||
<div class="slider"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- In the Name section -->
|
||||
<div class="mb-5">
|
||||
<label for="name" class="font-weight-bold">{{ 'ldn-new-service.form.label.name' | translate }}</label>
|
||||
<input [class.invalid-field]="formModel.get('name').invalid && formModel.get('name').touched"
|
||||
[placeholder]="'ldn-new-service.form.placeholder.name' | translate" class="form-control"
|
||||
formControlName="name"
|
||||
id="name"
|
||||
name="name"
|
||||
type="text">
|
||||
<div *ngIf="formModel.get('name').invalid && formModel.get('name').touched" class="error-text">
|
||||
{{ 'ldn-new-service.form.error.name' | translate }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- In the description section -->
|
||||
<div class="mb-5 mt-5 d-flex flex-column">
|
||||
<label for="description" class="font-weight-bold">{{ 'ldn-new-service.form.label.description' | translate }}</label>
|
||||
<textarea [placeholder]="'ldn-new-service.form.placeholder.description' | translate"
|
||||
class="form-control" formControlName="description" id="description" name="description"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-5 mt-5">
|
||||
<!-- In the url section -->
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="d-flex flex-column w-50 mr-2">
|
||||
<label for="url" class="font-weight-bold">{{ 'ldn-new-service.form.label.url' | translate }}</label>
|
||||
<input [class.invalid-field]="formModel.get('url').invalid && formModel.get('url').touched"
|
||||
[placeholder]="'ldn-new-service.form.placeholder.url' | translate" class="form-control"
|
||||
formControlName="url"
|
||||
id="url"
|
||||
name="url"
|
||||
type="text">
|
||||
<div *ngIf="formModel.get('url').invalid && formModel.get('url').touched" class="error-text">
|
||||
{{ 'ldn-new-service.form.error.url' | translate }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-column w-50">
|
||||
<label for="score" class="font-weight-bold">{{ 'ldn-new-service.form.label.score' | translate }}</label>
|
||||
<input [class.invalid-field]="formModel.get('score').invalid && formModel.get('score').touched"
|
||||
[placeholder]="'ldn-new-service.form.placeholder.score' | translate" formControlName="score"
|
||||
id="score"
|
||||
name="score"
|
||||
min="0"
|
||||
max="1"
|
||||
step=".01"
|
||||
class="form-control"
|
||||
type="number">
|
||||
<div *ngIf="formModel.get('score').invalid && formModel.get('score').touched" class="error-text">
|
||||
{{ 'ldn-new-service.form.error.score' | translate }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- In the IP range section -->
|
||||
<div class="mb-5 mt-5">
|
||||
<label for="lowerIp" class="font-weight-bold">{{ 'ldn-new-service.form.label.ip-range' | translate }}</label>
|
||||
<div class="d-flex">
|
||||
<input [class.invalid-field]="formModel.get('lowerIp').invalid && formModel.get('lowerIp').touched"
|
||||
[placeholder]="'ldn-new-service.form.placeholder.lowerIp' | translate" class="form-control mr-2"
|
||||
formControlName="lowerIp"
|
||||
id="lowerIp"
|
||||
name="lowerIp"
|
||||
type="text">
|
||||
<input [class.invalid-field]="formModel.get('upperIp').invalid && formModel.get('upperIp').touched"
|
||||
[placeholder]="'ldn-new-service.form.placeholder.upperIp' | translate" class="form-control"
|
||||
formControlName="upperIp"
|
||||
id="upperIp"
|
||||
name="upperIp"
|
||||
type="text">
|
||||
</div>
|
||||
<div *ngIf="(formModel.get('lowerIp').invalid && formModel.get('lowerIp').touched) || (formModel.get('upperIp').invalid && formModel.get('upperIp').touched)" class="error-text">
|
||||
{{ 'ldn-new-service.form.error.ipRange' | translate }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
{{ 'ldn-new-service.form.hint.ipRange' | translate }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- In the ldnUrl section -->
|
||||
<div class="mb-5 mt-5">
|
||||
<label for="ldnUrl" class="font-weight-bold">{{ 'ldn-new-service.form.label.ldnUrl' | translate }}</label>
|
||||
<input [class.invalid-field]="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched"
|
||||
[placeholder]="'ldn-new-service.form.placeholder.ldnUrl' | translate" class="form-control"
|
||||
formControlName="ldnUrl"
|
||||
id="ldnUrl"
|
||||
name="ldnUrl"
|
||||
type="text">
|
||||
<div *ngIf="formModel.get('ldnUrl').invalid && formModel.get('ldnUrl').touched" class="error-text">
|
||||
{{ 'ldn-new-service.form.error.ldnurl' | translate }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- In the Inbound Patterns Labels section -->
|
||||
<div class="row mb-1 mt-5" *ngIf="areControlsInitialized">
|
||||
<div class="col">
|
||||
<label class="font-weight-bold">{{ 'ldn-new-service.form.label.inboundPattern' | translate }} </label>
|
||||
</div>
|
||||
<ng-container *ngIf="formModel.get('notifyServiceInboundPatterns')['controls'][0]?.value?.pattern">
|
||||
<div class="col">
|
||||
<label class="font-weight-bold">{{ 'ldn-new-service.form.label.ItemFilter' | translate }}</label>
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<label class="font-weight-bold">{{ 'ldn-new-service.form.label.automatic' | translate }}</label>
|
||||
</div>
|
||||
</ng-container>
|
||||
<div class="col-sm-2">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- In the Inbound Patterns section -->
|
||||
<div *ngIf="areControlsInitialized">
|
||||
<div *ngFor="let patternGroup of formModel.get('notifyServiceInboundPatterns')['controls']; let i = index"
|
||||
[class.marked-for-deletion]="markedForDeletionInboundPattern.includes(i)"
|
||||
formGroupName="notifyServiceInboundPatterns">
|
||||
|
||||
<ng-container [formGroupName]="i">
|
||||
|
||||
|
||||
<div class="row mb-1 align-items-center">
|
||||
<div class="col">
|
||||
<div #inboundPatternDropdown="ngbDropdown" class="w-80" display="dynamic"
|
||||
id="additionalInboundPattern{{i}}"
|
||||
ngbDropdown placement="top-start">
|
||||
<div class="position-relative right-addon" role="combobox" aria-expanded="false" aria-controls="inboundPatternDropdownButton">
|
||||
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
|
||||
ngbDropdownToggle></i>
|
||||
<input
|
||||
(click)="inboundPatternDropdown.open();"
|
||||
[readonly]="true"
|
||||
[value]="selectedInboundPatterns"
|
||||
class="form-control w-80 scrollable-dropdown-input"
|
||||
formControlName="patternLabel"
|
||||
id="inboundPatternDropdownButton"
|
||||
ngbDropdownAnchor
|
||||
type="text"
|
||||
[attr.aria-label]="'ldn-service-input-inbound-pattern-dropdown' | translate"
|
||||
/>
|
||||
<div aria-labelledby="inboundPatternDropdownButton"
|
||||
class="dropdown-menu dropdown-menu-top w-100 "
|
||||
ngbDropdownMenu>
|
||||
<div class="scrollable-menu" role="listbox">
|
||||
<button (click)="selectInboundPattern(pattern, i); $event.stopPropagation()"
|
||||
*ngFor="let pattern of inboundPatterns; let internalIndex = index"
|
||||
[title]="'ldn-service.form.pattern.' + pattern + '.description' | translate"
|
||||
class="dropdown-item collection-item text-truncate w-100"
|
||||
ngbDropdownItem
|
||||
type="button">
|
||||
<div>{{ 'ldn-service.form.pattern.' + pattern + '.label' | translate }}</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<ng-container
|
||||
*ngIf="formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern">
|
||||
<div #inboundItemfilterDropdown="ngbDropdown" class="w-100" id="constraint{{i}}" ngbDropdown
|
||||
placement="top-start">
|
||||
<div class="position-relative right-addon" aria-expanded="false" aria-controls="inboundItemfilterDropdown" role="combobox">
|
||||
<i aria-hidden="true" class="position-absolute scrollable-dropdown-toggle"
|
||||
ngbDropdownToggle></i>
|
||||
<input
|
||||
[readonly]="true"
|
||||
class="form-control d-none w-100 scrollable-dropdown-input"
|
||||
formControlName="constraint"
|
||||
id="inboundItemfilterDropdown"
|
||||
ngbDropdownAnchor
|
||||
type="text"
|
||||
[attr.aria-label]="'ldn-service-input-inbound-item-filter-dropdown' | translate"
|
||||
/>
|
||||
<input
|
||||
(click)="inboundItemfilterDropdown.open();"
|
||||
[readonly]="true"
|
||||
class="form-control w-100 scrollable-dropdown-input"
|
||||
formControlName="constraintFormatted"
|
||||
id="inboundItemfilterDropdownPrettified"
|
||||
ngbDropdownAnchor
|
||||
type="text"
|
||||
[attr.aria-label]="'ldn-service-input-inbound-item-filter-dropdown' | translate"
|
||||
/>
|
||||
<div aria-labelledby="inboundItemfilterDropdownButton"
|
||||
class="dropdown-menu scrollable-dropdown-menu w-100 "
|
||||
ngbDropdownMenu>
|
||||
<div class="scrollable-menu" role="listbox">
|
||||
<button (click)="selectInboundItemFilter('', i); $event.stopPropagation()"
|
||||
class="dropdown-item collection-item text-truncate w-100" ngbDropdownItem type="button">
|
||||
<span> {{'ldn-service.control-constaint-select-none' | translate}} </span>
|
||||
</button>
|
||||
<button (click)="selectInboundItemFilter(constraint.id, i); $event.stopPropagation()"
|
||||
*ngFor="let constraint of (itemfiltersRD$ | async)?.payload?.page; let internalIndex = index"
|
||||
class="dropdown-item collection-item text-truncate w-100"
|
||||
ngbDropdownItem
|
||||
type="button">
|
||||
<div>{{ constraint.id + '.label' | translate }}</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
||||
<div
|
||||
[style.visibility]="formModel.get('notifyServiceInboundPatterns')['controls'][i].value.pattern ? 'visible' : 'hidden'"
|
||||
class="col-sm-1">
|
||||
<input formControlName="automatic" hidden id="automatic{{i}}" name="automatic{{i}}"
|
||||
type="checkbox">
|
||||
<div (click)="toggleAutomatic(i)"
|
||||
[class.checked]="formModel.get('notifyServiceInboundPatterns.' + i + '.automatic').value"
|
||||
class="toggle-switch">
|
||||
<div class="slider"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-sm-2">
|
||||
<div class="btn-group">
|
||||
<button (click)="markForInboundPatternDeletion(i)" class="btn btn-outline-dark trash-button"
|
||||
[title]="'ldn-service-button-mark-inbound-deletion' | translate"
|
||||
type="button">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
|
||||
|
||||
<button (click)="unmarkForInboundPatternDeletion(i)"
|
||||
*ngIf="markedForDeletionInboundPattern.includes(i)"
|
||||
[title]="'ldn-service-button-unmark-inbound-deletion' | translate"
|
||||
class="btn btn-warning "
|
||||
type="button">
|
||||
<i class="fas fa-undo"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span (click)="addInboundPattern()"
|
||||
class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span>
|
||||
|
||||
<div class="submission-form-footer my-1 position-sticky d-flex justify-content-between" role="group">
|
||||
<button (click)="resetFormAndLeave()" class="btn btn-primary" type="button">
|
||||
<span> {{ 'submission.general.back.submit' | translate }}</span>
|
||||
</button>
|
||||
<button class="btn btn-primary" type="submit">
|
||||
<span><i class="fas fa-save"></i> {{ 'ldn-new-service.form.label.submit' | translate }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<ng-template #confirmModal>
|
||||
<div class="modal-header">
|
||||
<h4 *ngIf="!isNewService">{{'service.overview.edit.modal' | translate }}</h4>
|
||||
<h4 *ngIf="isNewService">{{'service.overview.create.modal' | translate }}</h4>
|
||||
<button (click)="closeModal()" aria-label="Close"
|
||||
class="close" type="button">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div *ngIf="!isNewService">
|
||||
{{ 'service.overview.edit.body' | translate }}
|
||||
</div>
|
||||
<span *ngIf="isNewService">
|
||||
{{ 'service.overview.create.body' | translate }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div *ngIf="!isNewService">
|
||||
<button (click)="closeModal()" class="btn btn-danger mr-2"
|
||||
id="delete-confirm-edit">{{ 'service.detail.return' | translate }}
|
||||
</button>
|
||||
<button *ngIf="!isNewService" (click)="patchService()"
|
||||
class="btn btn-primary">{{ 'service.detail.update' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
<div *ngIf="isNewService">
|
||||
<button (click)="closeModal()" class="btn btn-danger mr-2 "
|
||||
id="delete-confirm-new">{{ 'service.refuse.create' | translate }}
|
||||
</button>
|
||||
<button (click)="createService()"
|
||||
class="btn btn-primary">{{ 'service.confirm.create' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
|
@@ -0,0 +1,143 @@
|
||||
@import '../../../shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.scss';
|
||||
@import '../../../shared/form/form.component.scss';
|
||||
|
||||
form {
|
||||
font-size: 14px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
input,
|
||||
select {
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
option:not(:first-child) {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.trash-button {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
height: 200px;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
.add-pattern-link {
|
||||
color: #0048ff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.remove-pattern-link {
|
||||
color: #e34949;
|
||||
cursor: pointer;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.status-checkbox {
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
|
||||
.invalid-field {
|
||||
border: 1px solid red;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: red;
|
||||
font-size: 0.8em;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.toggle-switch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
opacity: 0.8;
|
||||
position: relative;
|
||||
width: 60px;
|
||||
height: 30px;
|
||||
background-color: #ccc;
|
||||
border-radius: 15px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.toggle-switch.checked {
|
||||
background-color: #24cc9a;
|
||||
}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
background-color: #fff;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
|
||||
.toggle-switch .slider {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.toggle-switch.checked .slider {
|
||||
transform: translateX(30px);
|
||||
}
|
||||
|
||||
.toggle-switch-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-end;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.small-text {
|
||||
font-size: 0.7em;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.toggle-switch {
|
||||
cursor: pointer;
|
||||
margin-top: 3px;
|
||||
margin-right: 3px
|
||||
}
|
||||
|
||||
.label-box {
|
||||
margin-left: 11px;
|
||||
}
|
||||
|
||||
.label-box-2 {
|
||||
margin-left: 14px;
|
||||
}
|
||||
|
||||
.label-box-3 {
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.submission-form-footer {
|
||||
border-radius: var(--bs-card-border-radius);
|
||||
bottom: 0;
|
||||
background-color: var(--bs-gray-400);
|
||||
padding: calc(var(--bs-spacer) / 2);
|
||||
z-index: calc(var(--ds-submission-footer-z-index) + 1);
|
||||
}
|
||||
|
||||
.marked-for-deletion {
|
||||
background-color: lighten($red, 30%);
|
||||
}
|
||||
|
||||
.dropdown-menu-top, .scrollable-dropdown-menu {
|
||||
z-index: var(--ds-submission-footer-z-index);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,241 @@
|
||||
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
|
||||
import {NgbDropdownModule, NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
||||
import {LdnServiceFormComponent} from './ldn-service-form.component';
|
||||
import {ChangeDetectorRef, EventEmitter} from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {TranslateModule, TranslateService} from '@ngx-translate/core';
|
||||
import {PaginationService} from 'ngx-pagination';
|
||||
import {NotificationsService} from '../../../shared/notifications/notifications.service';
|
||||
import {LdnItemfiltersService} from '../ldn-services-data/ldn-itemfilters-data.service';
|
||||
import {LdnServicesService} from '../ldn-services-data/ldn-services-data.service';
|
||||
import {RouterStub} from '../../../shared/testing/router.stub';
|
||||
import {MockActivatedRoute} from '../../../shared/mocks/active-router.mock';
|
||||
import {NotificationsServiceStub} from '../../../shared/testing/notifications-service.stub';
|
||||
import { of as observableOf, of } from 'rxjs';
|
||||
import {RouteService} from '../../../core/services/route.service';
|
||||
import {provideMockStore} from '@ngrx/store/testing';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
describe('LdnServiceFormEditComponent', () => {
|
||||
let component: LdnServiceFormComponent;
|
||||
let fixture: ComponentFixture<LdnServiceFormComponent>;
|
||||
|
||||
let ldnServicesService: LdnServicesService;
|
||||
let ldnItemfiltersService: any;
|
||||
let cdRefStub: any;
|
||||
let modalService: any;
|
||||
let activatedRoute: MockActivatedRoute;
|
||||
|
||||
const testId = '1234';
|
||||
const routeParams = {
|
||||
serviceId: testId,
|
||||
};
|
||||
const routeUrlSegments = [{path: 'path'}];
|
||||
const formMockValue = {
|
||||
'id': '',
|
||||
'name': 'name',
|
||||
'description': 'description',
|
||||
'url': 'www.test.com',
|
||||
'ldnUrl': 'https://test.com',
|
||||
'lowerIp': '127.0.0.1',
|
||||
'upperIp': '100.100.100.100',
|
||||
'score': 1,
|
||||
'inboundPattern': '',
|
||||
'constraintPattern': '',
|
||||
'enabled': '',
|
||||
'type': 'ldnservice',
|
||||
'notifyServiceInboundPatterns': [
|
||||
{
|
||||
'pattern': '',
|
||||
'patternLabel': 'Select a pattern',
|
||||
'constraint': '',
|
||||
'automatic': false
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
const translateServiceStub = {
|
||||
get: () => of('translated-text'),
|
||||
instant: () => 'translated-text',
|
||||
onLangChange: new EventEmitter(),
|
||||
onTranslationChange: new EventEmitter(),
|
||||
onDefaultLangChange: new EventEmitter()
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
ldnServicesService = jasmine.createSpyObj('ldnServicesService', {
|
||||
create: observableOf(null),
|
||||
update: observableOf(null),
|
||||
findById: createSuccessfulRemoteDataObject$({}),
|
||||
});
|
||||
|
||||
ldnItemfiltersService = {
|
||||
findAll: () => of(['item1', 'item2']),
|
||||
};
|
||||
cdRefStub = Object.assign({
|
||||
detectChanges: () => fixture.detectChanges()
|
||||
});
|
||||
modalService = {
|
||||
open: () => {/*comment*/
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
activatedRoute = new MockActivatedRoute(routeParams, routeUrlSegments);
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ReactiveFormsModule, TranslateModule.forRoot(), NgbDropdownModule],
|
||||
declarations: [LdnServiceFormComponent],
|
||||
providers: [
|
||||
{provide: LdnServicesService, useValue: ldnServicesService},
|
||||
{provide: LdnItemfiltersService, useValue: ldnItemfiltersService},
|
||||
{provide: Router, useValue: new RouterStub()},
|
||||
{provide: ActivatedRoute, useValue: activatedRoute},
|
||||
{provide: ChangeDetectorRef, useValue: cdRefStub},
|
||||
{provide: NgbModal, useValue: modalService},
|
||||
{provide: NotificationsService, useValue: new NotificationsServiceStub()},
|
||||
{provide: TranslateService, useValue: translateServiceStub},
|
||||
{provide: PaginationService, useValue: {}},
|
||||
FormBuilder,
|
||||
RouteService,
|
||||
provideMockStore({}),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(LdnServiceFormComponent);
|
||||
component = fixture.componentInstance;
|
||||
spyOn(component, 'filterPatternObjectsAndAssignLabel').and.callFake((a) => a);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
expect(component.formModel instanceof FormGroup).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should init properties correctly', fakeAsync(() => {
|
||||
spyOn(component, 'fetchServiceData');
|
||||
spyOn(component, 'setItemfilters');
|
||||
component.ngOnInit();
|
||||
tick(100);
|
||||
expect((component as any).serviceId).toEqual(testId);
|
||||
expect(component.isNewService).toBeFalsy();
|
||||
expect(component.areControlsInitialized).toBeTruthy();
|
||||
expect(component.formModel.controls.notifyServiceInboundPatterns).toBeDefined();
|
||||
expect(component.fetchServiceData).toHaveBeenCalledWith(testId);
|
||||
expect(component.setItemfilters).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should unsubscribe on destroy', () => {
|
||||
spyOn((component as any).routeSubscription, 'unsubscribe');
|
||||
component.ngOnDestroy();
|
||||
expect((component as any).routeSubscription.unsubscribe).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle create service with valid form', () => {
|
||||
spyOn(component, 'fetchServiceData').and.callFake((a) => a);
|
||||
component.formModel.addControl('notifyServiceInboundPatterns', (component as any).formBuilder.array([{pattern: 'patternValue'}]));
|
||||
const nameInput = fixture.debugElement.query(By.css('#name'));
|
||||
const descriptionInput = fixture.debugElement.query(By.css('#description'));
|
||||
const urlInput = fixture.debugElement.query(By.css('#url'));
|
||||
const scoreInput = fixture.debugElement.query(By.css('#score'));
|
||||
const lowerIpInput = fixture.debugElement.query(By.css('#lowerIp'));
|
||||
const upperIpInput = fixture.debugElement.query(By.css('#upperIp'));
|
||||
const ldnUrlInput = fixture.debugElement.query(By.css('#ldnUrl'));
|
||||
component.formModel.patchValue(formMockValue);
|
||||
|
||||
nameInput.nativeElement.value = 'testName';
|
||||
descriptionInput.nativeElement.value = 'testDescription';
|
||||
urlInput.nativeElement.value = 'tetsUrl.com';
|
||||
ldnUrlInput.nativeElement.value = 'tetsLdnUrl.com';
|
||||
scoreInput.nativeElement.value = 1;
|
||||
lowerIpInput.nativeElement.value = '127.0.0.1';
|
||||
upperIpInput.nativeElement.value = '127.0.0.1';
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.formModel.valid).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should handle create service with invalid form', () => {
|
||||
const nameInput = fixture.debugElement.query(By.css('#name'));
|
||||
|
||||
nameInput.nativeElement.value = 'testName';
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.formModel.valid).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not create service with invalid form', () => {
|
||||
spyOn(component.formModel, 'markAllAsTouched');
|
||||
spyOn(component, 'closeModal');
|
||||
component.createService();
|
||||
|
||||
expect(component.formModel.markAllAsTouched).toHaveBeenCalled();
|
||||
expect(component.closeModal).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should create service with valid form', () => {
|
||||
spyOn(component.formModel, 'markAllAsTouched');
|
||||
spyOn(component, 'closeModal');
|
||||
spyOn(component, 'checkPatterns').and.callFake(() => true);
|
||||
component.formModel.addControl('notifyServiceInboundPatterns', (component as any).formBuilder.array([{pattern: 'patternValue'}]));
|
||||
component.formModel.patchValue(formMockValue);
|
||||
component.createService();
|
||||
|
||||
expect(component.formModel.markAllAsTouched).toHaveBeenCalled();
|
||||
expect(component.closeModal).not.toHaveBeenCalled();
|
||||
expect(ldnServicesService.create).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should check patterns', () => {
|
||||
const arrValid = new FormArray([
|
||||
new FormGroup({
|
||||
pattern: new FormControl('pattern')
|
||||
}),
|
||||
]);
|
||||
|
||||
const arrInvalid = new FormArray([
|
||||
new FormGroup({
|
||||
pattern: new FormControl('')
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(component.checkPatterns(arrValid)).toBeTruthy();
|
||||
expect(component.checkPatterns(arrInvalid)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should fetch service data', () => {
|
||||
component.fetchServiceData(testId);
|
||||
expect(ldnServicesService.findById).toHaveBeenCalledWith(testId);
|
||||
expect(component.filterPatternObjectsAndAssignLabel).toHaveBeenCalled();
|
||||
expect((component as any).ldnService).toEqual({});
|
||||
});
|
||||
|
||||
it('should generate patch operations', () => {
|
||||
spyOn(component as any, 'createReplaceOperation');
|
||||
spyOn(component as any, 'handlePatterns');
|
||||
component.generatePatchOperations();
|
||||
expect((component as any).createReplaceOperation).toHaveBeenCalledTimes(7);
|
||||
expect((component as any).handlePatterns).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should open modal on submit', () => {
|
||||
spyOn(component, 'openConfirmModal');
|
||||
component.onSubmit();
|
||||
expect(component.openConfirmModal).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
it('should reset form and leave', () => {
|
||||
spyOn(component as any, 'sendBack');
|
||||
|
||||
component.resetFormAndLeave();
|
||||
expect((component as any).sendBack).toHaveBeenCalled();
|
||||
});
|
||||
});
|
@@ -0,0 +1,557 @@
|
||||
import {
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
TemplateRef,
|
||||
ViewChild
|
||||
} from '@angular/core';
|
||||
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||
import {LDN_SERVICE} from '../ldn-services-model/ldn-service.resource-type';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {LdnServicesService} from '../ldn-services-data/ldn-services-data.service';
|
||||
import {notifyPatterns} from '../ldn-services-patterns/ldn-service-coar-patterns';
|
||||
import {animate, state, style, transition, trigger} from '@angular/animations';
|
||||
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
||||
import {NotificationsService} from '../../../shared/notifications/notifications.service';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
import {LdnService} from '../ldn-services-model/ldn-services.model';
|
||||
import {RemoteData} from 'src/app/core/data/remote-data';
|
||||
import {Operation} from 'fast-json-patch';
|
||||
import {getFirstCompletedRemoteData} from '../../../core/shared/operators';
|
||||
import {LdnItemfiltersService} from '../ldn-services-data/ldn-itemfilters-data.service';
|
||||
import {Itemfilter} from '../ldn-services-model/ldn-service-itemfilters';
|
||||
import {PaginatedList} from '../../../core/data/paginated-list.model';
|
||||
import {combineLatestWith, Observable, Subscription} from 'rxjs';
|
||||
import {PaginationService} from '../../../core/pagination/pagination.service';
|
||||
import {FindListOptions} from '../../../core/data/find-list-options.model';
|
||||
import {NotifyServicePattern} from '../ldn-services-model/ldn-service-patterns.model';
|
||||
import { IpV4Validator } from '../../../shared/utils/ipV4.validator';
|
||||
|
||||
|
||||
/**
|
||||
* Component for editing LDN service through a form that allows to create or edit the properties of a service
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-ldn-service-form',
|
||||
templateUrl: './ldn-service-form.component.html',
|
||||
styleUrls: ['./ldn-service-form.component.scss'],
|
||||
animations: [
|
||||
trigger('toggleAnimation', [
|
||||
state('true', style({})),
|
||||
state('false', style({})),
|
||||
transition('true <=> false', animate('300ms ease-in')),
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class LdnServiceFormComponent implements OnInit, OnDestroy {
|
||||
formModel: FormGroup;
|
||||
|
||||
@ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef<any>;
|
||||
@ViewChild('resetFormModal', {static: true}) resetFormModal: TemplateRef<any>;
|
||||
|
||||
public inboundPatterns: string[] = notifyPatterns;
|
||||
public isNewService: boolean;
|
||||
public areControlsInitialized: boolean;
|
||||
public itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
|
||||
public config: FindListOptions = Object.assign(new FindListOptions(), {
|
||||
elementsPerPage: 20
|
||||
});
|
||||
public markedForDeletionInboundPattern: number[] = [];
|
||||
public selectedInboundPatterns: string[];
|
||||
|
||||
protected serviceId: string;
|
||||
|
||||
private deletedInboundPatterns: number[] = [];
|
||||
private modalRef: any;
|
||||
private ldnService: LdnService;
|
||||
private selectPatternDefaultLabeli18Key = 'ldn-service.form.label.placeholder.default-select';
|
||||
private routeSubscription: Subscription;
|
||||
|
||||
constructor(
|
||||
protected ldnServicesService: LdnServicesService,
|
||||
private ldnItemfiltersService: LdnItemfiltersService,
|
||||
private formBuilder: FormBuilder,
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private cdRef: ChangeDetectorRef,
|
||||
protected modalService: NgbModal,
|
||||
private notificationService: NotificationsService,
|
||||
private translateService: TranslateService,
|
||||
protected paginationService: PaginationService
|
||||
) {
|
||||
|
||||
this.formModel = this.formBuilder.group({
|
||||
id: [''],
|
||||
name: ['', Validators.required],
|
||||
description: [''],
|
||||
url: ['', Validators.required],
|
||||
ldnUrl: ['', Validators.required],
|
||||
lowerIp: ['', [Validators.required, new IpV4Validator()]],
|
||||
upperIp: ['', [Validators.required, new IpV4Validator()]],
|
||||
score: ['', [Validators.required, Validators.pattern('^0*(\.[0-9]+)?$|^1(\.0+)?$')]], inboundPattern: [''],
|
||||
constraintPattern: [''],
|
||||
enabled: [''],
|
||||
type: LDN_SERVICE.value,
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.routeSubscription = this.route.params.pipe(
|
||||
combineLatestWith(this.route.url)
|
||||
).subscribe(([params, segment]) => {
|
||||
this.serviceId = params.serviceId;
|
||||
this.isNewService = segment[0].path === 'new';
|
||||
this.formModel.addControl('notifyServiceInboundPatterns', this.formBuilder.array([this.createInboundPatternFormGroup()]));
|
||||
this.areControlsInitialized = true;
|
||||
if (this.serviceId && !this.isNewService) {
|
||||
this.fetchServiceData(this.serviceId);
|
||||
}
|
||||
});
|
||||
this.setItemfilters();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.routeSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets item filters using LDN item filters service
|
||||
*/
|
||||
setItemfilters() {
|
||||
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
|
||||
getFirstCompletedRemoteData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the creation of an LDN service by retrieving and validating form fields,
|
||||
* and submitting the form data to the LDN services endpoint.
|
||||
*/
|
||||
createService() {
|
||||
this.formModel.markAllAsTouched();
|
||||
const notifyServiceInboundPatterns = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||
const hasInboundPattern = notifyServiceInboundPatterns?.length > 0 ? this.checkPatterns(notifyServiceInboundPatterns) : false;
|
||||
|
||||
if (this.formModel.invalid) {
|
||||
this.closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasInboundPattern) {
|
||||
this.notificationService.warning(this.translateService.get('ldn-service-notification.created.warning.title'));
|
||||
this.closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.formModel.value.notifyServiceInboundPatterns = this.formModel.value.notifyServiceInboundPatterns.map((pattern: {
|
||||
pattern: string;
|
||||
patternLabel: string,
|
||||
constraintFormatted: string;
|
||||
}) => {
|
||||
const {patternLabel, ...rest} = pattern;
|
||||
delete rest.constraintFormatted;
|
||||
return rest;
|
||||
});
|
||||
|
||||
const values = {...this.formModel.value, enabled: true};
|
||||
|
||||
const ldnServiceData = this.ldnServicesService.create(values);
|
||||
|
||||
ldnServiceData.pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
).subscribe((rd: RemoteData<LdnService>) => {
|
||||
if (rd.hasSucceeded) {
|
||||
this.notificationService.success(this.translateService.get('ldn-service-notification.created.success.title'),
|
||||
this.translateService.get('ldn-service-notification.created.success.body'));
|
||||
this.closeModal();
|
||||
this.sendBack();
|
||||
} else {
|
||||
this.notificationService.error(this.translateService.get('ldn-service-notification.created.failure.title'),
|
||||
this.translateService.get('ldn-service-notification.created.failure.body'));
|
||||
this.closeModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if at least one pattern in the specified form array has a value.
|
||||
*
|
||||
* @param {FormArray} formArray - The form array containing patterns to check.
|
||||
* @returns {boolean} - True if at least one pattern has a value, otherwise false.
|
||||
*/
|
||||
checkPatterns(formArray: FormArray): boolean {
|
||||
for (let i = 0; i < formArray.length; i++) {
|
||||
const pattern = formArray.at(i).get('pattern').value;
|
||||
if (pattern) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches LDN service data by ID and updates the form
|
||||
* @param serviceId - The ID of the LDN service
|
||||
*/
|
||||
fetchServiceData(serviceId: string): void {
|
||||
this.ldnServicesService.findById(serviceId).pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
).subscribe(
|
||||
(data: RemoteData<LdnService>) => {
|
||||
if (data.hasSucceeded) {
|
||||
this.ldnService = data.payload;
|
||||
this.formModel.patchValue({
|
||||
id: this.ldnService.id,
|
||||
name: this.ldnService.name,
|
||||
description: this.ldnService.description,
|
||||
url: this.ldnService.url,
|
||||
score: this.ldnService.score,
|
||||
ldnUrl: this.ldnService.ldnUrl,
|
||||
type: this.ldnService.type,
|
||||
enabled: this.ldnService.enabled,
|
||||
lowerIp: this.ldnService.lowerIp,
|
||||
upperIp: this.ldnService.upperIp
|
||||
});
|
||||
this.filterPatternObjectsAndAssignLabel('notifyServiceInboundPatterns');
|
||||
let notifyServiceInboundPatternsFormArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||
notifyServiceInboundPatternsFormArray.controls.forEach(
|
||||
control => {
|
||||
const controlFormGroup = control as FormGroup;
|
||||
const controlConstraint = controlFormGroup.get('constraint').value;
|
||||
controlFormGroup.patchValue({
|
||||
constraintFormatted: controlConstraint ? this.translateService.instant((controlConstraint as string) + '.label') : ''
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters pattern objects, initializes form groups, assigns labels, and adds them to the specified form array so the correct string is shown in the dropdown..
|
||||
* @param formArrayName - The name of the form array to be populated
|
||||
*/
|
||||
filterPatternObjectsAndAssignLabel(formArrayName: string) {
|
||||
const PatternsArray = this.formModel.get(formArrayName) as FormArray;
|
||||
PatternsArray.clear();
|
||||
|
||||
let servicesToUse = this.ldnService.notifyServiceInboundPatterns;
|
||||
|
||||
servicesToUse.forEach((patternObj: NotifyServicePattern) => {
|
||||
let patternFormGroup;
|
||||
patternFormGroup = this.initializeInboundPatternFormGroup();
|
||||
const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {
|
||||
...patternObj,
|
||||
patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj?.pattern + '.label')
|
||||
});
|
||||
patternFormGroup.patchValue(newPatternObjWithLabel);
|
||||
|
||||
PatternsArray.push(patternFormGroup);
|
||||
this.cdRef.detectChanges();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array of patch operations based on form changes
|
||||
* @returns Array of patch operations
|
||||
*/
|
||||
generatePatchOperations(): any[] {
|
||||
const patchOperations: any[] = [];
|
||||
|
||||
this.createReplaceOperation(patchOperations, 'name', '/name');
|
||||
this.createReplaceOperation(patchOperations, 'description', '/description');
|
||||
this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl');
|
||||
this.createReplaceOperation(patchOperations, 'url', '/url');
|
||||
this.createReplaceOperation(patchOperations, 'score', '/score');
|
||||
this.createReplaceOperation(patchOperations, 'lowerIp', '/lowerIp');
|
||||
this.createReplaceOperation(patchOperations, 'upperIp', '/upperIp');
|
||||
|
||||
this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
|
||||
this.deletedInboundPatterns.forEach(index => {
|
||||
const removeOperation: Operation = {
|
||||
op: 'remove',
|
||||
path: `notifyServiceInboundPatterns[${index}]`
|
||||
};
|
||||
patchOperations.push(removeOperation);
|
||||
});
|
||||
|
||||
return patchOperations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the form by opening the confirmation modal
|
||||
*/
|
||||
onSubmit() {
|
||||
this.openConfirmModal(this.confirmModal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new inbound pattern form group to the array of inbound patterns in the form
|
||||
*/
|
||||
addInboundPattern() {
|
||||
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||
notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects an inbound pattern by updating its values based on the provided pattern value and index
|
||||
* @param patternValue - The selected pattern value
|
||||
* @param index - The index of the inbound pattern in the array
|
||||
*/
|
||||
selectInboundPattern(patternValue: string, index: number): void {
|
||||
const patternArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray);
|
||||
patternArray.controls[index].patchValue({pattern: patternValue});
|
||||
patternArray.controls[index].patchValue({patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternValue + '.label')});
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects an inbound item filter by updating its value based on the provided filter value and index
|
||||
* @param filterValue - The selected filter value
|
||||
* @param index - The index of the inbound pattern in the array
|
||||
*/
|
||||
selectInboundItemFilter(filterValue: string, index: number): void {
|
||||
const filterArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray);
|
||||
filterArray.controls[index].patchValue({
|
||||
constraint: filterValue,
|
||||
constraintFormatted: this.translateService.instant((filterValue !== '' ? filterValue : 'ldn.no-filter') + '.label')
|
||||
});
|
||||
filterArray.markAllAsTouched();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the automatic property of an inbound pattern at the specified index
|
||||
* @param i - The index of the inbound pattern in the array
|
||||
*/
|
||||
toggleAutomatic(i: number) {
|
||||
const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`);
|
||||
if (automaticControl) {
|
||||
automaticControl.markAsTouched();
|
||||
automaticControl.setValue(!automaticControl.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the enabled status of the LDN service by sending a patch request
|
||||
*/
|
||||
toggleEnabled() {
|
||||
const newStatus = !this.formModel.get('enabled').value;
|
||||
|
||||
const patchOperation: Operation = {
|
||||
op: 'replace',
|
||||
path: '/enabled',
|
||||
value: newStatus,
|
||||
};
|
||||
|
||||
this.ldnServicesService.patch(this.ldnService, [patchOperation]).pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
).subscribe(
|
||||
() => {
|
||||
this.formModel.get('enabled').setValue(newStatus);
|
||||
this.cdRef.detectChanges();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the modal
|
||||
*/
|
||||
closeModal() {
|
||||
this.modalRef.close();
|
||||
this.cdRef.detectChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a confirmation modal with the specified content
|
||||
* @param content - The content to be displayed in the modal
|
||||
*/
|
||||
openConfirmModal(content) {
|
||||
this.modalRef = this.modalService.open(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches the LDN service by retrieving and sending patch operations geenrated in generatePatchOperations()
|
||||
*/
|
||||
patchService() {
|
||||
this.deleteMarkedInboundPatterns();
|
||||
|
||||
const patchOperations = this.generatePatchOperations();
|
||||
this.formModel.markAllAsTouched();
|
||||
// If the form is invalid, close the modal and return
|
||||
if (this.formModel.invalid) {
|
||||
this.closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
const notifyServiceInboundPatterns = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||
const deletedInboundPatternsLength = this.deletedInboundPatterns.length;
|
||||
// If no inbound patterns are specified, close the modal and return
|
||||
// notify the user that no patterns are specified
|
||||
if (notifyServiceInboundPatterns.length === deletedInboundPatternsLength) {
|
||||
this.notificationService.warning(this.translateService.get('ldn-service-notification.created.warning.title'));
|
||||
this.deletedInboundPatterns = [];
|
||||
this.closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
this.ldnServicesService.patch(this.ldnService, patchOperations).pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
).subscribe(
|
||||
(rd: RemoteData<LdnService>) => {
|
||||
if (rd.hasSucceeded) {
|
||||
this.closeModal();
|
||||
this.sendBack();
|
||||
this.notificationService.success(this.translateService.get('admin.registries.services-formats.modify.success.head'),
|
||||
this.translateService.get('admin.registries.services-formats.modify.success.content'));
|
||||
} else {
|
||||
this.notificationService.error(this.translateService.get('admin.registries.services-formats.modify.failure.head'),
|
||||
this.translateService.get('admin.registries.services-formats.modify.failure.content'));
|
||||
this.closeModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the form and navigates back to the LDN services page
|
||||
*/
|
||||
resetFormAndLeave() {
|
||||
this.sendBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the specified inbound pattern for deletion
|
||||
* @param index - The index of the inbound pattern in the array
|
||||
*/
|
||||
markForInboundPatternDeletion(index: number) {
|
||||
if (!this.markedForDeletionInboundPattern.includes(index)) {
|
||||
this.markedForDeletionInboundPattern.push(index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmarks the specified inbound pattern for deletion
|
||||
* @param index - The index of the inbound pattern in the array
|
||||
*/
|
||||
unmarkForInboundPatternDeletion(index: number) {
|
||||
const i = this.markedForDeletionInboundPattern.indexOf(index);
|
||||
if (i !== -1) {
|
||||
this.markedForDeletionInboundPattern.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes marked inbound patterns from the form model
|
||||
*/
|
||||
deleteMarkedInboundPatterns() {
|
||||
this.markedForDeletionInboundPattern.sort((a, b) => b - a);
|
||||
const patternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||
|
||||
for (const index of this.markedForDeletionInboundPattern) {
|
||||
if (index >= 0 && index < patternsArray.length) {
|
||||
const patternGroup = patternsArray.at(index) as FormGroup;
|
||||
const patternValue = patternGroup.value;
|
||||
if (patternValue.isNew) {
|
||||
patternsArray.removeAt(index);
|
||||
} else {
|
||||
this.deletedInboundPatterns.push(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.markedForDeletionInboundPattern = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a replace operation and adds it to the patch operations if the form control is dirty
|
||||
* @param patchOperations - The array to store patch operations
|
||||
* @param formControlName - The name of the form control
|
||||
* @param path - The JSON Patch path for the operation
|
||||
*/
|
||||
private createReplaceOperation(patchOperations: any[], formControlName: string, path: string): void {
|
||||
if (this.formModel.get(formControlName).dirty) {
|
||||
patchOperations.push({
|
||||
op: 'replace',
|
||||
path,
|
||||
value: this.formModel.get(formControlName).value.toString(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles patterns in the form array, checking if an add or replace operations is required
|
||||
* @param patchOperations - The array to store patch operations
|
||||
* @param formArrayName - The name of the form array
|
||||
*/
|
||||
private handlePatterns(patchOperations: any[], formArrayName: string): void {
|
||||
const patternsArray = this.formModel.get(formArrayName) as FormArray;
|
||||
|
||||
for (let i = 0; i < patternsArray.length; i++) {
|
||||
const patternGroup = patternsArray.at(i) as FormGroup;
|
||||
|
||||
const patternValue = patternGroup.value;
|
||||
delete patternValue.constraintFormatted;
|
||||
if (patternGroup.touched && patternGroup.valid) {
|
||||
delete patternValue?.patternLabel;
|
||||
if (patternValue.isNew) {
|
||||
delete patternValue.isNew;
|
||||
const addOperation = {
|
||||
op: 'add',
|
||||
path: `${formArrayName}/-`,
|
||||
value: patternValue,
|
||||
};
|
||||
patchOperations.push(addOperation);
|
||||
} else {
|
||||
const replaceOperation = {
|
||||
op: 'replace',
|
||||
path: `${formArrayName}[${i}]`,
|
||||
value: patternValue,
|
||||
};
|
||||
patchOperations.push(replaceOperation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigates back to the LDN services page
|
||||
*/
|
||||
private sendBack() {
|
||||
this.router.navigateByUrl('admin/ldn/services');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form group for inbound patterns
|
||||
* @returns The form group for inbound patterns
|
||||
*/
|
||||
private createInboundPatternFormGroup(): FormGroup {
|
||||
const inBoundFormGroup = {
|
||||
pattern: '',
|
||||
patternLabel: this.translateService.instant(this.selectPatternDefaultLabeli18Key),
|
||||
constraint: '',
|
||||
constraintFormatted: '',
|
||||
automatic: false,
|
||||
isNew: true
|
||||
};
|
||||
|
||||
if (this.isNewService) {
|
||||
delete inBoundFormGroup.isNew;
|
||||
}
|
||||
|
||||
return this.formBuilder.group(inBoundFormGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes an existing form group for inbound patterns
|
||||
* @returns The initialized form group for inbound patterns
|
||||
*/
|
||||
private initializeInboundPatternFormGroup(): FormGroup {
|
||||
return this.formBuilder.group({
|
||||
pattern: '',
|
||||
patternLabel: '',
|
||||
constraint: '',
|
||||
constraintFormatted: '',
|
||||
automatic: '',
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,111 @@
|
||||
import {LdnService} from '../ldn-services-model/ldn-services.model';
|
||||
import {LDN_SERVICE} from '../ldn-services-model/ldn-service.resource-type';
|
||||
import {RemoteData} from '../../../core/data/remote-data';
|
||||
import {PaginatedList} from '../../../core/data/paginated-list.model';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {createSuccessfulRemoteDataObject$} from '../../../shared/remote-data.utils';
|
||||
|
||||
export const mockLdnService: LdnService = {
|
||||
uuid: '1',
|
||||
enabled: false,
|
||||
score: 0,
|
||||
id: 1,
|
||||
lowerIp: '192.0.2.146',
|
||||
upperIp: '192.0.2.255',
|
||||
name: 'Service Name',
|
||||
description: 'Service Description',
|
||||
url: 'Service URL',
|
||||
ldnUrl: 'Service LDN URL',
|
||||
notifyServiceInboundPatterns: [
|
||||
{
|
||||
pattern: 'patternA',
|
||||
constraint: 'itemFilterA',
|
||||
automatic: 'false',
|
||||
},
|
||||
{
|
||||
pattern: 'patternB',
|
||||
constraint: 'itemFilterB',
|
||||
automatic: 'true',
|
||||
},
|
||||
],
|
||||
type: LDN_SERVICE,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'http://localhost/api/ldn/ldnservices/1'
|
||||
},
|
||||
},
|
||||
get self(): string {
|
||||
return '';
|
||||
},
|
||||
};
|
||||
|
||||
export const mockLdnServiceRD$ = createSuccessfulRemoteDataObject$(mockLdnService);
|
||||
|
||||
|
||||
export const mockLdnServices: LdnService[] = [{
|
||||
uuid: '1',
|
||||
enabled: false,
|
||||
score: 0,
|
||||
id: 1,
|
||||
lowerIp: '192.0.2.146',
|
||||
upperIp: '192.0.2.255',
|
||||
name: 'Service Name',
|
||||
description: 'Service Description',
|
||||
url: 'Service URL',
|
||||
ldnUrl: 'Service LDN URL',
|
||||
notifyServiceInboundPatterns: [
|
||||
{
|
||||
pattern: 'patternA',
|
||||
constraint: 'itemFilterA',
|
||||
automatic: 'false',
|
||||
},
|
||||
{
|
||||
pattern: 'patternB',
|
||||
constraint: 'itemFilterB',
|
||||
automatic: 'true',
|
||||
},
|
||||
],
|
||||
type: LDN_SERVICE,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'http://localhost/api/ldn/ldnservices/1'
|
||||
},
|
||||
},
|
||||
get self(): string {
|
||||
return '';
|
||||
},
|
||||
}, {
|
||||
uuid: '2',
|
||||
enabled: false,
|
||||
score: 0,
|
||||
id: 2,
|
||||
lowerIp: '192.0.2.146',
|
||||
upperIp: '192.0.2.255',
|
||||
name: 'Service Name',
|
||||
description: 'Service Description',
|
||||
url: 'Service URL',
|
||||
ldnUrl: 'Service LDN URL',
|
||||
notifyServiceInboundPatterns: [
|
||||
{
|
||||
pattern: 'patternA',
|
||||
constraint: 'itemFilterA',
|
||||
automatic: 'false',
|
||||
},
|
||||
{
|
||||
pattern: 'patternB',
|
||||
constraint: 'itemFilterB',
|
||||
automatic: 'true',
|
||||
},
|
||||
],
|
||||
type: LDN_SERVICE,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'http://localhost/api/ldn/ldnservices/1'
|
||||
},
|
||||
},
|
||||
get self(): string {
|
||||
return '';
|
||||
},
|
||||
}
|
||||
];
|
||||
export const mockLdnServicesRD$: Observable<RemoteData<PaginatedList<LdnService>>> = of((mockLdnServices as unknown) as RemoteData<PaginatedList<LdnService>>);
|
@@ -0,0 +1,89 @@
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
import { LdnItemfiltersService } from './ldn-itemfilters-data.service';
|
||||
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 { RequestEntry } from '../../../core/data/request-entry.model';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { RequestEntryState } from '../../../core/data/request-entry-state.model';
|
||||
import { cold, getTestScheduler } from 'jasmine-marbles';
|
||||
import { RestResponse } from '../../../core/cache/response.models';
|
||||
import { of } from 'rxjs';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||
import { FindAllData } from '../../../core/data/base/find-all-data';
|
||||
import { testFindAllDataImplementation } from '../../../core/data/base/find-all-data.spec';
|
||||
|
||||
describe('LdnItemfiltersService test', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: LdnItemfiltersService;
|
||||
let requestService: RequestService;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let objectCache: ObjectCacheService;
|
||||
let halService: HALEndpointService;
|
||||
let notificationsService: NotificationsService;
|
||||
let responseCacheEntry: RequestEntry;
|
||||
|
||||
const endpointURL = `https://rest.api/rest/api/ldn/itemfilters`;
|
||||
const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';
|
||||
|
||||
const remoteDataMocks = {
|
||||
Success: new RemoteData(null, null, null, RequestEntryState.Success, null, null, 200),
|
||||
};
|
||||
|
||||
function initTestService() {
|
||||
return new LdnItemfiltersService(
|
||||
requestService,
|
||||
rdbService,
|
||||
objectCache,
|
||||
halService,
|
||||
notificationsService,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
|
||||
objectCache = {} as ObjectCacheService;
|
||||
notificationsService = {} as NotificationsService;
|
||||
responseCacheEntry = new RequestEntry();
|
||||
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
|
||||
responseCacheEntry.response = new RestResponse(true, 200, 'Success');
|
||||
|
||||
requestService = jasmine.createSpyObj('requestService', {
|
||||
generateRequestId: requestUUID,
|
||||
send: true,
|
||||
removeByHrefSubstring: {},
|
||||
getByHref: of(responseCacheEntry),
|
||||
getByUUID: of(responseCacheEntry),
|
||||
});
|
||||
|
||||
halService = jasmine.createSpyObj('halService', {
|
||||
getEndpoint: of(endpointURL)
|
||||
});
|
||||
|
||||
rdbService = jasmine.createSpyObj('rdbService', {
|
||||
buildSingle: createSuccessfulRemoteDataObject$({}, 500),
|
||||
buildList: cold('a', { a: remoteDataMocks.Success })
|
||||
});
|
||||
|
||||
|
||||
service = initTestService();
|
||||
});
|
||||
|
||||
describe('composition', () => {
|
||||
const initFindAllService = () => new LdnItemfiltersService(null, null, null, null, null) as unknown as FindAllData<any>;
|
||||
testFindAllDataImplementation(initFindAllService);
|
||||
});
|
||||
|
||||
describe('get endpoint', () => {
|
||||
it('should retrieve correct endpoint', (done) => {
|
||||
service.getEndpoint().subscribe(() => {
|
||||
expect(halService.getEndpoint).toHaveBeenCalledWith('itemfilters');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,61 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {dataService} from '../../../core/data/base/data-service.decorator';
|
||||
import {LDN_SERVICE_CONSTRAINT_FILTERS} from '../ldn-services-model/ldn-service.resource-type';
|
||||
import {IdentifiableDataService} from '../../../core/data/base/identifiable-data.service';
|
||||
import {FindAllData, FindAllDataImpl} from '../../../core/data/base/find-all-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 {Itemfilter} from '../ldn-services-model/ldn-service-itemfilters';
|
||||
import {PaginatedList} from '../../../core/data/paginated-list.model';
|
||||
|
||||
|
||||
/**
|
||||
* A service responsible for fetching/sending data from/to the REST API on the itemfilters endpoint
|
||||
*/
|
||||
@Injectable()
|
||||
@dataService(LDN_SERVICE_CONSTRAINT_FILTERS)
|
||||
export class LdnItemfiltersService extends IdentifiableDataService<Itemfilter> implements FindAllData<Itemfilter> {
|
||||
private findAllData: FindAllDataImpl<Itemfilter>;
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
) {
|
||||
super('itemfilters', requestService, rdbService, objectCache, halService);
|
||||
|
||||
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the endpoint URL for the itemfilters.
|
||||
*
|
||||
* @returns {string} - The endpoint URL.
|
||||
*/
|
||||
getEndpoint() {
|
||||
return this.halService.getEndpoint(this.linkPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all itemfilters based on the provided options and link configurations.
|
||||
*
|
||||
* @param {FindListOptions} options - The options for finding a list of itemfilters.
|
||||
* @param {boolean} useCachedVersionIfAvailable - Whether to use the cached version if available.
|
||||
* @param {boolean} reRequestOnStale - Whether to re-request the data if it's stale.
|
||||
* @param {...FollowLinkConfig<Itemfilter>[]} linksToFollow - Configurations for following specific links.
|
||||
* @returns {Observable<RemoteData<PaginatedList<Itemfilter>>>} - An observable of remote data containing a paginated list of itemfilters.
|
||||
*/
|
||||
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Itemfilter>[]): Observable<RemoteData<PaginatedList<Itemfilter>>> {
|
||||
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
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 { RequestEntry } from '../../../core/data/request-entry.model';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { RequestEntryState } from '../../../core/data/request-entry-state.model';
|
||||
import { cold, getTestScheduler } from 'jasmine-marbles';
|
||||
import { RestResponse } from '../../../core/cache/response.models';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||
import { FindAllData } from '../../../core/data/base/find-all-data';
|
||||
import { testFindAllDataImplementation } from '../../../core/data/base/find-all-data.spec';
|
||||
import { LdnServicesService } from './ldn-services-data.service';
|
||||
import { testDeleteDataImplementation } from '../../../core/data/base/delete-data.spec';
|
||||
import { DeleteData } from '../../../core/data/base/delete-data';
|
||||
import { testSearchDataImplementation } from '../../../core/data/base/search-data.spec';
|
||||
import { SearchData } from '../../../core/data/base/search-data';
|
||||
import { testPatchDataImplementation } from '../../../core/data/base/patch-data.spec';
|
||||
import { PatchData } from '../../../core/data/base/patch-data';
|
||||
import { CreateData } from '../../../core/data/base/create-data';
|
||||
import { testCreateDataImplementation } from '../../../core/data/base/create-data.spec';
|
||||
import { FindListOptions } from '../../../core/data/find-list-options.model';
|
||||
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
||||
import { mockLdnService } from '../ldn-service-serviceMock/ldnServicesRD$-mock';
|
||||
import { createPaginatedList } from '../../../shared/testing/utils.test';
|
||||
|
||||
|
||||
describe('LdnServicesService test', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: LdnServicesService;
|
||||
let requestService: RequestService;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let objectCache: ObjectCacheService;
|
||||
let halService: HALEndpointService;
|
||||
let notificationsService: NotificationsService;
|
||||
let responseCacheEntry: RequestEntry;
|
||||
|
||||
const endpointURL = `https://rest.api/rest/api/ldn/ldnservices`;
|
||||
const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';
|
||||
|
||||
const remoteDataMocks = {
|
||||
Success: new RemoteData(null, null, null, RequestEntryState.Success, null, null, 200),
|
||||
};
|
||||
|
||||
function initTestService() {
|
||||
return new LdnServicesService(
|
||||
requestService,
|
||||
rdbService,
|
||||
objectCache,
|
||||
halService,
|
||||
notificationsService,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
|
||||
objectCache = {} as ObjectCacheService;
|
||||
notificationsService = {} as NotificationsService;
|
||||
responseCacheEntry = new RequestEntry();
|
||||
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
|
||||
responseCacheEntry.response = new RestResponse(true, 200, 'Success');
|
||||
|
||||
requestService = jasmine.createSpyObj('requestService', {
|
||||
generateRequestId: requestUUID,
|
||||
send: true,
|
||||
removeByHrefSubstring: {},
|
||||
getByHref: observableOf(responseCacheEntry),
|
||||
getByUUID: observableOf(responseCacheEntry),
|
||||
});
|
||||
|
||||
halService = jasmine.createSpyObj('halService', {
|
||||
getEndpoint: observableOf(endpointURL)
|
||||
});
|
||||
|
||||
rdbService = jasmine.createSpyObj('rdbService', {
|
||||
buildSingle: createSuccessfulRemoteDataObject$({}, 500),
|
||||
buildList: cold('a', { a: remoteDataMocks.Success })
|
||||
});
|
||||
|
||||
|
||||
service = initTestService();
|
||||
});
|
||||
|
||||
describe('composition', () => {
|
||||
const initFindAllService = () => new LdnServicesService(null, null, null, null, null) as unknown as FindAllData<any>;
|
||||
const initDeleteService = () => new LdnServicesService(null, null, null, null, null) as unknown as DeleteData<any>;
|
||||
const initSearchService = () => new LdnServicesService(null, null, null, null, null) as unknown as SearchData<any>;
|
||||
const initPatchService = () => new LdnServicesService(null, null, null, null, null) as unknown as PatchData<any>;
|
||||
const initCreateService = () => new LdnServicesService(null, null, null, null, null) as unknown as CreateData<any>;
|
||||
|
||||
testFindAllDataImplementation(initFindAllService);
|
||||
testDeleteDataImplementation(initDeleteService);
|
||||
testSearchDataImplementation(initSearchService);
|
||||
testPatchDataImplementation(initPatchService);
|
||||
testCreateDataImplementation(initCreateService);
|
||||
});
|
||||
|
||||
describe('custom methods', () => {
|
||||
it('should find service by inbound pattern', (done) => {
|
||||
const params = [new RequestParam('pattern', 'testPattern')];
|
||||
const findListOptions = Object.assign(new FindListOptions(), {}, {searchParams: params});
|
||||
spyOn(service, 'searchBy').and.returnValue(observableOf(null));
|
||||
spyOn((service as any).searchData, 'searchBy').and.returnValue(createSuccessfulRemoteDataObject$(createPaginatedList([mockLdnService])));
|
||||
|
||||
service.findByInboundPattern('testPattern').subscribe(() => {
|
||||
expect(service.searchBy).toHaveBeenCalledWith('byInboundPattern', findListOptions, undefined, undefined );
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,217 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {dataService} from '../../../core/data/base/data-service.decorator';
|
||||
import {LDN_SERVICE} from '../ldn-services-model/ldn-service.resource-type';
|
||||
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 {LdnService} from '../ldn-services-model/ldn-services.model';
|
||||
|
||||
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 {CreateData, CreateDataImpl} from '../../../core/data/base/create-data';
|
||||
import {LdnServiceConstrain} from '../ldn-services-model/ldn-service.constrain.model';
|
||||
import {SearchDataImpl} from '../../../core/data/base/search-data';
|
||||
import {RequestParam} from '../../../core/cache/models/request-param.model';
|
||||
|
||||
/**
|
||||
* Injectable service responsible for fetching/sending data from/to the REST API on the ldnservices endpoint.
|
||||
*
|
||||
* @export
|
||||
* @class LdnServicesService
|
||||
* @extends {IdentifiableDataService<LdnService>}
|
||||
* @implements {FindAllData<LdnService>}
|
||||
* @implements {DeleteData<LdnService>}
|
||||
* @implements {PatchData<LdnService>}
|
||||
* @implements {CreateData<LdnService>}
|
||||
*/
|
||||
@Injectable()
|
||||
@dataService(LDN_SERVICE)
|
||||
export class LdnServicesService extends IdentifiableDataService<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService>, PatchData<LdnService>, CreateData<LdnService> {
|
||||
createData: CreateDataImpl<LdnService>;
|
||||
private findAllData: FindAllDataImpl<LdnService>;
|
||||
private deleteData: DeleteDataImpl<LdnService>;
|
||||
private patchData: PatchDataImpl<LdnService>;
|
||||
private comparator: ChangeAnalyzer<LdnService>;
|
||||
private searchData: SearchDataImpl<LdnService>;
|
||||
|
||||
private findByPatternEndpoint = 'byInboundPattern';
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
) {
|
||||
super('ldnservices', requestService, rdbService, objectCache, halService);
|
||||
|
||||
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.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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an LDN service by sending a POST request to the REST API.
|
||||
*
|
||||
* @param {LdnService} object - The LDN service object to be created.
|
||||
* @param params Array with additional params to combine with query string
|
||||
* @returns {Observable<RemoteData<LdnService>>} - Observable containing the result of the creation operation.
|
||||
*/
|
||||
create(object: LdnService, ...params: RequestParam[]): Observable<RemoteData<LdnService>> {
|
||||
return this.createData.create(object, ...params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an LDN service by applying a set of operations through a PATCH request to the REST API.
|
||||
*
|
||||
* @param {LdnService} object - The LDN service object to be updated.
|
||||
* @param {Operation[]} operations - The patch operations to be applied.
|
||||
* @returns {Observable<RemoteData<LdnService>>} - Observable containing the result of the update operation.
|
||||
*/
|
||||
patch(object: LdnService, operations: Operation[]): Observable<RemoteData<LdnService>> {
|
||||
return this.patchData.patch(object, operations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an LDN service by sending a PUT request to the REST API.
|
||||
*
|
||||
* @param {LdnService} object - The LDN service object to be updated.
|
||||
* @returns {Observable<RemoteData<LdnService>>} - Observable containing the result of the update operation.
|
||||
*/
|
||||
update(object: LdnService): Observable<RemoteData<LdnService>> {
|
||||
return this.patchData.update(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits pending updates by sending a PATCH request to the REST API.
|
||||
*
|
||||
* @param {RestRequestMethod} [method] - The HTTP method to be used for the request.
|
||||
*/
|
||||
commitUpdates(method?: RestRequestMethod): void {
|
||||
return this.patchData.commitUpdates(method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a patch representing the changes made to the LDN service in the cache.
|
||||
*
|
||||
* @param {LdnService} object - The LDN service object for which to create the patch.
|
||||
* @returns {Observable<Operation[]>} - Observable containing the patch operations.
|
||||
*/
|
||||
createPatchFromCache(object: LdnService): Observable<Operation[]> {
|
||||
return this.patchData.createPatchFromCache(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all LDN services from the REST API based on the provided options.
|
||||
*
|
||||
* @param {FindListOptions} [options] - The options to be applied to the request.
|
||||
* @param {boolean} [useCachedVersionIfAvailable] - Flag indicating whether to use cached data if available.
|
||||
* @param {boolean} [reRequestOnStale] - Flag indicating whether to re-request data if it's stale.
|
||||
* @param {...FollowLinkConfig<LdnService>[]} linksToFollow - Optional links to follow during the request.
|
||||
* @returns {Observable<RemoteData<PaginatedList<LdnService>>>} - Observable containing the result of the request.
|
||||
*/
|
||||
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {
|
||||
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves LDN services based on the inbound pattern from the REST API.
|
||||
*
|
||||
* @param {string} pattern - The inbound pattern to be used in the search.
|
||||
* @param {FindListOptions} [options] - The options to be applied to the request.
|
||||
* @param {boolean} [useCachedVersionIfAvailable] - Flag indicating whether to use cached data if available.
|
||||
* @param {boolean} [reRequestOnStale] - Flag indicating whether to re-request data if it's stale.
|
||||
* @param {...FollowLinkConfig<LdnService>[]} linksToFollow - Optional links to follow during the request.
|
||||
* @returns {Observable<RemoteData<PaginatedList<LdnService>>>} - Observable containing the result of the request.
|
||||
*/
|
||||
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.searchBy(this.findByPatternEndpoint, findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an LDN service by sending a DELETE request to the REST API.
|
||||
*
|
||||
* @param {string} objectId - The ID of the LDN service to be deleted.
|
||||
* @param {string[]} [copyVirtualMetadata] - Optional virtual metadata to be copied during the deletion.
|
||||
* @returns {Observable<RemoteData<NoContent>>} - Observable containing the result of the deletion operation.
|
||||
*/
|
||||
public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
||||
return this.deleteData.delete(objectId, copyVirtualMetadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an LDN service by its HATEOAS link.
|
||||
*
|
||||
* @param {string} href - The HATEOAS link of the LDN service to be deleted.
|
||||
* @param {string[]} [copyVirtualMetadata] - Optional virtual metadata to be copied during the deletion.
|
||||
* @returns {Observable<RemoteData<NoContent>>} - Observable containing the result of the deletion operation.
|
||||
*/
|
||||
public deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
||||
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a new FindListRequest with given search method
|
||||
*
|
||||
* @param searchMethod The search method for the object
|
||||
* @param options The [[FindListOptions]] object
|
||||
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
|
||||
* no valid cached version. Defaults to true
|
||||
* @param reRequestOnStale Whether or not the request should automatically be re-
|
||||
* requested after the response becomes stale
|
||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
|
||||
* {@link HALLink}s should be automatically resolved
|
||||
* @return {Observable<RemoteData<PaginatedList<T>>}
|
||||
* Return an observable that emits response from the server
|
||||
*/
|
||||
public searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {
|
||||
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||
}
|
||||
|
||||
public invoke(serviceName: string, serviceId: string, parameters: LdnServiceConstrain[], files: File[]): Observable<RemoteData<LdnService>> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
this.getBrowseEndpoint().pipe(
|
||||
take(1),
|
||||
map((endpoint: string) => new URLCombiner(endpoint, serviceName, 'processes', serviceId).toString()),
|
||||
map((endpoint: string) => {
|
||||
const body = this.getInvocationFormData(parameters, files);
|
||||
return new MultipartPostRequest(requestId, endpoint, body);
|
||||
})
|
||||
).subscribe((request: RestRequest) => this.requestService.send(request));
|
||||
|
||||
return this.rdbService.buildFromRequestUUID<LdnService>(requestId);
|
||||
}
|
||||
|
||||
private getInvocationFormData(constrain: LdnServiceConstrain[], files: File[]): FormData {
|
||||
const form: FormData = new FormData();
|
||||
form.set('properties', JSON.stringify(constrain));
|
||||
files.forEach((file: File) => {
|
||||
form.append('file', file);
|
||||
});
|
||||
return form;
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
<div class="container">
|
||||
<div class="d-flex">
|
||||
<h1 class="flex-grow-1">{{ 'ldn-registered-services.title' | translate }}</h1>
|
||||
</div>
|
||||
<div class="d-flex justify-content-end">
|
||||
<button class="btn btn-success" routerLink="/admin/ldn/services/new"><i
|
||||
class="fas fa-plus pr-2"></i>{{ 'process.overview.new' | translate }}</button>
|
||||
</div>
|
||||
<ds-pagination *ngIf="(ldnServicesRD$ | async)?.payload?.totalElements > 0"
|
||||
[collectionSize]="(ldnServicesRD$ | async)?.payload?.totalElements"
|
||||
[hideGear]="true"
|
||||
[hidePagerWhenSinglePage]="true"
|
||||
[pageInfoState]="(ldnServicesRD$ | async)?.payload"
|
||||
[paginationOptions]="pageConfig">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{{ 'service.overview.table.name' | translate }}</th>
|
||||
<th scope="col">{{ 'service.overview.table.description' | translate }}</th>
|
||||
<th scope="col">{{ 'service.overview.table.status' | translate }}</th>
|
||||
<th scope="col">{{ 'service.overview.table.actions' | translate }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let ldnService of (ldnServicesRD$ | async)?.payload?.page">
|
||||
<td class="col-3">{{ ldnService.name }}</td>
|
||||
<td>
|
||||
<ds-truncatable [id]="ldnService.id">
|
||||
<ds-truncatable-part [id]="ldnService.id" [minLines]="2">
|
||||
<div>
|
||||
{{ ldnService.description }}
|
||||
</div>
|
||||
</ds-truncatable-part>
|
||||
</ds-truncatable>
|
||||
</td>
|
||||
<td>
|
||||
<span (click)="toggleStatus(ldnService, ldnServicesService)"
|
||||
[ngClass]="{ 'status-enabled': ldnService.enabled, 'status-disabled': !ldnService.enabled }"
|
||||
[title]="ldnService.enabled ? ('ldn-service.overview.table.clickToDisable' | translate) : ('ldn-service.overview.table.clickToEnable' | translate)"
|
||||
class="status-indicator">
|
||||
{{ ldnService.enabled ? ('ldn-service.overview.table.enabled' | translate) : ('ldn-service.overview.table.disabled' | translate) }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
<button
|
||||
(click)="selectServiceToDelete(ldnService.id)"
|
||||
[attr.aria-label]="'ldn-service-overview-select-delete' | translate"
|
||||
class="btn btn-outline-danger">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
<button [routerLink]="['/admin/ldn/services/edit/', ldnService.id]"
|
||||
[attr.aria-label]="'ldn-service-overview-select-edit' | translate"
|
||||
class="btn btn-outline-dark">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</ds-pagination>
|
||||
</div>
|
||||
|
||||
<ng-template #deleteModal>
|
||||
|
||||
<div>
|
||||
|
||||
<div class="modal-header">
|
||||
<div>
|
||||
<h4>{{'service.overview.delete.header' | translate }}</h4>
|
||||
</div>
|
||||
<button (click)="closeModal()" aria-label="Close"
|
||||
[attr.aria-label]="'ldn-service-overview-close-modal' | translate"
|
||||
class="close" type="button">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div>
|
||||
{{ 'service.overview.delete.body' | translate }}
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<button (click)="closeModal()"
|
||||
[attr.aria-label]="'ldn-service-overview-close-modal' | translate"
|
||||
class="btn btn-primary mr-2">{{ 'service.detail.delete.cancel' | translate }}</button>
|
||||
<button (click)="deleteSelected(this.selectedServiceId.toString(), ldnServicesService)"
|
||||
class="btn btn-danger"
|
||||
[attr.aria-label]="'ldn-service-overview-select-delete' | translate"
|
||||
id="delete-confirm">{{ 'service.overview.delete' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
@@ -0,0 +1,29 @@
|
||||
.status-indicator {
|
||||
padding: 2.5px 25px 2.5px 25px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.5s;
|
||||
}
|
||||
|
||||
.status-enabled {
|
||||
background-color: #daf7a6;
|
||||
color: #4f5359;
|
||||
font-size: 85%;
|
||||
font-weight: bold;
|
||||
|
||||
}
|
||||
|
||||
.status-enabled:hover {
|
||||
background-color: #faa0a0;
|
||||
}
|
||||
|
||||
.status-disabled {
|
||||
background-color: #faa0a0;
|
||||
color: #4f5359;
|
||||
font-size: 85%;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.status-disabled:hover {
|
||||
background-color: #daf7a6;
|
||||
}
|
@@ -0,0 +1,144 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
|
||||
import {ChangeDetectorRef, EventEmitter} from '@angular/core';
|
||||
import {NotificationsService} from '../../../shared/notifications/notifications.service';
|
||||
import {NotificationsServiceStub} from '../../../shared/testing/notifications-service.stub';
|
||||
import {TranslateModule, TranslateService} from '@ngx-translate/core';
|
||||
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
||||
import {LdnServicesService} from '../ldn-services-data/ldn-services-data.service';
|
||||
import {PaginationService} from '../../../core/pagination/pagination.service';
|
||||
import {PaginationServiceStub} from '../../../shared/testing/pagination-service.stub';
|
||||
import {of} from 'rxjs';
|
||||
import {LdnService} from '../ldn-services-model/ldn-services.model';
|
||||
import {PaginatedList} from '../../../core/data/paginated-list.model';
|
||||
import {RemoteData} from '../../../core/data/remote-data';
|
||||
import {LdnServicesOverviewComponent} from './ldn-services-directory.component';
|
||||
import {createSuccessfulRemoteDataObject$} from '../../../shared/remote-data.utils';
|
||||
import {createPaginatedList} from '../../../shared/testing/utils.test';
|
||||
|
||||
describe('LdnServicesOverviewComponent', () => {
|
||||
let component: LdnServicesOverviewComponent;
|
||||
let fixture: ComponentFixture<LdnServicesOverviewComponent>;
|
||||
let ldnServicesService;
|
||||
let paginationService;
|
||||
let modalService: NgbModal;
|
||||
let notificationsService: NotificationsService;
|
||||
let translateService: TranslateService;
|
||||
|
||||
const translateServiceStub = {
|
||||
get: () => of('translated-text'),
|
||||
onLangChange: new EventEmitter(),
|
||||
onTranslationChange: new EventEmitter(),
|
||||
onDefaultLangChange: new EventEmitter()
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
paginationService = new PaginationServiceStub();
|
||||
ldnServicesService = jasmine.createSpyObj('LdnServicesService', ['findAll', 'delete', 'patch']);
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [LdnServicesOverviewComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: LdnServicesService,
|
||||
useValue: ldnServicesService
|
||||
},
|
||||
{provide: PaginationService, useValue: paginationService},
|
||||
{
|
||||
provide: NgbModal, useValue: {
|
||||
open: () => { /*comment*/
|
||||
}
|
||||
}
|
||||
},
|
||||
{provide: ChangeDetectorRef, useValue: {}},
|
||||
{provide: NotificationsService, useValue: NotificationsServiceStub},
|
||||
{provide: TranslateService, useValue: translateServiceStub},
|
||||
]
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(LdnServicesOverviewComponent);
|
||||
component = fixture.componentInstance;
|
||||
ldnServicesService = TestBed.inject(LdnServicesService);
|
||||
paginationService = TestBed.inject(PaginationService);
|
||||
modalService = TestBed.inject(NgbModal);
|
||||
notificationsService = TestBed.inject(NotificationsService);
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
component.modalRef = jasmine.createSpyObj({close: null});
|
||||
component.isProcessingSub = jasmine.createSpyObj({unsubscribe: null});
|
||||
component.ldnServicesRD$ = of({} as RemoteData<PaginatedList<LdnService>>);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('ngOnInit', () => {
|
||||
it('should call setLdnServices', fakeAsync(() => {
|
||||
spyOn(component, 'setLdnServices').and.callThrough();
|
||||
component.ngOnInit();
|
||||
tick();
|
||||
expect(component.setLdnServices).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should set ldnServicesRD$ with mock data', fakeAsync(() => {
|
||||
spyOn(component, 'setLdnServices').and.callThrough();
|
||||
const testData: LdnService[] = Object.assign([new LdnService()], [
|
||||
{id: 1, name: 'Service 1', description: 'Description 1', enabled: true},
|
||||
{id: 2, name: 'Service 2', description: 'Description 2', enabled: false},
|
||||
{id: 3, name: 'Service 3', description: 'Description 3', enabled: true}]);
|
||||
|
||||
const mockLdnServicesRD = createPaginatedList(testData);
|
||||
component.ldnServicesRD$ = createSuccessfulRemoteDataObject$(mockLdnServicesRD);
|
||||
fixture.detectChanges();
|
||||
|
||||
const tableRows = fixture.debugElement.nativeElement.querySelectorAll('tbody tr');
|
||||
expect(tableRows.length).toBe(testData.length);
|
||||
const firstRowContent = tableRows[0].textContent;
|
||||
expect(firstRowContent).toContain('Service 1');
|
||||
expect(firstRowContent).toContain('Description 1');
|
||||
}));
|
||||
});
|
||||
|
||||
describe('ngOnDestroy', () => {
|
||||
it('should call paginationService.clearPagination and unsubscribe', () => {
|
||||
// spyOn(paginationService, 'clearPagination');
|
||||
// spyOn(component.isProcessingSub, 'unsubscribe');
|
||||
component.ngOnDestroy();
|
||||
expect(paginationService.clearPagination).toHaveBeenCalledWith(component.pageConfig.id);
|
||||
expect(component.isProcessingSub.unsubscribe).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('openDeleteModal', () => {
|
||||
it('should open delete modal', () => {
|
||||
spyOn(modalService, 'open');
|
||||
component.openDeleteModal(component.deleteModal);
|
||||
expect(modalService.open).toHaveBeenCalledWith(component.deleteModal);
|
||||
});
|
||||
});
|
||||
|
||||
describe('closeModal', () => {
|
||||
it('should close modal and detect changes', () => {
|
||||
// spyOn(component.modalRef, 'close');
|
||||
spyOn(component.cdRef, 'detectChanges');
|
||||
component.closeModal();
|
||||
expect(component.modalRef.close).toHaveBeenCalled();
|
||||
expect(component.cdRef.detectChanges).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteSelected', () => {
|
||||
it('should delete selected service and update data', fakeAsync(() => {
|
||||
const serviceId = '123';
|
||||
const mockRemoteData = { /* just an empty object to retrieve as as RemoteData<PaginatedList<LdnService>> */};
|
||||
spyOn(component, 'setLdnServices').and.callThrough();
|
||||
const deleteSpy = ldnServicesService.delete.and.returnValue(of(mockRemoteData as RemoteData<PaginatedList<LdnService>>));
|
||||
component.selectedServiceId = serviceId;
|
||||
component.deleteSelected(serviceId, ldnServicesService);
|
||||
tick();
|
||||
expect(deleteSpy).toHaveBeenCalledWith(serviceId);
|
||||
}));
|
||||
});
|
||||
});
|
@@ -0,0 +1,176 @@
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
TemplateRef,
|
||||
ViewChild
|
||||
} from '@angular/core';
|
||||
import {Observable, Subscription} from 'rxjs';
|
||||
import {RemoteData} from '../../../core/data/remote-data';
|
||||
import {PaginatedList} from '../../../core/data/paginated-list.model';
|
||||
import {FindListOptions} from '../../../core/data/find-list-options.model';
|
||||
import {LdnService} from '../ldn-services-model/ldn-services.model';
|
||||
import {PaginationComponentOptions} from '../../../shared/pagination/pagination-component-options.model';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {LdnServicesService} from 'src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service';
|
||||
import {PaginationService} from 'src/app/core/pagination/pagination.service';
|
||||
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
||||
import {hasValue} from '../../../shared/empty.util';
|
||||
import {Operation} from 'fast-json-patch';
|
||||
import {getFirstCompletedRemoteData} from '../../../core/shared/operators';
|
||||
import {NotificationsService} from '../../../shared/notifications/notifications.service';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
|
||||
|
||||
/**
|
||||
* The `LdnServicesOverviewComponent` is a component that provides an overview of LDN (Linked Data Notifications) services.
|
||||
* It displays a paginated list of LDN services, allows users to edit and delete services,
|
||||
* toggle the status of each service directly form the page and allows for creation of new services redirecting the user on the creation/edit form
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-ldn-services-directory',
|
||||
templateUrl: './ldn-services-directory.component.html',
|
||||
styleUrls: ['./ldn-services-directory.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.Default
|
||||
})
|
||||
export class LdnServicesOverviewComponent implements OnInit, OnDestroy {
|
||||
|
||||
selectedServiceId: string | number | null = null;
|
||||
servicesData: any[] = [];
|
||||
@ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef<any>;
|
||||
ldnServicesRD$: Observable<RemoteData<PaginatedList<LdnService>>>;
|
||||
config: FindListOptions = Object.assign(new FindListOptions(), {
|
||||
elementsPerPage: 10
|
||||
});
|
||||
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
|
||||
id: 'po',
|
||||
pageSize: 10
|
||||
});
|
||||
isProcessingSub: Subscription;
|
||||
modalRef: any;
|
||||
|
||||
|
||||
constructor(
|
||||
protected ldnServicesService: LdnServicesService,
|
||||
protected paginationService: PaginationService,
|
||||
protected modalService: NgbModal,
|
||||
public cdRef: ChangeDetectorRef,
|
||||
private notificationService: NotificationsService,
|
||||
private translateService: TranslateService,
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.setLdnServices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the LDN services by fetching and observing the paginated list of services.
|
||||
*/
|
||||
setLdnServices() {
|
||||
this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe(
|
||||
switchMap((config) => this.ldnServicesService.findAll(config, false, false).pipe(
|
||||
getFirstCompletedRemoteData()
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.paginationService.clearPagination(this.pageConfig.id);
|
||||
if (hasValue(this.isProcessingSub)) {
|
||||
this.isProcessingSub.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the delete confirmation modal.
|
||||
*
|
||||
* @param {any} content - The content of the modal.
|
||||
*/
|
||||
openDeleteModal(content) {
|
||||
this.modalRef = this.modalService.open(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the currently open modal and triggers change detection.
|
||||
*/
|
||||
closeModal() {
|
||||
this.modalRef.close();
|
||||
this.cdRef.detectChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected LDN service ID for deletion and opens the delete confirmation modal.
|
||||
*
|
||||
* @param {number} serviceId - The ID of the service to be deleted.
|
||||
*/
|
||||
selectServiceToDelete(serviceId: number) {
|
||||
this.selectedServiceId = serviceId;
|
||||
this.openDeleteModal(this.deleteModal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the selected LDN service.
|
||||
*
|
||||
* @param {string} serviceId - The ID of the service to be deleted.
|
||||
* @param {LdnServicesService} ldnServicesService - The service for managing LDN services.
|
||||
*/
|
||||
deleteSelected(serviceId: string, ldnServicesService: LdnServicesService): void {
|
||||
if (this.selectedServiceId !== null) {
|
||||
ldnServicesService.delete(serviceId).pipe(getFirstCompletedRemoteData()).subscribe((rd: RemoteData<LdnService>) => {
|
||||
if (rd.hasSucceeded) {
|
||||
this.servicesData = this.servicesData.filter(service => service.id !== serviceId);
|
||||
this.ldnServicesRD$ = this.ldnServicesRD$.pipe(
|
||||
map((remoteData: RemoteData<PaginatedList<LdnService>>) => {
|
||||
if (remoteData.hasSucceeded) {
|
||||
remoteData.payload.page = remoteData.payload.page.filter(service => service.id.toString() !== serviceId);
|
||||
}
|
||||
return remoteData;
|
||||
})
|
||||
);
|
||||
this.cdRef.detectChanges();
|
||||
this.closeModal();
|
||||
this.notificationService.success(this.translateService.get('ldn-service-delete.notification.success.title'),
|
||||
this.translateService.get('ldn-service-delete.notification.success.content'));
|
||||
} else {
|
||||
this.notificationService.error(this.translateService.get('ldn-service-delete.notification.error.title'),
|
||||
this.translateService.get('ldn-service-delete.notification.error.content'));
|
||||
this.cdRef.detectChanges();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the status (enabled/disabled) of an LDN service.
|
||||
*
|
||||
* @param {any} ldnService - The LDN service object.
|
||||
* @param {LdnServicesService} ldnServicesService - The service for managing LDN services.
|
||||
*/
|
||||
toggleStatus(ldnService: any, ldnServicesService: LdnServicesService): void {
|
||||
const newStatus = !ldnService.enabled;
|
||||
const originalStatus = ldnService.enabled;
|
||||
|
||||
const patchOperation: Operation = {
|
||||
op: 'replace',
|
||||
path: '/enabled',
|
||||
value: newStatus,
|
||||
};
|
||||
|
||||
ldnServicesService.patch(ldnService, [patchOperation]).pipe(getFirstCompletedRemoteData()).subscribe(
|
||||
(rd: RemoteData<LdnService>) => {
|
||||
if (rd.hasSucceeded) {
|
||||
ldnService.enabled = newStatus;
|
||||
this.notificationService.success(this.translateService.get('ldn-enable-service.notification.success.title'),
|
||||
this.translateService.get('ldn-enable-service.notification.success.content'));
|
||||
} else {
|
||||
ldnService.enabled = originalStatus;
|
||||
this.notificationService.error(this.translateService.get('ldn-enable-service.notification.error.title'),
|
||||
this.translateService.get('ldn-enable-service.notification.error.content'));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
import {autoserialize, deserialize, inheritSerialization} from 'cerialize';
|
||||
import {LDN_SERVICE_CONSTRAINT_FILTER} from './ldn-service.resource-type';
|
||||
import {CacheableObject} from '../../../core/cache/cacheable-object.model';
|
||||
import {typedObject} from '../../../core/cache/builders/build-decorators';
|
||||
import {excludeFromEquals} from '../../../core/utilities/equals.decorators';
|
||||
import {ResourceType} from '../../../core/shared/resource-type';
|
||||
|
||||
/** A single filter value and its properties. */
|
||||
@typedObject
|
||||
@inheritSerialization(CacheableObject)
|
||||
export class Itemfilter extends CacheableObject {
|
||||
static type = LDN_SERVICE_CONSTRAINT_FILTER;
|
||||
|
||||
@excludeFromEquals
|
||||
@autoserialize
|
||||
type: ResourceType;
|
||||
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
@deserialize
|
||||
_links: {
|
||||
self: {
|
||||
href: string;
|
||||
};
|
||||
};
|
||||
|
||||
get self(): string {
|
||||
return this._links.self.href;
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
import {autoserialize} from 'cerialize';
|
||||
|
||||
/**
|
||||
* A single notify service pattern and his properties
|
||||
*/
|
||||
export class NotifyServicePattern {
|
||||
@autoserialize
|
||||
pattern: string;
|
||||
@autoserialize
|
||||
constraint: string;
|
||||
@autoserialize
|
||||
automatic: string;
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* List of services statuses
|
||||
*/
|
||||
export enum LdnServiceStatus {
|
||||
UNKOWN,
|
||||
DISABLED,
|
||||
ENABLED,
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
export class LdnServiceConstrain {
|
||||
void: any;
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* 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 LDN_SERVICE = new ResourceType('ldnservice');
|
||||
export const LDN_SERVICE_CONSTRAINT_FILTERS = new ResourceType('itemfilters');
|
||||
|
||||
export const LDN_SERVICE_CONSTRAINT_FILTER = new ResourceType('itemfilter');
|
@@ -0,0 +1,72 @@
|
||||
import {ResourceType} from '../../../core/shared/resource-type';
|
||||
import {CacheableObject} from '../../../core/cache/cacheable-object.model';
|
||||
import {autoserialize, deserialize, deserializeAs, inheritSerialization} from 'cerialize';
|
||||
import {LDN_SERVICE} from './ldn-service.resource-type';
|
||||
import {excludeFromEquals} from '../../../core/utilities/equals.decorators';
|
||||
import {typedObject} from '../../../core/cache/builders/build-decorators';
|
||||
import {NotifyServicePattern} from './ldn-service-patterns.model';
|
||||
|
||||
|
||||
/**
|
||||
* LDN Services bounded to each selected pattern, relation set in service creation
|
||||
*/
|
||||
|
||||
export interface LdnServiceByPattern {
|
||||
allowsMultipleRequests: boolean;
|
||||
services: LdnService[];
|
||||
}
|
||||
|
||||
/** An LdnService and its properties. */
|
||||
@typedObject
|
||||
@inheritSerialization(CacheableObject)
|
||||
export class LdnService extends CacheableObject {
|
||||
static type = LDN_SERVICE;
|
||||
|
||||
@excludeFromEquals
|
||||
@autoserialize
|
||||
type: ResourceType;
|
||||
|
||||
@autoserialize
|
||||
id: number;
|
||||
|
||||
@deserializeAs('id')
|
||||
uuid: string;
|
||||
|
||||
@autoserialize
|
||||
name: string;
|
||||
|
||||
@autoserialize
|
||||
description: string;
|
||||
|
||||
@autoserialize
|
||||
url: string;
|
||||
|
||||
@autoserialize
|
||||
score: number;
|
||||
|
||||
@autoserialize
|
||||
enabled: boolean;
|
||||
|
||||
@autoserialize
|
||||
ldnUrl: string;
|
||||
|
||||
@autoserialize
|
||||
lowerIp: string;
|
||||
|
||||
@autoserialize
|
||||
upperIp: string;
|
||||
|
||||
@autoserialize
|
||||
notifyServiceInboundPatterns?: NotifyServicePattern[];
|
||||
|
||||
@deserialize
|
||||
_links: {
|
||||
self: {
|
||||
href: string;
|
||||
};
|
||||
};
|
||||
|
||||
get self(): string {
|
||||
return this._links.self.href;
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* List of parameter types used for scripts
|
||||
*/
|
||||
export enum LdnServiceConstrainType {
|
||||
STRING = 'String',
|
||||
DATE = 'date',
|
||||
BOOLEAN = 'boolean',
|
||||
FILE = 'InputStream',
|
||||
OUTPUT = 'OutputStream'
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* All available patterns for LDN service creation.
|
||||
* They are used to populate a dropdown in the LDN service form creation
|
||||
*/
|
||||
|
||||
export const notifyPatterns = [
|
||||
|
||||
'request-endorsement',
|
||||
|
||||
'request-ingest',
|
||||
|
||||
'request-review',
|
||||
|
||||
];
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/r
|
||||
/**
|
||||
* Interface for the route parameters.
|
||||
*/
|
||||
export interface AdminNotificationsPublicationClaimPageParams {
|
||||
export interface NotificationsSuggestionTargetsPageParams {
|
||||
pageId?: string;
|
||||
pageSize?: number;
|
||||
currentPage?: number;
|
||||
@@ -14,7 +14,7 @@ export interface AdminNotificationsPublicationClaimPageParams {
|
||||
* This class represents a resolver that retrieve the route data before the route is activated.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AdminNotificationsPublicationClaimPageResolver implements Resolve<AdminNotificationsPublicationClaimPageParams> {
|
||||
export class NotificationsSuggestionTargetsPageResolver implements Resolve<NotificationsSuggestionTargetsPageParams> {
|
||||
|
||||
/**
|
||||
* Method for resolving the parameters in the current route.
|
||||
@@ -22,7 +22,7 @@ export class AdminNotificationsPublicationClaimPageResolver implements Resolve<A
|
||||
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
|
||||
* @returns AdminNotificationsSuggestionTargetsPageParams Emits the route parameters
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): AdminNotificationsPublicationClaimPageParams {
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): NotificationsSuggestionTargetsPageParams {
|
||||
return {
|
||||
pageId: route.queryParams.pageId,
|
||||
pageSize: parseInt(route.queryParams.pageSize, 10),
|
||||
|
@@ -1,13 +1,15 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AdminNotificationsPublicationClaimPageComponent } from './admin-notifications-publication-claim-page.component';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import {
|
||||
NotificationsSuggestionTargetsPageComponent
|
||||
} from '../../../quality-assurance-notifications-pages/notifications-suggestion-targets-page/notifications-suggestion-targets-page.component';
|
||||
|
||||
describe('AdminNotificationsPublicationClaimPageComponent', () => {
|
||||
let component: AdminNotificationsPublicationClaimPageComponent;
|
||||
let fixture: ComponentFixture<AdminNotificationsPublicationClaimPageComponent>;
|
||||
describe('NotificationsSuggestionTargetsPageComponent', () => {
|
||||
let component: NotificationsSuggestionTargetsPageComponent;
|
||||
let fixture: ComponentFixture<NotificationsSuggestionTargetsPageComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@@ -16,10 +18,10 @@ describe('AdminNotificationsPublicationClaimPageComponent', () => {
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
AdminNotificationsPublicationClaimPageComponent
|
||||
NotificationsSuggestionTargetsPageComponent
|
||||
],
|
||||
providers: [
|
||||
AdminNotificationsPublicationClaimPageComponent
|
||||
NotificationsSuggestionTargetsPageComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
@@ -27,7 +29,7 @@ describe('AdminNotificationsPublicationClaimPageComponent', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AdminNotificationsPublicationClaimPageComponent);
|
||||
fixture = TestBed.createComponent(NotificationsSuggestionTargetsPageComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
@@ -6,22 +6,37 @@ import { I18nBreadcrumbResolver } from '../../core/breadcrumbs/i18n-breadcrumb.r
|
||||
import { I18nBreadcrumbsService } from '../../core/breadcrumbs/i18n-breadcrumbs.service';
|
||||
import { PUBLICATION_CLAIMS_PATH } from './admin-notifications-routing-paths';
|
||||
import { AdminNotificationsPublicationClaimPageComponent } from './admin-notifications-publication-claim-page/admin-notifications-publication-claim-page.component';
|
||||
import { AdminNotificationsPublicationClaimPageResolver } from './admin-notifications-publication-claim-page/admin-notifications-publication-claim-page-resolver.service';
|
||||
import { QUALITY_ASSURANCE_EDIT_PATH } from './admin-notifications-routing-paths';
|
||||
import { AdminQualityAssuranceTopicsPageComponent } from './admin-quality-assurance-topics-page/admin-quality-assurance-topics-page.component';
|
||||
import { AdminQualityAssuranceEventsPageComponent } from './admin-quality-assurance-events-page/admin-quality-assurance-events-page.component';
|
||||
import { AdminQualityAssuranceTopicsPageResolver } from './admin-quality-assurance-topics-page/admin-quality-assurance-topics-page-resolver.service';
|
||||
import { AdminQualityAssuranceEventsPageResolver } from './admin-quality-assurance-events-page/admin-quality-assurance-events-page.resolver';
|
||||
import { AdminQualityAssuranceSourcePageComponent } from './admin-quality-assurance-source-page-component/admin-quality-assurance-source-page.component';
|
||||
import { AdminQualityAssuranceSourcePageResolver } from './admin-quality-assurance-source-page-component/admin-quality-assurance-source-page-resolver.service';
|
||||
import {
|
||||
SiteAdministratorGuard
|
||||
} from '../../core/data/feature-authorization/feature-authorization-guard/site-administrator.guard';
|
||||
import { QualityAssuranceBreadcrumbResolver } from '../../core/breadcrumbs/quality-assurance-breadcrumb.resolver';
|
||||
import { QualityAssuranceBreadcrumbService } from '../../core/breadcrumbs/quality-assurance-breadcrumb.service';
|
||||
import {
|
||||
QualityAssuranceEventsPageResolver
|
||||
} from '../../quality-assurance-notifications-pages/quality-assurance-events-page/quality-assurance-events-page.resolver';
|
||||
import {
|
||||
AdminNotificationsPublicationClaimPageResolver
|
||||
} from '../../quality-assurance-notifications-pages/notifications-suggestion-targets-page/notifications-suggestion-targets-page-resolver.service';
|
||||
import {
|
||||
QualityAssuranceTopicsPageComponent
|
||||
} from '../../quality-assurance-notifications-pages/quality-assurance-topics-page/quality-assurance-topics-page.component';
|
||||
import {
|
||||
QualityAssuranceTopicsPageResolver
|
||||
} from '../../quality-assurance-notifications-pages/quality-assurance-topics-page/quality-assurance-topics-page-resolver.service';
|
||||
import {
|
||||
QualityAssuranceSourcePageComponent
|
||||
} from '../../quality-assurance-notifications-pages/quality-assurance-source-page-component/quality-assurance-source-page.component';
|
||||
import {
|
||||
QualityAssuranceSourcePageResolver
|
||||
} from '../../quality-assurance-notifications-pages/quality-assurance-source-page-component/quality-assurance-source-page-resolver.service';
|
||||
import {
|
||||
SourceDataResolver
|
||||
} from './admin-quality-assurance-source-page-component/admin-quality-assurance-source-data.resolver';
|
||||
} from '../../quality-assurance-notifications-pages/quality-assurance-source-page-component/quality-assurance-source-data.resolver';
|
||||
import {
|
||||
QualityAssuranceEventsPageComponent
|
||||
} from '../../quality-assurance-notifications-pages/quality-assurance-events-page/quality-assurance-events-page.component';
|
||||
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -44,11 +59,11 @@ import {
|
||||
{
|
||||
canActivate: [ AuthenticatedGuard ],
|
||||
path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId`,
|
||||
component: AdminQualityAssuranceTopicsPageComponent,
|
||||
component: QualityAssuranceTopicsPageComponent,
|
||||
pathMatch: 'full',
|
||||
resolve: {
|
||||
breadcrumb: QualityAssuranceBreadcrumbResolver,
|
||||
openaireQualityAssuranceTopicsParams: AdminQualityAssuranceTopicsPageResolver
|
||||
openaireQualityAssuranceTopicsParams: QualityAssuranceTopicsPageResolver
|
||||
},
|
||||
data: {
|
||||
title: 'admin.quality-assurance.page.title',
|
||||
@@ -59,11 +74,11 @@ import {
|
||||
{
|
||||
canActivate: [ AuthenticatedGuard ],
|
||||
path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId/target/:targetId`,
|
||||
component: AdminQualityAssuranceTopicsPageComponent,
|
||||
component: QualityAssuranceTopicsPageComponent,
|
||||
pathMatch: 'full',
|
||||
resolve: {
|
||||
breadcrumb: I18nBreadcrumbResolver,
|
||||
openaireQualityAssuranceTopicsParams: AdminQualityAssuranceTopicsPageResolver
|
||||
openaireQualityAssuranceTopicsParams: QualityAssuranceTopicsPageResolver
|
||||
},
|
||||
data: {
|
||||
title: 'admin.quality-assurance.page.title',
|
||||
@@ -74,11 +89,11 @@ import {
|
||||
{
|
||||
canActivate: [ SiteAdministratorGuard ],
|
||||
path: `${QUALITY_ASSURANCE_EDIT_PATH}`,
|
||||
component: AdminQualityAssuranceSourcePageComponent,
|
||||
component: QualityAssuranceSourcePageComponent,
|
||||
pathMatch: 'full',
|
||||
resolve: {
|
||||
breadcrumb: I18nBreadcrumbResolver,
|
||||
openaireQualityAssuranceSourceParams: AdminQualityAssuranceSourcePageResolver,
|
||||
openaireQualityAssuranceSourceParams: QualityAssuranceSourcePageResolver,
|
||||
sourceData: SourceDataResolver
|
||||
},
|
||||
data: {
|
||||
@@ -90,11 +105,11 @@ import {
|
||||
{
|
||||
canActivate: [ AuthenticatedGuard ],
|
||||
path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId/:topicId`,
|
||||
component: AdminQualityAssuranceEventsPageComponent,
|
||||
component: QualityAssuranceEventsPageComponent,
|
||||
pathMatch: 'full',
|
||||
resolve: {
|
||||
breadcrumb: QualityAssuranceBreadcrumbResolver,
|
||||
openaireQualityAssuranceEventsParams: AdminQualityAssuranceEventsPageResolver
|
||||
openaireQualityAssuranceEventsParams: QualityAssuranceEventsPageResolver
|
||||
},
|
||||
data: {
|
||||
title: 'admin.notifications.event.page.title',
|
||||
@@ -109,10 +124,10 @@ import {
|
||||
I18nBreadcrumbsService,
|
||||
AdminNotificationsPublicationClaimPageResolver,
|
||||
SourceDataResolver,
|
||||
AdminQualityAssuranceSourcePageResolver,
|
||||
AdminQualityAssuranceTopicsPageResolver,
|
||||
AdminQualityAssuranceEventsPageResolver,
|
||||
AdminQualityAssuranceSourcePageResolver,
|
||||
QualityAssuranceSourcePageResolver,
|
||||
QualityAssuranceTopicsPageResolver,
|
||||
QualityAssuranceEventsPageResolver,
|
||||
QualityAssuranceSourcePageResolver,
|
||||
QualityAssuranceBreadcrumbResolver,
|
||||
QualityAssuranceBreadcrumbService
|
||||
]
|
||||
|
@@ -4,11 +4,14 @@ import { CoreModule } from '../../core/core.module';
|
||||
import { SharedModule } from '../../shared/shared.module';
|
||||
import { AdminNotificationsRoutingModule } from './admin-notifications-routing.module';
|
||||
import { AdminNotificationsPublicationClaimPageComponent } from './admin-notifications-publication-claim-page/admin-notifications-publication-claim-page.component';
|
||||
import { AdminQualityAssuranceTopicsPageComponent } from './admin-quality-assurance-topics-page/admin-quality-assurance-topics-page.component';
|
||||
import { AdminQualityAssuranceEventsPageComponent } from './admin-quality-assurance-events-page/admin-quality-assurance-events-page.component';
|
||||
import { AdminQualityAssuranceSourcePageComponent } from './admin-quality-assurance-source-page-component/admin-quality-assurance-source-page.component';
|
||||
import { NotificationsModule } from '../../notifications/notifications.module';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
@@ -19,9 +22,6 @@ import { NotificationsModule } from '../../notifications/notifications.module';
|
||||
],
|
||||
declarations: [
|
||||
AdminNotificationsPublicationClaimPageComponent,
|
||||
AdminQualityAssuranceTopicsPageComponent,
|
||||
AdminQualityAssuranceEventsPageComponent,
|
||||
AdminQualityAssuranceSourcePageComponent
|
||||
],
|
||||
entryComponents: []
|
||||
})
|
||||
|
@@ -1,27 +0,0 @@
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AdminQualityAssuranceSourcePageComponent } from './admin-quality-assurance-source-page.component';
|
||||
|
||||
describe('AdminQualityAssuranceSourcePageComponent', () => {
|
||||
let component: AdminQualityAssuranceSourcePageComponent;
|
||||
let fixture: ComponentFixture<AdminQualityAssuranceSourcePageComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ AdminQualityAssuranceSourcePageComponent ],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AdminQualityAssuranceSourcePageComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create AdminQualityAssuranceSourcePageComponent', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@@ -1,10 +0,0 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
/**
|
||||
* Component for the page that show the QA sources.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-admin-quality-assurance-source-page-component',
|
||||
templateUrl: './admin-quality-assurance-source-page.component.html',
|
||||
})
|
||||
export class AdminQualityAssuranceSourcePageComponent {}
|
@@ -1,26 +0,0 @@
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AdminQualityAssuranceTopicsPageComponent } from './admin-quality-assurance-topics-page.component';
|
||||
|
||||
describe('AdminQualityAssuranceTopicsPageComponent', () => {
|
||||
let component: AdminQualityAssuranceTopicsPageComponent;
|
||||
let fixture: ComponentFixture<AdminQualityAssuranceTopicsPageComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ AdminQualityAssuranceTopicsPageComponent ],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AdminQualityAssuranceTopicsPageComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create AdminQualityAssuranceTopicsPageComponent', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@@ -4,12 +4,19 @@ import { getQualityAssuranceEditRoute } from './admin-notifications/admin-notifi
|
||||
|
||||
export const REGISTRIES_MODULE_PATH = 'registries';
|
||||
export const NOTIFICATIONS_MODULE_PATH = 'notifications';
|
||||
export const LDN_PATH = 'ldn';
|
||||
export const REPORTS_MODULE_PATH = 'reports';
|
||||
|
||||
|
||||
|
||||
export function getRegistriesModuleRoute() {
|
||||
return new URLCombiner(getAdminModuleRoute(), REGISTRIES_MODULE_PATH).toString();
|
||||
}
|
||||
|
||||
export function getLdnServicesModuleRoute() {
|
||||
return new URLCombiner(getAdminModuleRoute(), LDN_PATH).toString();
|
||||
}
|
||||
|
||||
export function getNotificationsModuleRoute() {
|
||||
return new URLCombiner(getAdminModuleRoute(), NOTIFICATIONS_MODULE_PATH).toString();
|
||||
}
|
||||
|
@@ -6,7 +6,11 @@ import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.reso
|
||||
import { AdminWorkflowPageComponent } from './admin-workflow-page/admin-workflow-page.component';
|
||||
import { I18nBreadcrumbsService } from '../core/breadcrumbs/i18n-breadcrumbs.service';
|
||||
import { AdminCurationTasksComponent } from './admin-curation-tasks/admin-curation-tasks.component';
|
||||
import { REGISTRIES_MODULE_PATH, REPORTS_MODULE_PATH } from './admin-routing-paths';
|
||||
import {
|
||||
LDN_PATH,
|
||||
NOTIFICATIONS_MODULE_PATH,
|
||||
REGISTRIES_MODULE_PATH, REPORTS_MODULE_PATH,
|
||||
} from './admin-routing-paths';
|
||||
import { BatchImportPageComponent } from './admin-import-batch-page/batch-import-page.component';
|
||||
import {
|
||||
SiteAdministratorGuard
|
||||
@@ -15,17 +19,17 @@ import {
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild([
|
||||
{
|
||||
path: NOTIFICATIONS_MODULE_PATH,
|
||||
loadChildren: () => import('./admin-notifications/admin-notifications.module')
|
||||
.then((m) => m.AdminNotificationsModule),
|
||||
},
|
||||
{
|
||||
path: REGISTRIES_MODULE_PATH,
|
||||
loadChildren: () => import('./admin-registries/admin-registries.module')
|
||||
.then((m) => m.AdminRegistriesModule),
|
||||
canActivate: [SiteAdministratorGuard]
|
||||
},
|
||||
{
|
||||
path: REPORTS_MODULE_PATH,
|
||||
loadChildren: () => import('./admin-reports/admin-reports.module')
|
||||
.then((m) => m.AdminReportsModule),
|
||||
},
|
||||
{
|
||||
path: 'search',
|
||||
resolve: { breadcrumb: I18nBreadcrumbResolver },
|
||||
@@ -68,6 +72,22 @@ import {
|
||||
data: {title: 'admin.system-wide-alert.title', breadcrumbKey: 'admin.system-wide-alert'},
|
||||
canActivate: [SiteAdministratorGuard]
|
||||
},
|
||||
{
|
||||
path: LDN_PATH,
|
||||
children: [
|
||||
{ path: '', pathMatch: 'full', redirectTo: 'services' },
|
||||
{
|
||||
path: 'services',
|
||||
loadChildren: () => import('./admin-ldn-services/admin-ldn-services.module')
|
||||
.then((m) => m.AdminLdnServicesModule),
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
path: REPORTS_MODULE_PATH,
|
||||
loadChildren: () => import('./admin-reports/admin-reports.module')
|
||||
.then((m) => m.AdminReportsModule),
|
||||
},
|
||||
])
|
||||
],
|
||||
providers: [
|
||||
|
@@ -31,6 +31,7 @@ export function getBitstreamRequestACopyRoute(item, bitstream): { routerLink: st
|
||||
}
|
||||
};
|
||||
}
|
||||
export const COAR_NOTIFY_SUPPORT = 'coar-notify-support';
|
||||
|
||||
export const HOME_PAGE_PATH = 'admin';
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { NoPreloading, RouterModule } from '@angular/router';
|
||||
import { RouterModule, NoPreloading } from '@angular/router';
|
||||
import { AuthBlockingGuard } from './core/auth/auth-blocking.guard';
|
||||
|
||||
import { AuthenticatedGuard } from './core/auth/authenticated.guard';
|
||||
@@ -94,10 +94,7 @@ import { ForgotPasswordCheckGuard } from './core/rest-property/forgot-password-c
|
||||
path: FORGOT_PASSWORD_PATH,
|
||||
loadChildren: () => import('./forgot-password/forgot-password.module')
|
||||
.then((m) => m.ForgotPasswordModule),
|
||||
canActivate: [
|
||||
ForgotPasswordCheckGuard,
|
||||
EndUserAgreementCurrentUserGuard
|
||||
]
|
||||
canActivate: [EndUserAgreementCurrentUserGuard, ForgotPasswordCheckGuard]
|
||||
},
|
||||
{
|
||||
path: COMMUNITY_MODULE_PATH,
|
||||
@@ -165,6 +162,12 @@ import { ForgotPasswordCheckGuard } from './core/rest-property/forgot-password-c
|
||||
.then((m) => m.AdminNotificationsModule),
|
||||
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: NOTIFICATIONS_MODULE_PATH,
|
||||
loadChildren: () => import('./quality-assurance-notifications-pages/notifications-pages.module')
|
||||
.then((m) => m.NotificationsPageModule),
|
||||
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'login',
|
||||
loadChildren: () => import('./login-page/login-page.module')
|
||||
|
@@ -0,0 +1,52 @@
|
||||
import { NavigationBreadcrumbResolver } from './navigation-breadcrumb.resolver';
|
||||
|
||||
describe('NavigationBreadcrumbResolver', () => {
|
||||
describe('resolve', () => {
|
||||
let resolver: NavigationBreadcrumbResolver;
|
||||
let NavigationBreadcrumbService: any;
|
||||
let i18nKey: string;
|
||||
let relatedI18nKey: string;
|
||||
let route: any;
|
||||
let expectedPath;
|
||||
let state;
|
||||
beforeEach(() => {
|
||||
i18nKey = 'example.key';
|
||||
relatedI18nKey = 'related.key';
|
||||
route = {
|
||||
data: {
|
||||
breadcrumbKey: i18nKey,
|
||||
relatedRoutes: [
|
||||
{
|
||||
path: '',
|
||||
data: {breadcrumbKey: relatedI18nKey},
|
||||
}
|
||||
]
|
||||
},
|
||||
routeConfig: {
|
||||
path: 'example'
|
||||
},
|
||||
parent: {
|
||||
routeConfig: {
|
||||
path: ''
|
||||
},
|
||||
url: [{
|
||||
path: 'base'
|
||||
}]
|
||||
} as any
|
||||
};
|
||||
|
||||
state = {
|
||||
url: '/base/example'
|
||||
};
|
||||
expectedPath = '/base/example:/base';
|
||||
NavigationBreadcrumbService = {};
|
||||
resolver = new NavigationBreadcrumbResolver(NavigationBreadcrumbService);
|
||||
});
|
||||
|
||||
it('should resolve the breadcrumb config', () => {
|
||||
const resolvedConfig = resolver.resolve(route, state);
|
||||
const expectedConfig = { provider: NavigationBreadcrumbService, key: `${i18nKey}:${relatedI18nKey}`, url: expectedPath };
|
||||
expect(resolvedConfig).toEqual(expectedConfig);
|
||||
});
|
||||
});
|
||||
});
|
52
src/app/core/breadcrumbs/navigation-breadcrumb.resolver.ts
Normal file
52
src/app/core/breadcrumbs/navigation-breadcrumb.resolver.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { BreadcrumbConfig } from '../../breadcrumbs/breadcrumb/breadcrumb-config.model';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
|
||||
import { NavigationBreadcrumbsService } from './navigation-breadcrumb.service';
|
||||
|
||||
/**
|
||||
* The class that resolves a BreadcrumbConfig object with an i18n key string for a route and related parents
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NavigationBreadcrumbResolver implements Resolve<BreadcrumbConfig<string>> {
|
||||
|
||||
private parentRoutes: ActivatedRouteSnapshot[] = [];
|
||||
constructor(protected breadcrumbService: NavigationBreadcrumbsService) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to collect all parent routes snapshot from current route snapshot
|
||||
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
|
||||
*/
|
||||
private getParentRoutes(route: ActivatedRouteSnapshot): void {
|
||||
if (route.parent) {
|
||||
this.parentRoutes.push(route.parent);
|
||||
this.getParentRoutes(route.parent);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Method for resolving an I18n breadcrumb configuration object
|
||||
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
|
||||
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
|
||||
* @returns BreadcrumbConfig object
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): BreadcrumbConfig<string> {
|
||||
this.getParentRoutes(route);
|
||||
const relatedRoutes = route.data.relatedRoutes;
|
||||
const parentPaths = this.parentRoutes.map(parent => parent.routeConfig?.path);
|
||||
const relatedParentRoutes = relatedRoutes.filter(relatedRoute => parentPaths.includes(relatedRoute.path));
|
||||
const baseUrlSegmentPath = route.parent.url[route.parent.url.length - 1].path;
|
||||
const baseUrl = state.url.substring(0, state.url.lastIndexOf(baseUrlSegmentPath) + baseUrlSegmentPath.length);
|
||||
|
||||
|
||||
const combinedParentBreadcrumbKeys = relatedParentRoutes.reduce((previous, current) => {
|
||||
return `${previous}:${current.data.breadcrumbKey}`;
|
||||
}, route.data.breadcrumbKey);
|
||||
const combinedUrls = relatedParentRoutes.reduce((previous, current) => {
|
||||
return `${previous}:${baseUrl}${current.path}`;
|
||||
}, state.url);
|
||||
|
||||
return {provider: this.breadcrumbService, key: combinedParentBreadcrumbKeys, url: combinedUrls};
|
||||
}
|
||||
}
|
30
src/app/core/breadcrumbs/navigation-breadcrumb.service.ts
Normal file
30
src/app/core/breadcrumbs/navigation-breadcrumb.service.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
|
||||
import { BreadcrumbsProviderService } from './breadcrumbsProviderService';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
/**
|
||||
* The postfix for i18n breadcrumbs
|
||||
*/
|
||||
export const BREADCRUMB_MESSAGE_POSTFIX = '.breadcrumbs';
|
||||
|
||||
/**
|
||||
* Service to calculate i18n breadcrumbs for a single part of the route
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NavigationBreadcrumbsService implements BreadcrumbsProviderService<string> {
|
||||
|
||||
/**
|
||||
* Method to calculate the breadcrumbs
|
||||
* @param key The key used to resolve the breadcrumb
|
||||
* @param url The url to use as a link for this breadcrumb
|
||||
*/
|
||||
getBreadcrumbs(key: string, url: string): Observable<Breadcrumb[]> {
|
||||
const keys = key.split(':');
|
||||
const urls = url.split(':');
|
||||
const breadcrumbs = keys.map((currentKey, index) => new Breadcrumb(currentKey + BREADCRUMB_MESSAGE_POSTFIX, urls[index] ));
|
||||
return observableOf(breadcrumbs.reverse());
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
|
||||
import { getTestScheduler } from 'jasmine-marbles';
|
||||
import { BREADCRUMB_MESSAGE_POSTFIX } from './i18n-breadcrumbs.service';
|
||||
import { NavigationBreadcrumbsService } from './navigation-breadcrumb.service';
|
||||
|
||||
describe('NavigationBreadcrumbsService', () => {
|
||||
let service: NavigationBreadcrumbsService;
|
||||
let exampleString;
|
||||
let exampleURL;
|
||||
let childrenString;
|
||||
let childrenUrl;
|
||||
let parentString;
|
||||
let parentUrl;
|
||||
|
||||
function init() {
|
||||
exampleString = 'example.string:parent.string';
|
||||
exampleURL = 'example.com:parent.com';
|
||||
childrenString = 'example.string';
|
||||
childrenUrl = 'example.com';
|
||||
parentString = 'parent.string';
|
||||
parentUrl = 'parent.com';
|
||||
}
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
init();
|
||||
TestBed.configureTestingModule({}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
service = new NavigationBreadcrumbsService();
|
||||
});
|
||||
|
||||
describe('getBreadcrumbs', () => {
|
||||
it('should return an array of breadcrumbs based on strings by adding the postfix', () => {
|
||||
const breadcrumbs = service.getBreadcrumbs(exampleString, exampleURL);
|
||||
getTestScheduler().expectObservable(breadcrumbs).toBe('(a|)', { a: [
|
||||
new Breadcrumb(childrenString + BREADCRUMB_MESSAGE_POSTFIX, childrenUrl),
|
||||
new Breadcrumb(parentString + BREADCRUMB_MESSAGE_POSTFIX, parentUrl),
|
||||
].reverse() });
|
||||
});
|
||||
});
|
||||
});
|
@@ -5,7 +5,6 @@ import {QualityAssuranceBreadcrumbService} from './quality-assurance-breadcrumb.
|
||||
|
||||
describe('QualityAssuranceBreadcrumbService', () => {
|
||||
let service: QualityAssuranceBreadcrumbService;
|
||||
let dataService: any;
|
||||
let translateService: any = {
|
||||
instant: (str) => str,
|
||||
};
|
||||
@@ -26,7 +25,7 @@ describe('QualityAssuranceBreadcrumbService', () => {
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
service = new QualityAssuranceBreadcrumbService(dataService,translateService);
|
||||
service = new QualityAssuranceBreadcrumbService(translateService);
|
||||
});
|
||||
|
||||
describe('getBreadcrumbs', () => {
|
||||
|
@@ -2,10 +2,7 @@ import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
|
||||
import { BreadcrumbsProviderService } from './breadcrumbsProviderService';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { getFirstCompletedRemoteData } from '../shared/operators';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { QualityAssuranceTopicDataService } from '../notifications/qa/topics/quality-assurance-topic-data.service';
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +16,6 @@ export class QualityAssuranceBreadcrumbService implements BreadcrumbsProviderSer
|
||||
|
||||
private QUALITY_ASSURANCE_BREADCRUMB_KEY = 'admin.quality-assurance.breadcrumbs';
|
||||
constructor(
|
||||
protected qualityAssuranceService: QualityAssuranceTopicDataService,
|
||||
private translationService: TranslateService,
|
||||
) {
|
||||
|
||||
@@ -32,18 +28,14 @@ export class QualityAssuranceBreadcrumbService implements BreadcrumbsProviderSer
|
||||
* @param url The url to use as a link for this breadcrumb
|
||||
*/
|
||||
getBreadcrumbs(key: string, url: string): Observable<Breadcrumb[]> {
|
||||
const sourceId = key.split(':')[0];
|
||||
const topicId = key.split(':')[2];
|
||||
const args = key.split(':');
|
||||
const sourceId = args[0];
|
||||
const topicId = args.length > 2 ? args[args.length - 1] : args[1];
|
||||
|
||||
if (topicId) {
|
||||
return this.qualityAssuranceService.getTopic(topicId).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
map((topic) => {
|
||||
return [new Breadcrumb(this.translationService.instant(this.QUALITY_ASSURANCE_BREADCRUMB_KEY), url),
|
||||
new Breadcrumb(sourceId, `${url}${sourceId}`),
|
||||
new Breadcrumb(topicId.replace(/[!:]/g, '/'), undefined)];
|
||||
})
|
||||
);
|
||||
return observableOf( [new Breadcrumb(this.translationService.instant(this.QUALITY_ASSURANCE_BREADCRUMB_KEY), url),
|
||||
new Breadcrumb(sourceId, `${url}${sourceId}`),
|
||||
new Breadcrumb(topicId, undefined)]);
|
||||
} else {
|
||||
return observableOf([new Breadcrumb(this.translationService.instant(this.QUALITY_ASSURANCE_BREADCRUMB_KEY), url),
|
||||
new Breadcrumb(sourceId, `${url}${sourceId}`)]);
|
||||
|
@@ -0,0 +1,18 @@
|
||||
<div class="container">
|
||||
<head>
|
||||
<title>{{ 'coar-notify-support.title' | translate }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ 'coar-notify-support.title' | translate }}</h1>
|
||||
<p [innerHTML]="('coar-notify-support-title.content' | translate)"></p>
|
||||
|
||||
<h2>{{ 'coar-notify-support.ldn-inbox.title' | translate }}</h2>
|
||||
<p [innerHTML]="('coar-notify-support.ldn-inbox.content' | translate).replace('{ldnInboxUrl}', generateCoarRestApiLinksHTML() | async)"></p>
|
||||
|
||||
<h2>{{ 'coar-notify-support.message-moderation.title' | translate }}</h2>
|
||||
<p>
|
||||
{{ 'coar-notify-support.message-moderation.content' | translate }}
|
||||
<a routerLink="/info/feedback" >{{ 'coar-notify-support.message-moderation.feedback-form' | translate }}</a>
|
||||
</p>
|
||||
</body>
|
||||
</div>
|
@@ -0,0 +1,37 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotifyInfoComponent } from './notify-info.component';
|
||||
import { NotifyInfoService } from './notify-info.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
describe('NotifyInfoComponent', () => {
|
||||
let component: NotifyInfoComponent;
|
||||
let fixture: ComponentFixture<NotifyInfoComponent>;
|
||||
let notifyInfoServiceSpy: any;
|
||||
|
||||
beforeEach(async () => {
|
||||
notifyInfoServiceSpy = jasmine.createSpyObj('NotifyInfoService', ['getCoarLdnLocalInboxUrls']);
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [ NotifyInfoComponent ],
|
||||
providers: [
|
||||
{ provide: NotifyInfoService, useValue: notifyInfoServiceSpy }
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NotifyInfoComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.coarRestApiUrl = of([]);
|
||||
spyOn(component, 'generateCoarRestApiLinksHTML').and.returnValue(of(''));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@@ -0,0 +1,39 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { NotifyInfoService } from './notify-info.service';
|
||||
import { Observable, map, of } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-notify-info',
|
||||
templateUrl: './notify-info.component.html',
|
||||
styleUrls: ['./notify-info.component.scss'],
|
||||
})
|
||||
/**
|
||||
* Component for displaying COAR notification information.
|
||||
*/
|
||||
export class NotifyInfoComponent implements OnInit {
|
||||
/**
|
||||
* Observable containing the COAR REST INBOX API URLs.
|
||||
*/
|
||||
coarRestApiUrl: Observable<string[]> = of([]);
|
||||
|
||||
constructor(private notifyInfoService: NotifyInfoService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.coarRestApiUrl = this.notifyInfoService.getCoarLdnLocalInboxUrls();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates HTML code for COAR REST API links.
|
||||
* @returns An Observable that emits the generated HTML code.
|
||||
*/
|
||||
generateCoarRestApiLinksHTML() {
|
||||
return this.coarRestApiUrl.pipe(
|
||||
// transform the data into HTML
|
||||
map((urls) => {
|
||||
return urls.map(url => `
|
||||
<code><a href="${url}" target="_blank"><span class="api-url">${url}</span></a></code>
|
||||
`).join(',');
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotifyInfoGuard } from './notify-info.guard';
|
||||
import { Router } from '@angular/router';
|
||||
import { NotifyInfoService } from './notify-info.service';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
describe('NotifyInfoGuard', () => {
|
||||
let guard: NotifyInfoGuard;
|
||||
let notifyInfoServiceSpy: any;
|
||||
let router: any;
|
||||
|
||||
beforeEach(() => {
|
||||
notifyInfoServiceSpy = jasmine.createSpyObj('NotifyInfoService', ['isCoarConfigEnabled']);
|
||||
router = jasmine.createSpyObj('Router', ['parseUrl']);
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
NotifyInfoGuard,
|
||||
{ provide: NotifyInfoService, useValue: notifyInfoServiceSpy},
|
||||
{ provide: Router, useValue: router}
|
||||
]
|
||||
});
|
||||
guard = TestBed.inject(NotifyInfoGuard);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(guard).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return true if COAR config is enabled', (done) => {
|
||||
notifyInfoServiceSpy.isCoarConfigEnabled.and.returnValue(of(true));
|
||||
|
||||
guard.canActivate(null, null).subscribe((result) => {
|
||||
expect(result).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call parseUrl method of Router if COAR config is not enabled', (done) => {
|
||||
notifyInfoServiceSpy.isCoarConfigEnabled.and.returnValue(of(false));
|
||||
router.parseUrl.and.returnValue(of('/404'));
|
||||
|
||||
guard.canActivate(null, null).subscribe(() => {
|
||||
expect(router.parseUrl).toHaveBeenCalledWith('/404');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
30
src/app/core/coar-notify/notify-info/notify-info.guard.ts
Normal file
30
src/app/core/coar-notify/notify-info/notify-info.guard.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { NotifyInfoService } from './notify-info.service';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NotifyInfoGuard implements CanActivate {
|
||||
constructor(
|
||||
private notifyInfoService: NotifyInfoService,
|
||||
private router: Router
|
||||
) {}
|
||||
|
||||
canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot
|
||||
): Observable<boolean | UrlTree> {
|
||||
return this.notifyInfoService.isCoarConfigEnabled().pipe(
|
||||
map(coarLdnEnabled => {
|
||||
if (coarLdnEnabled) {
|
||||
return true;
|
||||
} else {
|
||||
return this.router.parseUrl('/404');
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotifyInfoService } from './notify-info.service';
|
||||
import { ConfigurationDataService } from '../../data/configuration-data.service';
|
||||
import { of } from 'rxjs';
|
||||
import { AuthorizationDataService } from '../../data/feature-authorization/authorization-data.service';
|
||||
|
||||
describe('NotifyInfoService', () => {
|
||||
let service: NotifyInfoService;
|
||||
let configurationDataService: any;
|
||||
let authorizationDataService: any;
|
||||
beforeEach(() => {
|
||||
authorizationDataService = {
|
||||
isAuthorized: jasmine.createSpy('isAuthorized').and.returnValue(of(true)),
|
||||
};
|
||||
configurationDataService = {
|
||||
findByPropertyName: jasmine.createSpy('findByPropertyName').and.returnValue(of({})),
|
||||
};
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
NotifyInfoService,
|
||||
{ provide: ConfigurationDataService, useValue: configurationDataService },
|
||||
{ provide: AuthorizationDataService, useValue: authorizationDataService }
|
||||
]
|
||||
});
|
||||
service = TestBed.inject(NotifyInfoService);
|
||||
authorizationDataService = TestBed.inject(AuthorizationDataService);
|
||||
configurationDataService = TestBed.inject(ConfigurationDataService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should retrieve and map coar configuration', () => {
|
||||
const mockResponse = { payload: { values: ['true'] } };
|
||||
(configurationDataService.findByPropertyName as jasmine.Spy).and.returnValue(of(mockResponse));
|
||||
|
||||
service.isCoarConfigEnabled().subscribe((result) => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should retrieve and map LDN local inbox URLs', () => {
|
||||
const mockResponse = { values: ['inbox1', 'inbox2'] };
|
||||
(configurationDataService.findByPropertyName as jasmine.Spy).and.returnValue(of(mockResponse));
|
||||
|
||||
service.getCoarLdnLocalInboxUrls().subscribe((result) => {
|
||||
expect(result).toEqual(['inbox1', 'inbox2']);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the inbox relation link', () => {
|
||||
expect(service.getInboxRelationLink()).toBe('http://www.w3.org/ns/ldp#inbox');
|
||||
});
|
||||
});
|
52
src/app/core/coar-notify/notify-info/notify-info.service.ts
Normal file
52
src/app/core/coar-notify/notify-info/notify-info.service.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../shared/operators';
|
||||
import { ConfigurationDataService } from '../../data/configuration-data.service';
|
||||
import { map, Observable } from 'rxjs';
|
||||
import { ConfigurationProperty } from '../../shared/configuration-property.model';
|
||||
import { AuthorizationDataService } from '../../data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../../data/feature-authorization/feature-id';
|
||||
|
||||
/**
|
||||
* Service to check COAR availability and LDN services information for the COAR Notify functionalities
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NotifyInfoService {
|
||||
|
||||
/**
|
||||
* The relation link for the inbox
|
||||
*/
|
||||
private _inboxRelationLink = 'http://www.w3.org/ns/ldp#inbox';
|
||||
|
||||
constructor(
|
||||
private configService: ConfigurationDataService,
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
) {}
|
||||
|
||||
isCoarConfigEnabled(): Observable<boolean> {
|
||||
return this.authorizationService.isAuthorized(FeatureID.CoarNotifyEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url of the local inbox from the REST configuration
|
||||
* @returns the url of the local inbox
|
||||
*/
|
||||
getCoarLdnLocalInboxUrls(): Observable<string[]> {
|
||||
return this.configService.findByPropertyName('ldn.notify.inbox').pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
map((response: ConfigurationProperty) => {
|
||||
return response.values;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the relation link for the inbox
|
||||
* @returns the relation link for the inbox
|
||||
*/
|
||||
getInboxRelationLink(): string {
|
||||
return this._inboxRelationLink;
|
||||
}
|
||||
}
|
@@ -186,8 +186,18 @@ import { ValueListBrowseDefinition } from './shared/value-list-browse-definition
|
||||
import { NonHierarchicalBrowseDefinition } from './shared/non-hierarchical-browse-definition';
|
||||
import { BulkAccessConditionOptions } from './config/models/bulk-access-condition-options.model';
|
||||
import { CorrectionTypeDataService } from './submission/correctiontype-data.service';
|
||||
import { SuggestionTarget } from './suggestion-notifications/models/suggestion-target.model';
|
||||
import { SuggestionSource } from './suggestion-notifications/models/suggestion-source.model';
|
||||
import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service';
|
||||
import { LdnItemfiltersService } from '../admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service';
|
||||
import {
|
||||
CoarNotifyConfigDataService
|
||||
} from '../submission/sections/section-coar-notify/coar-notify-config-data.service';
|
||||
import { NotifyRequestsStatusDataService } from './data/notify-services-status-data.service';
|
||||
import { SuggestionTarget } from './notifications/models/suggestion-target.model';
|
||||
import { SuggestionSource } from './notifications/models/suggestion-source.model';
|
||||
import { NotifyRequestsStatus } from '../item-page/simple/notify-requests-status/notify-requests-status.model';
|
||||
import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model';
|
||||
import { Itemfilter } from '../admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters';
|
||||
import { SubmissionCoarNotifyConfig } from '../submission/sections/section-coar-notify/submission-coar-notify.config';
|
||||
|
||||
/**
|
||||
* When not in production, endpoint responses can be mocked for testing purposes
|
||||
@@ -311,7 +321,11 @@ const PROVIDERS = [
|
||||
OrcidQueueDataService,
|
||||
OrcidHistoryDataService,
|
||||
SupervisionOrderDataService,
|
||||
CorrectionTypeDataService
|
||||
CorrectionTypeDataService,
|
||||
LdnServicesService,
|
||||
LdnItemfiltersService,
|
||||
CoarNotifyConfigDataService,
|
||||
NotifyRequestsStatusDataService
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -392,7 +406,11 @@ export const models =
|
||||
ItemRequest,
|
||||
BulkAccessConditionOptions,
|
||||
SuggestionTarget,
|
||||
SuggestionSource
|
||||
SuggestionSource,
|
||||
LdnService,
|
||||
Itemfilter,
|
||||
SubmissionCoarNotifyConfig,
|
||||
NotifyRequestsStatus,
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
@@ -34,6 +34,7 @@ export enum FeatureID {
|
||||
CanEditItem = 'canEditItem',
|
||||
CanRegisterDOI = 'canRegisterDOI',
|
||||
CanSubscribe = 'canSubscribeDso',
|
||||
EPersonForgotPassword = 'epersonForgotPassword',
|
||||
CoarNotifyEnabled = 'coarNotifyEnabled',
|
||||
CanSeeQA = 'canSeeQA',
|
||||
EPersonForgotPassword = 'epersonForgotPassword'
|
||||
}
|
||||
|
46
src/app/core/data/notify-services-status-data.service.ts
Normal file
46
src/app/core/data/notify-services-status-data.service.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RequestService } from './request.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { IdentifiableDataService } from './base/identifiable-data.service';
|
||||
import { dataService } from './base/data-service.decorator';
|
||||
import { NotifyRequestsStatus } from '../../item-page/simple/notify-requests-status/notify-requests-status.model';
|
||||
import { NOTIFYREQUEST} from '../../item-page/simple/notify-requests-status/notify-requests-status.resource-type';
|
||||
import { Observable, map, take } from 'rxjs';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { GetRequest } from './request.models';
|
||||
|
||||
|
||||
@Injectable()
|
||||
@dataService(NOTIFYREQUEST)
|
||||
export class NotifyRequestsStatusDataService extends IdentifiableDataService<NotifyRequestsStatus> {
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected rdb: RemoteDataBuildService,
|
||||
) {
|
||||
super('notifyrequests', requestService, rdbService, objectCache, halService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the status of notify requests for a specific item.
|
||||
* @param itemUuid The UUID of the item.
|
||||
* @returns An Observable that emits the remote data containing the notify requests status.
|
||||
*/
|
||||
getNotifyRequestsStatus(itemUuid: string): Observable<RemoteData<NotifyRequestsStatus>> {
|
||||
const href$ = this.getEndpoint().pipe(
|
||||
map((url: string) => url + '/' + itemUuid ),
|
||||
);
|
||||
|
||||
href$.pipe(take(1)).subscribe((url: string) => {
|
||||
const request = new GetRequest(this.requestService.generateRequestId(), url);
|
||||
this.requestService.send(request, true);
|
||||
});
|
||||
|
||||
return this.rdb.buildFromHref(href$);
|
||||
}
|
||||
}
|
@@ -201,9 +201,7 @@ export class UpdateDataServiceImpl<T extends CacheableObject> extends Identifiab
|
||||
create(object: T, ...params: RequestParam[]): Observable<RemoteData<T>> {
|
||||
return this.createData.create(object, ...params);
|
||||
}
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* Perform a post on an endpoint related item with ID. Ex.: endpoint/<itemId>/related?item=<relatedItemId>
|
||||
* @param itemId The item id
|
||||
* @param relatedItemId The related item Id
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { Store } from '@ngrx/store';
|
||||
import {
|
||||
FlushPatchOperationAction,
|
||||
NewPatchAddOperationAction,
|
||||
NewPatchMoveOperationAction,
|
||||
NewPatchRemoveOperationAction,
|
||||
@@ -99,6 +100,20 @@ export class JsonPatchOperationsBuilder {
|
||||
path.path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a new FlushPatchOperationAction
|
||||
*
|
||||
* @param path
|
||||
* a JsonPatchOperationPathObject representing path
|
||||
*/
|
||||
flushOperation(path: JsonPatchOperationPathObject) {
|
||||
this.store.dispatch(
|
||||
new FlushPatchOperationAction(
|
||||
path.rootElement,
|
||||
path.subRootElement,
|
||||
path.path));
|
||||
}
|
||||
|
||||
protected prepareValue(value: any, plain: boolean, first: boolean) {
|
||||
let operationValue: any = null;
|
||||
if (hasValue(value)) {
|
||||
|
@@ -20,6 +20,7 @@ export const JsonPatchOperationsActionTypes = {
|
||||
COMMIT_JSON_PATCH_OPERATIONS: type('dspace/core/patch/COMMIT_JSON_PATCH_OPERATIONS'),
|
||||
ROLLBACK_JSON_PATCH_OPERATIONS: type('dspace/core/patch/ROLLBACK_JSON_PATCH_OPERATIONS'),
|
||||
FLUSH_JSON_PATCH_OPERATIONS: type('dspace/core/patch/FLUSH_JSON_PATCH_OPERATIONS'),
|
||||
FLUSH_JSON_PATCH_OPERATION: type('dspace/core/patch/FLUSH_JSON_PATCH_OPERATION'),
|
||||
START_TRANSACTION_JSON_PATCH_OPERATIONS: type('dspace/core/patch/START_TRANSACTION_JSON_PATCH_OPERATIONS'),
|
||||
DELETE_PENDING_JSON_PATCH_OPERATIONS: type('dspace/core/patch/DELETE_PENDING_JSON_PATCH_OPERATIONS'),
|
||||
};
|
||||
@@ -120,6 +121,32 @@ export class FlushPatchOperationsAction implements Action {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An ngrx action to flush a single operation of the JSON Patch operations
|
||||
*/
|
||||
export class FlushPatchOperationAction implements Action {
|
||||
type = JsonPatchOperationsActionTypes.FLUSH_JSON_PATCH_OPERATION;
|
||||
payload: {
|
||||
resourceType: string;
|
||||
resourceId: string;
|
||||
path: string
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new FlushPatchOperationsAction
|
||||
*
|
||||
* @param resourceType
|
||||
* the resource's type
|
||||
* @param resourceId
|
||||
* the resource's ID
|
||||
* @param path
|
||||
* the path of the operation
|
||||
*/
|
||||
constructor(resourceType: string, resourceId: string, path: string) {
|
||||
this.payload = { resourceType, resourceId, path };
|
||||
}
|
||||
}
|
||||
/**
|
||||
* An ngrx action to Add new HTTP/PATCH ADD operations to state
|
||||
*/
|
||||
@@ -284,4 +311,5 @@ export type PatchOperationsActions
|
||||
| NewPatchReplaceOperationAction
|
||||
| RollbacktPatchOperationsAction
|
||||
| StartTransactionPatchOperationsAction
|
||||
| DeletePendingJsonPatchOperationsAction;
|
||||
| DeletePendingJsonPatchOperationsAction
|
||||
| FlushPatchOperationAction;
|
||||
|
@@ -12,7 +12,7 @@ import {
|
||||
CommitPatchOperationsAction,
|
||||
StartTransactionPatchOperationsAction,
|
||||
RollbacktPatchOperationsAction,
|
||||
DeletePendingJsonPatchOperationsAction
|
||||
DeletePendingJsonPatchOperationsAction, FlushPatchOperationAction
|
||||
} from './json-patch-operations.actions';
|
||||
import { JsonPatchOperationModel, JsonPatchOperationType } from './json-patch.model';
|
||||
|
||||
@@ -71,7 +71,7 @@ export function jsonPatchOperationsReducer(state = initialState, action: PatchOp
|
||||
}
|
||||
|
||||
case JsonPatchOperationsActionTypes.FLUSH_JSON_PATCH_OPERATIONS: {
|
||||
return flushOperation(state, action as FlushPatchOperationsAction);
|
||||
return flushOperations(state, action as FlushPatchOperationsAction);
|
||||
}
|
||||
|
||||
case JsonPatchOperationsActionTypes.NEW_JSON_PATCH_ADD_OPERATION: {
|
||||
@@ -106,6 +106,10 @@ export function jsonPatchOperationsReducer(state = initialState, action: PatchOp
|
||||
return deletePendingOperations(state, action as DeletePendingJsonPatchOperationsAction);
|
||||
}
|
||||
|
||||
case JsonPatchOperationsActionTypes.FLUSH_JSON_PATCH_OPERATION: {
|
||||
return flushOperation(state, action as FlushPatchOperationAction);
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
@@ -197,6 +201,39 @@ function deletePendingOperations(state: JsonPatchOperationsState, action: Delete
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush one operation from JsonPatchOperationsState.
|
||||
*
|
||||
* @param state
|
||||
* the current state
|
||||
* @param action
|
||||
* an FlushPatchOperationsAction
|
||||
* @return JsonPatchOperationsState
|
||||
* the new state.
|
||||
*/
|
||||
function flushOperation(state: JsonPatchOperationsState, action: FlushPatchOperationAction): JsonPatchOperationsState {
|
||||
const payload = action.payload;
|
||||
if (state[payload.resourceType] && state[payload.resourceType].children) {
|
||||
const body = state[payload.resourceType].children[payload.resourceId].body;
|
||||
const operation = body.filter(operations => operations.operation.path === payload.path)[0];
|
||||
const operationIndex = body.indexOf(operation);
|
||||
const newBody = [...body];
|
||||
newBody.splice(operationIndex, 1);
|
||||
|
||||
return Object.assign({}, state, {
|
||||
[action.payload.resourceType]: Object.assign({}, {
|
||||
children: {
|
||||
[action.payload.resourceId]: {
|
||||
body: newBody,
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new JSON patch operation list.
|
||||
*
|
||||
@@ -273,7 +310,7 @@ function hasValidBody(state: JsonPatchOperationsState, resourceType: any, resour
|
||||
* @return SubmissionObjectState
|
||||
* the new state, with the section new validity status.
|
||||
*/
|
||||
function flushOperation(state: JsonPatchOperationsState, action: FlushPatchOperationsAction): JsonPatchOperationsState {
|
||||
function flushOperations(state: JsonPatchOperationsState, action: FlushPatchOperationsAction): JsonPatchOperationsState {
|
||||
if (hasValue(state[ action.payload.resourceType ])) {
|
||||
let newChildren;
|
||||
if (isNotUndefined(action.payload.resourceId)) {
|
||||
|
@@ -26,3 +26,5 @@ export type WorkspaceitemSectionDataType
|
||||
| WorkspaceitemSectionSherpaPoliciesObject
|
||||
| WorkspaceitemSectionIdentifiersObject
|
||||
| string;
|
||||
|
||||
|
||||
|
@@ -53,6 +53,20 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
|
||||
public delete(objectId: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
||||
return this.deleteData.delete(objectId, copyVirtualMetadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing object on the server
|
||||
* @param href The self link of the object to be removed
|
||||
* @param copyVirtualMetadata (optional parameter) the identifiers of the relationship types for which the virtual
|
||||
* metadata should be saved as real metadata
|
||||
* @return A RemoteData observable with an empty payload, but still representing the state of the request: statusCode,
|
||||
* errorMessage, timeCompleted, etc
|
||||
* Only emits once all request related to the DSO has been invalidated.
|
||||
*/
|
||||
public deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
||||
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the WorkspaceItem object found through the UUID of an item
|
||||
*
|
||||
@@ -96,19 +110,6 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
|
||||
return this.rdbService.buildFromRequestUUID(requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing object on the server
|
||||
* @param href The self link of the object to be removed
|
||||
* @param copyVirtualMetadata (optional parameter) the identifiers of the relationship types for which the virtual
|
||||
* metadata should be saved as real metadata
|
||||
* @return A RemoteData observable with an empty payload, but still representing the state of the request: statusCode,
|
||||
* errorMessage, timeCompleted, etc
|
||||
* Only emits once all request related to the DSO has been invalidated.
|
||||
*/
|
||||
deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable<RemoteData<NoContent>> {
|
||||
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new FindListRequest with given search method
|
||||
*
|
||||
|
@@ -82,6 +82,12 @@
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="notify-enabled text-white" [hidden]="!coarLdnEnabled">
|
||||
<a class="coar-notify-support-route" routerLink="info/coar-notify-support">
|
||||
<img class="n-coar" src="assets/images/n-coar.png" [attr.alt]="'menu.header.image.logo' | translate" />
|
||||
COAR Notify
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Copyright -->
|
||||
</footer>
|
||||
|
@@ -22,6 +22,23 @@
|
||||
}
|
||||
|
||||
.bottom-footer {
|
||||
.notify-enabled {
|
||||
position: absolute;
|
||||
bottom: 4px;
|
||||
right: 0;
|
||||
|
||||
.coar-notify-support-route {
|
||||
padding: 0 calc(var(--bs-spacer) / 2);
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.n-coar {
|
||||
height: var(--ds-footer-n-coar-height);
|
||||
margin-bottom: 8.5px;
|
||||
}
|
||||
|
||||
margin-top: 20px;
|
||||
}
|
||||
ul {
|
||||
li {
|
||||
display: inline-flex;
|
||||
@@ -55,3 +72,4 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// ... test imports
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { ComponentFixture, fakeAsync, inject, TestBed,waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core';
|
||||
|
||||
@@ -9,6 +9,7 @@ import { By } from '@angular/platform-browser';
|
||||
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
// Load the implementations that should be tested
|
||||
import { FooterComponent } from './footer.component';
|
||||
@@ -17,15 +18,21 @@ import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock';
|
||||
import { storeModuleConfig } from '../app.reducer';
|
||||
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
|
||||
import { AuthorizationDataServiceStub } from '../shared/testing/authorization-service.stub';
|
||||
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
|
||||
let comp: FooterComponent;
|
||||
let compAny: any;
|
||||
let fixture: ComponentFixture<FooterComponent>;
|
||||
let de: DebugElement;
|
||||
let el: HTMLElement;
|
||||
|
||||
describe('Footer component', () => {
|
||||
let notifyInfoService = {
|
||||
isCoarConfigEnabled: () => of(true)
|
||||
};
|
||||
|
||||
// waitForAsync beforeEach
|
||||
describe('Footer component', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
return TestBed.configureTestingModule({
|
||||
imports: [CommonModule, StoreModule.forRoot({}, storeModuleConfig), TranslateModule.forRoot({
|
||||
@@ -38,6 +45,7 @@ describe('Footer component', () => {
|
||||
providers: [
|
||||
FooterComponent,
|
||||
{ provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub },
|
||||
{ provide: NotifyInfoService, useValue: notifyInfoService }
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
@@ -46,9 +54,8 @@ describe('Footer component', () => {
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(FooterComponent);
|
||||
|
||||
comp = fixture.componentInstance; // component test instance
|
||||
|
||||
comp = fixture.componentInstance;
|
||||
compAny = comp as any;
|
||||
// query for the title <p> by CSS element selector
|
||||
de = fixture.debugElement.query(By.css('p'));
|
||||
el = de.nativeElement;
|
||||
@@ -59,4 +66,56 @@ describe('Footer component', () => {
|
||||
expect(app).toBeTruthy();
|
||||
}));
|
||||
|
||||
|
||||
it('should set showPrivacyPolicy to the value of environment.info.enablePrivacyStatement', () => {
|
||||
expect(comp.showPrivacyPolicy).toBe(environment.info.enablePrivacyStatement);
|
||||
});
|
||||
|
||||
it('should set showEndUserAgreement to the value of environment.info.enableEndUserAgreement', () => {
|
||||
expect(comp.showEndUserAgreement).toBe(environment.info.enableEndUserAgreement);
|
||||
});
|
||||
|
||||
describe('showCookieSettings', () => {
|
||||
it('should call cookies.showSettings() if cookies is defined', () => {
|
||||
const cookies = jasmine.createSpyObj('cookies', ['showSettings']);
|
||||
compAny.cookies = cookies;
|
||||
comp.showCookieSettings();
|
||||
expect(cookies.showSettings).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call cookies.showSettings() if cookies is undefined', () => {
|
||||
compAny.cookies = undefined;
|
||||
expect(() => comp.showCookieSettings()).not.toThrow();
|
||||
});
|
||||
|
||||
it('should return false', () => {
|
||||
expect(comp.showCookieSettings()).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when coarLdnEnabled is true', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(notifyInfoService, 'isCoarConfigEnabled').and.returnValue(of(true));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should set coarLdnEnabled based on notifyInfoService', () => {
|
||||
expect(comp.coarLdnEnabled).toBeTruthy();
|
||||
// Check if COAR Notify section is rendered
|
||||
const notifySection = fixture.debugElement.query(By.css('.notify-enabled'));
|
||||
expect(notifySection).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should redirect to info/coar-notify-support', () => {
|
||||
// Check if the link to the COAR Notify support page is present
|
||||
const routerLink = fixture.debugElement.query(By.css('a[routerLink="info/coar-notify-support"].coar-notify-support-route'));
|
||||
expect(routerLink).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have an img tag with the class "n-coar" when coarLdnEnabled is true', fakeAsync(() => {
|
||||
// Check if the img tag with the class "n-coar" is present
|
||||
const imgTag = fixture.debugElement.query(By.css('.notify-enabled img.n-coar'));
|
||||
expect(imgTag).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@@ -2,6 +2,7 @@ import { Component, Optional } from '@angular/core';
|
||||
import { hasValue } from '../shared/empty.util';
|
||||
import { KlaroService } from '../shared/cookies/klaro.service';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../core/data/feature-authorization/feature-id';
|
||||
@@ -21,12 +22,17 @@ export class FooterComponent {
|
||||
showPrivacyPolicy = environment.info.enablePrivacyStatement;
|
||||
showEndUserAgreement = environment.info.enableEndUserAgreement;
|
||||
showSendFeedback$: Observable<boolean>;
|
||||
coarLdnEnabled: boolean;
|
||||
|
||||
constructor(
|
||||
@Optional() private cookies: KlaroService,
|
||||
private authorizationService: AuthorizationDataService,
|
||||
private notifyInfoService: NotifyInfoService
|
||||
) {
|
||||
this.showSendFeedback$ = this.authorizationService.isAuthorized(FeatureID.CanSendFeedback);
|
||||
this.notifyInfoService.isCoarConfigEnabled().subscribe(coarLdnEnabled => {
|
||||
this.coarLdnEnabled = coarLdnEnabled;
|
||||
});
|
||||
}
|
||||
|
||||
showCookieSettings() {
|
||||
|
@@ -1,24 +1,52 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Component, Inject, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Site } from '../core/shared/site.model';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { isPlatformServer } from '@angular/common';
|
||||
import { ServerResponseService } from '../core/services/server-response.service';
|
||||
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
|
||||
import { LinkDefinition, LinkHeadService } from '../core/services/link-head.service';
|
||||
import { isNotEmpty } from '../shared/empty.util';
|
||||
|
||||
import { APP_CONFIG, AppConfig } from 'src/config/app-config.interface';
|
||||
@Component({
|
||||
selector: 'ds-home-page',
|
||||
styleUrls: ['./home-page.component.scss'],
|
||||
templateUrl: './home-page.component.html'
|
||||
})
|
||||
export class HomePageComponent implements OnInit {
|
||||
export class HomePageComponent implements OnInit, OnDestroy {
|
||||
|
||||
site$: Observable<Site>;
|
||||
recentSubmissionspageSize: number;
|
||||
/**
|
||||
* An array of LinkDefinition objects representing inbox links for the home page.
|
||||
*/
|
||||
inboxLinks: LinkDefinition[] = [];
|
||||
|
||||
constructor(
|
||||
@Inject(APP_CONFIG) protected appConfig: AppConfig,
|
||||
private route: ActivatedRoute,
|
||||
private responseService: ServerResponseService,
|
||||
private notifyInfoService: NotifyInfoService,
|
||||
protected linkHeadService: LinkHeadService,
|
||||
@Inject(PLATFORM_ID) private platformId: string
|
||||
) {
|
||||
this.recentSubmissionspageSize = environment.homePage.recentSubmissions.pageSize;
|
||||
// Get COAR REST API URLs from REST configuration
|
||||
// only if COAR configuration is enabled
|
||||
this.notifyInfoService.isCoarConfigEnabled().pipe(
|
||||
switchMap((coarLdnEnabled: boolean) => {
|
||||
if (coarLdnEnabled) {
|
||||
return this.notifyInfoService.getCoarLdnLocalInboxUrls();
|
||||
}
|
||||
})
|
||||
).subscribe((coarRestApiUrls: string[]) => {
|
||||
if (coarRestApiUrls.length > 0) {
|
||||
this.initPageLinks(coarRestApiUrls);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -26,4 +54,38 @@ export class HomePageComponent implements OnInit {
|
||||
map((data) => data.site as Site),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes page links for COAR REST API URLs.
|
||||
* @param coarRestApiUrls An array of COAR REST API URLs.
|
||||
*/
|
||||
private initPageLinks(coarRestApiUrls: string[]): void {
|
||||
const rel = this.notifyInfoService.getInboxRelationLink();
|
||||
let links = '';
|
||||
coarRestApiUrls.forEach((coarRestApiUrl: string) => {
|
||||
// Add link to head
|
||||
let tag: LinkDefinition = {
|
||||
href: coarRestApiUrl,
|
||||
rel: rel
|
||||
};
|
||||
this.inboxLinks.push(tag);
|
||||
this.linkHeadService.addTag(tag);
|
||||
|
||||
links = links + (isNotEmpty(links) ? ', ' : '') + `<${coarRestApiUrl}> ; rel="${rel}"`;
|
||||
});
|
||||
|
||||
if (isPlatformServer(this.platformId)) {
|
||||
// Add link to response header
|
||||
this.responseService.setHeader('Link', links);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It removes the inbox links from the head of the html.
|
||||
*/
|
||||
ngOnDestroy(): void {
|
||||
this.inboxLinks.forEach((link: LinkDefinition) => {
|
||||
this.linkHeadService.removeTag(`href='${link.href}'`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,9 @@ import { ThemedPrivacyComponent } from './privacy/themed-privacy.component';
|
||||
import { ThemedFeedbackComponent } from './feedback/themed-feedback.component';
|
||||
import { FeedbackGuard } from '../core/feedback/feedback.guard';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { COAR_NOTIFY_SUPPORT } from '../app-routing-paths';
|
||||
import { NotifyInfoComponent } from '../core/coar-notify/notify-info/notify-info.component';
|
||||
import { NotifyInfoGuard } from '../core/coar-notify/notify-info/notify-info.guard';
|
||||
|
||||
|
||||
const imports = [
|
||||
@@ -18,11 +21,20 @@ const imports = [
|
||||
data: { title: 'info.feedback.title', breadcrumbKey: 'info.feedback' },
|
||||
canActivate: [FeedbackGuard]
|
||||
}
|
||||
]),
|
||||
RouterModule.forChild([
|
||||
{
|
||||
path: COAR_NOTIFY_SUPPORT,
|
||||
component: NotifyInfoComponent,
|
||||
resolve: { breadcrumb: I18nBreadcrumbResolver },
|
||||
data: { title: 'info.coar-notify-support.title', breadcrumbKey: 'info.coar-notify' },
|
||||
canActivate: [NotifyInfoGuard]
|
||||
}
|
||||
])
|
||||
];
|
||||
|
||||
if (environment.info.enableEndUserAgreement) {
|
||||
imports.push(
|
||||
if (environment.info.enableEndUserAgreement) {
|
||||
imports.push(
|
||||
RouterModule.forChild([
|
||||
{
|
||||
path: END_USER_AGREEMENT_PATH,
|
||||
@@ -31,9 +43,9 @@ const imports = [
|
||||
data: { title: 'info.end-user-agreement.title', breadcrumbKey: 'info.end-user-agreement' }
|
||||
}
|
||||
]));
|
||||
}
|
||||
if (environment.info.enablePrivacyStatement) {
|
||||
imports.push(
|
||||
}
|
||||
if (environment.info.enablePrivacyStatement) {
|
||||
imports.push(
|
||||
RouterModule.forChild([
|
||||
{
|
||||
path: PRIVACY_PATH,
|
||||
@@ -42,7 +54,7 @@ const imports = [
|
||||
data: { title: 'info.privacy.title', breadcrumbKey: 'info.privacy' }
|
||||
}
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
|
@@ -13,6 +13,7 @@ import { FeedbackFormComponent } from './feedback/feedback-form/feedback-form.co
|
||||
import { ThemedFeedbackFormComponent } from './feedback/feedback-form/themed-feedback-form.component';
|
||||
import { ThemedFeedbackComponent } from './feedback/themed-feedback.component';
|
||||
import { FeedbackGuard } from '../core/feedback/feedback.guard';
|
||||
import { NotifyInfoComponent } from '../core/coar-notify/notify-info/notify-info.component';
|
||||
|
||||
|
||||
const DECLARATIONS = [
|
||||
@@ -25,7 +26,8 @@ const DECLARATIONS = [
|
||||
FeedbackComponent,
|
||||
FeedbackFormComponent,
|
||||
ThemedFeedbackFormComponent,
|
||||
ThemedFeedbackComponent
|
||||
ThemedFeedbackComponent,
|
||||
NotifyInfoComponent
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<ds-metadata-field-wrapper [label]="label | translate">
|
||||
<a class="dont-break-out" *ngFor="let mdValue of mdValues; let last=last;" [href]="mdValue.value">
|
||||
<a class="dont-break-out" *ngFor="let mdValue of mdValues; let last=last;" [href]="mdValue.value" [target]="hasInternalLink(mdValue.value) ? '_self' : '_blank'">
|
||||
{{ linktext || mdValue.value }}<span *ngIf="!last" [innerHTML]="separator"></span>
|
||||
</a>
|
||||
</ds-metadata-field-wrapper>
|
||||
|
@@ -5,6 +5,7 @@ import { BrowseDefinition } from '../../../core/shared/browse-definition.model';
|
||||
import { hasValue } from '../../../shared/empty.util';
|
||||
import { VALUE_LIST_BROWSE_DEFINITION } from '../../../core/shared/value-list-browse-definition.resource-type';
|
||||
import { ImageField } from '../../simple/field-components/specific-field/item-page-field.component';
|
||||
import { environment } from '../../../../environments/environment';
|
||||
|
||||
/**
|
||||
* This component renders the configured 'values' into the ds-metadata-field-wrapper component.
|
||||
@@ -96,4 +97,14 @@ export class MetadataValuesComponent implements OnChanges {
|
||||
}
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the given link value is an internal link.
|
||||
* @param linkValue - The link value to check.
|
||||
* @returns True if the link value starts with the base URL defined in the environment configuration, false otherwise.
|
||||
*/
|
||||
hasInternalLink(linkValue: string): boolean {
|
||||
return linkValue.startsWith(environment.ui.baseUrl);
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import { RemoteData } from '../../core/data/remote-data';
|
||||
import { ServerResponseService } from '../../core/services/server-response.service';
|
||||
import { SignpostingDataService } from '../../core/data/signposting-data.service';
|
||||
import { LinkHeadService } from '../../core/services/link-head.service';
|
||||
import { NotifyInfoService } from '../../core/coar-notify/notify-info/notify-info.service';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||
@@ -61,6 +62,7 @@ describe('FullItemPageComponent', () => {
|
||||
let serverResponseService: jasmine.SpyObj<ServerResponseService>;
|
||||
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
|
||||
let linkHeadService: jasmine.SpyObj<LinkHeadService>;
|
||||
let notifyInfoService: jasmine.SpyObj<NotifyInfoService>;
|
||||
|
||||
const mocklink = {
|
||||
href: 'http://test.org',
|
||||
@@ -105,6 +107,12 @@ describe('FullItemPageComponent', () => {
|
||||
removeTag: jasmine.createSpy('removeTag'),
|
||||
});
|
||||
|
||||
notifyInfoService = jasmine.createSpyObj('NotifyInfoService', {
|
||||
isCoarConfigEnabled: observableOf(true),
|
||||
getCoarLdnLocalInboxUrls: observableOf(['http://test.org']),
|
||||
getInboxRelationLink: observableOf('http://test.org'),
|
||||
});
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot({
|
||||
loader: {
|
||||
@@ -122,6 +130,7 @@ describe('FullItemPageComponent', () => {
|
||||
{ provide: ServerResponseService, useValue: serverResponseService },
|
||||
{ provide: SignpostingDataService, useValue: signpostingDataService },
|
||||
{ provide: LinkHeadService, useValue: linkHeadService },
|
||||
{ provide: NotifyInfoService, useValue: notifyInfoService },
|
||||
{ provide: PLATFORM_ID, useValue: 'server' }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
@@ -178,7 +187,7 @@ describe('FullItemPageComponent', () => {
|
||||
|
||||
it('should add the signposting links', () => {
|
||||
expect(serverResponseService.setHeader).toHaveBeenCalled();
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2);
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
});
|
||||
describe('when the item is withdrawn and the user is not an admin', () => {
|
||||
@@ -207,7 +216,7 @@ describe('FullItemPageComponent', () => {
|
||||
|
||||
it('should add the signposting links', () => {
|
||||
expect(serverResponseService.setHeader).toHaveBeenCalled();
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2);
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -224,7 +233,7 @@ describe('FullItemPageComponent', () => {
|
||||
|
||||
it('should add the signposting links', () => {
|
||||
expect(serverResponseService.setHeader).toHaveBeenCalled();
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2);
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -19,6 +19,7 @@ import { AuthorizationDataService } from '../../core/data/feature-authorization/
|
||||
import { ServerResponseService } from '../../core/services/server-response.service';
|
||||
import { SignpostingDataService } from '../../core/data/signposting-data.service';
|
||||
import { LinkHeadService } from '../../core/services/link-head.service';
|
||||
import { NotifyInfoService } from '../../core/coar-notify/notify-info/notify-info.service';
|
||||
|
||||
/**
|
||||
* This component renders a full item page.
|
||||
@@ -55,9 +56,10 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
|
||||
protected responseService: ServerResponseService,
|
||||
protected signpostingDataService: SignpostingDataService,
|
||||
protected linkHeadService: LinkHeadService,
|
||||
protected notifyInfoService: NotifyInfoService,
|
||||
@Inject(PLATFORM_ID) protected platformId: string,
|
||||
) {
|
||||
super(route, router, items, authService, authorizationService, responseService, signpostingDataService, linkHeadService, platformId);
|
||||
super(route, router, items, authService, authorizationService, responseService, signpostingDataService, linkHeadService, notifyInfoService, platformId);
|
||||
}
|
||||
|
||||
/*** AoT inheritance fix, will hopefully be resolved in the near future **/
|
||||
|
@@ -61,6 +61,8 @@ import {
|
||||
ThemedFullFileSectionComponent
|
||||
} from './full/field-components/file-section/themed-full-file-section.component';
|
||||
import { QaEventNotificationComponent } from './simple/qa-event-notification/qa-event-notification.component';
|
||||
import { NotifyRequestsStatusComponent } from './simple/notify-requests-status/notify-requests-status-component/notify-requests-status.component';
|
||||
import { RequestStatusAlertBoxComponent } from './simple/notify-requests-status/request-status-alert-box/request-status-alert-box.component';
|
||||
|
||||
const ENTRY_COMPONENTS = [
|
||||
// put only entry components that use custom decorator
|
||||
@@ -104,7 +106,9 @@ const DECLARATIONS = [
|
||||
ItemAlertsComponent,
|
||||
ThemedItemAlertsComponent,
|
||||
BitstreamRequestACopyPageComponent,
|
||||
QaEventNotificationComponent
|
||||
QaEventNotificationComponent,
|
||||
NotifyRequestsStatusComponent,
|
||||
RequestStatusAlertBoxComponent
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
@@ -3,6 +3,7 @@
|
||||
<div *ngIf="itemRD?.payload as item">
|
||||
<ds-themed-item-alerts [item]="item"></ds-themed-item-alerts>
|
||||
<ds-qa-event-notification [item]="item"></ds-qa-event-notification>
|
||||
<ds-notify-requests-status [itemUuid]="item.uuid"></ds-notify-requests-status>
|
||||
<ds-item-versions-notice [item]="item"></ds-item-versions-notice>
|
||||
<ds-view-tracker [object]="item"></ds-view-tracker>
|
||||
<ds-listable-object-component-loader *ngIf="!item.isWithdrawn || (isAdmin$|async)" [object]="item" [viewMode]="viewMode"></ds-listable-object-component-loader>
|
||||
|
@@ -26,6 +26,7 @@ import { ServerResponseService } from '../../core/services/server-response.servi
|
||||
import { SignpostingDataService } from '../../core/data/signposting-data.service';
|
||||
import { LinkDefinition, LinkHeadService } from '../../core/services/link-head.service';
|
||||
import { SignpostingLink } from '../../core/data/signposting-links.model';
|
||||
import { NotifyInfoService } from '../../core/coar-notify/notify-info/notify-info.service';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||
@@ -62,6 +63,7 @@ describe('ItemPageComponent', () => {
|
||||
let serverResponseService: jasmine.SpyObj<ServerResponseService>;
|
||||
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
|
||||
let linkHeadService: jasmine.SpyObj<LinkHeadService>;
|
||||
let notifyInfoService: jasmine.SpyObj<NotifyInfoService>;
|
||||
|
||||
const mockMetadataService = {
|
||||
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
|
||||
@@ -73,6 +75,8 @@ describe('ItemPageComponent', () => {
|
||||
data: observableOf({ dso: createSuccessfulRemoteDataObject(mockItem) })
|
||||
});
|
||||
|
||||
const getCoarLdnLocalInboxUrls = ['http://InboxUrls.org', 'http://InboxUrls2.org'];
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
authService = jasmine.createSpyObj('authService', {
|
||||
isAuthenticated: observableOf(true),
|
||||
@@ -94,6 +98,12 @@ describe('ItemPageComponent', () => {
|
||||
removeTag: jasmine.createSpy('removeTag'),
|
||||
});
|
||||
|
||||
notifyInfoService = jasmine.createSpyObj('NotifyInfoService', {
|
||||
getInboxRelationLink: 'http://www.w3.org/ns/ldp#inbox',
|
||||
isCoarConfigEnabled: observableOf(true),
|
||||
getCoarLdnLocalInboxUrls: observableOf(getCoarLdnLocalInboxUrls),
|
||||
});
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot({
|
||||
loader: {
|
||||
@@ -112,6 +122,7 @@ describe('ItemPageComponent', () => {
|
||||
{ provide: ServerResponseService, useValue: serverResponseService },
|
||||
{ provide: SignpostingDataService, useValue: signpostingDataService },
|
||||
{ provide: LinkHeadService, useValue: linkHeadService },
|
||||
{ provide: NotifyInfoService, useValue: notifyInfoService},
|
||||
{ provide: PLATFORM_ID, useValue: 'server' },
|
||||
],
|
||||
|
||||
@@ -166,7 +177,7 @@ describe('ItemPageComponent', () => {
|
||||
|
||||
it('should add the signposting links', () => {
|
||||
expect(serverResponseService.setHeader).toHaveBeenCalled();
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2);
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
|
||||
|
||||
@@ -175,7 +186,7 @@ describe('ItemPageComponent', () => {
|
||||
expect(comp.signpostingLinks).toEqual([mocklink, mocklink2]);
|
||||
|
||||
// Check if linkHeadService.addTag() was called with the correct arguments
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(mockSignpostingLinks.length);
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(mockSignpostingLinks.length + getCoarLdnLocalInboxUrls.length);
|
||||
let expected: LinkDefinition = mockSignpostingLinks[0] as LinkDefinition;
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledWith(expected);
|
||||
expected = {
|
||||
@@ -186,8 +197,7 @@ describe('ItemPageComponent', () => {
|
||||
});
|
||||
|
||||
it('should set Link header on the server', () => {
|
||||
|
||||
expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', '<http://test.org> ; rel="rel1" ; type="type1" , <http://test2.org> ; rel="rel2" ');
|
||||
expect(serverResponseService.setHeader).toHaveBeenCalledWith('Link', '<http://test.org> ; rel="rel1" ; type="type1" , <http://test2.org> ; rel="rel2" , <http://InboxUrls.org> ; rel="http://www.w3.org/ns/ldp#inbox", <http://InboxUrls2.org> ; rel="http://www.w3.org/ns/ldp#inbox"');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -217,7 +227,7 @@ describe('ItemPageComponent', () => {
|
||||
|
||||
it('should add the signposting links', () => {
|
||||
expect(serverResponseService.setHeader).toHaveBeenCalled();
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2);
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -234,7 +244,7 @@ describe('ItemPageComponent', () => {
|
||||
|
||||
it('should add the signposting links', () => {
|
||||
expect(serverResponseService.setHeader).toHaveBeenCalled();
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2);
|
||||
expect(linkHeadService.addTag).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -2,8 +2,8 @@ import { ChangeDetectionStrategy, Component, Inject, OnDestroy, OnInit, PLATFORM
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { isPlatformServer } from '@angular/common';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
@@ -21,6 +21,7 @@ import { SignpostingDataService } from '../../core/data/signposting-data.service
|
||||
import { SignpostingLink } from '../../core/data/signposting-links.model';
|
||||
import { isNotEmpty } from '../../shared/empty.util';
|
||||
import { LinkDefinition, LinkHeadService } from '../../core/services/link-head.service';
|
||||
import { NotifyInfoService } from 'src/app/core/coar-notify/notify-info/notify-info.service';
|
||||
|
||||
/**
|
||||
* This component renders a simple item page.
|
||||
@@ -32,7 +33,7 @@ import { LinkDefinition, LinkHeadService } from '../../core/services/link-head.s
|
||||
styleUrls: ['./item-page.component.scss'],
|
||||
templateUrl: './item-page.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
animations: [fadeInOut]
|
||||
animations: [fadeInOut],
|
||||
})
|
||||
export class ItemPageComponent implements OnInit, OnDestroy {
|
||||
|
||||
@@ -68,6 +69,13 @@ export class ItemPageComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
signpostingLinks: SignpostingLink[] = [];
|
||||
|
||||
/**
|
||||
* An array of LinkDefinition objects representing inbox links for the item page.
|
||||
*/
|
||||
inboxTags: LinkDefinition[] = [];
|
||||
|
||||
coarRestApiUrls: string[] = [];
|
||||
|
||||
constructor(
|
||||
protected route: ActivatedRoute,
|
||||
protected router: Router,
|
||||
@@ -77,6 +85,7 @@ export class ItemPageComponent implements OnInit, OnDestroy {
|
||||
protected responseService: ServerResponseService,
|
||||
protected signpostingDataService: SignpostingDataService,
|
||||
protected linkHeadService: LinkHeadService,
|
||||
protected notifyInfoService: NotifyInfoService,
|
||||
@Inject(PLATFORM_ID) protected platformId: string
|
||||
) {
|
||||
this.initPageLinks();
|
||||
@@ -106,7 +115,8 @@ export class ItemPageComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
private initPageLinks(): void {
|
||||
this.route.params.subscribe(params => {
|
||||
this.signpostingDataService.getLinks(params.id).pipe(take(1)).subscribe((signpostingLinks: SignpostingLink[]) => {
|
||||
combineLatest([this.signpostingDataService.getLinks(params.id).pipe(take(1)), this.getCoarLdnLocalInboxUrls()])
|
||||
.subscribe(([signpostingLinks, coarRestApiUrls]) => {
|
||||
let links = '';
|
||||
this.signpostingLinks = signpostingLinks;
|
||||
|
||||
@@ -124,6 +134,11 @@ export class ItemPageComponent implements OnInit, OnDestroy {
|
||||
this.linkHeadService.addTag(tag);
|
||||
});
|
||||
|
||||
if (coarRestApiUrls.length > 0) {
|
||||
let inboxLinks = this.initPageInboxLinks(coarRestApiUrls);
|
||||
links = links + (isNotEmpty(links) ? ', ' : '') + inboxLinks;
|
||||
}
|
||||
|
||||
if (isPlatformServer(this.platformId)) {
|
||||
this.responseService.setHeader('Link', links);
|
||||
}
|
||||
@@ -131,9 +146,49 @@ export class ItemPageComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the COAR LDN local inbox URL if COAR configuration is enabled.
|
||||
* If the COAR LDN local inbox URL is retrieved successfully, initializes the page inbox links.
|
||||
*/
|
||||
private getCoarLdnLocalInboxUrls(): Observable<string[]> {
|
||||
return this.notifyInfoService.isCoarConfigEnabled().pipe(
|
||||
switchMap((coarLdnEnabled: boolean) => {
|
||||
if (coarLdnEnabled) {
|
||||
return this.notifyInfoService.getCoarLdnLocalInboxUrls();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page inbox links.
|
||||
* @param coarRestApiUrls - An array of COAR REST API URLs.
|
||||
*/
|
||||
private initPageInboxLinks(coarRestApiUrls: string[]): string {
|
||||
const rel = this.notifyInfoService.getInboxRelationLink();
|
||||
let links = '';
|
||||
|
||||
coarRestApiUrls.forEach((coarRestApiUrl: string) => {
|
||||
// Add link to head
|
||||
let tag: LinkDefinition = {
|
||||
href: coarRestApiUrl,
|
||||
rel: rel
|
||||
};
|
||||
this.inboxTags.push(tag);
|
||||
this.linkHeadService.addTag(tag);
|
||||
|
||||
links = links + (isNotEmpty(links) ? ', ' : '') + `<${coarRestApiUrl}> ; rel="${rel}"`;
|
||||
});
|
||||
|
||||
return links;
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.signpostingLinks.forEach((link: SignpostingLink) => {
|
||||
this.linkHeadService.removeTag(`href='${link.href}'`);
|
||||
});
|
||||
this.inboxTags.forEach((link: LinkDefinition) => {
|
||||
this.linkHeadService.removeTag(`href='${link.href}'`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -84,6 +84,22 @@
|
||||
[label]="'item.page.uri'">
|
||||
</ds-item-page-uri-field>
|
||||
<ds-item-page-collections [item]="object"></ds-item-page-collections>
|
||||
<ds-item-page-uri-field [item]="object"
|
||||
[fields]="['notify.relation.endorsedBy']"
|
||||
[label]="'item.page.endorsment'">
|
||||
</ds-item-page-uri-field>
|
||||
<ds-item-page-uri-field [item]="object"
|
||||
[fields]="['datacite.relation.isReviewedBy']"
|
||||
[label]="'item.page.review'">
|
||||
</ds-item-page-uri-field>
|
||||
<ds-item-page-uri-field [item]="object"
|
||||
[fields]="['datacite.relation.isSupplementedBy']"
|
||||
[label]="'item.page.dataset'">
|
||||
</ds-item-page-uri-field>
|
||||
<ds-item-page-uri-field [item]="object"
|
||||
[fields]="['datacite.relation.isReferencedBy']"
|
||||
[label]="'item.page.dataset'">
|
||||
</ds-item-page-uri-field>
|
||||
<div>
|
||||
<a class="btn btn-outline-primary" role="button" [routerLink]="[itemPageRoute + '/full']">
|
||||
<i class="fas fa-info-circle"></i> {{"item.page.link.full" | translate}}
|
||||
|
@@ -70,6 +70,22 @@
|
||||
[label]="'item.page.uri'">
|
||||
</ds-item-page-uri-field>
|
||||
<ds-item-page-collections [item]="object"></ds-item-page-collections>
|
||||
<ds-item-page-uri-field [item]="object"
|
||||
[fields]="['notify.relation.endorsedBy']"
|
||||
[label]="'item.page.endorsment'">
|
||||
</ds-item-page-uri-field>
|
||||
<ds-item-page-uri-field [item]="object"
|
||||
[fields]="['datacite.relation.isReviewedBy']"
|
||||
[label]="'item.page.review'">
|
||||
</ds-item-page-uri-field>
|
||||
<ds-item-page-uri-field [item]="object"
|
||||
[fields]="['datacite.relation.isSupplementedBy']"
|
||||
[label]="'item.page.dataset'">
|
||||
</ds-item-page-uri-field>
|
||||
<ds-item-page-uri-field [item]="object"
|
||||
[fields]="['datacite.relation.isReferencedBy']"
|
||||
[label]="'item.page.dataset'">
|
||||
</ds-item-page-uri-field>
|
||||
<div>
|
||||
<a class="btn btn-outline-primary" [routerLink]="[itemPageRoute + '/full']" role="button">
|
||||
<i class="fas fa-info-circle"></i> {{"item.page.link.full" | translate}}
|
||||
|
@@ -0,0 +1,5 @@
|
||||
<ng-container *ngIf="(requestMap$ | async)?.size > 0">
|
||||
<ng-container *ngFor="let entry of (requestMap$ | async) | keyvalue ">
|
||||
<ds-request-status-alert-box [status]="entry.key" [data]="entry.value"></ds-request-status-alert-box>
|
||||
</ng-container>
|
||||
</ng-container>
|
@@ -0,0 +1,88 @@
|
||||
import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing';
|
||||
import { NotifyRequestsStatusComponent } from './notify-requests-status.component';
|
||||
import { NotifyRequestsStatusDataService } from 'src/app/core/data/notify-services-status-data.service';
|
||||
import { NotifyRequestsStatus } from '../notify-requests-status.model';
|
||||
import { RequestStatusEnum } from '../notify-status.enum';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('NotifyRequestsStatusComponent', () => {
|
||||
let component: NotifyRequestsStatusComponent;
|
||||
let fixture: ComponentFixture<NotifyRequestsStatusComponent>;
|
||||
let notifyInfoServiceSpy;
|
||||
|
||||
const mock: NotifyRequestsStatus = Object.assign(new NotifyRequestsStatus(), {
|
||||
notifyStatus: [],
|
||||
itemuuid: 'testUuid'
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
notifyInfoServiceSpy = {
|
||||
getNotifyRequestsStatus:() => createSuccessfulRemoteDataObject$(mock)
|
||||
};
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [NotifyRequestsStatusComponent],
|
||||
providers: [
|
||||
{ provide: NotifyRequestsStatusDataService, useValue: notifyInfoServiceSpy }
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NotifyRequestsStatusComponent);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create the component', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should fetch data from the service on initialization', fakeAsync(() => {
|
||||
const mockData: NotifyRequestsStatus = Object.assign(new NotifyRequestsStatus(), {
|
||||
notifyStatus: [],
|
||||
itemuuid: 'testUuid'
|
||||
});
|
||||
component.itemUuid = mockData.itemuuid;
|
||||
spyOn(notifyInfoServiceSpy, 'getNotifyRequestsStatus').and.callThrough();
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
tick();
|
||||
|
||||
expect(notifyInfoServiceSpy.getNotifyRequestsStatus).toHaveBeenCalledWith('testUuid');
|
||||
component.requestMap$.subscribe((map) => {
|
||||
expect(map.size).toBe(0);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should group data by status', () => {
|
||||
const mockData: NotifyRequestsStatus = Object.assign(new NotifyRequestsStatus(), {
|
||||
notifyStatus: [
|
||||
{
|
||||
serviceName: 'test1',
|
||||
serviceUrl: 'test',
|
||||
status: RequestStatusEnum.ACCEPTED,
|
||||
},
|
||||
{
|
||||
serviceName: 'test2',
|
||||
serviceUrl: 'test',
|
||||
status: RequestStatusEnum.REJECTED,
|
||||
},
|
||||
{
|
||||
serviceName: 'test3',
|
||||
serviceUrl: 'test',
|
||||
status: RequestStatusEnum.ACCEPTED,
|
||||
},
|
||||
],
|
||||
itemUuid: 'testUuid'
|
||||
});
|
||||
spyOn(notifyInfoServiceSpy, 'getNotifyRequestsStatus').and.returnValue(createSuccessfulRemoteDataObject$(mockData));
|
||||
fixture.detectChanges();
|
||||
(component as any).groupDataByStatus(mockData);
|
||||
component.requestMap$.subscribe((map) => {
|
||||
expect(map.size).toBe(2);
|
||||
expect(map.get(RequestStatusEnum.ACCEPTED)?.length).toBe(2);
|
||||
expect(map.get(RequestStatusEnum.REJECTED)?.length).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,78 @@
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
Input,
|
||||
OnInit,
|
||||
} from '@angular/core';
|
||||
import { Observable, filter, map } from 'rxjs';
|
||||
import {
|
||||
NotifyRequestsStatus,
|
||||
NotifyStatuses,
|
||||
} from '../notify-requests-status.model';
|
||||
import { NotifyRequestsStatusDataService } from '../../../../core/data/notify-services-status-data.service';
|
||||
import { RequestStatusEnum } from '../notify-status.enum';
|
||||
import {
|
||||
getFirstCompletedRemoteData,
|
||||
getRemoteDataPayload,
|
||||
} from '../../../../core/shared/operators';
|
||||
import { hasValue } from '../../../../shared/empty.util';
|
||||
@Component({
|
||||
selector: 'ds-notify-requests-status',
|
||||
templateUrl: './notify-requests-status.component.html',
|
||||
styleUrls: ['./notify-requests-status.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
|
||||
/**
|
||||
* Component to show an alert box for each update in th Notify feature (e.g. COAR updates)
|
||||
*/
|
||||
|
||||
export class NotifyRequestsStatusComponent implements OnInit {
|
||||
/**
|
||||
* The UUID of the item.
|
||||
*/
|
||||
@Input() itemUuid: string;
|
||||
|
||||
/**
|
||||
* Observable representing the request map.
|
||||
* The map contains request status enums as keys and arrays of notify statuses as values.
|
||||
*/
|
||||
requestMap$: Observable<Map<RequestStatusEnum, NotifyStatuses[]>>;
|
||||
|
||||
constructor(private notifyInfoService: NotifyRequestsStatusDataService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.requestMap$ = this.notifyInfoService
|
||||
.getNotifyRequestsStatus(this.itemUuid)
|
||||
.pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
filter((data) => hasValue(data)),
|
||||
getRemoteDataPayload(),
|
||||
filter((data: NotifyRequestsStatus) => hasValue(data)),
|
||||
map((data: NotifyRequestsStatus) => {
|
||||
return this.groupDataByStatus(data);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the notify requests status data by status.
|
||||
* @param notifyRequestsStatus The notify requests status data.
|
||||
*/
|
||||
private groupDataByStatus(notifyRequestsStatus: NotifyRequestsStatus) {
|
||||
const statusMap: Map<RequestStatusEnum, NotifyStatuses[]> = new Map();
|
||||
notifyRequestsStatus.notifyStatus?.forEach(
|
||||
(notifyStatus: NotifyStatuses) => {
|
||||
const status = notifyStatus.status;
|
||||
|
||||
if (!statusMap.has(status)) {
|
||||
statusMap.set(status, []);
|
||||
}
|
||||
|
||||
statusMap.get(status)?.push(notifyStatus);
|
||||
}
|
||||
);
|
||||
|
||||
return statusMap;
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
// eslint-disable-next-line max-classes-per-file
|
||||
import { autoserialize, deserialize, inheritSerialization } from 'cerialize';
|
||||
import { typedObject } from '../../../core/cache/builders/build-decorators';
|
||||
import { CacheableObject } from '../../../core/cache/cacheable-object.model';
|
||||
import { ResourceType } from '../../../core/shared/resource-type';
|
||||
import { excludeFromEquals } from '../../../core/utilities/equals.decorators';
|
||||
import { NOTIFYREQUEST } from './notify-requests-status.resource-type';
|
||||
import { HALLink } from '../../../core/shared/hal-link.model';
|
||||
import { RequestStatusEnum } from './notify-status.enum';
|
||||
|
||||
/**
|
||||
* Represents the status of notify requests for an item.
|
||||
*/
|
||||
@typedObject
|
||||
@inheritSerialization(CacheableObject)
|
||||
export class NotifyRequestsStatus implements CacheableObject {
|
||||
static type = NOTIFYREQUEST;
|
||||
|
||||
/**
|
||||
* The object type.
|
||||
*/
|
||||
@excludeFromEquals
|
||||
@autoserialize
|
||||
type: ResourceType;
|
||||
|
||||
/**
|
||||
* The notify statuses.
|
||||
*/
|
||||
@autoserialize
|
||||
notifyStatus: NotifyStatuses[];
|
||||
|
||||
/**
|
||||
* The UUID of the item.
|
||||
*/
|
||||
@autoserialize
|
||||
itemuuid: string;
|
||||
|
||||
/**
|
||||
* The links associated with the notify requests status.
|
||||
*/
|
||||
@deserialize
|
||||
_links: {
|
||||
self: HALLink;
|
||||
[k: string]: HALLink | HALLink[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the status of a notification request.
|
||||
*/
|
||||
export class NotifyStatuses {
|
||||
/**
|
||||
* The name of the service.
|
||||
*/
|
||||
serviceName: string;
|
||||
|
||||
/**
|
||||
* The URL of the service.
|
||||
*/
|
||||
serviceUrl: string;
|
||||
|
||||
/**
|
||||
* The status of the notification request.
|
||||
*/
|
||||
status: RequestStatusEnum;
|
||||
/**
|
||||
* Type of request.
|
||||
*/
|
||||
offerType: string;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,8 @@
|
||||
import {ResourceType} from '../../../core/shared/resource-type';
|
||||
/**
|
||||
* The resource type for the root endpoint
|
||||
*
|
||||
* Needs to be in a separate file to prevent circular
|
||||
* dependencies in webpack.
|
||||
*/
|
||||
export const NOTIFYREQUEST = new ResourceType('notifyrequests');
|
@@ -0,0 +1,5 @@
|
||||
export enum RequestStatusEnum {
|
||||
ACCEPTED = 'ACCEPTED',
|
||||
REJECTED = 'REJECTED',
|
||||
REQUESTED = 'REQUESTED',
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
<ng-container *ngIf="data?.length > 0 && displayOptions">
|
||||
<div
|
||||
[ngClass]="{'align-items-center': data.length == 1}"
|
||||
class="alert d-flex flex-row sections-gap {{
|
||||
displayOptions.alertType
|
||||
}}"
|
||||
>
|
||||
<img
|
||||
class="source-logo"
|
||||
src="assets/images/qa-coar-notify-logo.png"
|
||||
alt="notify logo"
|
||||
/>
|
||||
<ds-truncatable [id]="status">
|
||||
<ds-truncatable-part [id]="status" [minLines]="1">
|
||||
<div class="w-100 d-flex flex-column">
|
||||
<ng-container *ngFor="let request of data">
|
||||
<div
|
||||
[innerHTML]="
|
||||
displayOptions.text
|
||||
| translate
|
||||
: {
|
||||
serviceName: request.serviceName,
|
||||
serviceUrl: request.serviceUrl,
|
||||
offerType: request.offerType
|
||||
}
|
||||
"
|
||||
></div>
|
||||
</ng-container>
|
||||
</div>
|
||||
</ds-truncatable-part>
|
||||
</ds-truncatable>
|
||||
</div>
|
||||
</ng-container>
|
@@ -0,0 +1,7 @@
|
||||
.source-logo {
|
||||
max-height: var(--ds-header-logo-height);
|
||||
}
|
||||
|
||||
.sections-gap {
|
||||
gap: 1rem;
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
|
||||
import { RequestStatusAlertBoxComponent } from './request-status-alert-box.component';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { RequestStatusEnum } from '../notify-status.enum';
|
||||
|
||||
describe('RequestStatusAlertBoxComponent', () => {
|
||||
let component: RequestStatusAlertBoxComponent;
|
||||
let componentAsAny: any;
|
||||
let fixture: ComponentFixture<RequestStatusAlertBoxComponent>;
|
||||
|
||||
const mockData = [
|
||||
{
|
||||
serviceName: 'test',
|
||||
serviceUrl: 'test',
|
||||
status: RequestStatusEnum.ACCEPTED,
|
||||
offerType: 'test'
|
||||
},
|
||||
{
|
||||
serviceName: 'test1',
|
||||
serviceUrl: 'test',
|
||||
status: RequestStatusEnum.REJECTED,
|
||||
offerType: 'test'
|
||||
},
|
||||
];
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [RequestStatusAlertBoxComponent],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(RequestStatusAlertBoxComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.data = mockData;
|
||||
component.displayOptions = {
|
||||
alertType: 'alert-danger',
|
||||
text: 'request-status-alert-box.rejected',
|
||||
};
|
||||
componentAsAny = component;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create the component', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should display the alert box when data is available', fakeAsync(() => {
|
||||
const alertBoxElement = fixture.nativeElement.querySelector('.alert');
|
||||
expect(alertBoxElement).toBeTruthy();
|
||||
}));
|
||||
});
|
@@ -0,0 +1,82 @@
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
Input,
|
||||
type OnInit,
|
||||
} from '@angular/core';
|
||||
import { NotifyStatuses } from '../notify-requests-status.model';
|
||||
import { RequestStatusEnum } from '../notify-status.enum';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-request-status-alert-box',
|
||||
templateUrl: './request-status-alert-box.component.html',
|
||||
styleUrls: ['./request-status-alert-box.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
/**
|
||||
* Represents a component that displays the status of a request.
|
||||
*/
|
||||
export class RequestStatusAlertBoxComponent implements OnInit {
|
||||
/**
|
||||
* The status of the request.
|
||||
*/
|
||||
@Input() status: RequestStatusEnum;
|
||||
|
||||
/**
|
||||
* The input data for the request status alert box component.
|
||||
* @type {NotifyStatuses[]}
|
||||
*/
|
||||
@Input() data: NotifyStatuses[] = [];
|
||||
|
||||
/**
|
||||
* The display options for the request status alert box.
|
||||
*/
|
||||
displayOptions: NotifyRequestDisplayOptions;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.prepareDataToDisplay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the data to be displayed based on the current status.
|
||||
*/
|
||||
private prepareDataToDisplay() {
|
||||
switch (this.status) {
|
||||
case RequestStatusEnum.ACCEPTED:
|
||||
this.displayOptions = {
|
||||
alertType: 'alert-info',
|
||||
text: 'request-status-alert-box.accepted',
|
||||
};
|
||||
break;
|
||||
|
||||
case RequestStatusEnum.REJECTED:
|
||||
this.displayOptions = {
|
||||
alertType: 'alert-danger',
|
||||
text: 'request-status-alert-box.rejected',
|
||||
};
|
||||
break;
|
||||
|
||||
case RequestStatusEnum.REQUESTED:
|
||||
this.displayOptions = {
|
||||
alertType: 'alert-warning',
|
||||
text: 'request-status-alert-box.requested',
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the display options for a notification request.
|
||||
*/
|
||||
export interface NotifyRequestDisplayOptions {
|
||||
/**
|
||||
* The type of alert to display.
|
||||
* Possible values are 'alert-danger', 'alert-warning', or 'alert-info'.
|
||||
*/
|
||||
alertType: 'alert-danger' | 'alert-warning' | 'alert-info';
|
||||
/**
|
||||
* The text to display in the notification.
|
||||
*/
|
||||
text: string;
|
||||
}
|
@@ -175,8 +175,9 @@ export class MenuResolver implements Resolve<boolean> {
|
||||
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
|
||||
this.authorizationService.isAuthorized(FeatureID.CanSubmit),
|
||||
this.authorizationService.isAuthorized(FeatureID.CanEditItem),
|
||||
this.authorizationService.isAuthorized(FeatureID.CanSeeQA)
|
||||
]).subscribe(([isCollectionAdmin, isCommunityAdmin, isSiteAdmin, canSubmit, canEditItem, canSeeQa]) => {
|
||||
this.authorizationService.isAuthorized(FeatureID.CanSeeQA),
|
||||
this.authorizationService.isAuthorized(FeatureID.CoarNotifyEnabled),
|
||||
]).subscribe(([isCollectionAdmin, isCommunityAdmin, isSiteAdmin, canSubmit, canEditItem, canSeeQa, isCoarNotifyEnabled]) => {
|
||||
const newSubMenuList = [
|
||||
{
|
||||
id: 'new_community',
|
||||
@@ -227,6 +228,18 @@ export class MenuResolver implements Resolve<boolean> {
|
||||
text: 'menu.section.new_process',
|
||||
link: '/processes/new'
|
||||
} as LinkMenuItemModel,
|
||||
},/* ldn_services */
|
||||
{
|
||||
id: 'ldn_services_new',
|
||||
parentID: 'new',
|
||||
active: false,
|
||||
visible: isSiteAdmin && isCoarNotifyEnabled,
|
||||
model: {
|
||||
type: MenuItemType.LINK,
|
||||
text: 'menu.section.services_new',
|
||||
link: '/admin/ldn/services/new'
|
||||
} as LinkMenuItemModel,
|
||||
icon: '',
|
||||
},
|
||||
];
|
||||
const editSubMenuList = [
|
||||
@@ -355,6 +368,19 @@ export class MenuResolver implements Resolve<boolean> {
|
||||
icon: 'terminal',
|
||||
index: 10
|
||||
},
|
||||
/* LDN Services */
|
||||
{
|
||||
id: 'ldn_services',
|
||||
active: false,
|
||||
visible: isSiteAdmin && isCoarNotifyEnabled,
|
||||
model: {
|
||||
type: MenuItemType.LINK,
|
||||
text: 'menu.section.services',
|
||||
link: '/admin/ldn/services'
|
||||
} as LinkMenuItemModel,
|
||||
icon: 'inbox',
|
||||
index: 14
|
||||
},
|
||||
{
|
||||
id: 'health',
|
||||
active: false,
|
||||
@@ -367,8 +393,8 @@ export class MenuResolver implements Resolve<boolean> {
|
||||
icon: 'heartbeat',
|
||||
index: 11
|
||||
},
|
||||
/* Notifications */
|
||||
{
|
||||
/* Notifications */
|
||||
{
|
||||
id: 'notifications',
|
||||
active: false,
|
||||
visible: canSeeQa || isSiteAdmin,
|
||||
@@ -398,9 +424,10 @@ export class MenuResolver implements Resolve<boolean> {
|
||||
model: {
|
||||
type: MenuItemType.LINK,
|
||||
text: 'menu.section.notifications_publication-claim',
|
||||
link: '/notifications/' + PUBLICATION_CLAIMS_PATH
|
||||
link: '/admin/notifications/' + PUBLICATION_CLAIMS_PATH
|
||||
} as LinkMenuItemModel,
|
||||
},
|
||||
/* Admin Search */
|
||||
];
|
||||
menuList.forEach((menuSection) => this.menuService.addSection(MenuID.ADMIN, Object.assign(menuSection, {
|
||||
shouldPersistOnRouteChange: true
|
||||
@@ -573,7 +600,6 @@ export class MenuResolver implements Resolve<boolean> {
|
||||
this.authorizationService.isAuthorized(FeatureID.AdministratorOf)
|
||||
.subscribe((authorized) => {
|
||||
const menuList = [
|
||||
/* Admin Search */
|
||||
{
|
||||
id: 'admin_search',
|
||||
active: false,
|
||||
|
@@ -0,0 +1,36 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MyDspaceQaEventsNotificationsComponent } from './my-dspace-qa-events-notifications.component';
|
||||
import { QualityAssuranceSourceDataService } from '../../core/notifications/qa/source/quality-assurance-source-data.service';
|
||||
import { createSuccessfulRemoteDataObject$ } from 'src/app/shared/remote-data.utils';
|
||||
import { createPaginatedList } from 'src/app/shared/testing/utils.test';
|
||||
import { QualityAssuranceSourceObject } from 'src/app/core/notifications/qa/models/quality-assurance-source.model';
|
||||
|
||||
describe('MyDspaceQaEventsNotificationsComponent', () => {
|
||||
let component: MyDspaceQaEventsNotificationsComponent;
|
||||
let fixture: ComponentFixture<MyDspaceQaEventsNotificationsComponent>;
|
||||
|
||||
let qualityAssuranceSourceDataServiceStub: any;
|
||||
const obj = createSuccessfulRemoteDataObject$(createPaginatedList([new QualityAssuranceSourceObject()]));
|
||||
|
||||
beforeEach(async () => {
|
||||
qualityAssuranceSourceDataServiceStub = {
|
||||
getSources: () => obj
|
||||
};
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ MyDspaceQaEventsNotificationsComponent ],
|
||||
providers: [
|
||||
{ provide: QualityAssuranceSourceDataService, useValue: qualityAssuranceSourceDataServiceStub }
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(MyDspaceQaEventsNotificationsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@@ -1,9 +1,9 @@
|
||||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||
import { QualityAssuranceSourceDataService } from '../../core/notifications/qa/source/quality-assurance-source-data.service';
|
||||
import { getFirstCompletedRemoteData, getPaginatedListPayload, getRemoteDataPayload } from '../../core/shared/operators';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { QualityAssuranceSourceObject } from './../../core/notifications/qa/models/quality-assurance-source.model';
|
||||
import { Observable, of, tap } from 'rxjs';
|
||||
import { getNotificatioQualityAssuranceRoute } from '../../admin/admin-routing-paths';
|
||||
import { QualityAssuranceSourceObject } from 'src/app/core/notifications/qa/models/quality-assurance-source.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-my-dspace-qa-events-notifications',
|
||||
@@ -11,7 +11,8 @@ import { getNotificatioQualityAssuranceRoute } from '../../admin/admin-routing-p
|
||||
styleUrls: ['./my-dspace-qa-events-notifications.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class MyDspaceQaEventsNotificationsComponent implements OnInit {
|
||||
export class MyDspaceQaEventsNotificationsComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* An Observable that emits an array of QualityAssuranceSourceObject.
|
||||
*/
|
||||
@@ -22,6 +23,7 @@ export class MyDspaceQaEventsNotificationsComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
this.getSources();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sources for Quality Assurance.
|
||||
* @returns An Observable of the sources for Quality Assurance.
|
||||
@@ -29,11 +31,16 @@ export class MyDspaceQaEventsNotificationsComponent implements OnInit {
|
||||
*/
|
||||
getSources() {
|
||||
this.sources$ = this.qualityAssuranceSourceDataService.getSources()
|
||||
.pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
getPaginatedListPayload(),
|
||||
);
|
||||
.pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
tap((rd) => {
|
||||
if (rd.hasFailed) {
|
||||
throw new Error('Can\'t retrieve Quality Assurance sources');
|
||||
}
|
||||
}),
|
||||
getRemoteDataPayload(),
|
||||
getPaginatedListPayload(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user