Skip to content

Commit

Permalink
Merge pull request #703 from geonetwork/platform-service
Browse files Browse the repository at this point in the history
Add a Platform service
  • Loading branch information
fgravin authored Nov 28, 2023
2 parents ef6a273 + 548263b commit e7e9323
Show file tree
Hide file tree
Showing 172 changed files with 670 additions and 480 deletions.
2 changes: 1 addition & 1 deletion apps/data-platform/src/app/dataviz/dataviz.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { DatavizConfigurationModel } from '@geonetwork-ui/common/domain/dataviz-configuration.model'
import { DatavizConfigurationModel } from '@geonetwork-ui/common/domain/model/dataviz/dataviz-configuration.model'

export type DatavizConfigModel = DatavizConfigurationModel
3 changes: 2 additions & 1 deletion apps/datahub/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import {
provideRepositoryUrl,
} from '@geonetwork-ui/api/repository'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { LOGIN_URL } from '@geonetwork-ui/api/repository/gn4'
import { LOGIN_URL, provideGn4 } 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'
import { RecordOtherlinksComponent } from './record/record-otherlinks/record-otherlinks.component'
Expand Down Expand Up @@ -148,6 +148,7 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : []
providers: [
importProvidersFrom(FeatureAuthModule),
provideRepositoryUrl(() => getGlobalConfig().GN4_API_URL),
provideGn4(),
{ provide: RouterService, useClass: DatahubRouterService },
{ provide: GN_UI_VERSION, useValue: environment.version },
{
Expand Down
29 changes: 13 additions & 16 deletions apps/datahub/src/app/home/home-header/home-header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { By } from '@angular/platform-browser'
import {
RouterFacade,
ROUTER_ROUTE_SEARCH,
RouterFacade,
} from '@geonetwork-ui/feature/router'
import {
FieldsService,
Expand All @@ -15,10 +15,10 @@ import { BehaviorSubject, firstValueFrom, of } from 'rxjs'
import { ROUTER_ROUTE_NEWS } from '../../router/constants'
import { HeaderBadgeButtonComponent } from '../header-badge-button/header-badge-button.component'
import { HomeHeaderComponent } from './home-header.component'
import resetAllMocks = jest.resetAllMocks
import { SortByEnum } from '@geonetwork-ui/common/domain/search'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import { SortByEnum } from '@geonetwork-ui/common/domain/model/search'
import { _setLanguages } from '@geonetwork-ui/util/app-config'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import resetAllMocks = jest.resetAllMocks

jest.mock('@geonetwork-ui/util/app-config', () => {
let _languages = ['pt', 'de']
Expand Down Expand Up @@ -71,9 +71,9 @@ class searchServiceMock {
setFilters = jest.fn()
}

class AuthServiceMock {
authReady = jest.fn(() => this._authSubject$)
_authSubject$ = new BehaviorSubject({})
class PlatformServiceMock {
isAnonymous = jest.fn(() => this._isAnonymous$)
_isAnonymous$ = new BehaviorSubject(true)
}

class FieldsServiceMock {
Expand All @@ -83,10 +83,10 @@ class FieldsServiceMock {
describe('HeaderComponent', () => {
let component: HomeHeaderComponent
let fixture: ComponentFixture<HomeHeaderComponent>
let authService: AuthService
let searchService: SearchService
let searchFacade: SearchFacade
let routerFacade: RouterFacade
let platform: PlatformServiceInterface

beforeEach(async () => {
_setLanguages(['fr', 'de'])
Expand All @@ -108,19 +108,19 @@ describe('HeaderComponent', () => {
useClass: searchServiceMock,
},
{
provide: AuthService,
useClass: AuthServiceMock,
provide: PlatformServiceInterface,
useClass: PlatformServiceMock,
},
{
provide: FieldsService,
useClass: FieldsServiceMock,
},
],
}).compileComponents()
authService = TestBed.inject(AuthService)
searchService = TestBed.inject(SearchService)
searchFacade = TestBed.inject(SearchFacade)
routerFacade = TestBed.inject(RouterFacade)
platform = TestBed.inject(PlatformServiceInterface)
})

beforeEach(() => {
Expand All @@ -140,10 +140,7 @@ describe('HeaderComponent', () => {
describe('isAuthenticated$', () => {
describe('user is authenticated', () => {
beforeEach(() => {
;(authService as any)._authSubject$.next({
id: 'user-id',
name: 'testuser',
})
;(platform as any)._isAnonymous$.next(false)
})
it('displays favoriteBadge when authenticated', async () => {
const isAuthenticated = await firstValueFrom(
Expand All @@ -154,7 +151,7 @@ describe('HeaderComponent', () => {
})
describe('user is NOT authenticated', () => {
beforeEach(() => {
;(authService as any)._authSubject$.next(null)
;(platform as any)._isAnonymous$.next(true)
})
it('does NOT display favoriteBadge when NOT authenticated', async () => {
const isAuthenticated = await firstValueFrom(
Expand Down
21 changes: 12 additions & 9 deletions apps/datahub/src/app/home/home-header/home-header.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
import {
RouterFacade,
ROUTER_ROUTE_SEARCH,
RouterFacade,
} from '@geonetwork-ui/feature/router'
import {
FieldsService,
Expand All @@ -16,13 +16,16 @@ import {
SearchConfig,
SearchPreset,
} from '@geonetwork-ui/util/app-config'
import { SortByEnum, SortByField } from '@geonetwork-ui/common/domain/search'
import {
SortByEnum,
SortByField,
} from '@geonetwork-ui/common/domain/model/search'
import { map } from 'rxjs/operators'
import { ROUTER_ROUTE_NEWS } from '../../router/constants'
import { firstValueFrom, lastValueFrom } from 'rxjs'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { lastValueFrom } from 'rxjs'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
import { sortByFromString } from '@geonetwork-ui/util/shared'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'

marker('datahub.header.myfavorites')
marker('datahub.header.lastRecords')
Expand Down Expand Up @@ -50,7 +53,7 @@ export class HomeHeaderComponent {
public routerFacade: RouterFacade,
public searchFacade: SearchFacade,
private searchService: SearchService,
private authService: AuthService,
private platformService: PlatformServiceInterface,
private fieldsService: FieldsService
) {}

Expand All @@ -62,9 +65,9 @@ export class HomeHeaderComponent {
)
)

isAuthenticated$ = this.authService
.authReady()
.pipe(map((user) => !!user?.id))
isAuthenticated$ = this.platformService
.isAnonymous()
.pipe(map((isAnonymous) => !isAnonymous))

onFuzzySearchSelection(record: CatalogRecord) {
this.routerFacade.goToMetadata(record)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'
import { RouterFacade } from '@geonetwork-ui/feature/router'
import { FIELDS_BRIEF, SearchFacade } from '@geonetwork-ui/feature/search'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'datahub-last-created',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { SearchService } from '@geonetwork-ui/feature/search'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { Organization } from '@geonetwork-ui/common/domain/record'
import { Organization } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'datahub-organisations-page',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { SearchFiltersComponent } from './search-filters.component'
import { TranslateModule } from '@ngx-translate/core'
import { By } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { FieldFilters } from '@geonetwork-ui/common/domain/search'
import { FieldFilters } from '@geonetwork-ui/common/domain/model/search'
import { USER_FIXTURE } from '@geonetwork-ui/common/fixtures'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'

jest.mock('@geonetwork-ui/util/app-config', () => ({
getOptionalSearchConfig: () => ({
Expand Down Expand Up @@ -103,10 +104,8 @@ class FieldsServiceMock {
}
}

class AuthServiceMock {
user$ = new BehaviorSubject(user)
authReady = jest.fn(() => this._authSubject$)
_authSubject$ = new BehaviorSubject({})
class PlatformServiceMock {
getMe = jest.fn(() => new BehaviorSubject(user))
}

describe('SearchFiltersComponent', () => {
Expand Down Expand Up @@ -138,8 +137,8 @@ describe('SearchFiltersComponent', () => {
useClass: FieldsServiceMock,
},
{
provide: AuthService,
useClass: AuthServiceMock,
provide: PlatformServiceInterface,
useClass: PlatformServiceMock,
},
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
QueryList,
ViewChildren,
} from '@angular/core'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import {
FieldsService,
FilterDropdownComponent,
Expand All @@ -16,6 +15,7 @@ import {
import { getOptionalSearchConfig } from '@geonetwork-ui/util/app-config'
import { Observable, switchMap } from 'rxjs'
import { map } from 'rxjs/operators'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'

@Component({
selector: 'datahub-search-filters',
Expand Down Expand Up @@ -46,11 +46,11 @@ export class SearchFiltersComponent implements OnInit {
public searchFacade: SearchFacade,
private searchService: SearchService,
private fieldsService: FieldsService,
private authService: AuthService
private platformService: PlatformServiceInterface
) {}

ngOnInit(): void {
this.authService.user$.subscribe((user) => (this.userId = user?.id))
this.platformService.getMe().subscribe((user) => (this.userId = user?.id))
this.searchConfig = (
getOptionalSearchConfig().ADVANCED_FILTERS || [
'publisher',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'
import { RouterFacade } from '@geonetwork-ui/feature/router'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
import { MetadataQualityDisplay } from '@geonetwork-ui/ui/elements'
import {
MetadataQualityConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'
import { SearchService } from '@geonetwork-ui/feature/search'
import { getThemeConfig } from '@geonetwork-ui/util/app-config'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'datahub-header-record',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RecordDownloadsComponent } from './record-downloads.component'
import { Component, Input, NO_ERRORS_SCHEMA } from '@angular/core'
import { By } from '@angular/platform-browser'
import { DataService } from '@geonetwork-ui/feature/dataviz'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/record'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record'
import { MdViewFacade } from '@geonetwork-ui/feature/record'

// This is used to work around a very weird bug when comparing URL objects would fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { catchError, map, switchMap } from 'rxjs/operators'
import {
DatasetDistribution,
DatasetServiceDistribution,
} from '@geonetwork-ui/common/domain/record'
} from '@geonetwork-ui/common/domain/model/record'
import { MdViewFacade } from '@geonetwork-ui/feature/record'

@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ErrorType, MetadataQualityDisplay } from '@geonetwork-ui/ui/elements'
import { BehaviorSubject, combineLatest } from 'rxjs'
import { filter, map, mergeMap } from 'rxjs/operators'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { Organization } from '@geonetwork-ui/common/domain/record'
import { Organization } from '@geonetwork-ui/common/domain/model/record'
import { MdViewFacade } from '@geonetwork-ui/feature/record'

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'datahub-record-related-records',
Expand Down
2 changes: 1 addition & 1 deletion apps/metadata-converter/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, ViewChild } from '@angular/core'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
import { StatusComponent } from './components/status/status.component'
import { RecordOutputXmlComponent } from './components/record-output-xml/record-output-xml.component'
import { RecordFormComponent } from './components/record-form/record-form.component'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ServiceOnlineResource,
ServiceOnlineResourceType,
ServiceRecord,
} from '@geonetwork-ui/common/domain/record'
} from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'gn-ui-record-form',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, EventEmitter, Input, Output } from '@angular/core'
import { toModel, toXml } from '@geonetwork-ui/api/metadata-converter'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'gn-ui-status',
Expand Down
2 changes: 2 additions & 0 deletions apps/metadata-editor/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { extModules } from './build-specifics'
import { DashboardPageComponent } from './dashboard/dashboard-page.component'
import { EditorRouterService } from './router.service'
import { provideRepositoryUrl } from '@geonetwork-ui/api/repository'
import { provideGn4 } from '@geonetwork-ui/api/repository/gn4'

@NgModule({
declarations: [AppComponent],
Expand Down Expand Up @@ -58,6 +59,7 @@ import { provideRepositoryUrl } from '@geonetwork-ui/api/repository'
importProvidersFrom(TranslateModule.forRoot(TRANSLATE_DEFAULT_CONFIG)),
provideRepositoryUrl(() => getGlobalConfig().GN4_API_URL),
importProvidersFrom(EffectsModule.forRoot()),
provideGn4(),
],
bootstrap: [AppComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<button>
<mat-icon class="icon-btn material-symbols-outlined">settings</mat-icon>
</button>
<ng-container *ngrxLet="authService.user$ as user">
<ng-container *ngrxLet="platformService.getMe() as user">
<gn-ui-user-preview
*ngIf="user && user.name"
[user]="user"
Expand Down
Loading

0 comments on commit e7e9323

Please sign in to comment.