Commits

Alexandre Vryghem authored 2fb393db7f8
Removed the AbstractBrowseByTypeComponent
No tags

src/app/browse-by/browse-by-metadata-page/browse-by-metadata-page.component.ts

Modified
1 -import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
2 -import { Component, Inject, OnInit, OnDestroy } from '@angular/core';
1 +import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
2 +import { Component, Inject, OnInit, OnDestroy, Input } from '@angular/core';
3 3 import { RemoteData } from '../../core/data/remote-data';
4 4 import { PaginatedList } from '../../core/data/paginated-list.model';
5 5 import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
6 6 import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
7 7 import { ActivatedRoute, Params, Router } from '@angular/router';
8 8 import { hasValue, isNotEmpty } from '../../shared/empty.util';
9 9 import { BrowseService } from '../../core/browse/browse.service';
10 10 import { BrowseEntry } from '../../core/shared/browse-entry.model';
11 11 import { Item } from '../../core/shared/item.model';
12 12 import { BrowseEntrySearchOptions } from '../../core/browse/browse-entry-search-options.model';
16 16 import { StartsWithType } from '../../shared/starts-with/starts-with-decorator';
17 17 import { PaginationService } from '../../core/pagination/pagination.service';
18 18 import { filter, map, mergeMap } from 'rxjs/operators';
19 19 import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
20 20 import { Bitstream } from '../../core/shared/bitstream.model';
21 21 import { Collection } from '../../core/shared/collection.model';
22 22 import { Community } from '../../core/shared/community.model';
23 23 import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
24 24 import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
25 25 import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
26 -import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component';
27 26 import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
27 +import { Context } from '../../core/shared/context.model';
28 28
29 29 export const BBM_PAGINATION_ID = 'bbm';
30 30
31 31 @Component({
32 32 selector: 'ds-browse-by-metadata-page',
33 33 styleUrls: ['./browse-by-metadata-page.component.scss'],
34 34 templateUrl: './browse-by-metadata-page.component.html'
35 35 })
36 36 /**
37 37 * Component for browsing (items) by metadata definition.
38 38 * A metadata definition (a.k.a. browse id) is a short term used to describe one
39 39 * or multiple metadata fields. An example would be 'author' for
40 40 * 'dc.contributor.*'
41 41 */
42 42 @rendersBrowseBy(BrowseByDataType.Metadata)
43 -export class BrowseByMetadataPageComponent extends AbstractBrowseByTypeComponent implements OnInit, OnDestroy {
43 +export class BrowseByMetadataPageComponent implements OnInit, OnDestroy {
44 +
45 + /**
46 + * The optional context
47 + */
48 + @Input() context: Context;
49 +
50 + /**
51 + * The {@link BrowseByDataType} of this Component
52 + */
53 + @Input() browseByType: BrowseByDataType;
44 54
45 55 /**
46 56 * The list of browse-entries to display
47 57 */
48 58 browseEntries$: Observable<RemoteData<PaginatedList<BrowseEntry>>>;
49 59
50 60 /**
51 61 * The list of items to display when a value is present
52 62 */
53 63 items$: Observable<RemoteData<PaginatedList<Item>>>;
70 80 /**
71 81 * The pagination observable
72 82 */
73 83 currentPagination$: Observable<PaginationComponentOptions>;
74 84
75 85 /**
76 86 * The sorting config observable
77 87 */
78 88 currentSort$: Observable<SortOptions>;
79 89
90 + /**
91 + * List of subscriptions
92 + */
93 + subs: Subscription[] = [];
94 +
80 95 /**
81 96 * The default browse id to resort to when none is provided
82 97 */
83 98 defaultBrowseId = 'author';
84 99
85 100 /**
86 101 * The current browse id
87 102 */
88 103 browseId = this.defaultBrowseId;
89 104
122 137 fetchThumbnails: boolean;
123 138
124 139 public constructor(protected route: ActivatedRoute,
125 140 protected browseService: BrowseService,
126 141 protected dsoService: DSpaceObjectDataService,
127 142 protected paginationService: PaginationService,
128 143 protected router: Router,
129 144 @Inject(APP_CONFIG) public appConfig: AppConfig,
130 145 public dsoNameService: DSONameService,
131 146 ) {
132 - super();
133 147 this.fetchThumbnails = this.appConfig.browseBy.showThumbnails;
134 148 this.paginationConfig = Object.assign(new PaginationComponentOptions(), {
135 149 id: BBM_PAGINATION_ID,
136 150 currentPage: 1,
137 151 pageSize: this.appConfig.browseBy.pageSize,
138 152 });
139 153 }
140 154
141 155
142 156 ngOnInit(): void {
266 280 this.items$ = this.browseService.getNextBrowseItems(items);
267 281 });
268 282 } else if (this.browseEntries$) {
269 283 this.browseEntries$.pipe(getFirstSucceededRemoteData()).subscribe((entries) => {
270 284 this.browseEntries$ = this.browseService.getNextBrowseEntries(entries);
271 285 });
272 286 }
273 287 }
274 288
275 289 ngOnDestroy(): void {
276 - super.ngOnDestroy();
290 + this.subs.filter((sub: Subscription) => hasValue(sub)).forEach((sub: Subscription) => sub.unsubscribe());
277 291 this.paginationService.clearPagination(this.paginationConfig.id);
278 292 }
279 293
280 294
281 295 }
282 296
283 297 /**
284 298 * Creates browse entry search options.
285 299 * @param defaultBrowseId the metadata definition to fetch entries or items for
286 300 * @param paginationConfig the required pagination configuration

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut