diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6d01c4d770..15692f7b55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -101,13 +101,7 @@ You'll need manual configuration to make the application running: // ... // provide API url and proxy path providers: [ - { - provide: Configuration, - useFactory: () => - new Configuration({ - basePath: getGlobalConfig().GN4_API_URL, - }), - }, + provideRepositoryUrl(() => getGlobalConfig().GN4_API_URL), { provide: PROXY_PATH, useFactory: () => getGlobalConfig().PROXY_PATH, diff --git a/apps/datahub/src/app/app.module.ts b/apps/datahub/src/app/app.module.ts index 6b18b04fa7..6d7754b4b0 100644 --- a/apps/datahub/src/app/app.module.ts +++ b/apps/datahub/src/app/app.module.ts @@ -3,17 +3,20 @@ import { importProvidersFrom, Inject, NgModule } from '@angular/core' import { MatIconModule } from '@angular/material/icon' import { BrowserModule } from '@angular/platform-browser' import { Router, RouterModule } from '@angular/router' -import { Configuration } from '@geonetwork-ui/data-access/gn4' import { FeatureCatalogModule, ORGANIZATION_URL_TOKEN, } from '@geonetwork-ui/feature/catalog' -import { FeatureRecordModule } from '@geonetwork-ui/feature/record' +import { + FeatureRecordModule, + GN_UI_VERSION, + WEB_COMPONENT_EMBEDDER_URL, +} from '@geonetwork-ui/feature/record' import { DefaultRouterModule, + ROUTE_PARAMS, ROUTER_ROUTE_DATASET, ROUTER_ROUTE_SEARCH, - ROUTE_PARAMS, RouterService, } from '@geonetwork-ui/feature/router' import { @@ -36,10 +39,10 @@ import { } from '@geonetwork-ui/util/app-config' import { UtilI18nModule } from '@geonetwork-ui/util/i18n' import { + getGeometryFromGeoJSON, PROXY_PATH, ThemeService, UtilSharedModule, - getGeometryFromGeoJSON, } from '@geonetwork-ui/util/shared' import { FeatureAuthModule } from '@geonetwork-ui/feature/auth' import { EffectsModule } from '@ngrx/effects' @@ -64,11 +67,12 @@ import { DatahubRouterService } from './router/datahub-router.service' import { NavigationMenuComponent } from './home/navigation-menu/navigation-menu.component' import { FormsModule } from '@angular/forms' import { UiDatavizModule } from '@geonetwork-ui/ui/dataviz' -import { WEB_COMPONENT_EMBEDDER_URL } from '@geonetwork-ui/feature/record' import { LANGUAGES_LIST, UiCatalogModule } from '@geonetwork-ui/ui/catalog' -import { METADATA_LANGUAGE } from '@geonetwork-ui/api/repository' +import { + METADATA_LANGUAGE, + provideRepositoryUrl, +} from '@geonetwork-ui/api/repository' import { BrowserAnimationsModule } from '@angular/platform-browser/animations' -import { GN_UI_VERSION } from '@geonetwork-ui/feature/record' import { LOGIN_URL } from '@geonetwork-ui/api/repository/gn4' import { RecordRelatedRecordsComponent } from './record/record-related-records/record-related-records.component' import { RecordMetadataComponent } from './record/record-metadata/record-metadata.component' @@ -142,16 +146,10 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : [] MatTabsModule, ], providers: [ - { provide: RouterService, useClass: DatahubRouterService }, importProvidersFrom(FeatureAuthModule), + provideRepositoryUrl(() => getGlobalConfig().GN4_API_URL), + { provide: RouterService, useClass: DatahubRouterService }, { provide: GN_UI_VERSION, useValue: environment.version }, - { - provide: Configuration, - useFactory: () => - new Configuration({ - basePath: getGlobalConfig().GN4_API_URL, - }), - }, { provide: PROXY_PATH, useFactory: () => getGlobalConfig().PROXY_PATH, diff --git a/apps/map-viewer/src/app/app.module.ts b/apps/map-viewer/src/app/app.module.ts index 7714d2ef09..aa85a6b4cc 100644 --- a/apps/map-viewer/src/app/app.module.ts +++ b/apps/map-viewer/src/app/app.module.ts @@ -14,7 +14,7 @@ import { StoreDevtoolsModule } from '@ngrx/store-devtools' import { EffectsModule } from '@ngrx/effects' import { storeFreeze } from 'ngrx-store-freeze' import { environment } from '../environments/environment' -import { Configuration } from '@geonetwork-ui/data-access/gn4' +import { provideRepositoryUrl } from '@geonetwork-ui/api/repository' export const metaReducers: MetaReducer[] = !environment.production ? [storeFreeze] @@ -31,15 +31,7 @@ export const metaReducers: MetaReducer[] = !environment.production StoreDevtoolsModule.instrument(), EffectsModule.forRoot(), ], - providers: [ - { - provide: Configuration, - useFactory: () => - new Configuration({ - basePath: '/geonetwork/srv/api', - }), - }, - ], + providers: [provideRepositoryUrl('/geonetwork/srv/api')], bootstrap: [AppComponent], }) export class AppModule { diff --git a/apps/metadata-editor/src/app/app.module.ts b/apps/metadata-editor/src/app/app.module.ts index 0df8bf2962..dca34bf612 100644 --- a/apps/metadata-editor/src/app/app.module.ts +++ b/apps/metadata-editor/src/app/app.module.ts @@ -10,7 +10,6 @@ import { DefaultRouterModule, RouterService, } from '@geonetwork-ui/feature/router' -import { Configuration } from '@geonetwork-ui/data-access/gn4' import { getGlobalConfig, getThemeConfig } from '@geonetwork-ui/util/app-config' import { ThemeService } from '@geonetwork-ui/util/shared' import { @@ -25,6 +24,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations' import { extModules } from './build-specifics' import { DashboardPageComponent } from './dashboard/dashboard-page.component' import { EditorRouterService } from './router.service' +import { provideRepositoryUrl } from '@geonetwork-ui/api/repository' @NgModule({ declarations: [AppComponent], @@ -56,13 +56,7 @@ import { EditorRouterService } from './router.service' importProvidersFrom(FeatureRecordModule), importProvidersFrom(UtilI18nModule), importProvidersFrom(TranslateModule.forRoot(TRANSLATE_DEFAULT_CONFIG)), - { - provide: Configuration, - useFactory: () => - new Configuration({ - basePath: getGlobalConfig().GN4_API_URL, - }), - }, + provideRepositoryUrl(() => getGlobalConfig().GN4_API_URL), importProvidersFrom(EffectsModule.forRoot()), ], bootstrap: [AppComponent], diff --git a/apps/metadata-editor/src/app/dashboard/search-header/search-header.component.spec.ts b/apps/metadata-editor/src/app/dashboard/search-header/search-header.component.spec.ts index 8f58b62611..2c0dab8edb 100644 --- a/apps/metadata-editor/src/app/dashboard/search-header/search-header.component.spec.ts +++ b/apps/metadata-editor/src/app/dashboard/search-header/search-header.component.spec.ts @@ -8,13 +8,13 @@ import { StoreModule } from '@ngrx/store' import { EffectsModule } from '@ngrx/effects' import { TranslateModule } from '@ngx-translate/core' import { TRANSLATE_DEFAULT_CONFIG } from '@geonetwork-ui/util/i18n' -import { Configuration } from '@geonetwork-ui/data-access/gn4' import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface' import { SearchFacade, SearchService } from '@geonetwork-ui/feature/search' import { AuthService, AvatarServiceInterface, } from '@geonetwork-ui/api/repository/gn4' +import { provideRepositoryUrl } from '@geonetwork-ui/api/repository' const user = USER_FIXTURE() class AuthServiceMock { @@ -63,15 +63,12 @@ describe('SearchHeaderComponent', () => { ], schemas: [NO_ERRORS_SCHEMA], providers: [ + provideRepositoryUrl('/geonetwork/srv/api'), { provide: AuthService, useClass: AuthServiceMock }, { provide: AvatarServiceInterface, useClass: AvatarServiceInterfaceMock, }, - { - provide: Configuration, - useValue: new Configuration({ basePath: '/geonetwork/srv/api' }), - }, { provide: OrganizationsServiceInterface, useClass: OrganisationsServiceMock, diff --git a/apps/search/src/app/app.module.ts b/apps/search/src/app/app.module.ts index 1b70f2abf0..e8eced3a70 100644 --- a/apps/search/src/app/app.module.ts +++ b/apps/search/src/app/app.module.ts @@ -7,10 +7,9 @@ import { FeatureMapModule } from '@geonetwork-ui/feature/map' import { UiLayoutModule } from '@geonetwork-ui/ui/layout' import { UiMapModule } from '@geonetwork-ui/ui/map' import { - UtilI18nModule, TRANSLATE_DEFAULT_CONFIG, + UtilI18nModule, } from '@geonetwork-ui/util/i18n' -import { Configuration } from '@geonetwork-ui/data-access/gn4' import { FeatureSearchModule } from '@geonetwork-ui/feature/search' import { EffectsModule } from '@ngrx/effects' import { MetaReducer, StoreModule } from '@ngrx/store' @@ -22,6 +21,7 @@ import { AppRoutingModule } from './app-routing.module' import { AppComponent } from './app.component' import { MainSearchComponent } from './main-search/main-search.component' import { NoopAnimationsModule } from '@angular/platform-browser/animations' +import { provideRepositoryUrl } from '@geonetwork-ui/api/repository' export const metaReducers: MetaReducer[] = !environment.production ? [storeFreeze] @@ -46,14 +46,7 @@ export const metaReducers: MetaReducer[] = !environment.production EffectsModule.forRoot(), NoopAnimationsModule, ], - providers: [ - { - provide: Configuration, - useValue: new Configuration({ - basePath: environment.API_BASE_PATH, - }), - }, - ], + providers: [provideRepositoryUrl(environment.API_BASE_PATH)], bootstrap: [AppComponent], }) export class AppModule {} diff --git a/libs/api/repository/src/index.ts b/libs/api/repository/src/index.ts index 64b5d303e2..f6b986adca 100644 --- a/libs/api/repository/src/index.ts +++ b/libs/api/repository/src/index.ts @@ -1 +1,2 @@ export * from './lib/metadata-language' +export * from './lib/repository-url' diff --git a/libs/api/repository/src/lib/repository-url.ts b/libs/api/repository/src/lib/repository-url.ts new file mode 100644 index 0000000000..3efbd3414c --- /dev/null +++ b/libs/api/repository/src/lib/repository-url.ts @@ -0,0 +1,14 @@ +import { Configuration } from '@geonetwork-ui/data-access/gn4' +import { Provider } from '@angular/core' + +export function provideRepositoryUrl( + urlFactory: string | (() => string) +): Provider { + return { + provide: Configuration, + useFactory: () => + new Configuration({ + basePath: typeof urlFactory === 'function' ? urlFactory() : urlFactory, + }), + } +} diff --git a/libs/feature/record/src/lib/data-view-permalink/data-view-permalink.component.spec.ts b/libs/feature/record/src/lib/data-view-permalink/data-view-permalink.component.spec.ts index 24a5cbc41e..139b057120 100644 --- a/libs/feature/record/src/lib/data-view-permalink/data-view-permalink.component.spec.ts +++ b/libs/feature/record/src/lib/data-view-permalink/data-view-permalink.component.spec.ts @@ -4,12 +4,12 @@ import { DataViewPermalinkComponent, WEB_COMPONENT_EMBEDDER_URL, } from './data-view-permalink.component' -import { Configuration } from '@geonetwork-ui/data-access/gn4' import { BehaviorSubject, firstValueFrom } from 'rxjs' import { MdViewFacade } from '../state' import { Component, Input } from '@angular/core' import { TranslateModule } from '@ngx-translate/core' import { GN_UI_VERSION } from '../gn-ui-version.token' +import { provideRepositoryUrl } from '@geonetwork-ui/api/repository' const chartConfig1 = { aggregation: 'sum', @@ -33,9 +33,6 @@ class MdViewFacadeMock { chartConfig$ = new BehaviorSubject(chartConfig1) metadata$ = new BehaviorSubject(metadata) } -class ConfigMock { - basePath: 'http://gn-api.url/' -} const baseUrl = 'https://example.com/wc-embedder' @@ -60,10 +57,7 @@ describe('DataViewPermalinkComponent', () => { declarations: [DataViewPermalinkComponent, MockCopyTextButtonComponent], imports: [TranslateModule.forRoot()], providers: [ - { - provide: Configuration, - useClass: ConfigMock, - }, + provideRepositoryUrl('http://gn-api.url/'), { provide: MdViewFacade, useClass: MdViewFacadeMock, diff --git a/libs/feature/record/src/lib/data-view-web-component/data-view-web-component.component.spec.ts b/libs/feature/record/src/lib/data-view-web-component/data-view-web-component.component.spec.ts index e5f2afadc3..b274b4299b 100644 --- a/libs/feature/record/src/lib/data-view-web-component/data-view-web-component.component.spec.ts +++ b/libs/feature/record/src/lib/data-view-web-component/data-view-web-component.component.spec.ts @@ -1,11 +1,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing' import { DataViewWebComponentComponent } from './data-view-web-component.component' import { BehaviorSubject, firstValueFrom } from 'rxjs' -import { Configuration } from '@geonetwork-ui/data-access/gn4' import { MdViewFacade } from '../state' import { TranslateModule } from '@ngx-translate/core' import { Component, Input } from '@angular/core' import { GN_UI_VERSION } from '../gn-ui-version.token' +import { provideRepositoryUrl } from '@geonetwork-ui/api/repository' const chartConfig1 = { aggregation: 'sum', @@ -31,9 +31,6 @@ class MdViewFacadeMock { chartConfig$ = new BehaviorSubject(chartConfig1) metadata$ = new BehaviorSubject(metadata) } -class ConfigMock { - basePath: 'http://gn-api.url/' -} @Component({ selector: 'gn-ui-copy-text-button', @@ -58,10 +55,7 @@ describe('DataViewWebComponentComponent', () => { ], imports: [TranslateModule.forRoot()], providers: [ - { - provide: Configuration, - useClass: ConfigMock, - }, + provideRepositoryUrl('http://gn-api.url/'), { provide: MdViewFacade, useClass: MdViewFacadeMock, @@ -88,7 +82,7 @@ describe('DataViewWebComponentComponent', () => { expect(html).toBe( ` { expect(html).toBe( `