diff --git a/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 b/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 index d85760f6325..3d77fcbc2dd 100644 --- a/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 +++ b/app/assets/javascripts/discourse/controllers/full-page-search.js.es6 @@ -14,12 +14,13 @@ const SortOrders = [ {name: I18n.t('search.latest_topic'), id: 4, term: 'order:latest_topic'}, ]; +const PAGE_LIMIT = 10; export default Ember.Controller.extend({ application: Ember.inject.controller(), bulkSelectEnabled: null, - loading: Em.computed.not("model"), + loading: false, queryParams: ["q", "expanded", "context_id", "context", "skip_context"], q: null, selected: [], @@ -30,11 +31,8 @@ export default Ember.Controller.extend({ sortOrder: 0, sortOrders: SortOrders, invalidSearch: false, - - @computed('model.posts') - resultCount(posts) { - return posts && posts.length; - }, + page: 1, + resultCount: null, @computed('resultCount') hasResults(resultCount) { @@ -113,6 +111,7 @@ export default Ember.Controller.extend({ @observes('sortOrder') triggerSearch() { if (this._searchOnSortChange) { + this.set("page", 1); this._search(); } }, @@ -143,6 +142,11 @@ export default Ember.Controller.extend({ this.set("application.showFooter", !this.get("loading")); }, + @observes('model.posts.length') + resultCountChanged() { + this.set("resultCount", this.get("model.posts.length")); + }, + @computed('hasResults') canBulkSelect(hasResults) { return this.currentUser && this.currentUser.staff && hasResults; @@ -158,6 +162,11 @@ export default Ember.Controller.extend({ return iconHTML(expanded ? "caret-down" : "caret-right"); }, + @computed('page') + isLastPage(page) { + return page == PAGE_LIMIT; + }, + _search() { if (this.get("searching")) { return; } @@ -169,10 +178,11 @@ export default Ember.Controller.extend({ } this.set("searching", true); + this.set("loading", true); this.set('bulkSelectEnabled', false); this.get('selected').clear(); - var args = { q: searchTerm }; + var args = { q: searchTerm, page: this.get('page') }; const sortOrder = this.get("sortOrder"); if (sortOrder && SortOrders[sortOrder].term) { @@ -180,7 +190,6 @@ export default Ember.Controller.extend({ } this.set("q", args.q); - this.set("model", null); const skip = this.get("skip_context"); if ((!skip && this.get('context')) || skip==="false"){ @@ -199,9 +208,20 @@ export default Ember.Controller.extend({ this.set('q', results.grouped_search_result.term); } - setTransient('lastSearch', { searchKey, model }, 5); - this.set("model", model); - }).finally(() => this.set("searching", false)); + if(args.page > 1){ + if (model){ + 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: { @@ -227,11 +247,20 @@ export default Ember.Controller.extend({ }, search() { + this.set("page", 1); this._search(); }, toggleAdvancedSearch() { 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(); + } + }, } }); diff --git a/app/assets/javascripts/discourse/templates/full-page-search.hbs b/app/assets/javascripts/discourse/templates/full-page-search.hbs index c1f0e6fa0ea..e823110ace6 100644 --- a/app/assets/javascripts/discourse/templates/full-page-search.hbs +++ b/app/assets/javascripts/discourse/templates/full-page-search.hbs @@ -45,32 +45,23 @@ {{/if}} - {{#conditional-loading-spinner condition=loading}} - - {{#unless hasResults}} -