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
Maja Komel 4b455e741e DEV: Ember 3.8.0
Co-Authored-By: majakomel <maja.komel@gmail.com>
2019-04-26 12:16:21 +02:00

56 lines
1.2 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.get("loadMoreUrl");
if (!loadMoreUrl) {
return;
}
const totalRows = this.get("totalRows");
if (this.get("length") < totalRows && !this.get("loadingMore")) {
this.set("loadingMore", true);
return this.store
.appendResults(this, this.get("__type"), loadMoreUrl)
.finally(() => this.set("loadingMore", false));
}
return Ember.RSVP.resolve();
},
refresh() {
if (this.get("refreshing")) {
return;
}
const refreshUrl = this.get("refreshUrl");
if (!refreshUrl) {
return;
}
this.set("refreshing", true);
return this.store
.refreshResults(this, this.get("__type"), refreshUrl)
.finally(() => this.set("refreshing", false));
}
});