Add infinite loading to full page search.
This commit is contained in:
parent
4eb7f7cd10
commit
2d45b3fc6d
|
@ -14,12 +14,13 @@ const SortOrders = [
|
||||||
{name: I18n.t('search.latest_topic'), id: 4, term: 'order:latest_topic'},
|
{name: I18n.t('search.latest_topic'), id: 4, term: 'order:latest_topic'},
|
||||||
|
|
||||||
];
|
];
|
||||||
|
const PAGE_LIMIT = 10;
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
application: Ember.inject.controller(),
|
application: Ember.inject.controller(),
|
||||||
bulkSelectEnabled: null,
|
bulkSelectEnabled: null,
|
||||||
|
|
||||||
loading: Em.computed.not("model"),
|
loading: false,
|
||||||
queryParams: ["q", "expanded", "context_id", "context", "skip_context"],
|
queryParams: ["q", "expanded", "context_id", "context", "skip_context"],
|
||||||
q: null,
|
q: null,
|
||||||
selected: [],
|
selected: [],
|
||||||
|
@ -30,11 +31,8 @@ export default Ember.Controller.extend({
|
||||||
sortOrder: 0,
|
sortOrder: 0,
|
||||||
sortOrders: SortOrders,
|
sortOrders: SortOrders,
|
||||||
invalidSearch: false,
|
invalidSearch: false,
|
||||||
|
page: 1,
|
||||||
@computed('model.posts')
|
resultCount: null,
|
||||||
resultCount(posts) {
|
|
||||||
return posts && posts.length;
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed('resultCount')
|
@computed('resultCount')
|
||||||
hasResults(resultCount) {
|
hasResults(resultCount) {
|
||||||
|
@ -113,6 +111,7 @@ export default Ember.Controller.extend({
|
||||||
@observes('sortOrder')
|
@observes('sortOrder')
|
||||||
triggerSearch() {
|
triggerSearch() {
|
||||||
if (this._searchOnSortChange) {
|
if (this._searchOnSortChange) {
|
||||||
|
this.set("page", 1);
|
||||||
this._search();
|
this._search();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -143,6 +142,11 @@ export default Ember.Controller.extend({
|
||||||
this.set("application.showFooter", !this.get("loading"));
|
this.set("application.showFooter", !this.get("loading"));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@observes('model.posts.length')
|
||||||
|
resultCountChanged() {
|
||||||
|
this.set("resultCount", this.get("model.posts.length"));
|
||||||
|
},
|
||||||
|
|
||||||
@computed('hasResults')
|
@computed('hasResults')
|
||||||
canBulkSelect(hasResults) {
|
canBulkSelect(hasResults) {
|
||||||
return this.currentUser && this.currentUser.staff && hasResults;
|
return this.currentUser && this.currentUser.staff && hasResults;
|
||||||
|
@ -158,6 +162,11 @@ export default Ember.Controller.extend({
|
||||||
return iconHTML(expanded ? "caret-down" : "caret-right");
|
return iconHTML(expanded ? "caret-down" : "caret-right");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed('page')
|
||||||
|
isLastPage(page) {
|
||||||
|
return page == PAGE_LIMIT;
|
||||||
|
},
|
||||||
|
|
||||||
_search() {
|
_search() {
|
||||||
if (this.get("searching")) { return; }
|
if (this.get("searching")) { return; }
|
||||||
|
|
||||||
|
@ -169,10 +178,11 @@ export default Ember.Controller.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set("searching", true);
|
this.set("searching", true);
|
||||||
|
this.set("loading", true);
|
||||||
this.set('bulkSelectEnabled', false);
|
this.set('bulkSelectEnabled', false);
|
||||||
this.get('selected').clear();
|
this.get('selected').clear();
|
||||||
|
|
||||||
var args = { q: searchTerm };
|
var args = { q: searchTerm, page: this.get('page') };
|
||||||
|
|
||||||
const sortOrder = this.get("sortOrder");
|
const sortOrder = this.get("sortOrder");
|
||||||
if (sortOrder && SortOrders[sortOrder].term) {
|
if (sortOrder && SortOrders[sortOrder].term) {
|
||||||
|
@ -180,7 +190,6 @@ export default Ember.Controller.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set("q", args.q);
|
this.set("q", args.q);
|
||||||
this.set("model", null);
|
|
||||||
|
|
||||||
const skip = this.get("skip_context");
|
const skip = this.get("skip_context");
|
||||||
if ((!skip && this.get('context')) || skip==="false"){
|
if ((!skip && this.get('context')) || skip==="false"){
|
||||||
|
@ -199,9 +208,20 @@ export default Ember.Controller.extend({
|
||||||
this.set('q', results.grouped_search_result.term);
|
this.set('q', results.grouped_search_result.term);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTransient('lastSearch', { searchKey, model }, 5);
|
if(args.page > 1){
|
||||||
this.set("model", model);
|
if (model){
|
||||||
}).finally(() => this.set("searching", false));
|
this.get("model").posts.pushObjects(model.posts);
|
||||||
|
this.get("model").topics.pushObjects(model.topics);
|
||||||
|
this.get("model").set('grouped_search_result', results.grouped_search_result);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
setTransient('lastSearch', { searchKey, model }, 5);
|
||||||
|
this.set("model", model);
|
||||||
|
}
|
||||||
|
}).finally(() => {
|
||||||
|
this.set("searching", false);
|
||||||
|
this.set("loading", false);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -227,11 +247,20 @@ export default Ember.Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
search() {
|
search() {
|
||||||
|
this.set("page", 1);
|
||||||
this._search();
|
this._search();
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleAdvancedSearch() {
|
toggleAdvancedSearch() {
|
||||||
this.toggleProperty('expanded');
|
this.toggleProperty('expanded');
|
||||||
}
|
},
|
||||||
|
|
||||||
|
loadMore() {
|
||||||
|
var page = this.get('page');
|
||||||
|
if (this.get('model.grouped_search_result.more_full_page_results') && !this.get("loading") && page < PAGE_LIMIT){
|
||||||
|
this.incrementProperty("page");
|
||||||
|
this._search();
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,32 +45,23 @@
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#conditional-loading-spinner condition=loading}}
|
{{#if hasResults}}
|
||||||
|
<div class='search-title clearfix'>
|
||||||
{{#unless hasResults}}
|
<div class='result-count'>
|
||||||
<h3>
|
<span>
|
||||||
{{#if searchActive}}
|
{{{i18n "search.result_count" count=resultCount term=noSortQ}}}
|
||||||
{{i18n "search.no_results"}}
|
</span>
|
||||||
{{/if}}
|
|
||||||
</h3>
|
|
||||||
{{/unless}}
|
|
||||||
|
|
||||||
{{#if hasResults}}
|
|
||||||
<div class='search-title clearfix'>
|
|
||||||
<div class='result-count'>
|
|
||||||
<span>
|
|
||||||
{{{i18n "search.result_count" count=resultCount term=noSortQ}}}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class='sort-by'>
|
|
||||||
<span class='desc'>
|
|
||||||
{{i18n "search.sort_by"}}
|
|
||||||
</span>
|
|
||||||
{{combo-box value=sortOrder content=sortOrders castInteger="true"}}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
<div class='sort-by'>
|
||||||
|
<span class='desc'>
|
||||||
|
{{i18n "search.sort_by"}}
|
||||||
|
</span>
|
||||||
|
{{combo-box value=sortOrder content=sortOrders castInteger="true"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#load-more selector=".fps-result" action="loadMore"}}
|
||||||
{{#each model.posts as |result|}}
|
{{#each model.posts as |result|}}
|
||||||
<div class='fps-result'>
|
<div class='fps-result'>
|
||||||
<div class='author'>
|
<div class='author'>
|
||||||
|
@ -124,15 +115,30 @@
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
{{#if hasResults}}
|
{{#conditional-loading-spinner condition=loading }}
|
||||||
<h3 class="search-footer">
|
{{#unless hasResults}}
|
||||||
{{#if model.grouped_search_result.more_full_page_results}}
|
<h3>
|
||||||
{{i18n "search.more_results"}}
|
{{#if searchActive}}
|
||||||
{{else}}
|
{{i18n "search.no_results"}}
|
||||||
{{i18n "search.no_more_results"}}
|
{{/if}}
|
||||||
{{/if}}
|
|
||||||
</h3>
|
</h3>
|
||||||
{{/if}}
|
{{/unless}}
|
||||||
|
|
||||||
|
{{#if hasResults}}
|
||||||
|
{{#unless loading}}
|
||||||
|
<h3 class="search-footer">
|
||||||
|
{{#if model.grouped_search_result.more_full_page_results}}
|
||||||
|
{{#if isLastPage }}
|
||||||
|
{{i18n "search.more_results"}}
|
||||||
|
{{/if}}
|
||||||
|
{{else}}
|
||||||
|
{{i18n "search.no_more_results"}}
|
||||||
|
{{/if}}
|
||||||
|
</h3>
|
||||||
|
{{/unless}}
|
||||||
|
{{/if}}
|
||||||
|
{{/conditional-loading-spinner}}
|
||||||
|
|
||||||
|
{{/load-more}}
|
||||||
|
|
||||||
{{/conditional-loading-spinner}}
|
|
||||||
{{/d-section}}
|
{{/d-section}}
|
||||||
|
|
Loading…
Reference in New Issue