Skip to content

Commit 27de12f

Browse files
Merge pull request #1529 from geonetwork/dh-editor-link
[Datahub]: open editor from template url
2 parents 9badbe2 + f9a253f commit 27de12f

35 files changed

Lines changed: 600 additions & 258 deletions

apps/datahub-e2e/src/e2e/dataset/datasetHeader.cy.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('dataset: header', () => {
3131
.should('be.visible')
3232

3333
// it should display the title
34-
cy.get('datahub-header-record')
34+
cy.get('datahub-record-header')
3535
.find('header')
3636
.find('.font-title')
3737
.invoke('text')
@@ -156,4 +156,24 @@ describe('dataset: header', () => {
156156
.find('[data-cy="resources-mobile-menu"]')
157157
.should('not.exist')
158158
})
159+
// EDIT LINK
160+
it('should display the edit link when configured and the user can edit', () => {
161+
cy.intercept('GET', '/assets/configuration/default.toml', {
162+
fixture: 'config-with-edit-url-template.toml',
163+
})
164+
cy.login()
165+
cy.visit('/dataset/04bcec79-5b25-4b16-b635-73115f7456e4')
166+
167+
//it should display the edit link on editable dataset
168+
cy.get('datahub-record-page')
169+
.find('[data-cy=editButton]')
170+
.should('be.visible')
171+
172+
cy.visit('/dataset/01491630-78ce-49f3-b479-4b30dabc4c69')
173+
174+
//it should not display the edit link on non editable dataset (harvested)
175+
cy.get('datahub-record-page')
176+
.find('[data-cy=editButton]')
177+
.should('not.exist')
178+
})
159179
})

apps/datahub-e2e/src/e2e/dataset/datasetPreview.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ beforeEach(() => {
103103
)
104104
cy.intercept(
105105
'GET',
106-
'https://stacapi-cdos.apps.okd.crocc.meso.umontpellier.fr/collections/sentinel2-l2a-sen2cor/items?limit=12&datetime=2016-01-02T10%3A54%3A42.030Z%2F2019-12-31T23%3A00%3A00.000Z',
106+
'https://stacapi-cdos.apps.okd.crocc.meso.umontpellier.fr/collections/sentinel2-l2a-sen2cor/items?limit=12&datetime=2016-01-02T10%3A54%3A42.030Z%2F2020-01-01T00%3A00%3A00.000Z',
107107
{
108108
fixture: 'stac-items-date-modified.json',
109109
}

apps/datahub-e2e/src/e2e/reuse/reuseDetailPage.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('reuse pages', () => {
55
cy.visit('/reuse/7eb795c2-d612-4b5e-b15e-d985b0f4e697')
66
// Header
77
// should display a link to the reuse
8-
cy.get('datahub-header-record')
8+
cy.get('datahub-record-header')
99
.find('header')
1010
.find('a')
1111
.first()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[global]
2+
geonetwork4_api_url = "/geonetwork/srv/api"
3+
proxy_path = ""
4+
5+
edit_url_template = "/metadata-editor/edit/${record_id}"
6+
7+
[theme]
8+
primary_color = "#c82850"
9+
secondary_color = "#001638"
10+
main_color = "#212029" # All-purpose text color
11+
background_color = "#fdfbff"

apps/datahub/src/app/record/navigation-bar/navigation-bar.component.css renamed to apps/datahub/src/app/record/record-header/navigation-bar/navigation-bar.component.css

File renamed without changes.

apps/datahub/src/app/record/navigation-bar/navigation-bar.component.html renamed to apps/datahub/src/app/record/record-header/navigation-bar/navigation-bar.component.html

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
<ng-icon name="matArrowBack"></ng-icon>
2424
</gn-ui-button>
2525
</div>
26+
2627
@if ((isMobile$ | async) === false) {
2728
@for (l of anchorLinks; track l) {
2829
<button
2930
type="button"
3031
[attr.data-cy]="l.anchor"
31-
gnUiAnchorLink="{{ l.anchor }}"
32+
[gnUiAnchorLink]="l.anchor"
3233
gnUiAnchorLinkDisabledClass="sm:hidden"
3334
gnUiAnchorLinkInViewClass="!border-b-primary border-b-[3px] pb-0"
3435
gnUiAnchorLinkOutOfViewClass="pb-1"
@@ -38,20 +39,17 @@
3839
{{ l.label }}
3940
</button>
4041
}
41-
}
42-
@if ((isMobile$ | async) === true) {
42+
} @else {
4343
<div
4444
(click)="toggleMobileMenu()"
4545
class="w-full flex justify-start items-start cursor-pointer"
4646
>
47-
@if ((isMobile$ | async) === true) {
48-
<button
49-
type="button"
50-
class="h-[60px] z-50 inline-flex items-center justify-center p-2 rounded-md shrink-0"
51-
>
52-
<ng-icon name="iconoirMenu" size="24px"></ng-icon>
53-
</button>
54-
}
47+
<button
48+
type="button"
49+
class="h-[60px] z-50 inline-flex items-center justify-center p-2 rounded-md shrink-0"
50+
>
51+
<ng-icon name="iconoirMenu" size="24px"></ng-icon>
52+
</button>
5553
@if (displayMobileMenu) {
5654
<div
5755
class="bg-nav-bar-color -ml-[60px] absolute shrink truncate w-screen border-b-2 border-b-slate-200"
@@ -61,7 +59,7 @@
6159
<div class="pl-[100px]">
6260
<button
6361
attr.data-cy="{{ l.anchor }}-mobile-menu"
64-
gnUiAnchorLink="{{ l.anchor }}"
62+
[gnUiAnchorLink]="l.anchor"
6563
gnUiAnchorLinkDisabledClass="hidden"
6664
class="h-[60px] block px-3 py-3 hover:bg-slate-50 font-medium text-left text-wrap uppercase"
6765
translate
@@ -73,14 +71,13 @@
7371
</div>
7472
}
7573
</div>
76-
}
77-
@if (!displayMobileMenu) {
74+
} @else {
7875
<div class="h-[60px]">
7976
@for (l of anchorLinks; track l) {
8077
<div>
8178
<button
8279
attr.data-cy="{{ l.anchor }}-mobile-title"
83-
gnUiAnchorLink="{{ l.anchor }}"
80+
[gnUiAnchorLink]="l.anchor"
8481
gnUiAnchorLinkDisabledClass="hidden"
8582
gnUiAnchorLinkInViewClass="block"
8683
gnUiAnchorLinkOutOfViewClass="hidden"
@@ -93,33 +90,26 @@
9390
</button>
9491
</div>
9592
}
96-
@if ((isMobile$ | async) === true && !displayMobileMenu) {
97-
<button
98-
class="h-[60px] block px-3 py-3 rounded-md font-medium shrink text-wrap text-left uppercase"
99-
translate
100-
>
101-
navbar.mobile.menuTitle
102-
</button>
103-
}
93+
94+
<button
95+
class="h-[60px] block px-3 py-3 rounded-md font-medium shrink text-wrap text-left uppercase"
96+
translate
97+
>
98+
navbar.mobile.menuTitle
99+
</button>
104100
</div>
105101
}
106102
</div>
107103
}
104+
108105
<div
109106
class="h-[60px] z-50 flex flex-row gap-3 justify-center items-center px-4 lg:pl-4 lg:justify-end text-sm"
110107
[class]="displayMobileMenu ? 'border-l-2 border-slate-200' : ''"
111108
>
112-
@if (metadata?.uniqueIdentifier && !isAuthDisabled) {
113-
<gn-ui-favorite-star
114-
[record]="metadata"
115-
[buttonType]="'outline'"
116-
[displayCount]="false"
117-
class="flex text-background content-center"
118-
></gn-ui-favorite-star>
119-
}
120-
@if (showLanguageSwitcher) {
121-
<gn-ui-language-switcher></gn-ui-language-switcher>
122-
}
109+
<datahub-record-actions
110+
[metadata]="metadata"
111+
[showLabel]="false"
112+
></datahub-record-actions>
123113
</div>
124114
</div>
125115
</nav>

apps/datahub/src/app/record/navigation-bar/navigation-bar.component.spec.ts renamed to apps/datahub/src/app/record/record-header/navigation-bar/navigation-bar.component.spec.ts

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,34 @@
1-
import { Location } from '@angular/common'
21
import { ElementRef } from '@angular/core'
32
import { ComponentFixture, TestBed } from '@angular/core/testing'
4-
import { Router } from '@angular/router'
5-
import { SearchService } from '@geonetwork-ui/feature/search'
63
import { MockBuilder, MockProvider } from 'ng-mocks'
7-
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
4+
import { BehaviorSubject } from 'rxjs'
5+
import { RecordHeaderService } from '../record-header.service'
86
import { NavigationBarComponent } from './navigation-bar.component'
97

108
jest.mock('@geonetwork-ui/util/app-config', () => ({
11-
getGlobalConfig() {
12-
return {
13-
LANGUAGES: ['en', 'es'],
14-
}
15-
},
169
getOptionalSearchConfig() {
1710
return {
1811
LIMIT: 10,
1912
}
2013
},
2114
}))
2215

23-
const routerMock: Partial<Router> = {
24-
lastSuccessfulNavigation: {
25-
previousNavigation: null,
26-
} as any,
27-
navigateByUrl: jest.fn(),
28-
}
29-
const locationMock: Partial<Location> = {
30-
back: jest.fn(),
31-
}
32-
3316
describe('NavigationBarComponent', () => {
3417
let component: NavigationBarComponent
3518
let fixture: ComponentFixture<NavigationBarComponent>
36-
let router: Router
3719

3820
beforeEach(() => MockBuilder(NavigationBarComponent))
3921

4022
beforeEach(async () => {
4123
await TestBed.configureTestingModule({
4224
providers: [
43-
MockProvider(SearchService, {
44-
updateFilters: jest.fn(),
45-
}),
46-
{
47-
provide: Router,
48-
useValue: routerMock,
49-
},
50-
{
51-
provide: Location,
52-
useValue: locationMock,
53-
},
54-
MockProvider(PlatformServiceInterface, {
55-
supportsAuthentication: jest.fn(() => true),
25+
MockProvider(RecordHeaderService, {
26+
back: jest.fn(),
27+
canEditFromUrl$: new BehaviorSubject(true),
28+
openEditUrl: jest.fn(),
5629
}),
5730
],
5831
}).compileComponents()
59-
router = TestBed.inject(Router)
6032
})
6133

6234
beforeEach(() => {
@@ -121,18 +93,4 @@ describe('NavigationBarComponent', () => {
12193
expect(component.displayMobileMenu).toBe(false)
12294
})
12395
})
124-
125-
describe('#back', () => {
126-
it('should call the back function of Location if previous navigation', () => {
127-
router.lastSuccessfulNavigation.previousNavigation = {} as any
128-
component.back()
129-
expect(locationMock.back).toHaveBeenCalled()
130-
})
131-
132-
it('should call the navigateByUrl function of Router to /search if no previous navigation', () => {
133-
router.lastSuccessfulNavigation.previousNavigation = null
134-
component.back()
135-
expect(router.navigateByUrl).toHaveBeenCalledWith('/search')
136-
})
137-
})
13896
})

apps/datahub/src/app/record/navigation-bar/navigation-bar.component.ts renamed to apps/datahub/src/app/record/record-header/navigation-bar/navigation-bar.component.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CommonModule, Location } from '@angular/common'
1+
import { CommonModule } from '@angular/common'
22
import {
33
ChangeDetectionStrategy,
44
Component,
@@ -8,20 +8,17 @@ import {
88
ViewChild,
99
inject,
1010
} from '@angular/core'
11-
import { Router } from '@angular/router'
1211
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
1312
import { DatasetRecord } from '@geonetwork-ui/common/domain/model/record'
14-
import { FavoriteStarComponent } from '@geonetwork-ui/feature/search'
15-
import { LanguageSwitcherComponent } from '@geonetwork-ui/ui/catalog'
1613
import { ButtonComponent } from '@geonetwork-ui/ui/inputs'
1714
import { AnchorLinkDirective } from '@geonetwork-ui/ui/layout'
18-
import { getGlobalConfig } from '@geonetwork-ui/util/app-config'
1915
import { getIsMobile } from '@geonetwork-ui/util/shared'
20-
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
2116
import { NgIcon, provideIcons, provideNgIconsConfig } from '@ng-icons/core'
2217
import { iconoirMenu } from '@ng-icons/iconoir'
2318
import { matArrowBack } from '@ng-icons/material-icons/baseline'
2419
import { TranslateDirective } from '@ngx-translate/core'
20+
import { RecordActionsComponent } from '../record-actions/record-actions.component'
21+
import { RecordHeaderService } from '../record-header.service'
2522

2623
marker('record.metadata.about')
2724
marker('record.metadata.capabilities')
@@ -41,9 +38,8 @@ marker('record.metadata.userFeedbacks')
4138
CommonModule,
4239
TranslateDirective,
4340
ButtonComponent,
44-
LanguageSwitcherComponent,
45-
FavoriteStarComponent,
4641
AnchorLinkDirective,
42+
RecordActionsComponent,
4743
],
4844
viewProviders: [
4945
provideIcons({ iconoirMenu, matArrowBack }),
@@ -53,9 +49,7 @@ marker('record.metadata.userFeedbacks')
5349
],
5450
})
5551
export class NavigationBarComponent {
56-
private router = inject(Router)
57-
private location = inject(Location)
58-
private platformServiceInterface = inject(PlatformServiceInterface)
52+
private headerService = inject(RecordHeaderService)
5953

6054
@Input() metadata: DatasetRecord
6155
@ViewChild('navBar', { static: false }) mobileMenuRef: ElementRef
@@ -90,13 +84,8 @@ export class NavigationBarComponent {
9084
label: 'record.metadata.userFeedbacks',
9185
},
9286
]
93-
showLanguageSwitcher = getGlobalConfig().LANGUAGES?.length > 0
9487
isMobile$ = getIsMobile()
9588

96-
get isAuthDisabled(): boolean {
97-
return !this.platformServiceInterface.supportsAuthentication()
98-
}
99-
10089
@HostListener('window:scroll', [])
10190
onWindowScroll() {
10291
this.displayMobileMenu = false
@@ -115,9 +104,8 @@ export class NavigationBarComponent {
115104
toggleMobileMenu() {
116105
this.displayMobileMenu = !this.displayMobileMenu
117106
}
107+
118108
back() {
119-
this.router.lastSuccessfulNavigation.previousNavigation
120-
? this.location.back()
121-
: this.router.navigateByUrl('/search')
109+
this.headerService.back()
122110
}
123111
}

apps/datahub/src/app/record/record-header/record-actions/record-actions.component.css

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<div class="flex flex-row content-center gap-3">
2+
@if ((canEdit$ | async) && (isMobile$ | async) === false) {
3+
<gn-ui-button
4+
type="outline"
5+
(buttonClick)="openEdit()"
6+
[style.--gn-ui-button-color]="color"
7+
[style.--gn-ui-button-background]="'none'"
8+
data-cy="editButton"
9+
>
10+
<ng-icon name="matEditNote"></ng-icon>
11+
@if (showLabel) {
12+
<span class="mx-2">{{
13+
'datahub.header.edit.url.open' | translate
14+
}}</span>
15+
}
16+
</gn-ui-button>
17+
}
18+
@if (metadata?.uniqueIdentifier && !isAuthDisabled) {
19+
<gn-ui-favorite-star
20+
[record]="metadata"
21+
[displayLabel]="showLabel && (isMobile$ | async) === false"
22+
[displayCount]="false"
23+
class="flex content-center"
24+
[buttonType]="'outline'"
25+
[style.--gn-ui-button-color]="color"
26+
[style.--gn-ui-button-background]="'none'"
27+
></gn-ui-favorite-star>
28+
}
29+
@if (showLanguageSwitcher) {
30+
<gn-ui-language-switcher
31+
[style.--color-main]="color"
32+
[style.--gn-ui-button-background]="'none'"
33+
></gn-ui-language-switcher>
34+
}
35+
</div>

0 commit comments

Comments
 (0)