forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathobject-audit-logs.component.ts
More file actions
176 lines (160 loc) · 5.17 KB
/
object-audit-logs.component.ts
File metadata and controls
176 lines (160 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import {
AsyncPipe,
Location,
} from '@angular/common';
import {
Component,
OnInit,
} from '@angular/core';
import {
ActivatedRoute,
Data,
Router,
RouterLink,
} from '@angular/router';
import { AuditDataService } from '@dspace/core/data/audit-data.service';
import { PaginationComponentOptions } from '@dspace/core/pagination/pagination-component-options.model';
import { getDSORoute } from '@dspace/core/router/utils/dso-route.utils';
import { TranslateModule } from '@ngx-translate/core';
import {
forkJoin,
Observable,
} from 'rxjs';
import {
filter,
map,
mergeMap,
switchMap,
tap,
} from 'rxjs/operators';
import { Audit } from '../../core/audit/model/audit.model';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { SortDirection } from '../../core/cache/models/sort-options.model';
import { CollectionDataService } from '../../core/data/collection-data.service';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
import { FindListOptions } from '../../core/data/find-list-options.model';
import { PaginatedList } from '../../core/data/paginated-list.model';
import { RemoteData } from '../../core/data/remote-data';
import { PaginationService } from '../../core/pagination/pagination.service';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import {
getFirstCompletedRemoteData,
getFirstSucceededRemoteDataPayload,
} from '../../core/shared/operators';
import { AuditTableComponent } from '../audit-table/audit-table.component';
/**
* Component displaying a list of all audit about a object in a paginated table
*/
@Component({
selector: 'ds-object-audit-logs',
templateUrl: './object-audit-logs.component.html',
imports: [
AsyncPipe,
AuditTableComponent,
RouterLink,
TranslateModule,
],
})
export class ObjectAuditLogsComponent implements OnInit {
/**
* The object extracted from the route.
*/
object: DSpaceObject;
/**
* List of all audits
*/
auditsRD$: Observable<RemoteData<PaginatedList<Audit>>>;
/**
* The current pagination configuration for the page used by the FindAll method
*/
config: FindListOptions = Object.assign(new FindListOptions(), {
elementsPerPage: 10,
sort: {
field: 'timeStamp',
direction: SortDirection.DESC,
},
});
/**
* The current pagination configuration for the page
*/
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'oop',
pageSize: 10,
});
/**
* Date format to use for start and end time of audits
*/
dateFormat = 'yyyy-MM-dd HH:mm:ss';
objectId$: Observable<string>;
objectId: string;
objectName: string;
objectRoute: string;
constructor(protected route: ActivatedRoute,
protected router: Router,
protected auditService: AuditDataService,
protected paginationService: PaginationService,
protected collectionDataService: CollectionDataService,
protected dsoNameService: DSONameService,
protected dSpaceObjectDataService: DSpaceObjectDataService,
protected location: Location,
) {}
ngOnInit(): void {
this.objectId$ = this.route.data.pipe(
switchMap((data: Data) => this.dSpaceObjectDataService.findById(data.dso.payload.id, true, true)),
getFirstSucceededRemoteDataPayload(),
tap((object) => {
this.objectRoute = getDSORoute(object);
this.objectId = object.id;
this.objectName = this.dsoNameService.getName(object);
this.setAudits();
}),
map(dso => dso.id),
);
}
/**
* Send a request to fetch all audits for the current page
*/
setAudits() {
const config$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config);
this.auditsRD$ = config$.pipe(
switchMap((config) =>
this.auditService.findByObject(this.objectId, config, false).pipe(
getFirstCompletedRemoteData(),
),
),
filter(data => data && data?.payload?.page?.length > 0),
map((audits) => {
audits.payload?.page.forEach((audit) => {
audit.hasDetails = this.auditService.auditHasDetails(audit);
});
return audits;
}),
mergeMap(auditsRD => {
const updatedAudits$ = auditsRD.payload.page.map(audit => {
return forkJoin({
epersonName: this.auditService.getEpersonName(audit),
otherAuditObject: this.auditService.getOtherObject(audit, this.objectId),
}).pipe(
map(({ epersonName, otherAuditObject }) =>
Object.assign(new Audit(), audit, { epersonName, otherAuditObject }),
),
);
});
return forkJoin(updatedAudits$).pipe(
map(updatedAudits => Object.assign(new RemoteData(
auditsRD.timeCompleted,
auditsRD.msToLive,
auditsRD.lastUpdated,
auditsRD.state,
auditsRD.errorMessage,
Object.assign(new PaginatedList(), { ...auditsRD.payload, page: updatedAudits }),
auditsRD.statusCode,
))),
);
}),
);
}
goBack(): void {
this.location.back();
}
}