1
1
import { createDispatchMap , select , Store } from '@ngxs/store' ;
2
2
3
- import { TranslatePipe } from '@ngx-translate/core' ;
3
+ import { TranslatePipe , TranslateService } from '@ngx-translate/core' ;
4
4
5
5
import { Button } from 'primeng/button' ;
6
6
import { Menu } from 'primeng/menu' ;
@@ -9,6 +9,7 @@ import { Tab, TabList, Tabs } from 'primeng/tabs';
9
9
10
10
import { switchMap } from 'rxjs' ;
11
11
12
+ import { DatePipe } from '@angular/common' ;
12
13
import {
13
14
ChangeDetectionStrategy ,
14
15
Component ,
@@ -37,8 +38,9 @@ import {
37
38
} from '@osf/features/metadata/store' ;
38
39
import { LoadingSpinnerComponent , MetadataTabsComponent , SubHeaderComponent } from '@osf/shared/components' ;
39
40
import { MetadataResourceEnum , ResourceType } from '@osf/shared/enums' ;
41
+ import { pathJoin } from '@osf/shared/helpers' ;
40
42
import { MetadataTabsModel , OsfFile } from '@osf/shared/models' ;
41
- import { CustomConfirmationService , ToastService } from '@osf/shared/services' ;
43
+ import { CustomConfirmationService , MetaTagsService , ToastService } from '@osf/shared/services' ;
42
44
43
45
import {
44
46
FileKeywordsComponent ,
@@ -58,6 +60,8 @@ import {
58
60
GetFileRevisions ,
59
61
} from '../../store' ;
60
62
63
+ import { environment } from 'src/environments/environment' ;
64
+
61
65
@Component ( {
62
66
selector : 'osf-file-detail' ,
63
67
imports : [
@@ -80,6 +84,7 @@ import {
80
84
templateUrl : './file-detail.component.html' ,
81
85
styleUrl : './file-detail.component.scss' ,
82
86
changeDetection : ChangeDetectionStrategy . OnPush ,
87
+ providers : [ DatePipe ] ,
83
88
} )
84
89
export class FileDetailComponent {
85
90
@HostBinding ( 'class' ) classes = 'flex flex-column flex-1 w-full h-full' ;
@@ -91,6 +96,9 @@ export class FileDetailComponent {
91
96
readonly sanitizer = inject ( DomSanitizer ) ;
92
97
readonly toastService = inject ( ToastService ) ;
93
98
readonly customConfirmationService = inject ( CustomConfirmationService ) ;
99
+ private readonly metaTags = inject ( MetaTagsService ) ;
100
+ private readonly datePipe = inject ( DatePipe ) ;
101
+ private readonly translateService = inject ( TranslateService ) ;
94
102
95
103
private readonly actions = createDispatchMap ( {
96
104
getFile : GetFile ,
@@ -110,8 +118,11 @@ export class FileDetailComponent {
110
118
isFileLoading = select ( FilesSelectors . isOpenedFileLoading ) ;
111
119
cedarRecords = select ( MetadataSelectors . getCedarRecords ) ;
112
120
cedarTemplates = select ( MetadataSelectors . getCedarTemplates ) ;
113
-
114
121
isAnonymous = select ( FilesSelectors . isFilesAnonymous ) ;
122
+ fileCustomMetadata = select ( FilesSelectors . getFileCustomMetadata ) ;
123
+ resourceMetadata = select ( FilesSelectors . getResourceMetadata ) ;
124
+ resourceContributors = select ( FilesSelectors . getContributors ) ;
125
+
115
126
safeLink : SafeResourceUrl | null = null ;
116
127
resourceId = '' ;
117
128
resourceType = '' ;
@@ -162,6 +173,33 @@ export class FileDetailComponent {
162
173
selectedCedarTemplate = signal < CedarMetadataDataTemplateJsonApi | null > ( null ) ;
163
174
cedarFormReadonly = signal < boolean > ( true ) ;
164
175
176
+ private readonly effectMetaTags = effect ( ( ) => {
177
+ const metaTagsData = this . metaTagsData ( ) ;
178
+ if ( metaTagsData ) {
179
+ this . metaTags . updateMetaTags ( metaTagsData , this . destroyRef ) ;
180
+ }
181
+ } ) ;
182
+
183
+ private readonly metaTagsData = computed ( ( ) => {
184
+ const file = this . file ( ) ;
185
+ if ( ! file ) return null ;
186
+ return {
187
+ title : this . fileCustomMetadata ( ) ?. title || file . name ,
188
+ description :
189
+ this . fileCustomMetadata ( ) ?. description ??
190
+ this . translateService . instant ( 'files.metaTagDescriptionPlaceholder' ) ,
191
+ url : pathJoin ( environment . webUrl , this . fileGuid ) ,
192
+ publishedDate : this . datePipe . transform ( file . dateCreated , 'yyyy-MM-dd' ) ,
193
+ modifiedDate : this . datePipe . transform ( file . dateModified , 'yyyy-MM-dd' ) ,
194
+ language : this . fileCustomMetadata ( ) ?. language ,
195
+ contributors : this . resourceContributors ( ) ?. map ( ( contributor ) => ( {
196
+ fullName : contributor . fullName ,
197
+ givenName : contributor . givenName ,
198
+ familyName : contributor . familyName ,
199
+ } ) ) ,
200
+ } ;
201
+ } ) ;
202
+
165
203
constructor ( ) {
166
204
this . route . params
167
205
. pipe (
0 commit comments