@@ -10,6 +10,18 @@ import {
1010 ActivatedRoute ,
1111 Router ,
1212} from '@angular/router' ;
13+ import { UpdateDataService } from '@dspace/core/data/update-data.service' ;
14+ import {
15+ APP_DATA_SERVICES_MAP ,
16+ LazyDataServicesMap ,
17+ } from '@dspace/core/data-services-map-type' ;
18+ import { lazyDataService } from '@dspace/core/lazy-data-service' ;
19+ import { NotificationsService } from '@dspace/core/notification-system/notifications.service' ;
20+ import {
21+ hasNoValue ,
22+ hasValue ,
23+ isNotEmpty ,
24+ } from '@dspace/shared/utils/empty.util' ;
1325import {
1426 TranslateModule ,
1527 TranslateService ,
@@ -22,35 +34,26 @@ import {
2234import {
2335 first ,
2436 map ,
37+ switchMap ,
2538} from 'rxjs/operators' ;
2639
27- import { getDSORoute } from '../../core/router/utils/dso-route.utils' ;
28- import { DATA_SERVICE_FACTORY } from '../../core/cache/builders/build-decorators' ;
29- import { PatchData } from '../../core/data/base/patch-data' ;
3040import { RemoteData } from '../../core/data/remote-data' ;
41+ import { getDSORoute } from '../../core/router/utils/dso-route.utils' ;
3142import { DSpaceObject } from '../../core/shared/dspace-object.model' ;
32- import { GenericConstructor } from '../../core/shared/generic-constructor' ;
3343import {
3444 getFirstCompletedRemoteData ,
3545 getFirstSucceededRemoteDataPayload ,
3646} from '../../core/shared/operators' ;
3747import { ResourceType } from '../../core/shared/resource-type' ;
38- import {
39- hasNoValue ,
40- hasValue ,
41- isNotEmpty ,
42- } from '@dspace/shared/utils/empty.util' ;
43- import { NotificationsService } from '@dspace/core/notification-system/notifications.service' ;
4448import { PdfViewerEnableComponent } from '../pdf-viewer-enable/pdf-viewer-enable.component' ;
4549
4650@Component ( {
4751 selector : 'ds-pdf-viewer-enable-dso' ,
4852 templateUrl : './pdf-viewer-enable-dso.component.html' ,
4953 styleUrls : [ './pdf-viewer-enable-dso.component.scss' ] ,
50- standalone : true ,
5154 imports : [
52- PdfViewerEnableComponent ,
5355 CommonModule ,
56+ PdfViewerEnableComponent ,
5457 TranslateModule ,
5558 ] ,
5659} )
@@ -62,7 +65,7 @@ export class PdfViewerEnableDsoComponent implements OnInit, OnDestroy {
6265
6366 enableViewer : boolean ;
6467
65- protected dataservice : PatchData < DSpaceObject > ;
68+ protected dsoDataService : UpdateDataService < DSpaceObject > ;
6669
6770 buttonStyle$ : Observable < string > ;
6871
@@ -75,7 +78,7 @@ export class PdfViewerEnableDsoComponent implements OnInit, OnDestroy {
7578 protected notificationsService : NotificationsService ,
7679 protected translate : TranslateService ,
7780 protected parentInjector : Injector ,
78- @Inject ( DATA_SERVICE_FACTORY ) private getDataServiceFor : ( resourceType : ResourceType ) => GenericConstructor < any > ,
81+ @Inject ( APP_DATA_SERVICES_MAP ) private dataServiceMap : LazyDataServicesMap ,
7982 ) {
8083 }
8184
@@ -85,46 +88,41 @@ export class PdfViewerEnableDsoComponent implements OnInit, OnDestroy {
8588 this . subs . push (
8689 this . dsoRD$ . pipe (
8790 getFirstSucceededRemoteDataPayload ( ) ,
88- ) . subscribe ( async ( dso ) => {
89- this . initialDSO = dso ;
90-
91- let resourceType = this . initialDSO . type ;
92-
93- if ( isNotEmpty ( resourceType ) && hasNoValue ( resourceType . value ) ) {
94- resourceType = new ResourceType ( resourceType as any as string ) ;
95- }
96-
97- const provider = this . getDataServiceFor ( resourceType ) ;
98- const DataServiceClass = hasValue ( provider ) && typeof ( provider as any ) . then === 'function'
99- ? await ( provider as unknown as Promise < any > )
100- : provider ;
101- if ( hasValue ( DataServiceClass ) ) {
102- this . dataservice = Injector . create ( {
103- providers : [ ] ,
104- parent : this . parentInjector ,
105- } ) . get ( DataServiceClass ) ;
106- }
107- } ) ) ;
91+ switchMap ( ( dso : DSpaceObject ) => {
92+ this . initialDSO = dso ;
93+
94+ let resourceType = this . initialDSO . type ;
95+ if ( isNotEmpty ( resourceType ) && hasNoValue ( resourceType . value ) ) {
96+ resourceType = new ResourceType ( resourceType as any as string ) ;
97+ }
98+
99+ const lazyProvider$ : Observable < UpdateDataService < DSpaceObject > > = lazyDataService ( this . dataServiceMap , resourceType . value , this . parentInjector ) ;
100+ return lazyProvider$ ;
101+ } ) ,
102+ ) . subscribe ( ( lazyDsoDataService : UpdateDataService < DSpaceObject > ) => {
103+ this . dsoDataService = lazyDsoDataService ;
104+ } ) ,
105+ ) ;
108106 this . buttonStyle$ = this . route . data . pipe ( first ( ) ,
109107 map ( ( data ) => data . buttonStyle ) ) ;
110108 }
111109
112110 onSubmit ( ) : void {
113- if ( hasNoValue ( this . dataservice ) || hasNoValue ( this . initialDSO ) ) {
111+ if ( hasNoValue ( this . dsoDataService ) || hasNoValue ( this . initialDSO ) ) {
114112 return ;
115113 }
116- const operations : Operation [ ] = [ ] ;
117114
115+ const operations : Operation [ ] = [ ] ;
118116 operations . push ( {
119- op : ' replace',
117+ op : hasValue ( this . initialDSO . firstMetadataValue ( 'dspace.pdfviewer.enabled' ) ) ? ' replace' : 'add ',
120118 path : `/metadata/dspace.pdfviewer.enabled` ,
121119 value : {
122120 value : this . enableViewer ,
123121 language : null ,
124122 } ,
125123 } ) ;
126124
127- this . handleResponse ( this . dataservice . patch ( this . initialDSO , operations ) ) ;
125+ this . handleResponse ( this . dsoDataService . patch ( this . initialDSO , operations ) ) ;
128126 }
129127
130128 handleResponse ( response : Observable < RemoteData < DSpaceObject > > ) : void {
0 commit comments