Can refresh queued posts via button
This commit is contained in:
parent
cce8693354
commit
3cb4554bbb
|
@ -2,6 +2,7 @@ export default Ember.ArrayProxy.extend({
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingMore: false,
|
loadingMore: false,
|
||||||
totalRows: 0,
|
totalRows: 0,
|
||||||
|
refreshing: false,
|
||||||
|
|
||||||
loadMore() {
|
loadMore() {
|
||||||
const loadMoreUrl = this.get('loadMoreUrl');
|
const loadMoreUrl = this.get('loadMoreUrl');
|
||||||
|
@ -18,5 +19,19 @@ export default Ember.ArrayProxy.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ember.RSVP.resolve();
|
return Ember.RSVP.resolve();
|
||||||
|
},
|
||||||
|
|
||||||
|
refresh() {
|
||||||
|
if (this.get('refreshing')) { return; }
|
||||||
|
|
||||||
|
const refreshUrl = this.get('refreshUrl');
|
||||||
|
if (!refreshUrl) { return; }
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
this.set('refreshing', true);
|
||||||
|
return this.store.refreshResults(this, this.get('__type'), refreshUrl).then(function() {
|
||||||
|
self.set('refreshing', false);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,6 +67,15 @@ export default Ember.Object.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
refreshResults(resultSet, type, url) {
|
||||||
|
const self = this;
|
||||||
|
return Discourse.ajax(url).then(function(result) {
|
||||||
|
const typeName = Ember.String.underscore(self.pluralize(type)),
|
||||||
|
content = result[typeName].map(obj => self._hydrate(type, obj, result));
|
||||||
|
resultSet.set('content', content);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
appendResults(resultSet, type, url) {
|
appendResults(resultSet, type, url) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
|
@ -112,9 +121,10 @@ export default Ember.Object.extend({
|
||||||
const typeName = Ember.String.underscore(this.pluralize(type)),
|
const typeName = Ember.String.underscore(this.pluralize(type)),
|
||||||
content = result[typeName].map(obj => this._hydrate(type, obj, result)),
|
content = result[typeName].map(obj => this._hydrate(type, obj, result)),
|
||||||
totalRows = result["total_rows_" + typeName] || content.length,
|
totalRows = result["total_rows_" + typeName] || content.length,
|
||||||
loadMoreUrl = result["load_more_" + typeName];
|
loadMoreUrl = result["load_more_" + typeName],
|
||||||
|
refreshUrl = result['refresh_' + typeName];
|
||||||
|
|
||||||
return ResultSet.create({ content, totalRows, loadMoreUrl, store: this, __type: type });
|
return ResultSet.create({ content, totalRows, loadMoreUrl, refreshUrl, store: this, __type: type });
|
||||||
},
|
},
|
||||||
|
|
||||||
_build(type, obj) {
|
_build(type, obj) {
|
||||||
|
|
|
@ -3,5 +3,11 @@ import DiscourseRoute from 'discourse/routes/discourse';
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
model() {
|
model() {
|
||||||
return this.store.find('queuedPost', {status: 'new'});
|
return this.store.find('queuedPost', {status: 'new'});
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
refresh() {
|
||||||
|
this.modelFor('queued-posts').refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -75,5 +75,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<p>{{i18n "queue.none"}}</p>
|
<p>{{i18n "queue.none"}}</p>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
|
{{d-button action="refresh" label="refresh" icon="refresh" disabled=model.refreshing id='refresh-queued'}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -224,7 +224,14 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def render_json_dump(obj, opts=nil)
|
def render_json_dump(obj, opts=nil)
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
obj['__rest_serializer'] = "1" if opts[:rest_serializer]
|
if opts[:rest_serializer]
|
||||||
|
obj['__rest_serializer'] = "1"
|
||||||
|
opts.each do |k, v|
|
||||||
|
obj[k] = v if k.to_s.start_with?("refresh_")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
render json: MultiJson.dump(obj), status: opts[:status] || 200
|
render json: MultiJson.dump(obj), status: opts[:status] || 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,12 @@ class QueuedPostsController < ApplicationController
|
||||||
state ||= QueuedPost.states[:new]
|
state ||= QueuedPost.states[:new]
|
||||||
|
|
||||||
@queued_posts = QueuedPost.visible.where(state: state).includes(:topic, :user)
|
@queued_posts = QueuedPost.visible.where(state: state).includes(:topic, :user)
|
||||||
render_serialized(@queued_posts, QueuedPostSerializer, root: :queued_posts, rest_serializer: true)
|
render_serialized(@queued_posts,
|
||||||
|
QueuedPostSerializer,
|
||||||
|
root: :queued_posts,
|
||||||
|
rest_serializer: true,
|
||||||
|
refresh_queued_posts: "/queued_posts?status=new")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
@ -225,7 +225,10 @@ export default function() {
|
||||||
if (qp.id) { result = result.filterBy('id', parseInt(qp.id)); }
|
if (qp.id) { result = result.filterBy('id', parseInt(qp.id)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
return response({ widgets: result, total_rows_widgets: 4, load_more_widgets: '/load-more-widgets' });
|
return response({ widgets: result,
|
||||||
|
total_rows_widgets: 4,
|
||||||
|
load_more_widgets: '/load-more-widgets',
|
||||||
|
refresh_widgets: '/widgets?refresh=true' });
|
||||||
});
|
});
|
||||||
|
|
||||||
this.get('/load-more-widgets', function() {
|
this.get('/load-more-widgets', function() {
|
||||||
|
|
|
@ -10,6 +10,7 @@ test('defaults', function() {
|
||||||
ok(!rs.get('loadMoreUrl'));
|
ok(!rs.get('loadMoreUrl'));
|
||||||
ok(!rs.get('loading'));
|
ok(!rs.get('loading'));
|
||||||
ok(!rs.get('loadingMore'));
|
ok(!rs.get('loadingMore'));
|
||||||
|
ok(!rs.get('refreshing'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('pagination support', function() {
|
test('pagination support', function() {
|
||||||
|
@ -18,11 +19,29 @@ test('pagination support', function() {
|
||||||
equal(rs.get('length'), 2);
|
equal(rs.get('length'), 2);
|
||||||
equal(rs.get('totalRows'), 4);
|
equal(rs.get('totalRows'), 4);
|
||||||
ok(rs.get('loadMoreUrl'), 'has a url to load more');
|
ok(rs.get('loadMoreUrl'), 'has a url to load more');
|
||||||
|
ok(!rs.get('loadingMore'), 'it is not loading more');
|
||||||
|
|
||||||
rs.loadMore().then(function() {
|
const promise = rs.loadMore();
|
||||||
|
|
||||||
|
ok(rs.get('loadingMore'), 'it is loading more');
|
||||||
|
promise.then(function() {
|
||||||
|
ok(!rs.get('loadingMore'), 'it finished loading more');
|
||||||
equal(rs.get('length'), 4);
|
equal(rs.get('length'), 4);
|
||||||
ok(!rs.get('loadMoreUrl'));
|
ok(!rs.get('loadMoreUrl'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('refresh support', function() {
|
||||||
|
const store = createStore();
|
||||||
|
store.findAll('widget').then(function(rs) {
|
||||||
|
equal(rs.get('refreshUrl'), '/widgets?refresh=true', 'it has the refresh url');
|
||||||
|
|
||||||
|
const promise = rs.refresh();
|
||||||
|
|
||||||
|
ok(rs.get('refreshing'), 'it is refreshing');
|
||||||
|
promise.then(function() {
|
||||||
|
ok(!rs.get('refreshing'), 'it is finished refreshing');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue