mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[Manage epeeople page] EPerson search scope change & minor improvements/name changes
This commit is contained in:
@@ -13,7 +13,7 @@ import { type } from '../../../shared/ngrx/type';
|
||||
export const EPeopleRegistryActionTypes = {
|
||||
|
||||
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 */
|
||||
@@ -25,8 +25,8 @@ export class EPeopleRegistryEditEPersonAction implements Action {
|
||||
|
||||
eperson: EPerson;
|
||||
|
||||
constructor(registry: EPerson) {
|
||||
this.eperson = registry;
|
||||
constructor(eperson: EPerson) {
|
||||
this.eperson = eperson;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,9 +19,8 @@
|
||||
<form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)" class="row">
|
||||
<div class="col-12 col-sm-3">
|
||||
<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="email">{{labelPrefix + 'search.scope.email' | translate}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-9 col-12">
|
||||
|
@@ -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, {
|
||||
this.ePeople = this.epersonService.searchByScope(data.scope, data.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
|
||||
* @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;
|
||||
|
@@ -6,7 +6,7 @@ import {
|
||||
} from './epeople-registry.actions';
|
||||
|
||||
/**
|
||||
* The metadata registry state.
|
||||
* The EPeople registry state.
|
||||
* @interface EPeopleRegistryState
|
||||
*/
|
||||
export interface EPeopleRegistryState {
|
||||
|
@@ -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<any> = 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());
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,6 @@ const editEPersonSelector = createSelector(ePeopleRegistryStateSelector, (ePeopl
|
||||
export class EPersonDataService extends DataService<EPerson> {
|
||||
|
||||
protected linkPath = 'epersons';
|
||||
protected searchByNamePath = 'byName';
|
||||
protected searchByEmailPath = 'byEmail';
|
||||
protected searchByMetadataPath = 'byMetadata';
|
||||
|
||||
@@ -58,7 +57,7 @@ export class EPersonDataService extends DataService<EPerson> {
|
||||
|
||||
/**
|
||||
* 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>>> {
|
||||
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=<>)
|
||||
* @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<FollowLinkConfig<EPerson>>): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||
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<EPerson> {
|
||||
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
|
||||
* 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<RemoteData<EPerson>> {
|
||||
public updateEPerson(ePerson: EPerson): Observable<RemoteData<EPerson>> {
|
||||
const oldVersion$ = this.findByHref(ePerson._links.self.href);
|
||||
return oldVersion$.pipe(
|
||||
getSucceededRemoteData(),
|
||||
@@ -165,7 +156,7 @@ export class EPersonDataService extends DataService<EPerson> {
|
||||
* @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<EPerson> {
|
||||
|
||||
/**
|
||||
* Method to delete an EPerson
|
||||
* @param id The EPerson to delete
|
||||
* @param ePerson The EPerson to delete
|
||||
*/
|
||||
public deleteEPerson(ePerson: EPerson): Observable<boolean> {
|
||||
return this.delete(ePerson);
|
||||
return this.delete(ePerson.id);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user