[Manage epeeople page] EPerson search scope change & minor improvements/name changes

This commit is contained in:
Marie Verdonck
2020-03-05 10:23:53 +01:00
parent 4f4c2d25ed
commit a0b9ddcab7
6 changed files with 48 additions and 75 deletions

View File

@@ -13,7 +13,7 @@ import { type } from '../../../shared/ngrx/type';
export const EPeopleRegistryActionTypes = { export const EPeopleRegistryActionTypes = {
EDIT_EPERSON: type('dspace/epeople-registry/EDIT_EPERSON'), EDIT_EPERSON: type('dspace/epeople-registry/EDIT_EPERSON'),
CANCEL_EDIT_EPERSON: type('dspace/epeople-registry/CANCEL_SCHEMA'), CANCEL_EDIT_EPERSON: type('dspace/epeople-registry/CANCEL_EDIT_EPERSON'),
}; };
/* tslint:disable:max-classes-per-file */ /* tslint:disable:max-classes-per-file */
@@ -25,8 +25,8 @@ export class EPeopleRegistryEditEPersonAction implements Action {
eperson: EPerson; eperson: EPerson;
constructor(registry: EPerson) { constructor(eperson: EPerson) {
this.eperson = registry; this.eperson = eperson;
} }
} }

View File

@@ -19,9 +19,8 @@
<form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)" class="row"> <form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)" class="row">
<div class="col-12 col-sm-3"> <div class="col-12 col-sm-3">
<select name="scope" id="scope" formControlName="scope" class="form-control" aria-label="Search scope"> <select name="scope" id="scope" formControlName="scope" class="form-control" aria-label="Search scope">
<option value="name">{{labelPrefix + 'search.scope.name' | translate}}</option>
<option value="email">{{labelPrefix + 'search.scope.email' | translate}}</option>
<option value="metadata">{{labelPrefix + 'search.scope.metadata' | translate}}</option> <option value="metadata">{{labelPrefix + 'search.scope.metadata' | translate}}</option>
<option value="email">{{labelPrefix + 'search.scope.email' | translate}}</option>
</select> </select>
</div> </div>
<div class="col-sm-9 col-12"> <div class="col-sm-9 col-12">

View File

@@ -55,7 +55,7 @@ export class EPeopleRegistryComponent {
}); });
this.isEPersonFormShown = false; this.isEPersonFormShown = false;
this.searchForm = this.formBuilder.group(({ this.searchForm = this.formBuilder.group(({
scope: 'name', scope: 'metadata',
query: '', query: '',
})); }));
} }
@@ -85,42 +85,18 @@ export class EPeopleRegistryComponent {
public forceUpdateEPeople() { public forceUpdateEPeople() {
this.epersonService.clearEPersonRequests(); this.epersonService.clearEPersonRequests();
this.isEPersonFormShown = false; 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 * @param data Contains scope and query param
*/ */
search(data: any) { search(data: any) {
const query = data.query; this.ePeople = this.epersonService.searchByScope(data.scope, data.query, {
const scope = data.scope; currentPage: 1,
switch (scope) { elementsPerPage: this.config.pageSize
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;
}
} }
/** /**
@@ -141,11 +117,11 @@ export class EPeopleRegistryComponent {
} }
/** /**
* Start editing the selected metadata schema * Start editing the selected EPerson
* @param schema * @param ePerson
*/ */
editEPerson(ePerson: EPerson) { editEPerson(ePerson: EPerson) {
this.getActiveEPerson().pipe(take(1)).subscribe((activeEPerson) => { this.getActiveEPerson().pipe(take(1)).subscribe((activeEPerson: EPerson) => {
if (ePerson === activeEPerson) { if (ePerson === activeEPerson) {
this.epersonService.cancelEditEPerson(); this.epersonService.cancelEditEPerson();
this.isEPersonFormShown = false; 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) { deleteEPerson(ePerson: EPerson) {
if (hasValue(ePerson.id)) { 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.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: ePerson.name }));
this.forceUpdateEPeople(); this.forceUpdateEPeople();
} else { } 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.epersonService.cancelEditEPerson();
this.isEPersonFormShown = false; this.isEPersonFormShown = false;

View File

@@ -6,7 +6,7 @@ import {
} from './epeople-registry.actions'; } from './epeople-registry.actions';
/** /**
* The metadata registry state. * The EPeople registry state.
* @interface EPeopleRegistryState * @interface EPeopleRegistryState
*/ */
export interface EPeopleRegistryState { export interface EPeopleRegistryState {

View File

@@ -8,6 +8,7 @@ import {
} from '@ng-dynamic-forms/core'; } from '@ng-dynamic-forms/core';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { combineLatest } from 'rxjs/internal/observable/combineLatest'; import { combineLatest } from 'rxjs/internal/observable/combineLatest';
import { Subscription } from 'rxjs/internal/Subscription';
import { take } from 'rxjs/operators'; import { take } from 'rxjs/operators';
import { EPersonDataService } from '../../../../core/eperson/eperson-data.service'; import { EPersonDataService } from '../../../../core/eperson/eperson-data.service';
import { EPerson } from '../../../../core/eperson/models/eperson.model'; import { EPerson } from '../../../../core/eperson/models/eperson.model';
@@ -98,6 +99,11 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
*/ */
@Output() cancelForm: EventEmitter<any> = new EventEmitter(); @Output() cancelForm: EventEmitter<any> = new EventEmitter();
/**
* List of subscriptions
*/
subs: Subscription[] = [];
constructor(public epersonService: EPersonDataService, constructor(public epersonService: EPersonDataService,
private formBuilderService: FormBuilderService, private formBuilderService: FormBuilderService,
private translateService: TranslateService, private translateService: TranslateService,
@@ -162,7 +168,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
this.requireCertificate, this.requireCertificate,
]; ];
this.formGroup = this.formBuilderService.createFormGroup(this.formModel); 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({ this.formGroup.patchValue({
firstName: eperson != null ? eperson.firstMetadataValue('eperson.firstname') : '', firstName: eperson != null ? eperson.firstMetadataValue('eperson.firstname') : '',
lastName: eperson != null ? eperson.firstMetadataValue('eperson.lastname') : '', lastName: eperson != null ? eperson.firstMetadataValue('eperson.lastname') : '',
@@ -171,7 +177,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
requireCertificate: eperson != null ? eperson.requireCertificate : false, requireCertificate: eperson != null ? eperson.requireCertificate : false,
selfRegistered: false, selfRegistered: false,
}); });
}); }));
}); });
} }
@@ -225,14 +231,14 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
* @param values * @param values
*/ */
createNewEPerson(values) { createNewEPerson(values) {
this.epersonService.createOrUpdateEPerson(Object.assign(new EPerson(), values)) this.subs.push(this.epersonService.create(Object.assign(new EPerson(), values), null)
.pipe( .pipe(
getSucceededRemoteData(), getSucceededRemoteData(),
getRemoteDataPayload()) getRemoteDataPayload())
.subscribe((newEPerson: EPerson) => { .subscribe((newEPerson: EPerson) => {
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.created.success', { name: newEPerson.name })); this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.created.success', { name: newEPerson.name }));
this.submitForm.emit(newEPerson); this.submitForm.emit(newEPerson);
}); }));
} }
/** /**
@@ -241,7 +247,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
* @param values * @param values
*/ */
editEPerson(ePerson: EPerson, values) { editEPerson(ePerson: EPerson, values) {
this.epersonService.createOrUpdateEPerson(Object.assign(new EPerson(), { this.epersonService.updateEPerson(Object.assign(new EPerson(), {
id: ePerson.id, id: ePerson.id,
metadata: { metadata: {
'eperson.firstname': [ '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 { ngOnDestroy(): void {
this.onCancel(); this.onCancel();
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
} }
} }

View File

@@ -39,7 +39,6 @@ const editEPersonSelector = createSelector(ePeopleRegistryStateSelector, (ePeopl
export class EPersonDataService extends DataService<EPerson> { export class EPersonDataService extends DataService<EPerson> {
protected linkPath = 'epersons'; protected linkPath = 'epersons';
protected searchByNamePath = 'byName';
protected searchByEmailPath = 'byEmail'; protected searchByEmailPath = 'byEmail';
protected searchByMetadataPath = 'byMetadata'; protected searchByMetadataPath = 'byMetadata';
@@ -58,7 +57,7 @@ export class EPersonDataService extends DataService<EPerson> {
/** /**
* Retrieves all EPeople * 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<RemoteData<PaginatedList<EPerson>>> { public getEPeople(options: FindListOptions = {}): Observable<RemoteData<PaginatedList<EPerson>>> {
const hrefObs = this.getFindAllHref(options, this.linkPath); const hrefObs = this.getFindAllHref(options, this.linkPath);
@@ -74,14 +73,20 @@ export class EPersonDataService extends DataService<EPerson> {
} }
/** /**
* Returns a search result list of EPeople, by name query (/eperson/epersons/search/{@link searchByNamePath}?q=<>) * Search the EPeople with a given scope and query
* @param query name query * @param scope Scope of the EPeople search, default byMetadata
* @param options * @param query Query of search
* @param linksToFollow * @param options Options of search request
*/ */
public getEpeopleByName(query: string, options?: FindListOptions, ...linksToFollow: Array<FollowLinkConfig<EPerson>>): Observable<RemoteData<PaginatedList<EPerson>>> { public searchByScope(scope: string, query: string, options: FindListOptions = {}) {
const searchParams = [new SearchParam('q', query)]; switch (scope) {
return this.getEPeopleBy(searchParams, this.searchByNamePath, options, ...linksToFollow); 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<EPerson> {
return this.searchBy(searchMethod, findListOptions, ...linksToFollow); 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<RemoteData<EPerson>> {
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 * 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 * The patch is derived from the differences between the given object and its version in the object cache
* @param {DSpaceObject} ePerson The given object * @param {DSpaceObject} ePerson The given object
*/ */
updateEPerson(ePerson: EPerson): Observable<RemoteData<EPerson>> { public updateEPerson(ePerson: EPerson): Observable<RemoteData<EPerson>> {
const oldVersion$ = this.findByHref(ePerson._links.self.href); const oldVersion$ = this.findByHref(ePerson._links.self.href);
return oldVersion$.pipe( return oldVersion$.pipe(
getSucceededRemoteData(), getSucceededRemoteData(),
@@ -165,7 +156,7 @@ export class EPersonDataService extends DataService<EPerson> {
* @param oldEPerson * @param oldEPerson
* @param newEPerson * @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'); let operations = this.comparator.diff(oldEPerson, newEPerson).filter((operation: Operation) => operation.op === 'replace');
if (hasValue(oldEPerson.email) && oldEPerson.email !== newEPerson.email) { if (hasValue(oldEPerson.email) && oldEPerson.email !== newEPerson.email) {
operations = [...operations, { operations = [...operations, {
@@ -223,10 +214,10 @@ export class EPersonDataService extends DataService<EPerson> {
/** /**
* Method to delete an EPerson * Method to delete an EPerson
* @param id The EPerson to delete * @param ePerson The EPerson to delete
*/ */
public deleteEPerson(ePerson: EPerson): Observable<boolean> { public deleteEPerson(ePerson: EPerson): Observable<boolean> {
return this.delete(ePerson); return this.delete(ePerson.id);
} }
} }