Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/app/home-page/geoip-warning/geoip-warning.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@if (showWarning$ | async) {
<ds-alert [type]="AlertType.Warning" [dismissible]="true"
[content]="'home.geoip-warning'"
(close)="onDismiss()">
</ds-alert>
}
96 changes: 96 additions & 0 deletions src/app/home-page/geoip-warning/geoip-warning.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {
AsyncPipe,
isPlatformBrowser,
} from '@angular/common';
import {
Component,
Inject,
OnInit,
PLATFORM_ID,
} from '@angular/core';
import { AuthorizationDataService } from '@dspace/core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '@dspace/core/data/feature-authorization/feature-id';
import {
HealthResponse,
HealthStatus,
} from '@dspace/core/shared/health-component.model';
import { TranslateModule } from '@ngx-translate/core';
import {
Observable,
of,
} from 'rxjs';
import {
catchError,
map,
switchMap,
take,
} from 'rxjs/operators';

import { HealthService } from '../../health-page/health.service';
import { AlertComponent } from '../../shared/alert/alert.component';
import { AlertType } from '../../shared/alert/alert-type';

const DISMISSED_KEY = 'geoip-warning-dismissed';

/**
* Component that displays a warning when the GeoLite database is not installed.
* Only visible to administrators. Once dismissed, stays hidden for the browser session.
*/
@Component({
selector: 'ds-geoip-warning',
templateUrl: './geoip-warning.component.html',
imports: [
AlertComponent,
AsyncPipe,
TranslateModule,
],
})
export class GeoIpWarningComponent implements OnInit {

/**
* Whether to show the GeoIP warning.
*/
showWarning$: Observable<boolean>;

readonly AlertType = AlertType;

constructor(
private authorizationService: AuthorizationDataService,
private healthService: HealthService,
@Inject(PLATFORM_ID) private platformId: object,
) {
}

ngOnInit(): void {
if (isPlatformBrowser(this.platformId) && sessionStorage.getItem(DISMISSED_KEY)) {
this.showWarning$ = of(false);
return;
}

this.showWarning$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf).pipe(
switchMap((isAdmin: boolean) => {
if (!isAdmin) {
return of(false);
}
return this.healthService.getHealth().pipe(
take(1),
map((data: any) => {
const response: HealthResponse = data.payload;
return response?.components?.geoIp?.status === HealthStatus.UP_WITH_ISSUES;
}),
catchError(() => of(false)),
);
}),
);
}

/**
* Dismiss the warning and remember it for the session.
*/
onDismiss(): void {
if (isPlatformBrowser(this.platformId)) {
sessionStorage.setItem(DISMISSED_KEY, 'true');
}
}

}
1 change: 1 addition & 0 deletions src/app/home-page/home-page.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<ds-geoip-warning></ds-geoip-warning>
<ds-home-coar></ds-home-coar>
<ds-home-news></ds-home-news>
@if (showDiscoverFilters) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/home-page/home-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { map } from 'rxjs/operators';
import { SuggestionsPopupComponent } from '../notifications/suggestions/popup/suggestions-popup.component';
import { ThemedConfigurationSearchPageComponent } from '../search-page/themed-configuration-search-page.component';
import { ThemedSearchFormComponent } from '../shared/search-form/themed-search-form.component';
import { GeoIpWarningComponent } from './geoip-warning/geoip-warning.component';
import { HomeCoarComponent } from './home-coar/home-coar.component';
import { ThemedHomeNewsComponent } from './home-news/themed-home-news.component';
import { RecentItemListComponent } from './recent-item-list/recent-item-list.component';
Expand All @@ -27,6 +28,7 @@ import { ThemedTopLevelCommunityListComponent } from './top-level-community-list
styleUrls: ['./home-page.component.scss'],
templateUrl: './home-page.component.html',
imports: [
GeoIpWarningComponent,
HomeCoarComponent,
NgTemplateOutlet,
RecentItemListComponent,
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,8 @@

"home.breadcrumbs": "Home",

"home.geoip-warning": "The GeoLite database is not installed. Location-based statistics (countries, cities) are unavailable. See the DSpace installation instructions for details.",

"home.search-form.placeholder": "Search the repository ...",

"home.title": "Home",
Expand Down
2 changes: 2 additions & 0 deletions src/themes/custom/app/home-page/home-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NgTemplateOutlet } from '@angular/common';
import { Component } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';

import { GeoIpWarningComponent } from '../../../../app/home-page/geoip-warning/geoip-warning.component';
import { HomeCoarComponent } from '../../../../app/home-page/home-coar/home-coar.component';
import { ThemedHomeNewsComponent } from '../../../../app/home-page/home-news/themed-home-news.component';
import { HomePageComponent as BaseComponent } from '../../../../app/home-page/home-page.component';
Expand All @@ -18,6 +19,7 @@ import { ThemedSearchFormComponent } from '../../../../app/shared/search-form/th
// templateUrl: './home-page.component.html'
templateUrl: '../../../../app/home-page/home-page.component.html',
imports: [
GeoIpWarningComponent,
HomeCoarComponent,
NgTemplateOutlet,
RecentItemListComponent,
Expand Down