mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 09:57:25 +08:00
FEATURE: Add user preference for title counter mode (#7364)
This commit is contained in:
@ -51,7 +51,9 @@ const Discourse = Ember.Application.extend({
|
|||||||
$("title").text(title);
|
$("title").text(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
var displayCount = Discourse.User.current()
|
var displayCount =
|
||||||
|
Discourse.User.current() &&
|
||||||
|
Discourse.User.currentProp("title_count_mode") === "notifications"
|
||||||
? this.get("notificationCount")
|
? this.get("notificationCount")
|
||||||
: this.get("contextCount");
|
: this.get("contextCount");
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ const USER_HOMES = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const TEXT_SIZES = ["smaller", "normal", "larger", "largest"];
|
const TEXT_SIZES = ["smaller", "normal", "larger", "largest"];
|
||||||
|
const TITLE_COUNT_MODES = ["notifications", "contextual"];
|
||||||
|
|
||||||
export default Ember.Controller.extend(PreferencesTabController, {
|
export default Ember.Controller.extend(PreferencesTabController, {
|
||||||
@computed("makeThemeDefault")
|
@computed("makeThemeDefault")
|
||||||
@ -35,7 +36,8 @@ export default Ember.Controller.extend(PreferencesTabController, {
|
|||||||
"allow_private_messages",
|
"allow_private_messages",
|
||||||
"homepage_id",
|
"homepage_id",
|
||||||
"hide_profile_and_presence",
|
"hide_profile_and_presence",
|
||||||
"text_size"
|
"text_size",
|
||||||
|
"title_count_mode"
|
||||||
];
|
];
|
||||||
|
|
||||||
if (makeDefault) {
|
if (makeDefault) {
|
||||||
@ -69,6 +71,13 @@ export default Ember.Controller.extend(PreferencesTabController, {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed
|
||||||
|
titleCountModes() {
|
||||||
|
return TITLE_COUNT_MODES.map(value => {
|
||||||
|
return { name: I18n.t(`user.title_count_mode.${value}`), value };
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
userSelectableThemes: function() {
|
userSelectableThemes: function() {
|
||||||
return listThemes(this.site);
|
return listThemes(this.site);
|
||||||
}.property(),
|
}.property(),
|
||||||
|
@ -286,7 +286,8 @@ const User = RestModel.extend({
|
|||||||
"allow_private_messages",
|
"allow_private_messages",
|
||||||
"homepage_id",
|
"homepage_id",
|
||||||
"hide_profile_and_presence",
|
"hide_profile_and_presence",
|
||||||
"text_size"
|
"text_size",
|
||||||
|
"title_count_mode"
|
||||||
];
|
];
|
||||||
|
|
||||||
if (fields) {
|
if (fields) {
|
||||||
|
@ -58,6 +58,13 @@
|
|||||||
{{#if isiPad}}
|
{{#if isiPad}}
|
||||||
{{preference-checkbox labelKey="user.enable_physical_keyboard" checked=disableSafariHacks}}
|
{{preference-checkbox labelKey="user.enable_physical_keyboard" checked=disableSafariHacks}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
<div class='controls controls-dropdown'>
|
||||||
|
<label for="user-email-level">{{i18n 'user.title_count_mode.title'}}</label>
|
||||||
|
{{combo-box valueAttribute="value"
|
||||||
|
content=titleCountModes
|
||||||
|
value=model.user_option.title_count_mode
|
||||||
|
id="user-title-count-mode"}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{plugin-outlet name="user-preferences-interface" args=(hash model=model save=(action "save"))}}
|
{{plugin-outlet name="user-preferences-interface" args=(hash model=model save=(action "save"))}}
|
||||||
|
@ -29,6 +29,10 @@ class UserOption < ActiveRecord::Base
|
|||||||
@text_sizes ||= Enum.new(normal: 0, larger: 1, largest: 2, smaller: 3)
|
@text_sizes ||= Enum.new(normal: 0, larger: 1, largest: 2, smaller: 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.title_count_modes
|
||||||
|
@title_count_modes ||= Enum.new(notifications: 0, contextual: 1)
|
||||||
|
end
|
||||||
|
|
||||||
def self.email_level_types
|
def self.email_level_types
|
||||||
@email_level_type ||= Enum.new(always: 0, only_when_away: 1, never: 2)
|
@email_level_type ||= Enum.new(always: 0, only_when_away: 1, never: 2)
|
||||||
end
|
end
|
||||||
@ -68,6 +72,8 @@ class UserOption < ActiveRecord::Base
|
|||||||
|
|
||||||
self.text_size = SiteSetting.default_text_size
|
self.text_size = SiteSetting.default_text_size
|
||||||
|
|
||||||
|
self.title_count_mode = SiteSetting.default_title_count_mode
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -164,6 +170,14 @@ class UserOption < ActiveRecord::Base
|
|||||||
self.text_size_key = UserOption.text_sizes[value.to_sym]
|
self.text_size_key = UserOption.text_sizes[value.to_sym]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def title_count_mode
|
||||||
|
UserOption.title_count_modes[title_count_mode_key]
|
||||||
|
end
|
||||||
|
|
||||||
|
def title_count_mode=(value)
|
||||||
|
self.title_count_mode_key = UserOption.title_count_modes[value.to_sym]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def update_tracked_topics
|
def update_tracked_topics
|
||||||
|
@ -43,7 +43,8 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
:hide_profile_and_presence,
|
:hide_profile_and_presence,
|
||||||
:groups,
|
:groups,
|
||||||
:second_factor_enabled,
|
:second_factor_enabled,
|
||||||
:ignored_users
|
:ignored_users,
|
||||||
|
:title_count_mode
|
||||||
|
|
||||||
def groups
|
def groups
|
||||||
object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name.downcase } }
|
object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name.downcase } }
|
||||||
@ -89,6 +90,10 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
object.user_option.dynamic_favicon
|
object.user_option.dynamic_favicon
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def title_count_mode
|
||||||
|
object.user_option.title_count_mode
|
||||||
|
end
|
||||||
|
|
||||||
def automatically_unpin_topics
|
def automatically_unpin_topics
|
||||||
object.user_option.automatically_unpin_topics
|
object.user_option.automatically_unpin_topics
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,8 @@ class UserOptionSerializer < ApplicationSerializer
|
|||||||
:homepage_id,
|
:homepage_id,
|
||||||
:hide_profile_and_presence,
|
:hide_profile_and_presence,
|
||||||
:text_size,
|
:text_size,
|
||||||
:text_size_seq
|
:text_size_seq,
|
||||||
|
:title_count_mode
|
||||||
|
|
||||||
def auto_track_topics_after_msecs
|
def auto_track_topics_after_msecs
|
||||||
object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs
|
object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs
|
||||||
|
@ -37,7 +37,8 @@ class UserUpdater
|
|||||||
:allow_private_messages,
|
:allow_private_messages,
|
||||||
:homepage_id,
|
:homepage_id,
|
||||||
:hide_profile_and_presence,
|
:hide_profile_and_presence,
|
||||||
:text_size
|
:text_size,
|
||||||
|
:title_count_mode
|
||||||
]
|
]
|
||||||
|
|
||||||
def initialize(actor, user)
|
def initialize(actor, user)
|
||||||
|
@ -1036,6 +1036,11 @@ en:
|
|||||||
larger: "Larger"
|
larger: "Larger"
|
||||||
largest: "Largest"
|
largest: "Largest"
|
||||||
|
|
||||||
|
title_count_mode:
|
||||||
|
title: "Background page title displays count of:"
|
||||||
|
notifications: "Unseen notifications"
|
||||||
|
contextual: "Unseen page content"
|
||||||
|
|
||||||
like_notification_frequency:
|
like_notification_frequency:
|
||||||
title: "Notify when liked"
|
title: "Notify when liked"
|
||||||
always: "Always"
|
always: "Always"
|
||||||
|
@ -1965,6 +1965,8 @@ en:
|
|||||||
|
|
||||||
default_text_size: "Text size which is selected by default"
|
default_text_size: "Text size which is selected by default"
|
||||||
|
|
||||||
|
default_title_count_mode: "Default mode for the page title counter"
|
||||||
|
|
||||||
retain_web_hook_events_period_days: "Number of days to retain web hook event records."
|
retain_web_hook_events_period_days: "Number of days to retain web hook event records."
|
||||||
retry_web_hook_events: "Automatically retry failed web hook events for 4 times. Time gaps between the retries are 1, 5, 25 and 125 minutes."
|
retry_web_hook_events: "Automatically retry failed web hook events for 4 times. Time gaps between the retries are 1, 5, 25 and 125 minutes."
|
||||||
|
|
||||||
|
@ -1910,6 +1910,12 @@ user_preferences:
|
|||||||
- larger
|
- larger
|
||||||
- largest
|
- largest
|
||||||
|
|
||||||
|
default_title_count_mode:
|
||||||
|
type: enum
|
||||||
|
default: notifications
|
||||||
|
choices:
|
||||||
|
- notifications
|
||||||
|
- contextual
|
||||||
api:
|
api:
|
||||||
retain_web_hook_events_period_days:
|
retain_web_hook_events_period_days:
|
||||||
default: 30
|
default: 30
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddTitleCountModeToUserOptions < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :user_options, :title_count_mode_key, :integer, null: false, default: 0
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user