-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathrecent-item-list.component.ts
More file actions
165 lines (151 loc) · 5.38 KB
/
recent-item-list.component.ts
File metadata and controls
165 lines (151 loc) · 5.38 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
import {
AsyncPipe,
isPlatformBrowser,
NgClass,
} from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
ElementRef,
Inject,
OnDestroy,
OnInit,
PLATFORM_ID,
} from '@angular/core';
import {
APP_CONFIG,
AppConfig,
} from '@dspace/config/app-config.interface';
import {
SortDirection,
SortOptions,
} from '@dspace/core/cache/models/sort-options.model';
import { PaginatedList } from '@dspace/core/data/paginated-list.model';
import { RemoteData } from '@dspace/core/data/remote-data';
import { PaginationService } from '@dspace/core/pagination/pagination.service';
import { PaginationComponentOptions } from '@dspace/core/pagination/pagination-component-options.model';
import { DSpaceObjectType } from '@dspace/core/shared/dspace-object-type.model';
import {
followLink,
FollowLinkConfig,
} from '@dspace/core/shared/follow-link-config.model';
import { Item } from '@dspace/core/shared/item.model';
import { toDSpaceObjectListRD } from '@dspace/core/shared/operators';
import { PaginatedSearchOptions } from '@dspace/core/shared/search/models/paginated-search-options.model';
import { SearchFilter } from '@dspace/core/shared/search/models/search-filter.model';
import { ViewMode } from '@dspace/core/shared/view-mode.model';
import { setPlaceHolderAttributes } from '@dspace/shared/utils/object-list-utils';
import { TranslateModule } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { environment } from '../../../environments/environment';
import {
fadeIn,
fadeInOut,
} from '../../shared/animations/fade';
import { ErrorComponent } from '../../shared/error/error.component';
import { ThemedLoadingComponent } from '../../shared/loading/themed-loading.component';
import { ListableObjectComponentLoaderComponent } from '../../shared/object-collection/shared/listable-object/listable-object-component-loader.component';
import { SearchService } from '../../shared/search/search.service';
import { SearchConfigurationService } from '../../shared/search/search-configuration.service';
import { VarDirective } from '../../shared/utils/var.directive';
@Component({
selector: 'ds-recent-item-list',
templateUrl: './recent-item-list.component.html',
styleUrls: ['./recent-item-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [
fadeIn,
fadeInOut,
],
imports: [
AsyncPipe,
ErrorComponent,
ListableObjectComponentLoaderComponent,
NgClass,
ThemedLoadingComponent,
TranslateModule,
VarDirective,
],
})
export class RecentItemListComponent implements OnInit, OnDestroy {
itemRD$: Observable<RemoteData<PaginatedList<Item>>>;
paginationConfig: PaginationComponentOptions;
sortConfig: SortOptions;
/**
* The view-mode we're currently on
* @type {ViewMode}
*/
viewMode = ViewMode.ListElement;
private _placeholderFontClass: string;
constructor(
private searchService: SearchService,
private paginationService: PaginationService,
public searchConfigurationService: SearchConfigurationService,
protected elementRef: ElementRef,
@Inject(APP_CONFIG) private appConfig: AppConfig,
@Inject(PLATFORM_ID) private platformId: any,
) {
this.paginationConfig = Object.assign(new PaginationComponentOptions(), {
id: 'hp',
pageSize: environment.homePage.recentSubmissions.pageSize,
currentPage: 1,
maxSize: 1,
});
this.sortConfig = new SortOptions(environment.homePage.recentSubmissions.sortField, SortDirection.DESC);
}
ngOnInit(): void {
const linksToFollow: FollowLinkConfig<Item>[] = [];
if (this.appConfig.browseBy.showThumbnails) {
linksToFollow.push(followLink('thumbnail'));
}
if (this.appConfig.item.showAccessStatuses) {
linksToFollow.push(followLink('accessStatus'));
}
const entityTypes = this.appConfig.homePage.recentSubmissions.entityTypes;
const filters = entityTypes?.length ? [new SearchFilter('f.entityType', entityTypes, 'equals')] : [];
this.itemRD$ = this.searchService.search(
new PaginatedSearchOptions({
pagination: this.paginationConfig,
dsoTypes: [DSpaceObjectType.ITEM],
sort: this.sortConfig,
filters: filters,
}),
undefined,
undefined,
undefined,
...linksToFollow,
).pipe(
toDSpaceObjectListRD(),
) as Observable<RemoteData<PaginatedList<Item>>>;
}
ngOnDestroy(): void {
this.paginationService.clearPagination(this.paginationConfig.id);
}
onLoadMore(): void {
const entityTypes = this.appConfig.homePage.recentSubmissions.entityTypes;
const extraParams: Record<string, unknown> = {};
if (entityTypes?.length) {
extraParams['f.entityType'] = entityTypes.map(type => `${type},equals`);
}
this.paginationService.updateRouteWithUrl(
this.searchConfigurationService.paginationID,
['search'],
{
sortField: environment.homePage.recentSubmissions.sortField,
sortDirection: 'DESC' as SortDirection,
page: 1,
},
extraParams);
}
get placeholderFontClass(): string {
if (this._placeholderFontClass === undefined) {
if (isPlatformBrowser(this.platformId)) {
const width = this.elementRef.nativeElement.offsetWidth;
this._placeholderFontClass = setPlaceHolderAttributes(width);
} else {
this._placeholderFontClass = 'hide-placeholder-text';
}
}
return this._placeholderFontClass;
}
}