mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
BUGFIX: show the draft on top page
This commit is contained in:
@@ -15,7 +15,13 @@ Discourse.TopList.reopenClass({
|
|||||||
var url = Discourse.getURL("/") + (filter || "top") + ".json";
|
var url = Discourse.getURL("/") + (filter || "top") + ".json";
|
||||||
return Discourse.ajax(url);
|
return Discourse.ajax(url);
|
||||||
}).then(function (result) {
|
}).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) {
|
Discourse.Site.currentProp('periods').forEach(function(period) {
|
||||||
// if there is a list for that 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}));
|
Discourse.set('title', I18n.t('filters.with_topics', {filter: filterText}));
|
||||||
this.controllerFor('discoveryTop').setProperties({ model: model, category: null });
|
this.controllerFor('discoveryTop').setProperties({ model: model, category: null });
|
||||||
this.controllerFor('navigationDefault').set('canCreateTopic', model.get('can_create_topic'));
|
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() {
|
renderTemplate: function() {
|
||||||
|
|||||||
@@ -120,6 +120,10 @@ class ListController < ApplicationController
|
|||||||
|
|
||||||
top = generate_top_lists(top_options)
|
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|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
@top = top
|
@top = top
|
||||||
@@ -267,7 +271,8 @@ class ListController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generate_top_lists(options)
|
def generate_top_lists(options)
|
||||||
top = {}
|
top = TopLists.new
|
||||||
|
|
||||||
options[:per_page] = SiteSetting.topics_per_period_in_top_summary
|
options[:per_page] = SiteSetting.topics_per_period_in_top_summary
|
||||||
topic_query = TopicQuery.new(current_user, options)
|
topic_query = TopicQuery.new(current_user, options)
|
||||||
|
|
||||||
@@ -277,7 +282,7 @@ class ListController < ApplicationController
|
|||||||
periods = TopTopic.periods
|
periods = TopTopic.periods
|
||||||
end
|
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
|
top
|
||||||
end
|
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
|
class TopListSerializer < ApplicationSerializer
|
||||||
|
|
||||||
attribute :can_create_topic
|
attributes :can_create_topic,
|
||||||
|
:draft,
|
||||||
|
:draft_key,
|
||||||
|
:draft_sequence
|
||||||
|
|
||||||
def can_create_topic
|
def can_create_topic
|
||||||
scope.can_create?(Topic)
|
scope.can_create?(Topic)
|
||||||
@@ -10,7 +13,7 @@ class TopListSerializer < ApplicationSerializer
|
|||||||
attribute period
|
attribute period
|
||||||
|
|
||||||
define_method(period) do
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user