mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: add help text for no bookmarks in user page
This commit is contained in:
parent
efe24f7cc6
commit
266322ce2e
@ -28,11 +28,21 @@ export default RestModel.extend({
|
|||||||
|
|
||||||
baseUrl: url('itemsLoaded', 'user.username_lower', '/user_actions.json?offset=%@&username=%@'),
|
baseUrl: url('itemsLoaded', 'user.username_lower', '/user_actions.json?offset=%@&username=%@'),
|
||||||
|
|
||||||
filterBy(filter) {
|
filterBy(filter, noContentHelpKey) {
|
||||||
this.setProperties({ filter, itemsLoaded: 0, content: [], lastLoadedUrl: null });
|
this.setProperties({
|
||||||
|
filter,
|
||||||
|
itemsLoaded: 0,
|
||||||
|
content: [],
|
||||||
|
noContentHelpKey: noContentHelpKey,
|
||||||
|
lastLoadedUrl: null
|
||||||
|
});
|
||||||
return this.findItems();
|
return this.findItems();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
noContent: function() {
|
||||||
|
return this.get('loaded') && this.get('content').length === 0;
|
||||||
|
}.property('loaded', 'content.@each'),
|
||||||
|
|
||||||
remove(userAction) {
|
remove(userAction) {
|
||||||
// 1) remove the user action from the child groups
|
// 1) remove the user action from the child groups
|
||||||
this.get("content").forEach(function (ua) {
|
this.get("content").forEach(function (ua) {
|
||||||
@ -61,6 +71,9 @@ export default RestModel.extend({
|
|||||||
if (this.get('filterParam')) {
|
if (this.get('filterParam')) {
|
||||||
findUrl += "&filter=" + this.get('filterParam');
|
findUrl += "&filter=" + this.get('filterParam');
|
||||||
}
|
}
|
||||||
|
if (this.get('noContentHelpKey')) {
|
||||||
|
findUrl += "&no_results_help_key=" + this.get('noContentHelpKey');
|
||||||
|
}
|
||||||
|
|
||||||
// Don't load the same stream twice. We're probably at the end.
|
// Don't load the same stream twice. We're probably at the end.
|
||||||
const lastLoadedUrl = this.get('lastLoadedUrl');
|
const lastLoadedUrl = this.get('lastLoadedUrl');
|
||||||
@ -69,6 +82,9 @@ export default RestModel.extend({
|
|||||||
if (this.get('loading')) { return Ember.RSVP.resolve(); }
|
if (this.get('loading')) { return Ember.RSVP.resolve(); }
|
||||||
this.set('loading', true);
|
this.set('loading', true);
|
||||||
return ajax(findUrl, {cache: 'false'}).then( function(result) {
|
return ajax(findUrl, {cache: 'false'}).then( function(result) {
|
||||||
|
if (result && result.no_results_help) {
|
||||||
|
self.set('noContentHelp', result.no_results_help);
|
||||||
|
}
|
||||||
if (result && result.user_actions) {
|
if (result && result.user_actions) {
|
||||||
const copy = Em.A();
|
const copy = Em.A();
|
||||||
result.user_actions.forEach(function(action) {
|
result.user_actions.forEach(function(action) {
|
||||||
@ -78,11 +94,11 @@ export default RestModel.extend({
|
|||||||
|
|
||||||
self.get('content').pushObjects(UserAction.collapseStream(copy));
|
self.get('content').pushObjects(UserAction.collapseStream(copy));
|
||||||
self.setProperties({
|
self.setProperties({
|
||||||
loaded: true,
|
|
||||||
itemsLoaded: self.get('itemsLoaded') + result.user_actions.length
|
itemsLoaded: self.get('itemsLoaded') + result.user_actions.length
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).finally(function() {
|
}).finally(function() {
|
||||||
|
self.set('loaded', true);
|
||||||
self.set('loading', false);
|
self.set('loading', false);
|
||||||
self.set('lastLoadedUrl', findUrl);
|
self.set('lastLoadedUrl', findUrl);
|
||||||
});
|
});
|
||||||
|
@ -2,5 +2,6 @@ import UserActivityStreamRoute from "discourse/routes/user-activity-stream";
|
|||||||
import UserAction from "discourse/models/user-action";
|
import UserAction from "discourse/models/user-action";
|
||||||
|
|
||||||
export default UserActivityStreamRoute.extend({
|
export default UserActivityStreamRoute.extend({
|
||||||
userActionType: UserAction.TYPES["bookmarks"]
|
userActionType: UserAction.TYPES["bookmarks"],
|
||||||
|
noContentHelpKey: "user_activity.no_bookmarks"
|
||||||
});
|
});
|
||||||
|
@ -2,5 +2,6 @@ import UserActivityStreamRoute from "discourse/routes/user-activity-stream";
|
|||||||
import UserAction from "discourse/models/user-action";
|
import UserAction from "discourse/models/user-action";
|
||||||
|
|
||||||
export default UserActivityStreamRoute.extend({
|
export default UserActivityStreamRoute.extend({
|
||||||
userActionType: UserAction.TYPES["likes_given"]
|
userActionType: UserAction.TYPES["likes_given"],
|
||||||
|
noContentHelpKey: 'no_likes_given'
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ export default Discourse.Route.extend(ViewingActionType, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
afterModel() {
|
afterModel() {
|
||||||
return this.modelFor("user").get("stream").filterBy(this.get("userActionType"));
|
return this.modelFor("user").get("stream").filterBy(this.get("userActionType"), this.get("noContentHelpKey"));
|
||||||
},
|
},
|
||||||
|
|
||||||
renderTemplate() {
|
renderTemplate() {
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
{{#if model.noContent}}
|
||||||
|
<div class='no-content'>
|
||||||
|
{{{model.noContentHelp}}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
{{#user-stream stream=model}}
|
{{#user-stream stream=model}}
|
||||||
{{#each model.content as |item|}}
|
{{#each model.content as |item|}}
|
||||||
{{stream-item item=item removeBookmark="removeBookmark"}}
|
{{stream-item item=item removeBookmark="removeBookmark"}}
|
||||||
|
@ -24,7 +24,21 @@ class UserActionsController < ApplicationController
|
|||||||
UserAction.stream(opts)
|
UserAction.stream(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
render_serialized(stream, UserActionSerializer, root: 'user_actions')
|
stream = stream.to_a
|
||||||
|
if stream.length == 0 && (help_key = params['no_results_help_key'])
|
||||||
|
if user.id == guardian.user.try(:id)
|
||||||
|
help_key += ".self"
|
||||||
|
else
|
||||||
|
help_key += ".other"
|
||||||
|
end
|
||||||
|
render json: {
|
||||||
|
user_action: [],
|
||||||
|
no_results_help: I18n.t(help_key)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
render_serialized(stream, UserActionSerializer, root: 'user_actions')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -599,6 +599,14 @@ en:
|
|||||||
description: 'Vote for this post'
|
description: 'Vote for this post'
|
||||||
long_form: 'voted for this post'
|
long_form: 'voted for this post'
|
||||||
|
|
||||||
|
user_activity:
|
||||||
|
no_bookmarks:
|
||||||
|
self: "You have no bookmarked posts, bookmarking posts allows you to easily access them later on."
|
||||||
|
other: "No bookmarks."
|
||||||
|
no_likes_given:
|
||||||
|
self: "You have not liked any posts."
|
||||||
|
other: "No liked posts."
|
||||||
|
|
||||||
topic_flag_types:
|
topic_flag_types:
|
||||||
spam:
|
spam:
|
||||||
title: 'Spam'
|
title: 'Spam'
|
||||||
|
@ -24,6 +24,28 @@ describe UserActionsController do
|
|||||||
expect(action["post_number"]).to eq(1)
|
expect(action["post_number"]).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'renders help text if provided for self' do
|
||||||
|
logged_in = log_in
|
||||||
|
|
||||||
|
xhr :get, :index, filter: UserAction::LIKE, username: logged_in.username, no_results_help_key: "user_activity.no_bookmarks"
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
parsed = JSON.parse(response.body)
|
||||||
|
|
||||||
|
expect(parsed["no_results_help"]).to eq(I18n.t("user_activity.no_bookmarks.self"))
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders help text for others' do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
xhr :get, :index, filter: UserAction::LIKE, username: user.username, no_results_help_key: "user_activity.no_bookmarks"
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
parsed = JSON.parse(response.body)
|
||||||
|
|
||||||
|
expect(parsed["no_results_help"]).to eq(I18n.t("user_activity.no_bookmarks.other"))
|
||||||
|
end
|
||||||
|
|
||||||
context "queued posts" do
|
context "queued posts" do
|
||||||
context "without access" do
|
context "without access" do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
|
Loading…
Reference in New Issue
Block a user