mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
BUGFIX: show the draft on top page
This commit is contained in:
parent
a710773bb4
commit
58202baa62
5 changed files with 36 additions and 5 deletions
|
@ -15,7 +15,13 @@ Discourse.TopList.reopenClass({
|
|||
var url = Discourse.getURL("/") + (filter || "top") + ".json";
|
||||
return Discourse.ajax(url);
|
||||
}).then(function (result) {
|
||||
var topList = Discourse.TopList.create({ can_create_topic: result.can_create_topic });
|
||||
|
||||
var topList = Discourse.TopList.create({
|
||||
can_create_topic: result.can_create_topic,
|
||||
draft: result.draft,
|
||||
draft_key: result.draft_key,
|
||||
draft_sequence: result.draft_sequence,
|
||||
});
|
||||
|
||||
Discourse.Site.currentProp('periods').forEach(function(period) {
|
||||
// if there is a list for that period
|
||||
|
|
|
@ -20,6 +20,16 @@ Discourse.DiscoveryTopRoute = Discourse.Route.extend({
|
|||
Discourse.set('title', I18n.t('filters.with_topics', {filter: filterText}));
|
||||
this.controllerFor('discoveryTop').setProperties({ model: model, category: null });
|
||||
this.controllerFor('navigationDefault').set('canCreateTopic', model.get('can_create_topic'));
|
||||
|
||||
// If there's a draft, open the create topic composer
|
||||
if (model.draft) {
|
||||
this.controllerFor('composer').open({
|
||||
action: Discourse.Composer.CREATE_TOPIC,
|
||||
draft: model.draft,
|
||||
draftKey: model.draft_key,
|
||||
draftSequence: model.draft_sequence
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
renderTemplate: function() {
|
||||
|
|
|
@ -120,6 +120,10 @@ class ListController < ApplicationController
|
|||
|
||||
top = generate_top_lists(top_options)
|
||||
|
||||
top.draft_key = Draft::NEW_TOPIC
|
||||
top.draft_sequence = DraftSequence.current(current_user, Draft::NEW_TOPIC)
|
||||
top.draft = Draft.get(current_user, top.draft_key, top.draft_sequence) if current_user
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
@top = top
|
||||
|
@ -267,7 +271,8 @@ class ListController < ApplicationController
|
|||
end
|
||||
|
||||
def generate_top_lists(options)
|
||||
top = {}
|
||||
top = TopLists.new
|
||||
|
||||
options[:per_page] = SiteSetting.topics_per_period_in_top_summary
|
||||
topic_query = TopicQuery.new(current_user, options)
|
||||
|
||||
|
@ -277,7 +282,7 @@ class ListController < ApplicationController
|
|||
periods = TopTopic.periods
|
||||
end
|
||||
|
||||
periods.each { |period| top[period] = topic_query.list_top_for(period) }
|
||||
periods.each { |period| top.send("#{period}=", topic_query.list_top_for(period)) }
|
||||
|
||||
top
|
||||
end
|
||||
|
|
7
app/models/top_lists.rb
Normal file
7
app/models/top_lists.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class TopLists
|
||||
include ActiveModel::Serialization
|
||||
|
||||
attr_accessor :draft, :draft_key, :draft_sequence
|
||||
|
||||
TopTopic.periods.each { |period| attr_accessor period }
|
||||
end
|
|
@ -1,6 +1,9 @@
|
|||
class TopListSerializer < ApplicationSerializer
|
||||
|
||||
attribute :can_create_topic
|
||||
attributes :can_create_topic,
|
||||
:draft,
|
||||
:draft_key,
|
||||
:draft_sequence
|
||||
|
||||
def can_create_topic
|
||||
scope.can_create?(Topic)
|
||||
|
@ -10,7 +13,7 @@ class TopListSerializer < ApplicationSerializer
|
|||
attribute period
|
||||
|
||||
define_method(period) do
|
||||
TopicListSerializer.new(object[period], scope: scope).as_json if object[period]
|
||||
TopicListSerializer.new(object.send(period), scope: scope).as_json if object.send(period)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue