mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 07:55:44 +08:00
FEATURE: dismissable banner topic
This commit is contained in:
@ -0,0 +1,25 @@
|
|||||||
|
export default Ember.Component.extend({
|
||||||
|
|
||||||
|
visible: function () {
|
||||||
|
var bannerKey = this.get("banner.key"),
|
||||||
|
dismissedBannerKey = this.get("user.dismissed_banner_key") ||
|
||||||
|
Discourse.KeyValueStore.get("dismissed_banner_key");
|
||||||
|
|
||||||
|
if (bannerKey) { bannerKey = parseInt(bannerKey, 10); }
|
||||||
|
if (dismissedBannerKey) { dismissedBannerKey = parseInt(dismissedBannerKey, 10); }
|
||||||
|
|
||||||
|
return bannerKey && dismissedBannerKey !== bannerKey;
|
||||||
|
}.property("user.dismissed_banner_key", "banner.key"),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
dismiss: function () {
|
||||||
|
if (this.get("user")) {
|
||||||
|
this.get("user").dismissBanner(this.get("banner.key"));
|
||||||
|
} else {
|
||||||
|
this.set("visible", false);
|
||||||
|
Discourse.KeyValueStore.set({ key: "dismissed_banner_key", value: this.get("banner.key") });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
@ -411,6 +411,14 @@ Discourse.User = Discourse.Model.extend({
|
|||||||
} else {
|
} else {
|
||||||
return Ember.RSVP.reject(I18n.t('user.delete_yourself_not_allowed'));
|
return Ember.RSVP.reject(I18n.t('user.delete_yourself_not_allowed'));
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dismissBanner: function (bannerKey) {
|
||||||
|
this.set("dismissed_banner_key", bannerKey);
|
||||||
|
Discourse.ajax("/users/" + this.get('username'), {
|
||||||
|
type: 'PUT',
|
||||||
|
data: { dismissed_banner_key: bannerKey }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
{{#if visible}}
|
||||||
|
<div id="banner">
|
||||||
|
<div id="banner-content">
|
||||||
|
<div class="close" {{action dismiss}}><i class="fa fa-times" title="{{i18n banner.close}}"></i></div>
|
||||||
|
{{{banner.html}}}
|
||||||
|
</div>
|
||||||
|
<a href="{{unbound banner.url}}" class="btn" title="{{i18n banner.read_more.title}}">{{i18n banner.read_more.text}}</a>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
@ -1,6 +1,7 @@
|
|||||||
<div class='container'>
|
<div class='container'>
|
||||||
{{custom-html "top"}}
|
{{custom-html "top"}}
|
||||||
{{Discourse.globalNotice}}
|
{{Discourse.globalNotice}}
|
||||||
|
{{discourse-banner user=currentUser banner=Discourse.banner}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='list-controls'>
|
<div class='list-controls'>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<div class='container'>
|
<div class='container'>
|
||||||
{{custom-html "top"}}
|
{{custom-html "top"}}
|
||||||
{{Discourse.globalNotice}}
|
{{Discourse.globalNotice}}
|
||||||
|
{{discourse-banner user=currentUser banner=Discourse.banner}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#if postStream.loaded}}
|
{{#if postStream.loaded}}
|
||||||
|
14
app/assets/stylesheets/common/components/banner.css.scss
Normal file
14
app/assets/stylesheets/common/components/banner.css.scss
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// --------------------------------------------------
|
||||||
|
// Banner
|
||||||
|
// --------------------------------------------------
|
||||||
|
|
||||||
|
#banner {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
.close {
|
||||||
|
font-size: 25px !important;
|
||||||
|
margin-top: 0 !important;
|
||||||
|
}
|
||||||
|
.meta {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
@ -63,16 +63,16 @@ animation: modal .25s;
|
|||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
padding: 10px 15px 7px;
|
padding: 10px 15px 7px;
|
||||||
}
|
}
|
||||||
.close {
|
}
|
||||||
float: right;
|
.close {
|
||||||
font-size: 20px;
|
float: right;
|
||||||
margin: 10px 10px 0;
|
font-size: 20px;
|
||||||
text-decoration: none;
|
margin: 10px 10px 0;
|
||||||
color: scale-color($primary, $lightness: 35%);
|
text-decoration: none;
|
||||||
cursor: pointer;
|
color: scale-color($primary, $lightness: 35%);
|
||||||
&:hover {
|
cursor: pointer;
|
||||||
color: $primary;
|
&:hover {
|
||||||
}
|
color: $primary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,18 +54,16 @@
|
|||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
padding: 0 0 0 20px;
|
padding: 0 0 0 20px;
|
||||||
}
|
}
|
||||||
.close {
|
|
||||||
float: right;
|
|
||||||
font-size: 24px;
|
|
||||||
padding: 15px; // more pixels to touch
|
|
||||||
margin: -15px 0 0 0;
|
|
||||||
text-decoration: none;
|
|
||||||
color: $primary;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
.close {
|
||||||
|
float: right;
|
||||||
|
font-size: 24px;
|
||||||
|
padding: 15px; // more pixels to touch
|
||||||
|
margin: -15px 0 0 0;
|
||||||
|
text-decoration: none;
|
||||||
|
color: $primary;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#move-selected {
|
#move-selected {
|
||||||
p {
|
p {
|
||||||
|
@ -234,6 +234,7 @@ class ApplicationController < ActionController::Base
|
|||||||
store_preloaded("site", Site.json_for(guardian))
|
store_preloaded("site", Site.json_for(guardian))
|
||||||
store_preloaded("siteSettings", SiteSetting.client_settings_json)
|
store_preloaded("siteSettings", SiteSetting.client_settings_json)
|
||||||
store_preloaded("customHTML", custom_html_json)
|
store_preloaded("customHTML", custom_html_json)
|
||||||
|
store_preloaded("banner", banner_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def preload_current_user_data
|
def preload_current_user_data
|
||||||
@ -259,16 +260,23 @@ class ApplicationController < ActionController::Base
|
|||||||
MultiJson.dump(data)
|
MultiJson.dump(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def banner_json
|
||||||
|
topic = Topic.where(archetype: Archetype.banner).limit(1).first
|
||||||
|
banner = topic.present? ? topic.banner : {}
|
||||||
|
|
||||||
|
MultiJson.dump(banner)
|
||||||
|
end
|
||||||
|
|
||||||
def render_json_error(obj)
|
def render_json_error(obj)
|
||||||
render json: MultiJson.dump(create_errors_json(obj)), status: 422
|
render json: MultiJson.dump(create_errors_json(obj)), status: 422
|
||||||
end
|
end
|
||||||
|
|
||||||
def success_json
|
def success_json
|
||||||
{success: 'OK'}
|
{ success: 'OK' }
|
||||||
end
|
end
|
||||||
|
|
||||||
def failed_json
|
def failed_json
|
||||||
{failed: 'FAILED'}
|
{ failed: 'FAILED' }
|
||||||
end
|
end
|
||||||
|
|
||||||
def json_result(obj, opts={})
|
def json_result(obj, opts={})
|
||||||
|
@ -634,12 +634,26 @@ class Topic < ActiveRecord::Base
|
|||||||
self.archetype = Archetype.banner
|
self.archetype = Archetype.banner
|
||||||
self.add_moderator_post(user, I18n.t("archetypes.banner.message.make"))
|
self.add_moderator_post(user, I18n.t("archetypes.banner.message.make"))
|
||||||
self.save
|
self.save
|
||||||
|
|
||||||
|
MessageBus.publish('/site/banner', banner)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_banner!(user)
|
def remove_banner!(user)
|
||||||
self.archetype = Archetype.default
|
self.archetype = Archetype.default
|
||||||
self.add_moderator_post(user, I18n.t("archetypes.banner.message.remove"))
|
self.add_moderator_post(user, I18n.t("archetypes.banner.message.remove"))
|
||||||
self.save
|
self.save
|
||||||
|
|
||||||
|
MessageBus.publish('/site/banner', nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
def banner
|
||||||
|
post = self.posts.order(:post_number).limit(1).first
|
||||||
|
|
||||||
|
{
|
||||||
|
html: post.cooked,
|
||||||
|
url: self.url,
|
||||||
|
key: self.id
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.starred_counts_per_day(sinceDaysAgo=30)
|
def self.starred_counts_per_day(sinceDaysAgo=30)
|
||||||
|
@ -23,7 +23,8 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
:redirected_to_top_reason,
|
:redirected_to_top_reason,
|
||||||
:disable_jump_reply,
|
:disable_jump_reply,
|
||||||
:custom_fields,
|
:custom_fields,
|
||||||
:muted_category_ids
|
:muted_category_ids,
|
||||||
|
:dismissed_banner_key
|
||||||
|
|
||||||
def include_site_flagged_posts_count?
|
def include_site_flagged_posts_count?
|
||||||
object.staff?
|
object.staff?
|
||||||
@ -100,4 +101,8 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
.pluck(:category_id)
|
.pluck(:category_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dismissed_banner_key
|
||||||
|
object.user_profile.dismissed_banner_key
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,8 @@ class UserUpdater
|
|||||||
]
|
]
|
||||||
|
|
||||||
PROFILE_ATTR = [
|
PROFILE_ATTR = [
|
||||||
:location
|
:location,
|
||||||
|
:dismissed_banner_key
|
||||||
]
|
]
|
||||||
|
|
||||||
def initialize(actor, user)
|
def initialize(actor, user)
|
||||||
|
@ -166,6 +166,12 @@ en:
|
|||||||
undo: "Undo"
|
undo: "Undo"
|
||||||
revert: "Revert"
|
revert: "Revert"
|
||||||
|
|
||||||
|
banner:
|
||||||
|
close: "Dismiss this banner."
|
||||||
|
read_more:
|
||||||
|
title: "Click to go to the topic."
|
||||||
|
text: "Read more"
|
||||||
|
|
||||||
choose_topic:
|
choose_topic:
|
||||||
none_found: "No topics found."
|
none_found: "No topics found."
|
||||||
title:
|
title:
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddDismissedBannerKeyToUserProfile < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :user_profiles, :dismissed_banner_key, :integer, nullable: true
|
||||||
|
end
|
||||||
|
end
|
@ -638,41 +638,44 @@ describe Topic do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "make_banner!" do
|
describe "banner" do
|
||||||
|
|
||||||
|
let(:topic) { Fabricate(:topic) }
|
||||||
|
let(:user) { topic.user }
|
||||||
|
let(:banner) { { html: "<p>BANNER</p>", url: topic.url, key: topic.id } }
|
||||||
|
|
||||||
|
before { topic.stubs(:banner).returns(banner) }
|
||||||
|
|
||||||
|
describe "make_banner!" do
|
||||||
|
|
||||||
|
it "changes the topic archetype to 'banner'" do
|
||||||
|
topic.expects(:add_moderator_post)
|
||||||
|
MessageBus.expects(:publish).with("/site/banner", banner)
|
||||||
|
topic.make_banner!(user)
|
||||||
|
topic.archetype.should == Archetype.banner
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ensures only one banner topic at all time" do
|
||||||
|
banner_topic = Fabricate(:banner_topic)
|
||||||
|
Topic.where(archetype: Archetype.banner).count.should == 1
|
||||||
|
|
||||||
|
topic.make_banner!(user)
|
||||||
|
Topic.where(archetype: Archetype.banner).count.should == 1
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
|
||||||
@topic = Fabricate(:topic)
|
|
||||||
@user = @topic.user
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "changes the topic archetype to 'banner'" do
|
describe "remove_banner!" do
|
||||||
@topic.expects(:add_moderator_post)
|
|
||||||
@topic.make_banner!(@user)
|
it "resets the topic archetype" do
|
||||||
@topic.archetype.should == Archetype.banner
|
topic.expects(:add_moderator_post)
|
||||||
|
MessageBus.expects(:publish).with("/site/banner", nil)
|
||||||
|
topic.remove_banner!(user)
|
||||||
|
topic.archetype.should == Archetype.default
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ensures only one banner topic at all time" do
|
|
||||||
banner_topic = Fabricate(:banner_topic)
|
|
||||||
Topic.where(archetype: Archetype.banner).count.should == 1
|
|
||||||
|
|
||||||
@topic.make_banner!(@user)
|
|
||||||
Topic.where(archetype: Archetype.banner).count.should == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "remove_banner!" do
|
|
||||||
|
|
||||||
before do
|
|
||||||
@topic = Fabricate(:topic)
|
|
||||||
@user = @topic.user
|
|
||||||
end
|
|
||||||
|
|
||||||
it "resets the topic archetype" do
|
|
||||||
@topic.expects(:add_moderator_post)
|
|
||||||
@topic.remove_banner!(@user)
|
|
||||||
@topic.archetype.should == Archetype.default
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user