diff --git a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts
index 6e0bd48af0..099d9a5b4c 100644
--- a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts
+++ b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts
@@ -55,7 +55,7 @@ export class EPeopleRegistryComponent {
});
this.isEPersonFormShown = false;
this.searchForm = this.formBuilder.group(({
- scope: 'name',
+ scope: 'metadata',
query: '',
}));
}
@@ -85,42 +85,18 @@ export class EPeopleRegistryComponent {
public forceUpdateEPeople() {
this.epersonService.clearEPersonRequests();
this.isEPersonFormShown = false;
- this.search({ query: '', scope: 'name' })
+ this.search({ query: '', scope: 'metadata' })
}
/**
- * Search in the EPeople by name, email or metadata
+ * Search in the EPeople by metadata (default) or email
* @param data Contains scope and query param
*/
search(data: any) {
- const query = data.query;
- const scope = data.scope;
- switch (scope) {
- case 'name':
- this.ePeople = this.epersonService.getEpeopleByName(query, {
- currentPage: 1,
- elementsPerPage: this.config.pageSize
- });
- break;
- case 'email':
- this.ePeople = this.epersonService.getEpeopleByEmail(query, {
- currentPage: 1,
- elementsPerPage: this.config.pageSize
- });
- break;
- case 'metadata':
- this.ePeople = this.epersonService.getEpeopleByMetadata(query, {
- currentPage: 1,
- elementsPerPage: this.config.pageSize
- });
- break;
- default:
- this.ePeople = this.epersonService.getEpeopleByEmail(query, {
- currentPage: 1,
- elementsPerPage: this.config.pageSize
- });
- break;
- }
+ this.ePeople = this.epersonService.searchByScope(data.scope, data.query, {
+ currentPage: 1,
+ elementsPerPage: this.config.pageSize
+ });
}
/**
@@ -141,11 +117,11 @@ export class EPeopleRegistryComponent {
}
/**
- * Start editing the selected metadata schema
- * @param schema
+ * Start editing the selected EPerson
+ * @param ePerson
*/
editEPerson(ePerson: EPerson) {
- this.getActiveEPerson().pipe(take(1)).subscribe((activeEPerson) => {
+ this.getActiveEPerson().pipe(take(1)).subscribe((activeEPerson: EPerson) => {
if (ePerson === activeEPerson) {
this.epersonService.cancelEditEPerson();
this.isEPersonFormShown = false;
@@ -158,7 +134,7 @@ export class EPeopleRegistryComponent {
}
/**
- * Delete EPerson
+ * Deletes EPerson, show notification on success/failure & updates EPeople list
*/
deleteEPerson(ePerson: EPerson) {
if (hasValue(ePerson.id)) {
@@ -167,7 +143,7 @@ export class EPeopleRegistryComponent {
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: ePerson.name }));
this.forceUpdateEPeople();
} else {
- this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.failure', { name: ePerson.name }));
+ this.notificationsService.error(this.translateService.get(this.labelPrefix + 'notification.deleted.failure', { name: ePerson.name }));
}
this.epersonService.cancelEditEPerson();
this.isEPersonFormShown = false;
diff --git a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.reducers.ts b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.reducers.ts
index 55fea8f862..3f90bc5207 100644
--- a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.reducers.ts
+++ b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.reducers.ts
@@ -6,7 +6,7 @@ import {
} from './epeople-registry.actions';
/**
- * The metadata registry state.
+ * The EPeople registry state.
* @interface EPeopleRegistryState
*/
export interface EPeopleRegistryState {
diff --git a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts
index 230466f0f8..915c4ba67a 100644
--- a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts
+++ b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts
@@ -8,6 +8,7 @@ import {
} from '@ng-dynamic-forms/core';
import { TranslateService } from '@ngx-translate/core';
import { combineLatest } from 'rxjs/internal/observable/combineLatest';
+import { Subscription } from 'rxjs/internal/Subscription';
import { take } from 'rxjs/operators';
import { EPersonDataService } from '../../../../core/eperson/eperson-data.service';
import { EPerson } from '../../../../core/eperson/models/eperson.model';
@@ -98,6 +99,11 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
*/
@Output() cancelForm: EventEmitter
= new EventEmitter();
+ /**
+ * List of subscriptions
+ */
+ subs: Subscription[] = [];
+
constructor(public epersonService: EPersonDataService,
private formBuilderService: FormBuilderService,
private translateService: TranslateService,
@@ -162,7 +168,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
this.requireCertificate,
];
this.formGroup = this.formBuilderService.createFormGroup(this.formModel);
- this.epersonService.getActiveEPerson().subscribe((eperson: EPerson) => {
+ this.subs.push(this.epersonService.getActiveEPerson().subscribe((eperson: EPerson) => {
this.formGroup.patchValue({
firstName: eperson != null ? eperson.firstMetadataValue('eperson.firstname') : '',
lastName: eperson != null ? eperson.firstMetadataValue('eperson.lastname') : '',
@@ -171,7 +177,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
requireCertificate: eperson != null ? eperson.requireCertificate : false,
selfRegistered: false,
});
- });
+ }));
});
}
@@ -225,14 +231,14 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
* @param values
*/
createNewEPerson(values) {
- this.epersonService.createOrUpdateEPerson(Object.assign(new EPerson(), values))
+ this.subs.push(this.epersonService.create(Object.assign(new EPerson(), values), null)
.pipe(
getSucceededRemoteData(),
getRemoteDataPayload())
.subscribe((newEPerson: EPerson) => {
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.created.success', { name: newEPerson.name }));
this.submitForm.emit(newEPerson);
- });
+ }));
}
/**
@@ -241,7 +247,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
* @param values
*/
editEPerson(ePerson: EPerson, values) {
- this.epersonService.createOrUpdateEPerson(Object.assign(new EPerson(), {
+ this.epersonService.updateEPerson(Object.assign(new EPerson(), {
id: ePerson.id,
metadata: {
'eperson.firstname': [
@@ -283,9 +289,10 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
}
/**
- * Cancel the current edit when component is destroyed
+ * Cancel the current edit when component is destroyed & unsub all subscriptions
*/
ngOnDestroy(): void {
this.onCancel();
+ this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
}
}
diff --git a/src/app/core/eperson/eperson-data.service.ts b/src/app/core/eperson/eperson-data.service.ts
index 5262f800d1..79c7ba6e19 100644
--- a/src/app/core/eperson/eperson-data.service.ts
+++ b/src/app/core/eperson/eperson-data.service.ts
@@ -39,7 +39,6 @@ const editEPersonSelector = createSelector(ePeopleRegistryStateSelector, (ePeopl
export class EPersonDataService extends DataService {
protected linkPath = 'epersons';
- protected searchByNamePath = 'byName';
protected searchByEmailPath = 'byEmail';
protected searchByMetadataPath = 'byMetadata';
@@ -58,7 +57,7 @@ export class EPersonDataService extends DataService {
/**
* Retrieves all EPeople
- * @param pagination The pagination info used to retrieve the EPeople
+ * @param options The options info used to retrieve the EPeople
*/
public getEPeople(options: FindListOptions = {}): Observable>> {
const hrefObs = this.getFindAllHref(options, this.linkPath);
@@ -74,14 +73,20 @@ export class EPersonDataService extends DataService {
}
/**
- * Returns a search result list of EPeople, by name query (/eperson/epersons/search/{@link searchByNamePath}?q=<>)
- * @param query name query
- * @param options
- * @param linksToFollow
+ * Search the EPeople with a given scope and query
+ * @param scope Scope of the EPeople search, default byMetadata
+ * @param query Query of search
+ * @param options Options of search request
*/
- public getEpeopleByName(query: string, options?: FindListOptions, ...linksToFollow: Array>): Observable>> {
- const searchParams = [new SearchParam('q', query)];
- return this.getEPeopleBy(searchParams, this.searchByNamePath, options, ...linksToFollow);
+ public searchByScope(scope: string, query: string, options: FindListOptions = {}) {
+ switch (scope) {
+ case 'metadata':
+ return this.getEpeopleByMetadata(query.trim(), options);
+ case 'email':
+ return this.getEpeopleByEmail(query.trim(), options);
+ default:
+ return this.getEpeopleByMetadata(query.trim(), options);
+ }
}
/**
@@ -126,26 +131,12 @@ export class EPersonDataService extends DataService {
return this.searchBy(searchMethod, findListOptions, ...linksToFollow);
}
- /**
- * Create or Update an EPerson
- * If the EPerson contains an id, it is assumed the eperson already exists and is updated instead
- * @param ePerson The EPerson to create or update
- */
- public createOrUpdateEPerson(ePerson: EPerson): Observable> {
- const isUpdate = hasValue(ePerson.id);
- if (isUpdate) {
- return this.updateEPerson(ePerson);
- } else {
- return this.create(ePerson, null);
- }
- }
-
/**
* Add a new patch to the object cache
* The patch is derived from the differences between the given object and its version in the object cache
* @param {DSpaceObject} ePerson The given object
*/
- updateEPerson(ePerson: EPerson): Observable> {
+ public updateEPerson(ePerson: EPerson): Observable> {
const oldVersion$ = this.findByHref(ePerson._links.self.href);
return oldVersion$.pipe(
getSucceededRemoteData(),
@@ -165,7 +156,7 @@ export class EPersonDataService extends DataService {
* @param oldEPerson
* @param newEPerson
*/
- generateOperations(oldEPerson: EPerson, newEPerson: EPerson): Operation[] {
+ private generateOperations(oldEPerson: EPerson, newEPerson: EPerson): Operation[] {
let operations = this.comparator.diff(oldEPerson, newEPerson).filter((operation: Operation) => operation.op === 'replace');
if (hasValue(oldEPerson.email) && oldEPerson.email !== newEPerson.email) {
operations = [...operations, {
@@ -223,10 +214,10 @@ export class EPersonDataService extends DataService {
/**
* Method to delete an EPerson
- * @param id The EPerson to delete
+ * @param ePerson The EPerson to delete
*/
public deleteEPerson(ePerson: EPerson): Observable {
- return this.delete(ePerson);
+ return this.delete(ePerson.id);
}
}