@@ -48,6 +48,7 @@ import { getUniqueList, getSplitParams, encodeParams } from '../../utils/elastic
4848 * showActiveFilters=showActiveFilters
4949 * sortOptions=sortOptions
5050 * subject=subject
51+ * themeProvider=themeProvider
5152* }}
5253 * ```
5354 * @class discover-page
@@ -107,11 +108,11 @@ export default Ember.Component.extend(Analytics, hostAppName, {
107108 { key: 'contributors', title: 'People', component: 'search-facet-typeahead', base: 'agents', type: 'person' }
108109 ]
109110 */
110- facets : Ember . computed ( 'processedTypes' , function ( ) {
111+ facets : Ember . computed ( function ( ) {
111112 return [
112113 { key : 'sources' , title : `${ this . get ( 'i18n' ) . t ( 'eosf.components.discoverPage.source' ) } ` , component : 'search-facet-source' } ,
113114 { key : 'date' , title : `${ this . get ( 'i18n' ) . t ( 'eosf.components.discoverPage.date' ) } ` , component : 'search-facet-daterange' } ,
114- { key : 'type' , title : `${ this . get ( 'i18n' ) . t ( 'eosf.components.discoverPage.type' ) } ` , component : 'search-facet-worktype' , data : this . get ( 'processedTypes' ) } ,
115+ { key : 'type' , title : `${ this . get ( 'i18n' ) . t ( 'eosf.components.discoverPage.type' ) } ` , component : 'search-facet-worktype' , } ,
115116 { key : 'tags' , title : `${ this . get ( 'i18n' ) . t ( 'eosf.components.discoverPage.tag' ) } ` , component : 'search-facet-typeahead' } ,
116117 { key : 'publishers' , title : `${ this . get ( 'i18n' ) . t ( 'eosf.components.discoverPage.publisher' ) } ` , component : 'search-facet-typeahead' , base : 'agents' , type : 'publisher' } ,
117118 { key : 'funders' , title : `${ this . get ( 'i18n' ) . t ( 'eosf.components.discoverPage.funder' ) } ` , component : 'search-facet-typeahead' , base : 'agents' , type : 'funder' } ,
@@ -179,7 +180,6 @@ export default Ember.Component.extend(Analytics, hostAppName, {
179180 * @default ''
180181 */
181182 provider : '' ,
182- providerName : null , // For PREPRINTS and REGISTRIES. Provider name, if theme.isProvider, ex: psyarxiv
183183 /**
184184 * Publishers query parameter. If "publishers" is one of your query params, it must be passed to the component so it can be reflected in the URL.
185185 * @property {String } publishers
@@ -287,6 +287,12 @@ export default Ember.Component.extend(Analytics, hostAppName, {
287287 * @default ''
288288 */
289289 tags : '' ,
290+ /**
291+ * themeProvider
292+ * @property {Object } Preprint provider loaded from theme service. Should be passed from consuming service so it is loaded before SHARE is queried.
293+ * @default ''
294+ */
295+ themeProvider : null ,
290296 took : 0 ,
291297 /**
292298 * type query parameter. If "type" is one of your query params, it must be passed to the component so it can be reflected in the URL.
@@ -348,11 +354,6 @@ export default Ember.Component.extend(Analytics, hostAppName, {
348354 this . setActiveFiltersAndReload ( 'activeFilters.providers' , filter . split ( 'OR' ) ) ;
349355 }
350356 } ) ) ,
351- processedTypes : Ember . computed ( 'types' , function ( ) {
352- // Ember-SHARE property
353- const types = this . get ( 'types' ) && this . get ( 'types' ) . CreativeWork ? this . get ( 'types' ) . CreativeWork . children : { } ;
354- return this . transformTypes ( types ) ;
355- } ) ,
356357 reloadSearch : Ember . observer ( 'activeFilters.providers.@each' , 'activeFilters.subjects.@each' , 'activeFilters.types.@each' , function ( ) {
357358 // For PREPRINTS and REGISTRIES. Reloads page if activeFilters change.
358359 this . set ( 'page' , 1 ) ;
@@ -478,11 +479,15 @@ export default Ember.Component.extend(Analytics, hostAppName, {
478479 } ) ;
479480 } ) ;
480481
481- // For PREPRINTS and REGISTRIES. If theme.isProvider, add this provider to the query body
482- if ( this . get ( 'theme.isProvider' ) && this . get ( 'providerName' ) !== null ) {
482+ // For PREPRINTS and REGISTRIES. If theme.isProvider, add provider(s) to query body
483+ if ( this . get ( 'theme.isProvider' ) && this . get ( 'themeProvider.name' ) !== null ) {
484+ const themeProvider = this . get ( 'themeProvider' ) ;
485+ // Regular preprint providers will have their search results restricted to the one provider.
486+ // If the provider has additionalProviders, all of these providers will be added to the "sources" SHARE query
487+ const sources = ( themeProvider . get ( 'additionalProviders' ) || [ ] ) . length ? themeProvider . get ( 'additionalProviders' ) : [ themeProvider . get ( 'name' ) ] ;
483488 filters . push ( {
484489 terms : {
485- sources : [ this . get ( 'providerName' ) ]
490+ sources : sources
486491 }
487492 } ) ;
488493 }
@@ -518,28 +523,13 @@ export default Ember.Component.extend(Analytics, hostAppName, {
518523 this . set ( 'displayQueryBody' , { query } ) ;
519524 return this . set ( 'queryBody' , queryBody ) ;
520525 } ,
521- getTypes ( ) {
522- // Ember-SHARE method
523- return Ember . $ . ajax ( {
524- url : config . OSF . shareApiUrl + '/schema/creativework/hierarchy/' ,
525- crossDomain : true ,
526- type : 'GET' ,
527- contentType : 'application/vnd.api+json' ,
528- } ) . then ( ( json ) => {
529- if ( json . data ) {
530- this . set ( 'types' , json . data ) ;
531- }
532- } ) ;
533- } ,
534526 init ( ) {
535527 //TODO Sort initial results on date_modified
536528 // Runs on initial render.
537529 this . _super ( ...arguments ) ;
538530 this . set ( 'firstLoad' , true ) ;
539531 this . set ( 'facetFilters' , Ember . Object . create ( ) ) ;
540- this . getTypes ( ) ;
541532 this . getCounts ( ) ;
542- this . loadProvider ( ) ;
543533 this . loadPage ( ) ;
544534 } ,
545535 loadPage ( ) {
@@ -565,7 +555,7 @@ export default Ember.Component.extend(Analytics, hostAppName, {
565555 hyperLinks : [ // Links that are hyperlinks from hit._source.lists.links
566556 {
567557 type : 'share' ,
568- url : config . OSF . shareBaseUrl + `${ hit . _source . type } ` + '/' + hit . _id
558+ url : config . OSF . shareBaseUrl + `${ hit . _source . type . replace ( / / g , '' ) } ` + '/' + hit . _id
569559 }
570560 ] ,
571561 infoLinks : [ ] , // Links that are not hyperlinks hit._source.lists.links
@@ -634,16 +624,6 @@ export default Ember.Component.extend(Analytics, hostAppName, {
634624 jqDeferred . fail ( ( reason ) => reject ( reason ) ) ;
635625 } ) ;
636626 } ,
637- loadProvider ( ) {
638- // For PREPRINTS and REGISTRIES - Loads preprint provider if theme.isProvider
639- // Needed because theme's provider was not loading before SHARE was queried.
640- if ( this . get ( 'theme.isProvider' ) ) {
641- this . get ( 'theme.provider' ) . then ( provider => {
642- this . set ( 'providerName' , provider . get ( 'name' ) ) ;
643- this . loadPage ( ) ;
644- } ) ;
645- }
646- } ,
647627 scrollToResults ( ) {
648628 // Scrolls to top of search results
649629 Ember . $ ( 'html, body' ) . scrollTop ( this . $ ( '.results-top' ) . position ( ) . top ) ;
@@ -675,21 +655,6 @@ export default Ember.Component.extend(Analytics, hostAppName, {
675655
676656 } ) ;
677657 } ,
678- transformTypes ( obj ) {
679- // Ember-SHARE method
680- if ( typeof ( obj ) !== 'object' ) {
681- return obj ;
682- }
683-
684- for ( let key in obj ) {
685- let lowKey = key . replace ( / ( [ A - Z ] ) / g, ' $1' ) . trim ( ) . toLowerCase ( ) ;
686- obj [ lowKey ] = this . transformTypes ( obj [ key ] ) ;
687- if ( key !== lowKey ) {
688- delete obj [ key ] ;
689- }
690- }
691- return obj ;
692- } ,
693658 actions : {
694659 addFilter ( type , filterValue ) {
695660 // Ember-SHARE action. Used to add filter from the search results.
0 commit comments