This repository has been archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
893 additions
and
1,251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import Ember from 'ember'; | ||
import config from 'ember-get-config'; | ||
|
||
var getProvidersPayload = '{"from": 0,"query": {"bool": {"must": {"query_string": {"query": "*"}}, "filter": [{"term": {"types": "registration"}}]}},"aggregations": {"sources": {"terms": {"field": "sources","size": 200}}}}'; | ||
|
||
/** | ||
* @module ember-osf-registries | ||
* @submodule components | ||
*/ | ||
|
||
/** | ||
* Builds registry's provider facet for discover page - to be used with Ember-OSF's discover-page component and faceted-search component. | ||
* | ||
* Sample usage: | ||
* ```handlebars | ||
* {{search-facet-provider | ||
* updateFilters=(action 'updateFilters') | ||
* activeFilters=activeFilters | ||
* options=facet | ||
* filterReplace=filterReplace | ||
* key=key | ||
* }} | ||
* ``` | ||
* @class search-facet-provider | ||
*/ | ||
export default Ember.Component.extend({ | ||
store: Ember.inject.service(), | ||
theme: Ember.inject.service(), | ||
otherProviders: [], | ||
searchUrl: config.OSF.shareSearchUrl, | ||
osfProviders: [ | ||
'OSF', | ||
// 'AEA Registry', //These need to be added to the language filter once on SHARE (OSF -> OSF Registries) | ||
// 'ANZCTR', | ||
// 'Clinicaltrials.gov', | ||
// 'EGAP', | ||
// 'EU Clinical Trials', | ||
// 'ISRCTN', | ||
// 'Research Registry', | ||
// 'RIDIE' | ||
], | ||
whiteListedProviders: [ | ||
'OSF', | ||
'ClinicalTrials.gov', | ||
'Research Registry' | ||
].map(item => item.toLowerCase()), | ||
|
||
init() { | ||
this._super(...arguments); | ||
|
||
Ember.$.ajax({ | ||
type: 'POST', | ||
url: this.get('searchUrl'), | ||
data: getProvidersPayload, | ||
contentType: 'application/json', | ||
crossDomain: true, | ||
}).then(results => { | ||
const hits = results.aggregations.sources.buckets; | ||
const whiteList = this.get('whiteListedProviders'); | ||
const providers = hits | ||
.filter(hit => whiteList.includes(hit.key.toLowerCase())); | ||
|
||
providers.push( | ||
...this.get('osfProviders') | ||
.filter(key => !providers | ||
.find(hit => hit.key.toLowerCase() === key.toLowerCase()) | ||
) | ||
.map(key => ({ | ||
key, | ||
doc_count: 0 | ||
})) | ||
); | ||
|
||
providers | ||
.sort((a, b) => a.key.toLowerCase() < b.key.toLowerCase() ? -1 : 1) | ||
.unshift( | ||
...providers.splice( | ||
providers.findIndex(item => item.key === 'OSF'), | ||
1 | ||
) | ||
); | ||
|
||
if (!this.get('theme.isProvider')) { | ||
this.set('otherProviders', providers); | ||
} else { | ||
const filtered = providers.filter( | ||
item => item.key.toLowerCase() === this.get('theme.id').toLowerCase() | ||
); | ||
|
||
this.set('otherProviders', filtered); | ||
this.get('activeFilters.providers').pushObject(filtered[0].key); | ||
} | ||
|
||
this.notifyPropertyChange('otherProviders'); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import Ember from 'ember'; | ||
|
||
/** | ||
* @module ember-osf-registries | ||
* @submodule components | ||
*/ | ||
|
||
/** | ||
* Builds registry's registration type facet for discover page - to be used with Ember-OSF's discover-page component and faceted-search component. | ||
* | ||
* Sample usage: | ||
* ```handlebars | ||
* {{search-facet-registration-type | ||
* updateFilters=(action 'updateFilters') | ||
* activeFilters=activeFilters | ||
* options=facet | ||
* filterReplace=filterReplace | ||
* key=key | ||
* }} | ||
* ``` | ||
* @class search-facet-registration-type | ||
*/ | ||
export default Ember.Component.extend({ | ||
registrationTypes: [ | ||
'AsPredicted Preregistration', | ||
'Election Research Preacceptance Competition', | ||
'Open-Ended Registration', | ||
'OSF-Standard Pre-Data Collection Registration', | ||
'Prereg Challenge', | ||
'Pre-Registration in Social Psychology (van \'t Veer & Giner-Sorolla, 2016): Pre-Registration', | ||
'Replication Recipe (Brandt et al., 2013): Post-Completion', | ||
'Replication Recipe (Brandt et al., 2013): Pre-Registration', | ||
], | ||
|
||
init() { | ||
this._super(...arguments); | ||
Ember.run.schedule('afterRender', () => { | ||
if (this.OSFIsSoleProvider()) { | ||
return; | ||
} | ||
this.toggleTypeCSS(false); | ||
}); | ||
}, | ||
registrationTypeCache: null, | ||
setVisibilityOfOSFFilters: Ember.observer('activeFilters.providers', function() { | ||
if (this.OSFIsSoleProvider()) { | ||
if (this.get('registrationTypeCache')) { | ||
this.set('activeFilters.types', Ember.$.extend(true, [], this.get('registrationTypeCache'))); | ||
this.set('registrationTypeCache', null); | ||
} | ||
this.toggleTypeCSS(true); | ||
} else { | ||
this.set('registrationTypeCache', Ember.$.extend(true, [], this.get('activeFilters.types'))); | ||
this.set('activeFilters.types', []); | ||
this.toggleTypeCSS(false); | ||
} | ||
}), | ||
// Disables search-facet-registration-type | ||
toggleTypeCSS(show) { | ||
if (show) { | ||
Ember.$('.type-selector-warning').hide(); | ||
Ember.$('.type-checkbox').removeAttr('disabled'); | ||
Ember.$('.registration-type-selector').fadeTo('slow', 1); | ||
} else { | ||
Ember.$('.type-selector-warning').show(); | ||
Ember.$('.type-checkbox').attr('disabled', 'disabled'); | ||
Ember.$('.registration-type-selector').fadeTo('slow', 0.5); | ||
} | ||
}, | ||
OSFIsSoleProvider() { | ||
let soleProvider = false; | ||
const providers = this.get('activeFilters.providers'); | ||
if (providers.length === 1 && providers[0] === 'OSF') { | ||
soleProvider = true; | ||
} | ||
return soleProvider; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.