mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
113904: Returning unkown when showing process of deleted user
This commit is contained in:
@@ -177,5 +177,36 @@ export class ProcessFormComponent implements OnInit {
|
|||||||
};
|
};
|
||||||
void this.router.navigate([getProcessListRoute()], extras);
|
void this.router.navigate([getProcessListRoute()], extras);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
updateScript($event: Script) {
|
||||||
|
this.selectedScript = $event;
|
||||||
|
this.parameters = undefined;
|
||||||
|
this.updateName();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateName(): void {
|
||||||
|
if (isEmpty(this.customName)) {
|
||||||
|
this.processName = this.generatedProcessName;
|
||||||
|
} else {
|
||||||
|
this.processName = this.customName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get generatedProcessName() {
|
||||||
|
const paramsString = this.parameters?.map((p: ProcessParameter) => {
|
||||||
|
const value = this.parseValue(p.value);
|
||||||
|
return isEmpty(value) ? p.name : `${p.name} ${value}`;
|
||||||
|
}).join(' ') || '';
|
||||||
|
return isEmpty(paramsString) ? this.selectedScript.name : `${this.selectedScript.name} ${paramsString}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseValue(value: any) {
|
||||||
|
if (typeof value === 'boolean') {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (value instanceof File) {
|
||||||
|
return value.name;
|
||||||
|
}
|
||||||
|
return value?.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -18,6 +18,16 @@ import { AuthService } from '../../../core/auth/auth.service';
|
|||||||
import { ProcessDataService } from '../../../core/data/processes/process-data.service';
|
import { ProcessDataService } from '../../../core/data/processes/process-data.service';
|
||||||
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';
|
||||||
|
import { ProcessBulkDeleteService } from '../process-bulk-delete.service';
|
||||||
|
import { ProcessStatus } from '../../processes/process-status.model';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||||
|
import { createPaginatedList } from '../../../shared/testing/utils.test';
|
||||||
|
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
|
||||||
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
import { NgbModal, NgbCollapse } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { VarDirective } from '../../../shared/utils/var.directive';
|
||||||
|
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { PaginationService } from '../../../core/pagination/pagination.service';
|
import { PaginationService } from '../../../core/pagination/pagination.service';
|
||||||
import { RouteService } from '../../../core/services/route.service';
|
import { RouteService } from '../../../core/services/route.service';
|
||||||
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
|
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
|
||||||
@@ -46,6 +56,7 @@ describe('ProcessOverviewTableComponent', () => {
|
|||||||
let modalService: NgbModal;
|
let modalService: NgbModal;
|
||||||
let authService; // : AuthService; Not typed as the mock does not fully implement AuthService
|
let authService; // : AuthService; Not typed as the mock does not fully implement AuthService
|
||||||
let routeService: RouteService;
|
let routeService: RouteService;
|
||||||
|
let translateService: TranslateService;
|
||||||
|
|
||||||
let processes: Process[];
|
let processes: Process[];
|
||||||
let ePerson: EPerson;
|
let ePerson: EPerson;
|
||||||
@@ -217,4 +228,50 @@ describe('ProcessOverviewTableComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
|
describe('getEPersonName', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
init();
|
||||||
|
translateService = getMockTranslateService();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the name when the ID is valid', () => {
|
||||||
|
const id = 'valid_id';
|
||||||
|
const expectedName = 'John Doe';
|
||||||
|
|
||||||
|
spyOn(dsoNameService, 'getName').and.returnValue(expectedName);
|
||||||
|
|
||||||
|
component.getEPersonName(id).subscribe(name => {
|
||||||
|
expect(name).toEqual(expectedName);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ePersonService.findById).toHaveBeenCalledWith(id);
|
||||||
|
});
|
||||||
|
|
||||||
|
fit('should return "Unknown" when the ID is invalid', () => {
|
||||||
|
const id = 'invalid_id';
|
||||||
|
const translationKey = 'unknown_user';
|
||||||
|
const expectedMessage = 'Unknown';
|
||||||
|
|
||||||
|
spyOn(translateService, 'get').and.returnValue(of(expectedMessage));
|
||||||
|
|
||||||
|
component.getEPersonName(id).subscribe(name => {
|
||||||
|
expect(name).toEqual(expectedMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ePersonService.findById).toHaveBeenCalledWith(id);
|
||||||
|
expect(translateService.get).toHaveBeenCalledWith(translationKey);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an empty observable when the ID is null', () => {
|
||||||
|
const id = null;
|
||||||
|
|
||||||
|
component.getEPersonName(id).subscribe(name => {
|
||||||
|
expect(name).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ePersonService.findById).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
*/
|
||||||
});
|
});
|
||||||
|
@@ -47,6 +47,7 @@ import { redirectOn4xx } from '../../../core/shared/authorized.operators';
|
|||||||
import {
|
import {
|
||||||
getAllCompletedRemoteData,
|
getAllCompletedRemoteData,
|
||||||
getFirstSucceededRemoteDataPayload,
|
getFirstSucceededRemoteDataPayload,
|
||||||
|
getAllCompletedRemoteData, getFirstCompletedRemoteData
|
||||||
} from '../../../core/shared/operators';
|
} from '../../../core/shared/operators';
|
||||||
import { hasValue } from '../../../shared/empty.util';
|
import { hasValue } from '../../../shared/empty.util';
|
||||||
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
|
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
|
||||||
@@ -60,6 +61,17 @@ import {
|
|||||||
ProcessOverviewService,
|
ProcessOverviewService,
|
||||||
ProcessSortField,
|
ProcessSortField,
|
||||||
} from '../process-overview.service';
|
} from '../process-overview.service';
|
||||||
|
import { map, switchMap, toArray, take, filter } from 'rxjs/operators';
|
||||||
|
import { EPerson } from '../../../core/eperson/models/eperson.model';
|
||||||
|
import { PaginationService } from 'src/app/core/pagination/pagination.service';
|
||||||
|
import { FindListOptions } from '../../../core/data/find-list-options.model';
|
||||||
|
import { redirectOn4xx } from '../../../core/shared/authorized.operators';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { AuthService } from '../../../core/auth/auth.service';
|
||||||
|
import { isPlatformBrowser } from '@angular/common';
|
||||||
|
import { RouteService } from '../../../core/services/route.service';
|
||||||
|
import { hasValue, isNotEmpty } from '../../../shared/empty.util';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
const NEW_PROCESS_PARAM = 'new_process_id';
|
const NEW_PROCESS_PARAM = 'new_process_id';
|
||||||
|
|
||||||
@@ -159,6 +171,7 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
|
|||||||
protected routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected auth: AuthService,
|
protected auth: AuthService,
|
||||||
|
private translateService: TranslateService,
|
||||||
@Inject(PLATFORM_ID) protected platformId: object,
|
@Inject(PLATFORM_ID) protected platformId: object,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
@@ -176,7 +189,7 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
|
|||||||
// Creates an ID from the first 2 characters of the process status.
|
// Creates an ID from the first 2 characters of the process status.
|
||||||
// Should two process status values ever start with the same substring,
|
// Should two process status values ever start with the same substring,
|
||||||
// increase the number of characters until the ids are distinct.
|
// increase the number of characters until the ids are distinct.
|
||||||
this.paginationId = this.processStatus.toLowerCase().substring(0,2);
|
this.paginationId = this.processStatus.toLowerCase().substring(0, 2);
|
||||||
|
|
||||||
const defaultPaginationOptions = Object.assign(new PaginationComponentOptions(), {
|
const defaultPaginationOptions = Object.assign(new PaginationComponentOptions(), {
|
||||||
id: this.paginationId,
|
id: this.paginationId,
|
||||||
@@ -243,7 +256,6 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
).subscribe((next: RemoteData<PaginatedList<ProcessOverviewTableEntry>>) => {
|
).subscribe((next: RemoteData<PaginatedList<ProcessOverviewTableEntry>>) => {
|
||||||
this.processesRD$.next(next);
|
this.processesRD$.next(next);
|
||||||
}));
|
}));
|
||||||
@@ -267,10 +279,20 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
|
|||||||
* @param id ID of the EPerson
|
* @param id ID of the EPerson
|
||||||
*/
|
*/
|
||||||
getEPersonName(id: string): Observable<string> {
|
getEPersonName(id: string): Observable<string> {
|
||||||
|
if (isNotEmpty(id)) {
|
||||||
return this.ePersonDataService.findById(id).pipe(
|
return this.ePersonDataService.findById(id).pipe(
|
||||||
getFirstSucceededRemoteDataPayload(),
|
getFirstCompletedRemoteData(),
|
||||||
map((eperson: EPerson) => this.dsoNameService.getName(eperson)),
|
switchMap((rd: RemoteData<EPerson>) => {
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
return observableFrom([this.dsoNameService.getName(rd.payload)]);
|
||||||
|
} else {
|
||||||
|
return this.translateService.get('process.overview.unknown.user');
|
||||||
|
}
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return this.translateService.get('process.overview.unknown.user');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -3846,6 +3846,8 @@
|
|||||||
|
|
||||||
"process.overview.delete.header": "Delete processes",
|
"process.overview.delete.header": "Delete processes",
|
||||||
|
|
||||||
|
"process.overview.unknown.user": "Unknown",
|
||||||
|
|
||||||
"process.bulk.delete.error.head": "Error on deleteing process",
|
"process.bulk.delete.error.head": "Error on deleteing process",
|
||||||
|
|
||||||
"process.bulk.delete.error.body": "The process with ID {{processId}} could not be deleted. The remaining processes will continue being deleted. ",
|
"process.bulk.delete.error.body": "The process with ID {{processId}} could not be deleted. The remaining processes will continue being deleted. ",
|
||||||
|
Reference in New Issue
Block a user