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
2020-03-12 13:29:55 -04:00

58 lines
1.2 KiB
JavaScript

import ArrayProxy from "@ember/array/proxy";
import discourseComputed from "discourse-common/utils/decorators";
import { Promise } from "rsvp";
export default ArrayProxy.extend({
loading: false,
loadingMore: false,
totalRows: 0,
refreshing: false,
content: null,
loadMoreUrl: null,
refreshUrl: null,
findArgs: null,
store: null,
__type: null,
resultSetMeta: null,
@discourseComputed("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 Promise.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));
}
});