Skip to content

Commit 95f3384

Browse files
committed
Merge remote-tracking branch 'origin/main' into w2p-101289_1578_primaryBitstream-edit-implementation
2 parents daf297b + 00d895b commit 95f3384

126 files changed

Lines changed: 5623 additions & 1717 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ package-lock.json
3939
/nbproject/
4040

4141
junit.xml
42+
43+
/src/mirador-viewer/config.local.js

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ dspace-angular
413413
│ ├── merge-i18n-files.ts *
414414
│ ├── serve.ts *
415415
│ ├── sync-i18n-files.ts *
416-
│ ├── test-rest.ts *
417-
│ └── webpack.js *
416+
│ └── test-rest.ts *
418417
├── src * The source of the application
419418
│ ├── app * The source code of the application, subdivided by module/page.
420419
│ ├── assets * Folder for static resources

scripts/webpack.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/app/access-control/epeople-registry/epeople-registry.component.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,17 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
287287
/**
288288
* This method will set everything to stale, which will cause the lists on this page to update.
289289
*/
290-
reset() {
290+
reset(): void {
291291
this.epersonService.getBrowseEndpoint().pipe(
292-
take(1)
293-
).subscribe((href: string) => {
294-
this.requestService.setStaleByHrefSubstring(href).pipe(take(1)).subscribe(() => {
295-
this.epersonService.cancelEditEPerson();
296-
this.isEPersonFormShown = false;
297-
});
292+
take(1),
293+
switchMap((href: string) => {
294+
return this.requestService.setStaleByHrefSubstring(href).pipe(
295+
take(1),
296+
);
297+
})
298+
).subscribe(()=>{
299+
this.epersonService.cancelEditEPerson();
300+
this.isEPersonFormShown = false;
298301
});
299302
}
300303
}

src/app/access-control/epeople-registry/eperson-form/eperson-form.component.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@ng-dynamic-forms/core';
99
import { TranslateService } from '@ngx-translate/core';
1010
import { combineLatest as observableCombineLatest, Observable, of as observableOf, Subscription } from 'rxjs';
11-
import { debounceTime, switchMap, take } from 'rxjs/operators';
11+
import { debounceTime, finalize, map, switchMap, take } from 'rxjs/operators';
1212
import { PaginatedList } from '../../../core/data/paginated-list.model';
1313
import { RemoteData } from '../../../core/data/remote-data';
1414
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
@@ -463,31 +463,42 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
463463
* Deletes the EPerson from the Repository. The EPerson will be the only that this form is showing.
464464
* It'll either show a success or error message depending on whether the delete was successful or not.
465465
*/
466-
delete() {
467-
this.epersonService.getActiveEPerson().pipe(take(1)).subscribe((eperson: EPerson) => {
468-
const modalRef = this.modalService.open(ConfirmationModalComponent);
469-
modalRef.componentInstance.dso = eperson;
470-
modalRef.componentInstance.headerLabel = 'confirmation-modal.delete-eperson.header';
471-
modalRef.componentInstance.infoLabel = 'confirmation-modal.delete-eperson.info';
472-
modalRef.componentInstance.cancelLabel = 'confirmation-modal.delete-eperson.cancel';
473-
modalRef.componentInstance.confirmLabel = 'confirmation-modal.delete-eperson.confirm';
474-
modalRef.componentInstance.brandColor = 'danger';
475-
modalRef.componentInstance.confirmIcon = 'fas fa-trash';
476-
modalRef.componentInstance.response.pipe(take(1)).subscribe((confirm: boolean) => {
477-
if (confirm) {
478-
if (hasValue(eperson.id)) {
479-
this.epersonService.deleteEPerson(eperson).pipe(getFirstCompletedRemoteData()).subscribe((restResponse: RemoteData<NoContent>) => {
480-
if (restResponse.hasSucceeded) {
481-
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: this.dsoNameService.getName(eperson) }));
482-
this.submitForm.emit();
483-
} else {
484-
this.notificationsService.error('Error occured when trying to delete EPerson with id: ' + eperson.id + ' with code: ' + restResponse.statusCode + ' and message: ' + restResponse.errorMessage);
485-
}
486-
this.cancelForm.emit();
487-
});
488-
}
489-
}
490-
});
466+
delete(): void {
467+
this.epersonService.getActiveEPerson().pipe(
468+
take(1),
469+
switchMap((eperson: EPerson) => {
470+
const modalRef = this.modalService.open(ConfirmationModalComponent);
471+
modalRef.componentInstance.dso = eperson;
472+
modalRef.componentInstance.headerLabel = 'confirmation-modal.delete-eperson.header';
473+
modalRef.componentInstance.infoLabel = 'confirmation-modal.delete-eperson.info';
474+
modalRef.componentInstance.cancelLabel = 'confirmation-modal.delete-eperson.cancel';
475+
modalRef.componentInstance.confirmLabel = 'confirmation-modal.delete-eperson.confirm';
476+
modalRef.componentInstance.brandColor = 'danger';
477+
modalRef.componentInstance.confirmIcon = 'fas fa-trash';
478+
479+
return modalRef.componentInstance.response.pipe(
480+
take(1),
481+
switchMap((confirm: boolean) => {
482+
if (confirm && hasValue(eperson.id)) {
483+
this.canDelete$ = observableOf(false);
484+
return this.epersonService.deleteEPerson(eperson).pipe(
485+
getFirstCompletedRemoteData(),
486+
map((restResponse: RemoteData<NoContent>) => ({ restResponse, eperson }))
487+
);
488+
} else {
489+
return observableOf(null);
490+
}
491+
}),
492+
finalize(() => this.canDelete$ = observableOf(true))
493+
);
494+
})
495+
).subscribe(({ restResponse, eperson }: { restResponse: RemoteData<NoContent> | null, eperson: EPerson }) => {
496+
if (restResponse?.hasSucceeded) {
497+
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: this.dsoNameService.getName(eperson) }));
498+
} else {
499+
this.notificationsService.error(`Error occurred when trying to delete EPerson with id: ${eperson?.id} with code: ${restResponse?.statusCode} and message: ${restResponse?.errorMessage}`);
500+
}
501+
this.cancelForm.emit();
491502
});
492503
}
493504

