Skip to content

Commit ce0774f

Browse files
authored
feat(signposting): add signposting to project/registration metadata pages (#880)
1 parent 2eadda3 commit ce0774f

7 files changed

Lines changed: 60 additions & 5 deletions

File tree

src/app/app.routes.server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ export const serverRoutes: ServerRoute[] = [
137137
path: ':id/overview',
138138
renderMode: RenderMode.Server,
139139
},
140+
{
141+
path: ':id/metadata/:recordId',
142+
renderMode: RenderMode.Server,
143+
},
140144
{
141145
path: ':id/files/**',
142146
renderMode: RenderMode.Server,

src/app/features/files/pages/file-detail/file-detail.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
effect,
2020
HostBinding,
2121
inject,
22+
OnDestroy,
2223
OnInit,
2324
signal,
2425
} from '@angular/core';
@@ -96,7 +97,7 @@ import {
9697
changeDetection: ChangeDetectionStrategy.OnPush,
9798
providers: [DatePipe],
9899
})
99-
export class FileDetailComponent implements OnInit {
100+
export class FileDetailComponent implements OnInit, OnDestroy {
100101
@HostBinding('class') classes = 'flex flex-column flex-1 w-full h-full';
101102

102103
readonly store = inject(Store);
@@ -291,6 +292,12 @@ export class FileDetailComponent implements OnInit {
291292
this.signpostingService.addSignposting(this.fileGuid);
292293
}
293294

295+
ngOnDestroy(): void {
296+
if (this.fileGuid) {
297+
this.signpostingService.removeSignpostingLinkTags();
298+
}
299+
}
300+
294301
getIframeLink(version: string) {
295302
const url = this.getMfrUrlWithVersion(version);
296303
if (url) {

src/app/features/metadata/metadata.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
DestroyRef,
1212
effect,
1313
inject,
14+
OnDestroy,
1415
OnInit,
1516
signal,
1617
} from '@angular/core';
@@ -24,6 +25,7 @@ import { MetadataResourceEnum } from '@osf/shared/enums/metadata-resource.enum';
2425
import { ResourceType } from '@osf/shared/enums/resource-type.enum';
2526
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
2627
import { CustomDialogService } from '@osf/shared/services/custom-dialog.service';
28+
import { SignpostingService } from '@osf/shared/services/signposting.service';
2729
import { ToastService } from '@osf/shared/services/toast.service';
2830
import { CollectionsSelectors, GetProjectSubmissions } from '@osf/shared/stores/collections';
2931
import {
@@ -117,14 +119,15 @@ import {
117119
styleUrl: './metadata.component.scss',
118120
changeDetection: ChangeDetectionStrategy.OnPush,
119121
})
120-
export class MetadataComponent implements OnInit {
122+
export class MetadataComponent implements OnInit, OnDestroy {
121123
private readonly activeRoute = inject(ActivatedRoute);
122124
private readonly router = inject(Router);
123125
private readonly destroyRef = inject(DestroyRef);
124126
private readonly customDialogService = inject(CustomDialogService);
125127
private readonly toastService = inject(ToastService);
126128
private readonly customConfirmationService = inject(CustomConfirmationService);
127129
private readonly environment = inject(ENVIRONMENT);
130+
private readonly signpostingService = inject(SignpostingService);
128131

129132
private resourceId = '';
130133

@@ -264,12 +267,18 @@ export class MetadataComponent implements OnInit {
264267
this.actions.getCedarTemplates();
265268
this.actions.fetchSelectedSubjects(this.resourceId, this.resourceType());
266269

270+
this.signpostingService.addMetadataSignposting(this.resourceId);
271+
267272
if (this.isProjectType()) {
268273
this.actions.getProjectSubmissions(this.resourceId);
269274
}
270275
}
271276
}
272277

278+
ngOnDestroy(): void {
279+
this.signpostingService.removeSignpostingLinkTags();
280+
}
281+
273282
onTabChange(tabId: string | number): void {
274283
const tab = this.tabs().find((x) => x.id === tabId.toString());
275284

src/app/features/preprints/pages/preprint-details/preprint-details.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
317317
this.actions.clearCurrentProvider();
318318
}
319319

320+
this.signpostingService.removeSignpostingLinkTags();
321+
320322
this.helpScoutService.unsetResourceType();
321323
}
322324

src/app/features/project/overview/project-overview.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
effect,
1717
HostBinding,
1818
inject,
19+
OnDestroy,
1920
OnInit,
2021
PLATFORM_ID,
2122
} from '@angular/core';
@@ -94,7 +95,7 @@ import {
9495
],
9596
changeDetection: ChangeDetectionStrategy.OnPush,
9697
})
97-
export class ProjectOverviewComponent implements OnInit {
98+
export class ProjectOverviewComponent implements OnInit, OnDestroy {
9899
@HostBinding('class') classes = 'flex flex-1 flex-column w-full h-full';
99100

100101
private readonly route = inject(ActivatedRoute);
@@ -199,6 +200,10 @@ export class ProjectOverviewComponent implements OnInit {
199200
}
200201
}
201202

203+
ngOnDestroy(): void {
204+
this.signpostingService.removeSignpostingLinkTags();
205+
}
206+
202207
handleOpenMakeDecisionDialog() {
203208
this.customDialogService
204209
.open(MakeDecisionDialogComponent, {

src/app/features/registry/pages/registry-overview/registry-overview.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
effect,
1616
HostBinding,
1717
inject,
18+
OnDestroy,
1819
OnInit,
1920
signal,
2021
} from '@angular/core';
@@ -77,7 +78,7 @@ import {
7778
styleUrl: './registry-overview.component.scss',
7879
changeDetection: ChangeDetectionStrategy.OnPush,
7980
})
80-
export class RegistryOverviewComponent implements OnInit {
81+
export class RegistryOverviewComponent implements OnInit, OnDestroy {
8182
@HostBinding('class') classes = 'flex-1 flex flex-column w-full h-full';
8283
private readonly route = inject(ActivatedRoute);
8384
private readonly router = inject(Router);
@@ -176,6 +177,10 @@ export class RegistryOverviewComponent implements OnInit {
176177
this.signpostingService.addSignposting(this.registryId());
177178
}
178179

180+
ngOnDestroy(): void {
181+
this.signpostingService.removeSignpostingLinkTags();
182+
}
183+
179184
openRevision(revisionIndex: number): void {
180185
this.selectedRevisionIndex.set(revisionIndex);
181186
}

src/app/shared/services/signposting.service.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,30 @@ export class SignpostingService {
2121
this.addSignpostingLinkTags(links);
2222
}
2323

24-
private generateSignpostingLinks(guid: string): SignpostingLink[] {
24+
addMetadataSignposting(guid: string): void {
25+
const links = this.generateSignpostingLinks(guid, true);
26+
27+
this.addSignpostingLinkHeaders(links);
28+
this.addSignpostingLinkTags(links);
29+
}
30+
31+
removeSignpostingLinkTags(): void {
32+
const linkElements = this.document.head.querySelectorAll('link[rel="linkset"], link[rel="describes"]');
33+
linkElements.forEach((linkElement) => {
34+
this.renderer.removeChild(this.document.head, linkElement);
35+
});
36+
}
37+
38+
private generateSignpostingLinks(guid: string, isMetadata?: boolean): SignpostingLink[] {
39+
if (isMetadata) {
40+
return [
41+
{
42+
rel: 'describes',
43+
href: `${this.environment.webUrl}/${guid}/`,
44+
type: 'text/html',
45+
},
46+
];
47+
}
2548
const baseUrl = `${this.environment.webUrl}/metadata/${guid}/`;
2649

2750
return [

0 commit comments

Comments
 (0)