mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FEATURE: User Bookmarks Menu
This commit is contained in:
parent
e129e4a19e
commit
aed2483bb9
9 changed files with 34 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
|||
export default Ember.ArrayController.extend(Discourse.HasCurrentUser, {
|
||||
showAdminLinks: Em.computed.alias("currentUser.staff"),
|
||||
|
||||
showBookmarksLink: Em.computed.alias("currentUser.hasBookmark"),
|
||||
|
||||
actions: {
|
||||
logout: function() {
|
||||
Discourse.logout();
|
||||
|
|
|
@ -32,5 +32,3 @@ export default Discourse.ObjectController.extend({
|
|||
privateMessagesUnreadActive: Em.computed.equal('pmView', 'unread')
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ Discourse.User = Discourse.Model.extend({
|
|||
hasPMs: Em.computed.gt("private_messages_stats.all", 0),
|
||||
hasStartedPMs: Em.computed.gt("private_messages_stats.mine", 0),
|
||||
hasUnreadPMs: Em.computed.gt("private_messages_stats.unread", 0),
|
||||
hasBookmark: Em.computed.gt('bookmarks_count', 0),
|
||||
|
||||
/**
|
||||
The user's stream
|
||||
|
@ -287,7 +288,6 @@ Discourse.User = Discourse.Model.extend({
|
|||
return this.get('stats').rejectProperty('isPM');
|
||||
}.property('stats.@each.isPM'),
|
||||
|
||||
|
||||
findDetails: function() {
|
||||
var user = this;
|
||||
|
||||
|
|
|
@ -24,5 +24,3 @@ Discourse.UserActionStat = Discourse.Model.extend({
|
|||
}.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}}
|
||||
{{/link-to}}
|
||||
</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><button {{action "logout"}} class='btn btn-danger right logout'><i class='fa fa-sign-out'></i>{{i18n user.log_out}}</button></li>
|
||||
</ul>
|
||||
|
|
|
@ -85,6 +85,10 @@ SQL
|
|||
{ all: all, mine: mine, unread: unread }
|
||||
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)
|
||||
stream(action_id: action_id, guardian: guardian).first
|
||||
end
|
||||
|
|
|
@ -10,6 +10,7 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||
:staff?,
|
||||
:reply_count,
|
||||
:topic_count,
|
||||
:bookmarks_count,
|
||||
:enable_quoting,
|
||||
:external_links_in_new_tab,
|
||||
:dynamic_favicon,
|
||||
|
@ -35,6 +36,10 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||
object.user_stat.topic_reply_count
|
||||
end
|
||||
|
||||
def bookmarks_count
|
||||
UserAction.bookmarks_stats(object.id)
|
||||
end
|
||||
|
||||
def site_flagged_posts_count
|
||||
PostAction.flagged_posts_count
|
||||
end
|
||||
|
|
|
@ -249,6 +249,7 @@ en:
|
|||
private_messages: "Messages"
|
||||
activity_stream: "Activity"
|
||||
preferences: "Preferences"
|
||||
bookmarks: "Bookmarks"
|
||||
bio: "About me"
|
||||
invited_by: "Invited By"
|
||||
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 () {
|
||||
var logout_mock = sinon.mock(Discourse, "logout");
|
||||
|
@ -14,10 +20,20 @@ test("showAdminLinks", function() {
|
|||
var currentUserStub = Ember.Object.create();
|
||||
this.stub(Discourse.User, "current").returns(currentUserStub);
|
||||
|
||||
var controller = controllerFor('user-dropdown');
|
||||
currentUserStub.set("staff", true);
|
||||
equal(controller.get("showAdminLinks"), true, "is true when current user is a staff member");
|
||||
|
||||
currentUserStub.set("staff", false);
|
||||
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 a new issue