Merge pull request #2435 from techAPJ/add-bookmark-menu
FEATURE: Add Bookmarks menu to user dropdown
This commit is contained in:
commit
6ceebc3f1c
|
@ -1,6 +1,8 @@
|
||||||
export default Ember.ArrayController.extend(Discourse.HasCurrentUser, {
|
export default Ember.ArrayController.extend(Discourse.HasCurrentUser, {
|
||||||
showAdminLinks: Em.computed.alias("currentUser.staff"),
|
showAdminLinks: Em.computed.alias("currentUser.staff"),
|
||||||
|
|
||||||
|
showBookmarksLink: Em.computed.alias("currentUser.hasBookmark"),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
logout: function() {
|
logout: function() {
|
||||||
Discourse.logout();
|
Discourse.logout();
|
||||||
|
|
|
@ -32,5 +32,3 @@ export default Discourse.ObjectController.extend({
|
||||||
privateMessagesUnreadActive: Em.computed.equal('pmView', 'unread')
|
privateMessagesUnreadActive: Em.computed.equal('pmView', 'unread')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ Discourse.User = Discourse.Model.extend({
|
||||||
hasPMs: Em.computed.gt("private_messages_stats.all", 0),
|
hasPMs: Em.computed.gt("private_messages_stats.all", 0),
|
||||||
hasStartedPMs: Em.computed.gt("private_messages_stats.mine", 0),
|
hasStartedPMs: Em.computed.gt("private_messages_stats.mine", 0),
|
||||||
hasUnreadPMs: Em.computed.gt("private_messages_stats.unread", 0),
|
hasUnreadPMs: Em.computed.gt("private_messages_stats.unread", 0),
|
||||||
|
hasBookmark: Em.computed.gt('bookmarks_count', 0),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The user's stream
|
The user's stream
|
||||||
|
@ -288,7 +289,6 @@ Discourse.User = Discourse.Model.extend({
|
||||||
return this.get('stats').rejectProperty('isPM');
|
return this.get('stats').rejectProperty('isPM');
|
||||||
}.property('stats.@each.isPM'),
|
}.property('stats.@each.isPM'),
|
||||||
|
|
||||||
|
|
||||||
findDetails: function() {
|
findDetails: function() {
|
||||||
var user = this;
|
var user = this;
|
||||||
|
|
||||||
|
|
|
@ -24,5 +24,3 @@ Discourse.UserActionStat = Discourse.Model.extend({
|
||||||
}.property('action_type')
|
}.property('action_type')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
{{#if currentUser.unread_private_messages}}<span class="badge-notification unread-private-messages">{{currentUser.unread_private_messages}}</span>{{/if}}{{i18n user.unread_message_count}}
|
{{#if currentUser.unread_private_messages}}<span class="badge-notification unread-private-messages">{{currentUser.unread_private_messages}}</span>{{/if}}{{i18n user.unread_message_count}}
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
</li>
|
</li>
|
||||||
|
{{#if showBookmarksLink}}
|
||||||
|
<li>{{#link-to 'userActivity.bookmarks' currentUser}}{{i18n user.bookmarks}}{{/link-to}}</li>
|
||||||
|
{{/if}}
|
||||||
<li>{{#link-to 'preferences' currentUser}}{{i18n user.preferences}}{{/link-to}}</li>
|
<li>{{#link-to 'preferences' currentUser}}{{i18n user.preferences}}{{/link-to}}</li>
|
||||||
<li><button {{action "logout"}} class='btn btn-danger right logout'><i class='fa fa-sign-out'></i>{{i18n user.log_out}}</button></li>
|
<li><button {{action "logout"}} class='btn btn-danger right logout'><i class='fa fa-sign-out'></i>{{i18n user.log_out}}</button></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -85,6 +85,10 @@ SQL
|
||||||
{ all: all, mine: mine, unread: unread }
|
{ all: all, mine: mine, unread: unread }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.bookmarks_stats(user_id)
|
||||||
|
UserAction.where(action_type: BOOKMARK, user_id: user_id).count
|
||||||
|
end
|
||||||
|
|
||||||
def self.stream_item(action_id, guardian)
|
def self.stream_item(action_id, guardian)
|
||||||
stream(action_id: action_id, guardian: guardian).first
|
stream(action_id: action_id, guardian: guardian).first
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ class CurrentUserSerializer < BasicUserSerializer
|
||||||
:staff?,
|
:staff?,
|
||||||
:reply_count,
|
:reply_count,
|
||||||
:topic_count,
|
:topic_count,
|
||||||
|
:bookmarks_count,
|
||||||
:enable_quoting,
|
:enable_quoting,
|
||||||
:external_links_in_new_tab,
|
:external_links_in_new_tab,
|
||||||
:dynamic_favicon,
|
:dynamic_favicon,
|
||||||
|
@ -35,6 +36,10 @@ class CurrentUserSerializer < BasicUserSerializer
|
||||||
object.user_stat.topic_reply_count
|
object.user_stat.topic_reply_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bookmarks_count
|
||||||
|
UserAction.bookmarks_stats(object.id)
|
||||||
|
end
|
||||||
|
|
||||||
def site_flagged_posts_count
|
def site_flagged_posts_count
|
||||||
PostAction.flagged_posts_count
|
PostAction.flagged_posts_count
|
||||||
end
|
end
|
||||||
|
|
|
@ -249,6 +249,7 @@ en:
|
||||||
private_messages: "Messages"
|
private_messages: "Messages"
|
||||||
activity_stream: "Activity"
|
activity_stream: "Activity"
|
||||||
preferences: "Preferences"
|
preferences: "Preferences"
|
||||||
|
bookmarks: "Bookmarks"
|
||||||
bio: "About me"
|
bio: "About me"
|
||||||
invited_by: "Invited By"
|
invited_by: "Invited By"
|
||||||
trust_level: "Trust Level"
|
trust_level: "Trust Level"
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
module("Discourse.UserDropdownController");
|
var controller;
|
||||||
|
|
||||||
|
module("controller:user-dropdown", {
|
||||||
|
setup: function() {
|
||||||
|
controller = testController('user-dropdown');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("logout action logs out the current user", function () {
|
test("logout action logs out the current user", function () {
|
||||||
var logout_mock = sinon.mock(Discourse, "logout");
|
var logout_mock = sinon.mock(Discourse, "logout");
|
||||||
|
@ -14,10 +20,20 @@ test("showAdminLinks", function() {
|
||||||
var currentUserStub = Ember.Object.create();
|
var currentUserStub = Ember.Object.create();
|
||||||
this.stub(Discourse.User, "current").returns(currentUserStub);
|
this.stub(Discourse.User, "current").returns(currentUserStub);
|
||||||
|
|
||||||
var controller = controllerFor('user-dropdown');
|
|
||||||
currentUserStub.set("staff", true);
|
currentUserStub.set("staff", true);
|
||||||
equal(controller.get("showAdminLinks"), true, "is true when current user is a staff member");
|
equal(controller.get("showAdminLinks"), true, "is true when current user is a staff member");
|
||||||
|
|
||||||
currentUserStub.set("staff", false);
|
currentUserStub.set("staff", false);
|
||||||
equal(controller.get("showAdminLinks"), false, "is false when current user is not a staff member");
|
equal(controller.get("showAdminLinks"), false, "is false when current user is not a staff member");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("showBookmarksLink", function() {
|
||||||
|
var currentUserStub = Ember.Object.create();
|
||||||
|
this.stub(Discourse.User, "current").returns(currentUserStub);
|
||||||
|
|
||||||
|
currentUserStub.set("hasBookmark", true);
|
||||||
|
equal(controller.get("showBookmarksLink"), true, "is true when current user have bookmarks");
|
||||||
|
|
||||||
|
currentUserStub.set("hasBookmark", false);
|
||||||
|
equal(controller.get("showBookmarksLink"), false, "is false when current user does not have bookmarks");
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue