Skip to content

Commit a1b602e

Browse files
[DURACOM-317] refactor, fix other object reference
1 parent fe25c55 commit a1b602e

8 files changed

Lines changed: 78 additions & 59 deletions

File tree

src/app/app.menus.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export const MENUS = buildMenuStructure({
9494
MenuRoute.ITEM_PAGE,
9595
),
9696
AuditLogsMenuProvider.onRoute(
97+
MenuRoute.COMMUNITY_PAGE,
98+
MenuRoute.COLLECTION_PAGE,
9799
MenuRoute.ITEM_PAGE,
98100
),
99101
OrcidMenuProvider.onRoute(

src/app/audit-page/audit-table/audit-table.component.html

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,13 @@
6363
<td>{{ audit.subjectType }}</td>
6464
} @else {
6565
<td>
66-
@if (object && object.id === audit.objectUUID) {
67-
<span>
68-
@if (audit.otherAuditObject; as dso) {
69-
{{ dsoNameService.getName(dso) }} <em>({{ dso.type }})</em>
70-
} @else {
71-
{{ dataNotAvailable }}
72-
}
73-
</span>
74-
} @else {
75-
{{ dataNotAvailable }}
76-
}
66+
<span>
67+
@if (audit.otherAuditObject; as dso) {
68+
{{ dsoNameService.getName(dso) }} <em>({{ dso.type }})</em>
69+
} @else {
70+
{{ dataNotAvailable }}
71+
}
72+
</span>
7773
</td>
7874
}
7975
</tr>

src/app/audit-page/object-audit-overview/object-audit-overview.component.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
<h1 class="flex-grow-1">{{'audit.object.overview.title' | translate}}</h1>
44
</div>
55

6-
@if (objectId) {
7-
<h2 class="h4 mt-4 mb-4">{{ objectName }}</h2>
6+
@if (objectId$ | async) {
7+
<div class="h4 my-4">
8+
<a [routerLink]="objectRoute">{{ objectName }}</a>
9+
</div>
810
@if ((auditsRD$ | async)?.payload; as audits) {
911
<ds-audit-table
1012
[audits]="audits"
1113
[pageConfig]="pageConfig"
1214
[object]="object"
1315
></ds-audit-table>
1416
}
15-
<a class="btn btn-light mt-3" [routerLink]="['/items', objectId]"><i class="fas fa-arrow-left"></i>{{ 'audit.object.back' | translate }}</a>
17+
<button class="btn btn-light mt-3" (click)="goBack()">
18+
<i class="fas fa-arrow-left"></i>{{ 'audit.object.back' | translate }}
19+
</button>
1620
@if ((auditsRD$ | async)?.statusCode === 404) {
1721
<h2 class="h4 mt-4 mb-4">{{'audit.object.overview.disabled.message' | translate}}</h2>
1822
}

src/app/audit-page/object-audit-overview/object-audit-overview.component.spec.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Location } from '@angular/common';
12
import { NO_ERRORS_SCHEMA } from '@angular/core';
23
import {
34
ComponentFixture,
@@ -21,7 +22,7 @@ import { APP_DATA_SERVICES_MAP } from 'src/config/app-config.interface';
2122

2223
import { AuditDataService } from '../../core/audit/audit-data.service';
2324
import { Audit } from '../../core/audit/model/audit.model';
24-
import { ItemDataService } from '../../core/data/item-data.service';
25+
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
2526
import { PaginationService } from '../../core/pagination/pagination.service';
2627
import { MockActivatedRoute } from '../../shared/mocks/active-router.mock';
2728
import { RouterMock } from '../../shared/mocks/router.mock';
@@ -38,25 +39,32 @@ describe('ObjectAuditOverviewComponent', () => {
3839

3940
let auditService: AuditDataService;
4041
let audits: Audit[];
41-
let itemService: ItemDataService;
42+
let dSpaceObjectDataService: DSpaceObjectDataService;
4243
let collectionService;
4344
let activatedRoute;
44-
45+
let locationStub: Location;
46+
const mockItem = new Item();
47+
const mockItemId = '1234';
48+
mockItem.id = mockItemId;
4549

4650
function init() {
4751
audits = [ AuditMock ];
4852
auditService = jasmine.createSpyObj('auditService', {
4953
findByObject: createSuccessfulRemoteDataObject$(createPaginatedList(audits)),
5054
getEpersonName: of('Eperson Name'),
5155
auditHasDetails: false,
56+
getOtherObject: of(new Audit()),
5257
});
53-
itemService = jasmine.createSpyObj('ItemService', { findById: createSuccessfulRemoteDataObject$(new Item()) });
58+
dSpaceObjectDataService = jasmine.createSpyObj('DSpaceObjectDataService', { findById: createSuccessfulRemoteDataObject$(mockItem) });
5459
collectionService = jasmine.createSpyObj('CollectionDataService',
5560
{ findOwningCollectionFor: createSuccessfulRemoteDataObject$(createPaginatedList([{ id : 'collectionId' }])) },
5661
);
57-
activatedRoute = new MockActivatedRoute({ objectId: '1234' });
62+
activatedRoute = new MockActivatedRoute({ objectId: mockItemId });
5863
activatedRoute.paramMap = of({
59-
get: () => '1234',
64+
get: () => mockItemId,
65+
});
66+
locationStub = jasmine.createSpyObj('location', {
67+
back: jasmine.createSpy('back'),
6068
});
6169
}
6270

@@ -73,11 +81,12 @@ describe('ObjectAuditOverviewComponent', () => {
7381
providers: [
7482
{ provide: AuditDataService, useValue: auditService },
7583
{ provide: PaginationService, useValue: new PaginationServiceStub() },
76-
{ provide: ItemDataService, useValue: itemService },
84+
{ provide: DSpaceObjectDataService, useValue: dSpaceObjectDataService },
7785
{ provide: ActivatedRoute, useValue: activatedRoute },
7886
{ provide: Router, useValue: new RouterMock() },
7987
{ provide: CollectionDataService, useValue: collectionService },
8088
{ provide: APP_DATA_SERVICES_MAP, useValue: new Map() },
89+
{ provide: Location, useValue: locationStub },
8190
provideMockStore({}),
8291
],
8392
schemas: [NO_ERRORS_SCHEMA],
@@ -104,8 +113,12 @@ describe('ObjectAuditOverviewComponent', () => {
104113
expect(component.setAudits).toHaveBeenCalled();
105114
}));
106115

107-
it('should set owning collection', () => {
108-
expect(component.owningCollection$).toBeTruthy();
116+
it('should set object id', (done) => {
117+
component.objectId$.subscribe((id) => {
118+
expect(id).toEqual(mockItemId);
119+
expect(component.objectId).toEqual(id);
120+
done();
121+
});
109122
});
110123
});
111124
});

src/app/audit-page/object-audit-overview/object-audit-overview.component.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { AsyncPipe } from '@angular/common';
1+
import {
2+
AsyncPipe,
3+
Location,
4+
} from '@angular/common';
25
import {
36
Component,
4-
OnDestroy,
57
OnInit,
68
} from '@angular/core';
79
import {
@@ -12,38 +14,38 @@ import {
1214
} from '@angular/router';
1315
import { TranslateModule } from '@ngx-translate/core';
1416
import {
15-
combineLatest,
1617
forkJoin,
1718
Observable,
18-
Subscription,
1919
} from 'rxjs';
2020
import {
2121
filter,
2222
map,
2323
mergeMap,
24-
switchMap, tap,
24+
switchMap,
25+
tap,
2526
} from 'rxjs/operators';
2627

27-
import { COLLECTION_PAGE_LINKS_TO_FOLLOW } from '../../collection-page/collection-page.resolver';
28+
import { getDSORoute } from '../../app-routing-paths';
2829
import {
2930
AUDIT_PERSON_NOT_AVAILABLE,
3031
AuditDataService,
3132
} from '../../core/audit/audit-data.service';
3233
import { Audit } from '../../core/audit/model/audit.model';
34+
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
3335
import { SortDirection } from '../../core/cache/models/sort-options.model';
3436
import { CollectionDataService } from '../../core/data/collection-data.service';
37+
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
3538
import { FindListOptions } from '../../core/data/find-list-options.model';
36-
import { ItemDataService } from '../../core/data/item-data.service';
3739
import { PaginatedList } from '../../core/data/paginated-list.model';
3840
import { RemoteData } from '../../core/data/remote-data';
3941
import { PaginationService } from '../../core/pagination/pagination.service';
40-
import { Collection } from '../../core/shared/collection.model';
41-
import { Item } from '../../core/shared/item.model';
42-
import {getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload} from '../../core/shared/operators';
42+
import { DSpaceObject } from '../../core/shared/dspace-object.model';
43+
import {
44+
getFirstCompletedRemoteData,
45+
getFirstSucceededRemoteDataPayload,
46+
} from '../../core/shared/operators';
4347
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
4448
import { AuditTableComponent } from '../audit-table/audit-table.component';
45-
import {DSONameService} from '../../core/breadcrumbs/dso-name.service';
46-
import {DSpaceObjectDataService} from '../../core/data/dspace-object-data.service';
4749
/**
4850
* Component displaying a list of all audit about a object in a paginated table
4951
*/
@@ -58,12 +60,12 @@ import {DSpaceObjectDataService} from '../../core/data/dspace-object-data.servic
5860
],
5961
standalone: true,
6062
})
61-
export class ObjectAuditOverviewComponent implements OnInit, OnDestroy {
63+
export class ObjectAuditOverviewComponent implements OnInit {
6264

6365
/**
6466
* The object extracted from the route.
6567
*/
66-
object: Item;
68+
object: DSpaceObject;
6769

6870
/**
6971
* List of all audits
@@ -94,40 +96,39 @@ export class ObjectAuditOverviewComponent implements OnInit, OnDestroy {
9496
*/
9597
dateFormat = 'yyyy-MM-dd HH:mm:ss';
9698

99+
objectId$: Observable<string>;
100+
97101
objectId: string;
98102

99103
objectName: string;
100104

101-
dataNotAvailable = AUDIT_PERSON_NOT_AVAILABLE;
105+
objectRoute: string;
102106

103-
sub: Subscription;
107+
dataNotAvailable = AUDIT_PERSON_NOT_AVAILABLE;
104108

105109
constructor(protected route: ActivatedRoute,
106110
protected router: Router,
107111
protected auditService: AuditDataService,
108-
protected itemService: ItemDataService,
109112
protected paginationService: PaginationService,
110113
protected collectionDataService: CollectionDataService,
111114
protected dsoNameService: DSONameService,
112115
protected dSpaceObjectDataService: DSpaceObjectDataService,
116+
protected location: Location,
113117
) {}
114118

115119
ngOnInit(): void {
116-
this.sub = this.route.paramMap.pipe(
120+
this.objectId$ = this.route.paramMap.pipe(
117121
map((paramMap: ParamMap) => paramMap.get('objectId')),
118122
switchMap((id: string) => this.dSpaceObjectDataService.findById(id, true, true)),
119123
getFirstSucceededRemoteDataPayload(),
120-
).subscribe((dso) => {
121-
this.objectId = dso.id;
122-
this.objectName = this.dsoNameService.getName(dso);
123-
this.setAudits();
124-
});
125-
}
126-
127-
ngOnDestroy(): void {
128-
if (this.sub) {
129-
this.sub.unsubscribe();
130-
}
124+
tap((object) => {
125+
this.objectRoute = getDSORoute(object);
126+
this.objectId = object.id;
127+
this.objectName = this.dsoNameService.getName(object);
128+
this.setAudits();
129+
}),
130+
map(dso => dso.id),
131+
);
131132
}
132133

133134
/**
@@ -138,7 +139,7 @@ export class ObjectAuditOverviewComponent implements OnInit, OnDestroy {
138139

139140
this.auditsRD$ = config$.pipe(
140141
switchMap((config) =>
141-
this.auditService.findByObject(this.objectId, config).pipe(
142+
this.auditService.findByObject(this.objectId, config, false).pipe(
142143
getFirstCompletedRemoteData(),
143144
),
144145
),
@@ -175,4 +176,8 @@ export class ObjectAuditOverviewComponent implements OnInit, OnDestroy {
175176
}),
176177
);
177178
}
179+
180+
goBack(): void {
181+
this.location.back();
182+
}
178183
}

src/app/audit-page/overview/audit-overview.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class AuditOverviewComponent implements OnInit {
8989
setAudits() {
9090
this.auditsRD$ = this.paginationService.getFindListOptions(this.pageId, this.config).pipe(
9191
switchMap((config) => {
92-
return this.auditService.findAll(config, true, true, followLink('eperson'));
92+
return this.auditService.findAll(config, false, true, followLink('eperson'));
9393
}),
9494
filter(data => data && data?.payload?.page?.length > 0),
9595
map((audits) => {

src/app/core/audit/audit-data.service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,17 @@ export class AuditDataService extends IdentifiableDataService<Audit>{
6262
*
6363
* @param objectId The objectId id
6464
* @param options The [[FindListOptions]] object
65-
* @param collUuid The Uuid of the collection
66-
* @param commUuid The Uuid of the community
65+
* @param useCachedVersionIfAvailable
6766
* @return Observable<RemoteData<PaginatedList<Audit>>>
6867
*/
69-
findByObject(objectId: string, options: FindListOptions = {}): Observable<RemoteData<PaginatedList<Audit>>> {
68+
findByObject(objectId: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true): Observable<RemoteData<PaginatedList<Audit>>> {
7069
const searchMethod = AUDIT_FIND_BY_OBJECT_SEARCH_METHOD;
7170
const searchParams = [new RequestParam('object', objectId)];
7271

7372
const optionsWithObject = Object.assign(new FindListOptions(), options, {
7473
searchParams,
7574
});
76-
return this.searchData.searchBy(searchMethod, optionsWithObject, true, true, followLink('eperson'));
75+
return this.searchData.searchBy(searchMethod, optionsWithObject, useCachedVersionIfAvailable, true, followLink('eperson'));
7776
}
7877

7978
/**

src/assets/i18n/en.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@
957957

958958
"audit.overview.breadcrumbs": "Audit Logs Overview",
959959

960-
"audit.object.back": "Back to Item",
960+
"audit.object.back": "Back",
961961

962962
"audit.object.breadcrumbs": "Subject Audit Logs",
963963

0 commit comments

Comments
 (0)