Skip to content

Commit

Permalink
add gn-record-view web component
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Dec 16, 2024
1 parent 3749bb3 commit 91e4058
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 13 deletions.
23 changes: 19 additions & 4 deletions apps/geoadmin-demo/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,34 @@
id="geoadmin-root"
src="https://map.geo.admin.ch/#embed?bgLayer=ch.swisstopo.pixelkarte-grau"
></iframe>

<input class="search-input" type="text" />

<!-- this stays hidden but is just there for initializing the GNUI global -->
<gn-search-input
style="display: none"
api-url="https://www.geocat.ch/geonetwork/srv/api"
primary-color="#0f4395"
secondary-color="#8bc832"
></gn-search-input>
<gn-results-list

<gn-record-view
api-url="https://www.geocat.ch/geonetwork/srv/api"
layout="ROW"
primary-color="#0f4395"
secondary-color="#8bc832"
></gn-results-list>
record-id="417e9f31-d9d7-4165-9a5c-2f12b7191926"
></gn-record-view>

<script>
// window.addEventListener(
// 'message',
// (e) => {
// if (e.origin !== 'https://map.geo.admin.ch') return
// console.log(e.data) // log iframe events
// },
// false
// )

GNUI.recordsRepository
.search({
filters: {
Expand All @@ -35,7 +50,7 @@
offset: 0,
limit: 10,
sort: ['desc', '_score'],
fields: ['resourceTitleObject', 'link'],
fields: ['resourceTitleObject', 'link', 'uuid'],
})
.subscribe(console.log)
</script>
Expand Down
13 changes: 12 additions & 1 deletion apps/geoadmin-demo/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ body {
border: 0;
}

gn-search-input {
.search-input {
position: absolute;
left: 20px;
top: 55px;
Expand All @@ -32,3 +32,14 @@ gn-results-list {
background: white;
overflow: auto;
}

gn-record-view {
position: absolute;
right: 20px;
top: 125px;
bottom: 20px;
width: 40%;
padding: 8px;
background: white;
overflow: auto;
}
15 changes: 8 additions & 7 deletions apps/geoadmin-demo/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
globalThis.ngJest = {
testEnvironmentOptions: {
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
},
}
import 'jest-preset-angular/setup-jest'
import '../../../jest.setup'

class ResizeObserverMock {
observe = jest.fn()
unobserve = jest.fn()
}

;(window as any).ResizeObserver = ResizeObserverMock
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import '../../../styles.css';

.mdc-menu-surface.mat-mdc-autocomplete-panel {
margin-top: 10px !important;
border-radius: 8px;
}

:host {
display: block;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<ng-container *ngrxLet="record$ as record">
<gn-ui-content-ghost
ghostClass="w-full h-full"
[showContent]="!!record?.title"
>
<div class="font-title text-[28px] line-clamp-3 mb-4">
{{ record.title }}
</div>
<gn-ui-metadata-info [metadata]="record"></gn-ui-metadata-info>

<gn-ui-image-overlay-preview
class="block h-[185px] mb-5"
[imageUrl]="record?.overviews?.[0]?.url"
>
</gn-ui-image-overlay-preview>
<gn-ui-metadata-contact [metadata]="record"> </gn-ui-metadata-contact>

<div class="font-title text-lg mt-4 mb-2 flex flex-row gap-4 items-center">
<span translate> record.metadata.download</span>
<gn-ui-previous-next-buttons
*ngIf="downloads.pagesCount > 1"
[listComponent]="downloads"
></gn-ui-previous-next-buttons>
</div>
<gn-ui-block-list
[pageSize]="4"
containerClass="gap-4 pt-3 pb-6"
#downloads
>
<gn-ui-download-item
#block
*ngFor="let otherLink of getDownloads(record.onlineResources)"
[link]="otherLink"
></gn-ui-download-item>
</gn-ui-block-list>

<div class="font-title text-lg mt-4 mb-2 flex flex-row gap-4 items-center">
<span translate>record.metadata.links</span>
<gn-ui-previous-next-buttons
*ngIf="links.pagesCount > 1"
[listComponent]="links"
></gn-ui-previous-next-buttons>
</div>
<gn-ui-block-list [pageSize]="4" containerClass="gap-4 pt-3 pb-6" #links>
<gn-ui-link-card
#block
*ngFor="let otherLink of getLinks(record.onlineResources)"
[link]="otherLink"
[compact]="true"
></gn-ui-link-card>
</gn-ui-block-list>

<div class="font-title text-lg mt-4 mb-2 flex flex-row gap-4 items-center">
<span translate>record.metadata.api</span>
<gn-ui-previous-next-buttons
*ngIf="apis.pagesCount > 1"
[listComponent]="apis"
></gn-ui-previous-next-buttons>
</div>
<gn-ui-block-list [pageSize]="4" containerClass="gap-4 pt-3 pb-6" #apis>
<gn-ui-api-card
#block
*ngFor="let otherLink of getAPIs(record.onlineResources)"
[link]="otherLink"
></gn-ui-api-card>
</gn-ui-block-list>
</gn-ui-content-ghost>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
ChangeDetectionStrategy,
Component,
Injector,
Input,
OnInit,
ViewEncapsulation,
} from '@angular/core'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { BaseComponent } from '../base.component'
import { Observable } from 'rxjs'
import {
CatalogRecord,
OnlineResource,
} from '@geonetwork-ui/common/domain/model/record'

// TODO in this component:
// - Support metadata quality option
// - show data preview

@Component({
selector: 'wc-gn-record-view',
templateUrl: './gn-record-view.component.html',
styleUrls: ['./gn-record-view.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.ShadowDom,
providers: [SearchFacade],
})
export class GnRecordViewComponent extends BaseComponent implements OnInit {
@Input() recordId!: string

record$: Observable<CatalogRecord>

constructor(injector: Injector) {
super(injector)
}

ngOnInit() {
super.ngOnInit()
// todo
this.record$ = this.recordsRepository.getRecord(this.recordId)
}

getDownloads(onlineResources: OnlineResource[]) {
return onlineResources.filter((d) => d.type === 'download')
}
getAPIs(onlineResources: OnlineResource[]) {
return onlineResources.filter((d) => d.type === 'service')
}
getLinks(onlineResources: OnlineResource[]) {
return onlineResources.filter((d) => d.type === 'link')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Web Component Demo</title>
<base href="./" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
type="text/css"
/>
<style>
body {
margin: 0;
}
header {
height: 200px;
background-color: #5bd261;
}
.container {
max-width: 750px;
margin-left: auto;
margin-right: auto;
padding-top: 3rem;
padding-bottom: 3rem;
}
</style>
</head>
<body>
<header>
<div class="container">
<script src="gn-wc.js"></script>
<gn-record-view
api-url="https://www.geo2france.fr/geonetwork/srv/api"
open-on-search="https://www.geo2france.fr/datahub/home/search/?q=${search}"
open-on-select="https://www.geo2france.fr/datahub/dataset/${uuid}"
primary-color="#0f4395"
secondary-color="#8bc832"
main-color="#555"
background-color="#fdfbff"
main-font="'Inter', sans-serif"
title-font="'DM Serif Display', serif"
></gn-record-view>
</div>
</header>
<main></main>
</body>
</html>
33 changes: 32 additions & 1 deletion apps/webcomponents/src/app/webcomponents.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ import { BrowserModule } from '@angular/platform-browser'
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import { FeatureRecordModule } from '@geonetwork-ui/feature/record'
import { FeatureSearchModule } from '@geonetwork-ui/feature/search'
import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import {
ApiCardComponent,
ContentGhostComponent,
DownloadItemComponent,
DownloadsListComponent,
ImageOverlayPreviewComponent,
LinkCardComponent,
MetadataContactComponent,
MetadataInfoComponent,
MetadataQualityComponent,
UiElementsModule,
} from '@geonetwork-ui/ui/elements'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import { UiSearchModule } from '@geonetwork-ui/ui/search'
import {
Expand Down Expand Up @@ -46,6 +57,12 @@ import { UiDatavizModule } from '@geonetwork-ui/ui/dataviz'
import { GnDatasetViewMapComponent } from './components/gn-dataset-view-map/gn-dataset-view-map.component'
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/repository/records-repository.interface'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import { GnRecordViewComponent } from './components/gn-record-view/gn-record-view.component'
import { LetDirective } from '@ngrx/component'
import {
BlockListComponent,
PreviousNextButtonsComponent,
} from '@geonetwork-ui/ui/layout'

const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
[GnFacetsComponent, 'gn-facets'],
Expand All @@ -57,6 +74,7 @@ const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
[GnMapViewerComponent, 'gn-map-viewer'],
[GnFigureDatasetsComponent, 'gn-figure-datasets'],
[GnDatasetViewMapComponent, 'gn-dataset-view-map'],
[GnRecordViewComponent, 'gn-record-view'],
]

@NgModule({
Expand All @@ -73,6 +91,7 @@ const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
GnMapViewerComponent,
GnFigureDatasetsComponent,
GnDatasetViewMapComponent,
GnRecordViewComponent,
],
imports: [
CommonModule,
Expand All @@ -99,6 +118,18 @@ const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
BrowserAnimationsModule,
MapStateContainerComponent,
LayersPanelComponent,
MetadataInfoComponent,
ContentGhostComponent,
LetDirective,
ImageOverlayPreviewComponent,
MetadataContactComponent,
MetadataQualityComponent,
DownloadsListComponent,
BlockListComponent,
LinkCardComponent,
ApiCardComponent,
DownloadItemComponent,
PreviousNextButtonsComponent,
],
providers: [
provideGn4(),
Expand Down

0 comments on commit 91e4058

Please sign in to comment.