Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/dspace 7.6.1 coar notify/CST-15256 #95

Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ <h1 class="flex-grow-1">{{ isNewService ? ('ldn-create-service.title' | translat
<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"
*ngFor="let constraint of (itemFiltersRD$ | async)?.payload?.page; let internalIndex = index"
class="dropdown-item collection-item text-truncate w-100"
ngbDropdownItem
type="button">
Expand Down Expand Up @@ -263,14 +263,18 @@ <h1 class="flex-grow-1">{{ isNewService ? ('ldn-create-service.title' | translat

<span (click)="addInboundPattern()"
class="add-pattern-link mb-2">{{ 'ldn-new-service.form.label.addPattern' | translate }}</span>
<hr>
<div class="form-group row">
<div class="col text-right space-children-mr">
<ng-content select="[before]"></ng-content>
<button (click)="resetFormAndLeave()" class="btn btn-outline-secondary" type="button">
<span>&nbsp;{{ 'submission.general.back.submit' | translate }}</span>
</button>
<button class="btn btn-primary" type="submit">
<span><i class="fas fa-save"></i>&nbsp;{{ 'ldn-new-service.form.label.submit' | translate }}</span>
</button>

<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>&nbsp;{{ 'submission.general.back.submit' | translate }}</span>
</button>
<button class="btn btn-primary" type="submit">
<span><i class="fas fa-save"></i>&nbsp;{{ 'ldn-new-service.form.label.submit' | translate }}</span>
</button>
</div>
</div>
</form>
</div>
Expand All @@ -294,15 +298,15 @@ <h4 *ngIf="isNewService">{{'service.overview.create.modal' | translate }}</h4>
</div>
<div class="modal-footer">
<div *ngIf="!isNewService">
<button (click)="closeModal()" class="btn btn-danger mr-2"
<button (click)="closeModal()" class="btn btn-outline-secondary 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 "
<button (click)="closeModal()" class="btn btn-outline-secondary mr-2 "
id="delete-confirm-new">{{ 'service.refuse.create' | translate }}
</button>
<button (click)="createService()"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
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 {
ChangeDetectorRef,
EventEmitter,
} from '@angular/core';
import {
ComponentFixture,
fakeAsync,
TestBed,
tick,
} from '@angular/core/testing';
import {
FormArray,
FormBuilder,
FormControl,
FormGroup,
ReactiveFormsModule,
} from '@angular/forms';
import { By } from '@angular/platform-browser';
import {
ActivatedRoute,
Router,
} from '@angular/router';
import {
NgbDropdownModule,
NgbModal,
} from '@ng-bootstrap/ng-bootstrap';
import { provideMockStore } from '@ngrx/store/testing';
import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import { PaginationService } from 'ngx-pagination';
import {
of as observableOf,
of,
} from 'rxjs';

import { RouteService } from '../../../core/services/route.service';
import { MockActivatedRoute } from '../../../shared/mocks/active-router.mock';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
import { RouterStub } from '../../../shared/testing/router.stub';
import { LdnItemfiltersService } from '../ldn-services-data/ldn-itemfilters-data.service';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
import { LdnServiceFormComponent } from './ldn-service-form.component';

describe('LdnServiceFormEditComponent', () => {
let component: LdnServiceFormComponent;
Expand All @@ -33,7 +59,7 @@ describe('LdnServiceFormEditComponent', () => {
const routeParams = {
serviceId: testId,
};
const routeUrlSegments = [{path: 'path'}];
const routeUrlSegments = [{ path: 'path' }];
const formMockValue = {
'id': '',
'name': 'name',
Expand All @@ -52,9 +78,9 @@ describe('LdnServiceFormEditComponent', () => {
'pattern': '',
'patternLabel': 'Select a pattern',
'constraint': '',
'automatic': false
}
]
'automatic': false,
},
],
};


Expand All @@ -63,7 +89,7 @@ describe('LdnServiceFormEditComponent', () => {
instant: () => 'translated-text',
onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter()
onDefaultLangChange: new EventEmitter(),
};

beforeEach(async () => {
Expand All @@ -77,11 +103,11 @@ describe('LdnServiceFormEditComponent', () => {
findAll: () => of(['item1', 'item2']),
};
cdRefStub = Object.assign({
detectChanges: () => fixture.detectChanges()
detectChanges: () => fixture.detectChanges(),
});
modalService = {
open: () => {/*comment*/
}
},
};


Expand All @@ -91,19 +117,19 @@ describe('LdnServiceFormEditComponent', () => {
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: {}},
{ 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();

Expand All @@ -120,15 +146,15 @@ describe('LdnServiceFormEditComponent', () => {

it('should init properties correctly', fakeAsync(() => {
spyOn(component, 'fetchServiceData');
spyOn(component, 'setItemfilters');
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();
expect(component.setItemFilters).toHaveBeenCalled();
}));

it('should unsubscribe on destroy', () => {
Expand All @@ -139,7 +165,7 @@ describe('LdnServiceFormEditComponent', () => {

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'}]));
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'));
Expand Down Expand Up @@ -184,7 +210,7 @@ describe('LdnServiceFormEditComponent', () => {
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.addControl('notifyServiceInboundPatterns', (component as any).formBuilder.array([{ pattern: 'patternValue' }]));
component.formModel.patchValue(formMockValue);
component.createService();

Expand All @@ -196,13 +222,13 @@ describe('LdnServiceFormEditComponent', () => {
it('should check patterns', () => {
const arrValid = new FormArray([
new FormGroup({
pattern: new FormControl('pattern')
pattern: new FormControl('pattern'),
}),
]);

const arrInvalid = new FormArray([
new FormGroup({
pattern: new FormControl('')
pattern: new FormControl(''),
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
public inboundPatterns: string[] = notifyPatterns;
public isNewService: boolean;
public areControlsInitialized: boolean;
public itemfiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
public itemFiltersRD$: Observable<RemoteData<PaginatedList<Itemfilter>>>;
public config: FindListOptions = Object.assign(new FindListOptions(), {
elementsPerPage: 20
});
Expand All @@ -70,12 +70,12 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
private deletedInboundPatterns: number[] = [];
private modalRef: any;
private ldnService: LdnService;
private selectPatternDefaultLabeli18Key = 'ldn-service.form.label.placeholder.default-select';
private selectPatternDefaultLabelI18Key = 'ldn-service.form.label.placeholder.default-select';
private routeSubscription: Subscription;

constructor(
protected ldnServicesService: LdnServicesService,
private ldnItemfiltersService: LdnItemfiltersService,
private ldnItemFiltersService: LdnItemfiltersService,
private formBuilder: FormBuilder,
private router: Router,
private route: ActivatedRoute,
Expand Down Expand Up @@ -113,7 +113,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
this.fetchServiceData(this.serviceId);
}
});
this.setItemfilters();
this.setItemFilters();
}

ngOnDestroy(): void {
Expand All @@ -123,8 +123,8 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
/**
* Sets item filters using LDN item filters service
*/
setItemfilters() {
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
setItemFilters() {
this.itemFiltersRD$ = this.ldnItemFiltersService.findAll().pipe(
getFirstCompletedRemoteData());
}

Expand All @@ -134,21 +134,12 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
*/
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,
Expand Down Expand Up @@ -245,14 +236,17 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
const PatternsArray = this.formModel.get(formArrayName) as FormArray;
PatternsArray.clear();

let servicesToUse = this.ldnService.notifyServiceInboundPatterns;

const servicesToUse = [...this.ldnService.notifyServiceInboundPatterns];
if (servicesToUse.length === 0) {
servicesToUse.push({ pattern: '', constraint: '', automatic: 'false' });
}
servicesToUse.forEach((patternObj: NotifyServicePattern) => {
let patternFormGroup;
const patternLabel = patternObj?.pattern ? 'ldn-service.form.pattern.' + patternObj?.pattern + '.label' : 'ldn-service.form.label.placeholder.default-select';
patternFormGroup = this.initializeInboundPatternFormGroup();
const newPatternObjWithLabel = Object.assign(new NotifyServicePattern(), {
...patternObj,
patternLabel: this.translateService.instant('ldn-service.form.pattern.' + patternObj?.pattern + '.label')
patternLabel: this.translateService.instant(patternLabel),
});
patternFormGroup.patchValue(newPatternObjWithLabel);

Expand Down Expand Up @@ -392,17 +386,6 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
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(
Expand Down Expand Up @@ -538,7 +521,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
private createInboundPatternFormGroup(): FormGroup {
const inBoundFormGroup = {
pattern: '',
patternLabel: this.translateService.instant(this.selectPatternDefaultLabeli18Key),
patternLabel: this.translateService.instant(this.selectPatternDefaultLabelI18Key),
constraint: '',
constraintFormatted: '',
automatic: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ <h4>{{'service.overview.delete.header' | translate }}</h4>
<div>
{{ 'service.overview.delete.body' | translate }}
</div>
<div class="mt-4">
<div class="mt-4 text-right">
<button (click)="closeModal()"
[attr.aria-label]="'ldn-service-overview-close-modal' | translate"
class="btn btn-primary mr-2">{{ 'service.detail.delete.cancel' | translate }}</button>
class="btn btn-outline-secondary 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const notifyPatterns = [

'request-review',

'announce-relationship',

];


Loading
Loading