mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-19 03:52:25 -05:00
39 lines
919 B
JavaScript
39 lines
919 B
JavaScript
import RestAdapter from 'discourse/adapters/rest';
|
|
|
|
export function finderFor(filter, params) {
|
|
return function() {
|
|
let url = Discourse.getURL("/") + filter + ".json";
|
|
|
|
if (params) {
|
|
const keys = Object.keys(params),
|
|
encoded = [];
|
|
|
|
keys.forEach(function(p) {
|
|
const value = encodeURI(params[p]);
|
|
if (typeof value !== 'undefined') {
|
|
encoded.push(p + "=" + value);
|
|
}
|
|
});
|
|
|
|
if (encoded.length > 0) {
|
|
url += "?" + encoded.join('&');
|
|
}
|
|
}
|
|
return Discourse.ajax(url);
|
|
};
|
|
}
|
|
|
|
export default RestAdapter.extend({
|
|
|
|
find(store, type, findArgs) {
|
|
const filter = findArgs.filter;
|
|
const params = findArgs.params;
|
|
|
|
return PreloadStore.getAndRemove("topic_list_" + filter, finderFor(filter, params)).then(function(result) {
|
|
result.filter = filter;
|
|
result.params = params;
|
|
return result;
|
|
});
|
|
}
|
|
});
|
|
|