mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[DURACOM-271] Remove form validation for patterns
This commit is contained in:
@@ -212,7 +212,7 @@
|
||||
<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">
|
||||
|
@@ -145,7 +145,7 @@ 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);
|
||||
@@ -153,7 +153,7 @@ describe('LdnServiceFormEditComponent', () => {
|
||||
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', () => {
|
||||
|
@@ -92,7 +92,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,
|
||||
});
|
||||
@@ -104,12 +104,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,
|
||||
@@ -147,7 +147,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
|
||||
this.fetchServiceData(this.serviceId);
|
||||
}
|
||||
});
|
||||
this.setItemfilters();
|
||||
this.setItemFilters();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
@@ -157,8 +157,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());
|
||||
}
|
||||
|
||||
@@ -168,21 +168,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,
|
||||
@@ -272,20 +263,24 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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..
|
||||
* 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();
|
||||
|
||||
const servicesToUse = this.ldnService.notifyServiceInboundPatterns;
|
||||
const servicesToUse = [...this.ldnService.notifyServiceInboundPatterns];
|
||||
if (servicesToUse.length === 0) {
|
||||
servicesToUse.push({ pattern: '', constraint: '', automatic: 'false' });
|
||||
}
|
||||
|
||||
servicesToUse.forEach((patternObj: NotifyServicePattern) => {
|
||||
const patternFormGroup = this.initializeInboundPatternFormGroup();
|
||||
const patternLabel = patternObj?.pattern ? 'ldn-service.form.pattern.' + patternObj?.pattern + '.label' : 'ldn-service.form.label.placeholder.default-select';
|
||||
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);
|
||||
|
||||
@@ -412,7 +407,7 @@ export class LdnServiceFormComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches the LDN service by retrieving and sending patch operations geenrated in generatePatchOperations()
|
||||
* Patches the LDN service by retrieving and sending patch operations generated in generatePatchOperations()
|
||||
*/
|
||||
patchService() {
|
||||
this.deleteMarkedInboundPatterns();
|
||||
@@ -425,17 +420,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(
|
||||
@@ -571,7 +555,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,
|
||||
|
@@ -6218,7 +6218,7 @@
|
||||
"ldn-new-service.form.error.patterns": "At least a pattern is required",
|
||||
"ldn-new-service.form.error.score": "Please enter a valid score (between 0 and 1). Use the “.” as decimal separator",
|
||||
|
||||
"ldn-new-service.form.label.inboundPattern": "Inbound Pattern",
|
||||
"ldn-new-service.form.label.inboundPattern": "Supported Pattern",
|
||||
"ldn-new-service.form.label.addPattern": "+ Add more",
|
||||
"ldn-new-service.form.label.removeItemFilter": "Remove",
|
||||
"ldn-register-new-service.breadcrumbs": "New Service",
|
||||
|
Reference in New Issue
Block a user