-
Notifications
You must be signed in to change notification settings - Fork 5
GROVE-334 : adds 'show more' link to show more facets in the Vue template #8
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { polyfill } from 'es6-promise'; | ||
import 'isomorphic-fetch'; | ||
|
||
polyfill(); | ||
|
||
export default { | ||
name: 'ValuesApi', | ||
|
||
getValues(name, params, options, searchState, qtext, facetObject) { | ||
//get options | ||
return fetch('/v1/config/query/all?format=json', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json' | ||
}, | ||
credentials: 'same-origin' | ||
}).then( | ||
response => { | ||
return response.json().then(function(json) { | ||
let options = json.options || {}; | ||
|
||
let path = ''; | ||
let collation = ''; | ||
for (let i=0; i < options.constraint.length; i++) { | ||
if (options.constraint[i].name === name){ | ||
path = options.constraint[i].range['path-index'].text; | ||
collation = options.constraint[i].range.collation; | ||
} | ||
} | ||
|
||
options.values = { | ||
name: name, | ||
range: { | ||
collation: collation, | ||
type: 'xs:string', | ||
'path-index': { | ||
text: path, | ||
ns: '' | ||
} | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to just copy the entire range object from the constraint. Might not be string, might not be path index.. |
||
'values-option' : ['frequency-order'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy these from facet-options.. some facets use item-order for sure.. |
||
}; | ||
//combine with search | ||
let searchType = 'all'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. searchType should be provided as param, like in searchApi.. |
||
// let searchType = searchType !== undefined ? searchType : 'all'; | ||
let start = facetObject.facetValues.length +1 || 1; | ||
// let start = 1; | ||
let pageLength = 10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about using facet limit as page-length? |
||
// var limit = 100; | ||
var limit = start + pageLength - 1; | ||
|
||
let facets = Object.keys(searchState.activeFacets || {}).map(function(facetName) { | ||
let constraintType = searchState.activeFacets[facetName].type; | ||
if (constraintType && constraintType.substring(0, 3) === 'xs:') { | ||
constraintType = 'range'; | ||
} | ||
let temp = { | ||
'range-constraint-query' :{ | ||
'constraint-name': facetName, | ||
constraintType: constraintType | ||
} | ||
}; | ||
searchState.activeFacets[facetName].values.map(function(facetValue) { | ||
temp.value = [facetValue.value]; | ||
if (facetValue.negated) { | ||
temp['range-operator'] = 'NE'; | ||
} | ||
}); | ||
|
||
return temp; | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think latest searchApi in development branch has captured this in a helper function that you could expose and reuse here.. |
||
let valuesParams = new URLSearchParams(); | ||
valuesParams.append('q', qtext); | ||
valuesParams.append('start', start); | ||
valuesParams.append('pageLength', pageLength); | ||
valuesParams.append('limit', limit); | ||
valuesParams.append('direction', 'descending'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. direction should match direction of facet.. |
||
let valuesParamsString = valuesParams.toString(); | ||
|
||
return fetch('/v1/values/' + name + '?'+valuesParamsString, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar to getting of config, make a call to |
||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
search: { | ||
query: { | ||
queries: { | ||
and: [].concat(facets) | ||
}}, | ||
options: options | ||
}}), | ||
credentials: 'same-origin' | ||
}).then( | ||
response => { | ||
return response.json().then(function(json) { | ||
|
||
return { response: json }; | ||
}); | ||
}, | ||
error => { | ||
return error; | ||
} | ||
); | ||
}); | ||
}, | ||
error => { | ||
return error; | ||
} | ||
); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
<ml-input :qtext="qtext" :search="search" :suggest="suggest" class="search"></ml-input> | ||
</div> | ||
<div class="col-xs-12 col-sm-4 col-md-3 facets-col"> | ||
<ml-facets v-if="facets" :facets="facets" :toggle="toggleFacet" :active-facets="activeFacets" :negate="toggleNegatedFacet"></ml-facets> | ||
<ml-facets v-if="facets" :facets="facets" :toggle="toggleFacet" :active-facets="activeFacets" :negate="toggleNegatedFacet" :showMore="showMore"></ml-facets> | ||
</div> | ||
<div class="col-xs-12 col-sm-8 col-md-9 results-col"> | ||
<i class="fa fa-refresh pull-right" :class="searchPending ? 'fa-spin' : ''" | ||
|
@@ -109,6 +109,16 @@ export default { | |
} | ||
}, | ||
methods: { | ||
showMore(facet, facetName) { | ||
if (facet.displayingAll) { | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be unnecessary I think. the button should simply not show if displayingAll is true.. |
||
this.$store | ||
.dispatch('search/' + this.type + '/showMore', {facet, facetName}) | ||
.then(() => { | ||
this.searchPending = false; | ||
}); | ||
}, | ||
toggleFacet(facet, type, value) { | ||
console.log('Toggle ' + facet + ' ' + type + ' ' + value); | ||
this.searchPending = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should make a call to
/search/{type}/config
.. (see comments in grove-node PR)