Skip to content

Commit b2c14df

Browse files
Moved home COAR functionality to separate component
1 parent fcabea0 commit b2c14df

4 files changed

Lines changed: 103 additions & 86 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { isPlatformServer } from '@angular/common';
2+
import {
3+
Component,
4+
Inject,
5+
OnDestroy,
6+
OnInit,
7+
PLATFORM_ID,
8+
} from '@angular/core';
9+
import {
10+
of as observableOf,
11+
Subscription,
12+
} from 'rxjs';
13+
import { switchMap } from 'rxjs/operators';
14+
15+
import { NotifyInfoService } from '../../core/coar-notify/notify-info/notify-info.service';
16+
import {
17+
LinkDefinition,
18+
LinkHeadService,
19+
} from '../../core/services/link-head.service';
20+
import { ServerResponseService } from '../../core/services/server-response.service';
21+
import { isNotEmpty } from '../../shared/empty.util';
22+
23+
@Component({
24+
selector: 'ds-home-coar',
25+
template: '',
26+
standalone: true,
27+
})
28+
export class HomeCoarComponent implements OnInit, OnDestroy {
29+
30+
/**
31+
* An array of LinkDefinition objects representing inbox links for the home page.
32+
*/
33+
inboxLinks: LinkDefinition[] = [];
34+
35+
subs: Subscription[] = [];
36+
37+
constructor(
38+
protected linkHeadService: LinkHeadService,
39+
protected notifyInfoService: NotifyInfoService,
40+
protected responseService: ServerResponseService,
41+
@Inject(PLATFORM_ID) protected platformId: string,
42+
) {
43+
}
44+
45+
ngOnInit(): void {
46+
// Get COAR REST API URLs from REST configuration
47+
// only if COAR configuration is enabled
48+
this.subs.push(this.notifyInfoService.isCoarConfigEnabled().pipe(
49+
switchMap((coarLdnEnabled: boolean) => coarLdnEnabled ? this.notifyInfoService.getCoarLdnLocalInboxUrls() : observableOf([])),
50+
).subscribe((coarRestApiUrls: string[]) => {
51+
if (coarRestApiUrls.length > 0) {
52+
this.initPageLinks(coarRestApiUrls);
53+
}
54+
}));
55+
}
56+
57+
/**
58+
* It removes the inbox links from the head of the html.
59+
*/
60+
ngOnDestroy(): void {
61+
this.subs.forEach((sub: Subscription) => sub.unsubscribe());
62+
this.inboxLinks.forEach((link: LinkDefinition) => {
63+
this.linkHeadService.removeTag(`href='${link.href}'`);
64+
});
65+
}
66+
67+
/**
68+
* Initializes page links for COAR REST API URLs.
69+
* @param coarRestApiUrls An array of COAR REST API URLs.
70+
*/
71+
private initPageLinks(coarRestApiUrls: string[]): void {
72+
const rel = this.notifyInfoService.getInboxRelationLink();
73+
let links = '';
74+
coarRestApiUrls.forEach((coarRestApiUrl: string) => {
75+
// Add link to head
76+
const tag: LinkDefinition = {
77+
href: coarRestApiUrl,
78+
rel: rel,
79+
};
80+
this.inboxLinks.push(tag);
81+
this.linkHeadService.addTag(tag);
82+
83+
links = links + (isNotEmpty(links) ? ', ' : '') + `<${coarRestApiUrl}> ; rel="${rel}"`;
84+
});
85+
86+
if (isPlatformServer(this.platformId)) {
87+
// Add link to response header
88+
this.responseService.setHeader('Link', links);
89+
}
90+
}
91+
92+
}

src/app/home-page/home-page.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<ds-home-coar></ds-home-coar>
12
<ds-themed-home-news></ds-themed-home-news>
23
<div [ngClass]="showDiscoverFilters ? 'container-fluid' : 'container'">
34
<ds-page-with-sidebar [sidebarContent]="sidebar" [sideBarWidth]="showDiscoverFilters ? 3 : 0" [class]="showDiscoverFilters ? 'row mx-3' : ''">
Lines changed: 8 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,32 @@
11
import {
22
AsyncPipe,
3-
isPlatformServer,
43
NgClass,
54
NgIf,
65
} from '@angular/common';
76
import {
87
Component,
98
Inject,
10-
OnDestroy,
119
OnInit,
12-
PLATFORM_ID,
1310
} from '@angular/core';
1411
import { ActivatedRoute } from '@angular/router';
15-
import { Observable } from 'rxjs';
16-
import { Site } from '../core/shared/site.model';
17-
import { isPlatformServer } from '@angular/common';
18-
import { ServerResponseService } from '../core/services/server-response.service';
1912
import { TranslateModule } from '@ngx-translate/core';
20-
import {
21-
EMPTY,
22-
Observable,
23-
} from 'rxjs';
24-
import {
25-
map,
26-
switchMap,
27-
} from 'rxjs/operators';
13+
import { Observable } from 'rxjs';
14+
import { map } from 'rxjs/operators';
2815
import {
2916
APP_CONFIG,
3017
AppConfig,
3118
} from 'src/config/app-config.interface';
3219

33-
import { environment } from '../../environments/environment';
34-
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
35-
import {
36-
LinkDefinition,
37-
LinkHeadService,
38-
} from '../core/services/link-head.service';
39-
import { ServerResponseService } from '../core/services/server-response.service';
4020
import { Site } from '../core/shared/site.model';
4121
import { SuggestionsPopupComponent } from '../notifications/suggestions-popup/suggestions-popup.component';
4222
import { ConfigurationSearchPageComponent } from '../search-page/configuration-search-page.component';
43-
import { isNotEmpty } from '../shared/empty.util';
44-
import { APP_CONFIG, AppConfig } from 'src/config/app-config.interface';
23+
import { ThemedConfigurationSearchPageComponent } from '../search-page/themed-configuration-search-page.component';
4524
import { HostWindowService } from '../shared/host-window.service';
46-
import { SidebarService } from '../shared/sidebar/sidebar.service';
47-
4825
import { ThemedSearchFormComponent } from '../shared/search-form/themed-search-form.component';
26+
import { PageWithSidebarComponent } from '../shared/sidebar/page-with-sidebar.component';
27+
import { SidebarService } from '../shared/sidebar/sidebar.service';
4928
import { ViewTrackerComponent } from '../statistics/angulartics/dspace/view-tracker.component';
29+
import { HomeCoarComponent } from './home-coar/home-coar.component';
5030
import { ThemedHomeNewsComponent } from './home-news/themed-home-news.component';
5131
import { RecentItemListComponent } from './recent-item-list/recent-item-list.component';
5232
import { ThemedTopLevelCommunityListComponent } from './top-level-community-list/themed-top-level-community-list.component';
@@ -56,47 +36,23 @@ import { ThemedTopLevelCommunityListComponent } from './top-level-community-list
5636
styleUrls: ['./home-page.component.scss'],
5737
templateUrl: './home-page.component.html',
5838
standalone: true,
59-
imports: [ThemedHomeNewsComponent, NgIf, ViewTrackerComponent, ThemedSearchFormComponent, ThemedTopLevelCommunityListComponent, RecentItemListComponent, AsyncPipe, TranslateModule, NgClass, ConfigurationSearchPageComponent, SuggestionsPopupComponent],
39+
imports: [ThemedHomeNewsComponent, NgIf, ViewTrackerComponent, ThemedSearchFormComponent, ThemedTopLevelCommunityListComponent, RecentItemListComponent, AsyncPipe, TranslateModule, NgClass, ConfigurationSearchPageComponent, SuggestionsPopupComponent, ThemedConfigurationSearchPageComponent, PageWithSidebarComponent, HomeCoarComponent],
6040
})
61-
export class HomePageComponent implements OnInit, OnDestroy {
41+
export class HomePageComponent implements OnInit {
6242

6343
site$: Observable<Site>;
6444
isXsOrSm$: Observable<boolean>;
6545
recentSubmissionspageSize: number;
6646
showDiscoverFilters: boolean;
67-
/**
68-
* An array of LinkDefinition objects representing inbox links for the home page.
69-
*/
70-
inboxLinks: LinkDefinition[] = [];
7147

7248
constructor(
7349
@Inject(APP_CONFIG) protected appConfig: AppConfig,
7450
protected route: ActivatedRoute,
75-
protected responseService: ServerResponseService,
76-
protected notifyInfoService: NotifyInfoService,
77-
protected linkHeadService: LinkHeadService,
78-
@Inject(PLATFORM_ID) private platformId: string,
7951
protected sidebarService: SidebarService,
8052
protected windowService: HostWindowService,
81-
@Inject(PLATFORM_ID) protected platformId: string,
8253
) {
8354
this.recentSubmissionspageSize = this.appConfig.homePage.recentSubmissions.pageSize;
8455
this.showDiscoverFilters = this.appConfig.homePage.showDiscoverFilters;
85-
// Get COAR REST API URLs from REST configuration
86-
// only if COAR configuration is enabled
87-
this.notifyInfoService.isCoarConfigEnabled().pipe(
88-
switchMap((coarLdnEnabled: boolean) => coarLdnEnabled ? this.notifyInfoService.getCoarLdnLocalInboxUrls() : EMPTY, /*{
89-
if (coarLdnEnabled) {
90-
return this.notifyInfoService.getCoarLdnLocalInboxUrls();
91-
} else {
92-
return of([]);
93-
}
94-
}*/),
95-
).subscribe((coarRestApiUrls: string[]) => {
96-
if (coarRestApiUrls?.length > 0) {
97-
this.initPageLinks(coarRestApiUrls);
98-
}
99-
});
10056
}
10157

10258
ngOnInit(): void {
@@ -106,37 +62,4 @@ export class HomePageComponent implements OnInit, OnDestroy {
10662
);
10763
}
10864

109-
/**
110-
* Initializes page links for COAR REST API URLs.
111-
* @param coarRestApiUrls An array of COAR REST API URLs.
112-
*/
113-
private initPageLinks(coarRestApiUrls: string[]): void {
114-
const rel = this.notifyInfoService.getInboxRelationLink();
115-
let links = '';
116-
coarRestApiUrls.forEach((coarRestApiUrl: string) => {
117-
// Add link to head
118-
const tag: LinkDefinition = {
119-
href: coarRestApiUrl,
120-
rel: rel,
121-
};
122-
this.inboxLinks.push(tag);
123-
this.linkHeadService.addTag(tag);
124-
125-
links = links + (isNotEmpty(links) ? ', ' : '') + `<${coarRestApiUrl}> ; rel="${rel}"`;
126-
});
127-
128-
if (isPlatformServer(this.platformId)) {
129-
// Add link to response header
130-
this.responseService.setHeader('Link', links);
131-
}
132-
}
133-
134-
/**
135-
* It removes the inbox links from the head of the html.
136-
*/
137-
ngOnDestroy(): void {
138-
this.inboxLinks.forEach((link: LinkDefinition) => {
139-
this.linkHeadService.removeTag(`href='${link.href}'`);
140-
});
141-
}
14265
}

src/themes/custom/app/home-page/home-page.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { Component } from '@angular/core';
77
import { TranslateModule } from '@ngx-translate/core';
88

9+
import { HomeCoarComponent } from '../../../../app/home-page/home-coar/home-coar.component';
910
import { ThemedHomeNewsComponent } from '../../../../app/home-page/home-news/themed-home-news.component';
1011
import { HomePageComponent as BaseComponent } from '../../../../app/home-page/home-page.component';
1112
import { RecentItemListComponent } from '../../../../app/home-page/recent-item-list/recent-item-list.component';
@@ -24,7 +25,7 @@ import { ViewTrackerComponent } from '../../../../app/statistics/angulartics/dsp
2425
// templateUrl: './home-page.component.html'
2526
templateUrl: '../../../../app/home-page/home-page.component.html',
2627
standalone: true,
27-
imports: [ThemedHomeNewsComponent, NgIf, ViewTrackerComponent, ThemedSearchFormComponent, ThemedTopLevelCommunityListComponent, RecentItemListComponent, AsyncPipe, TranslateModule, NgClass, ConfigurationSearchPageComponent, SuggestionsPopupComponent, ThemedConfigurationSearchPageComponent, PageWithSidebarComponent],
28+
imports: [ThemedHomeNewsComponent, NgIf, ViewTrackerComponent, ThemedSearchFormComponent, ThemedTopLevelCommunityListComponent, RecentItemListComponent, AsyncPipe, TranslateModule, NgClass, ConfigurationSearchPageComponent, SuggestionsPopupComponent, ThemedConfigurationSearchPageComponent, PageWithSidebarComponent, HomeCoarComponent],
2829
})
2930
export class HomePageComponent extends BaseComponent {
3031

0 commit comments

Comments
 (0)