Skip to content

Commit

Permalink
geocat: add geocat-header with langage switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas authored and jahow committed Mar 25, 2024
1 parent 0f593a0 commit cf579eb
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 5 deletions.
1 change: 1 addition & 0 deletions apps/datahub/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
gnUiSearchRouterContainer="mainSearch"
class="selection:bg-primary-lightest selection:text-primary-darker"
>
<datahub-geocat-header></datahub-geocat-header>
<router-outlet></router-outlet>
</div>
2 changes: 2 additions & 0 deletions apps/datahub/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { RecordDownloadsComponent } from './record/record-downloads/record-downl
import { RecordApisComponent } from './record/record-apis/record-apis.component'
import { MatTabsModule } from '@angular/material/tabs'
import { ORGANIZATIONS_STRATEGY } from '@geonetwork-ui/api/repository/gn4'
import { GeocatHeaderComponent } from './home/geocat-header/geocat-header.component'

export const metaReducers: MetaReducer[] = !environment.production ? [] : []
// https://github.com/nrwl/nx/issues/191
Expand All @@ -105,6 +106,7 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : []
RecordOtherlinksComponent,
RecordDownloadsComponent,
RecordApisComponent,
GeocatHeaderComponent,
],
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="px-5">
<div
class="mx-auto flex items-center justify-center sm:justify-end gap-2 py-1 text-sm"
>
<a class="block hover:underline mr-4" [href]="docLink" target="_blank">{{
'datahub.header.documentation' | translate
}}</a>
<a class="block hover:underline" [href]="gnLink" target="_blank">{{
'datahub.header.admin' | translate
}}</a>
<gn-ui-language-switcher
*ngIf="showLanguageSwitcher"
class="language-switcher"
></gn-ui-language-switcher>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { GeocatHeaderComponent } from './geocat-header.component'
import { TranslateModule } from '@ngx-translate/core'

jest.mock('@geonetwork-ui/util/app-config', () => ({
getGlobalConfig: jest.fn(() => ({
LANGUAGES: ['de', 'fr'],
})),
}))

describe('GeocatHeaderComponent', () => {
let component: GeocatHeaderComponent
let fixture: ComponentFixture<GeocatHeaderComponent>

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [GeocatHeaderComponent],
imports: [TranslateModule.forRoot()],
})
fixture = TestBed.createComponent(GeocatHeaderComponent)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
26 changes: 26 additions & 0 deletions apps/datahub/src/app/home/geocat-header/geocat-header.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component } from '@angular/core'
import { TranslateService } from '@ngx-translate/core'
import { LANG_2_TO_3_MAPPER } from '@geonetwork-ui/util/i18n'
import { getGlobalConfig } from '@geonetwork-ui/util/app-config'

@Component({
selector: 'datahub-geocat-header',
templateUrl: './geocat-header.component.html',
})
export class GeocatHeaderComponent {
showLanguageSwitcher = getGlobalConfig().LANGUAGES?.length > 0

constructor(private translate: TranslateService) {}

get docLink() {
return `https://www.geocat.admin.ch/${
this.translate.currentLang || 'en'
}/home.html`
}

get gnLink() {
return `/geonetwork/srv/${
LANG_2_TO_3_MAPPER[this.translate.currentLang] || 'eng'
}/catalog.edit#/board`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,4 @@
></datahub-navigation-menu>
</div>
</div>
<gn-ui-language-switcher
*ngIf="showLanguageSwitcher"
class="language-switcher absolute top-2.5 left-2.5 text-[13px]"
></gn-ui-language-switcher>
</header>
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ describe('HeaderComponent', () => {
})
})

describe('language switcher', () => {
// skipped for geocat
describe.skip('language switcher', () => {
describe('given predefined languages', () => {
it('should display language switcher', () => {
const languageSwitcher = fixture.debugElement.queryAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
ariaName="languages"
[showTitle]="false"
extraBtnClass="bg-transparent flex justify-items-center !pl-2 !py-1"
class="text-sm"
>
</gn-ui-dropdown-selector>

0 comments on commit cf579eb

Please sign in to comment.