@@ -523,7 +534,6 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
523534
* Cancel the current edit when component is destroyed & unsub all subscriptions
524535
*/
525536
ngOnDestroy(): void {
526-
this.onCancel();
527537
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
528538
this.paginationService.clearPagination(this.config.id);
529539
if (hasValue(this.emailValueChangeSubscribe)) {

src/app/admin/admin-registries/metadata-registry/metadata-schema-form/metadata-schema-form.component.spec.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
2-
32
import { MetadataSchemaFormComponent } from './metadata-schema-form.component';
43
import { NO_ERRORS_SCHEMA } from '@angular/core';
54
import { CommonModule } from '@angular/common';
@@ -29,14 +28,16 @@ describe('MetadataSchemaFormComponent', () => {
2928
createFormGroup: () => {
3029
return {
3130
patchValue: () => {
32-
}
31+
},
32+
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void {
33+
},
3334
};
3435
}
3536
};
3637
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
3738

3839
beforeEach(waitForAsync(() => {
39-
TestBed.configureTestingModule({
40+
return TestBed.configureTestingModule({
4041
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
4142
declarations: [MetadataSchemaFormComponent, EnumKeysPipe],
4243
providers: [
@@ -64,7 +65,7 @@ describe('MetadataSchemaFormComponent', () => {
6465
const expected = Object.assign(new MetadataSchema(), {
6566
namespace: namespace,
6667
prefix: prefix
67-
});
68+
} as MetadataSchema);
6869

6970
beforeEach(() => {
7071
spyOn(component.submitForm, 'emit');
@@ -79,31 +80,29 @@ describe('MetadataSchemaFormComponent', () => {
7980
fixture.detectChanges();
8081
});
8182

82-
it('should emit a new schema using the correct values', waitForAsync(() => {
83-
fixture.whenStable().then(() => {
84-
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
85-
});
86-
}));
83+
it('should emit a new schema using the correct values', async () => {
84+
await fixture.whenStable();
85+
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
86+
});
8787
});
8888

8989
describe('with an active schema', () => {
9090
const expectedWithId = Object.assign(new MetadataSchema(), {
9191
id: 1,
9292
namespace: namespace,
9393
prefix: prefix
94-
});
94+
} as MetadataSchema);
9595

9696
beforeEach(() => {
9797
spyOn(registryService, 'getActiveMetadataSchema').and.returnValue(observableOf(expectedWithId));
9898
component.onSubmit();
9999
fixture.detectChanges();
100100
});
101101

102-
it('should edit the existing schema using the correct values', waitForAsync(() => {
103-
fixture.whenStable().then(() => {
104-
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
105-
});
106-
}));
102+
it('should edit the existing schema using the correct values', async () => {
103+
await fixture.whenStable();
104+
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
105+
});
107106
});
108107
});
109108
});

src/app/admin/admin-registries/metadata-registry/metadata-schema-form/metadata-schema-form.component.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,37 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
7777
}
7878

7979
ngOnInit() {
80-
combineLatest(
80+
combineLatest([
8181
this.translateService.get(`${this.messagePrefix}.name`),
8282
this.translateService.get(`${this.messagePrefix}.namespace`)
83-
).subscribe(([name, namespace]) => {
83+
]).subscribe(([name, namespace]) => {
8484
this.name = new DynamicInputModel({
8585
id: 'name',
8686
label: name,
8787
name: 'name',
8888
validators: {
8989
required: null,
90-
pattern: '^[^ ,_]{1,32}$'
90+
pattern: '^[^. ,]*$',
91+
maxLength: 32,
9192
},
9293
required: true,
94+
errorMessages: {
95+
pattern: 'error.validation.metadata.name.invalid-pattern',
96+
maxLength: 'error.validation.metadata.name.max-length',
97+
},
9398
});
9499
this.namespace = new DynamicInputModel({
95100
id: 'namespace',
96101
label: namespace,
97102
name: 'namespace',
98103
validators: {
99104
required: null,
105+
maxLength: 256,
100106
},
101107
required: true,
108+
errorMessages: {
109+
maxLength: 'error.validation.metadata.namespace.max-length',
110+
},
102111
});
103112
this.formModel = [
104113
new DynamicFormGroupModel(
@@ -108,13 +117,18 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
108117
})
109118
];
110119
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
111-
this.registryService.getActiveMetadataSchema().subscribe((schema) => {
112-
this.formGroup.patchValue({
113-
metadatadataschemagroup:{
114-
name: schema != null ? schema.prefix : '',
115-
namespace: schema != null ? schema.namespace : ''
116-
}
117-
});
120+
this.registryService.getActiveMetadataSchema().subscribe((schema: MetadataSchema) => {
121+
if (schema == null) {
122+
this.clearFields();
123+
} else {
124+
this.formGroup.patchValue({
125+
metadatadataschemagroup: {
126+
name: schema.prefix,
127+
namespace: schema.namespace,
128+
},
129+
});
130+
this.name.disabled = true;
131+
}
118132
});
119133
});
120134
}
@@ -132,10 +146,10 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
132146
* When the schema has no id attached -> Create new schema
133147
* Emit the updated/created schema using the EventEmitter submitForm
134148
*/
135-
onSubmit() {
149+
onSubmit(): void {
136150
this.registryService.clearMetadataSchemaRequests().subscribe();
137151
this.registryService.getActiveMetadataSchema().pipe(take(1)).subscribe(
138-
(schema) => {
152+
(schema: MetadataSchema) => {
139153
const values = {
140154
prefix: this.name.value,
141155
namespace: this.namespace.value
@@ -147,9 +161,9 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
147161
} else {
148162
this.registryService.createOrUpdateMetadataSchema(Object.assign(new MetadataSchema(), schema, {
149163
id: schema.id,
150-
prefix: (values.prefix ? values.prefix : schema.prefix),
151-
namespace: (values.namespace ? values.namespace : schema.namespace)
152-
})).subscribe((updatedSchema) => {
164+
prefix: schema.prefix,
165+
namespace: values.namespace,
166+
})).subscribe((updatedSchema: MetadataSchema) => {
153167
this.submitForm.emit(updatedSchema);
154168
});
155169
}
@@ -162,13 +176,9 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
162176
/**
163177
* Reset all input-fields to be empty
164178
*/
165-
clearFields() {
166-
this.formGroup.patchValue({
167-
metadatadataschemagroup:{
168-
prefix: '',
169-
namespace: ''
170-
}
171-
});
179+
clearFields(): void {
180+
this.formGroup.reset('metadatadataschemagroup');
181+
this.name.disabled = false;
172182
}
173183

174184
/**

src/app/admin/admin-registries/metadata-schema/metadata-field-form/metadata-field-form.component.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ describe('MetadataFieldFormComponent', () => {
3939
createFormGroup: () => {
4040
return {
4141
patchValue: () => {
42-
}
42+
},
43+
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void {
44+
},
4345
};
4446
}
4547
};
4648
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
4749

4850
beforeEach(waitForAsync(() => {
49-
TestBed.configureTestingModule({
51+
return TestBed.configureTestingModule({
5052
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
5153
declarations: [MetadataFieldFormComponent, EnumKeysPipe],
5254
providers: [
@@ -98,11 +100,10 @@ describe('MetadataFieldFormComponent', () => {
98100
fixture.detectChanges();
99101
});
100102

101-
it('should emit a new field using the correct values', waitForAsync(() => {
102-
fixture.whenStable().then(() => {
103-
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
104-
});
105-
}));
103+
it('should emit a new field using the correct values', async () => {
104+
await fixture.whenStable();
105+
expect(component.submitForm.emit).toHaveBeenCalledWith(expected);
106+
});
106107
});
107108

108109
describe('with an active field', () => {
@@ -120,11 +121,10 @@ describe('MetadataFieldFormComponent', () => {
120121
fixture.detectChanges();
121122
});
122123

123-
it('should edit the existing field using the correct values', waitForAsync(() => {
124-
fixture.whenStable().then(() => {
125-
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
126-
});
127-
}));
124+
it('should edit the existing field using the correct values', async () => {
125+
await fixture.whenStable();
126+
expect(component.submitForm.emit).toHaveBeenCalledWith(expectedWithId);
127+
});
128128
});
129129
});
130130
});

0 commit comments

Comments
 (0)