This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/models/result-set.js.es6
2019-05-27 10:15:39 +02:00

56 lines
1.1 KiB
JavaScript

import computed from "ember-addons/ember-computed-decorators";
export default Ember.ArrayProxy.extend({
loading: false,
loadingMore: false,
totalRows: 0,
refreshing: false,
content: null,
loadMoreUrl: null,
refreshUrl: null,
findArgs: null,
store: null,
__type: null,
resultSetMeta: null,
@computed("totalRows", "length")
canLoadMore(totalRows, length) {
return length < totalRows;
},
loadMore() {
const loadMoreUrl = this.loadMoreUrl;
if (!loadMoreUrl) {
return;
}
const totalRows = this.totalRows;
if (this.length < totalRows && !this.loadingMore) {
this.set("loadingMore", true);
return this.store
.appendResults(this, this.__type, loadMoreUrl)
.finally(() => this.set("loadingMore", false));
}
return Ember.RSVP.resolve();
},
refresh() {
if (this.refreshing) {
return;
}
const refreshUrl = this.refreshUrl;
if (!refreshUrl) {
return;
}
this.set("refreshing", true);
return this.store
.refreshResults(this, this.__type, refreshUrl)
.finally(() => this.set("refreshing", false));
}
});