FEATURE: Button to reset new
This commit is contained in:
parent
3abe84941f
commit
f9cd354a2c
|
@ -43,6 +43,15 @@ Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
|
|||
this.get('selected').clear();
|
||||
},
|
||||
|
||||
resetNew: function() {
|
||||
var self = this;
|
||||
|
||||
Discourse.TopicTrackingState.current().resetNew();
|
||||
Discourse.Topic.resetNew().then(function() {
|
||||
self.send('refresh');
|
||||
});
|
||||
},
|
||||
|
||||
dismissRead: function() {
|
||||
var self = this,
|
||||
selected = this.get('selected'),
|
||||
|
@ -68,6 +77,10 @@ Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
|
|||
return this.get('filter') === 'unread' && this.get('topics.length') > 0;
|
||||
}.property('filter', 'topics.length'),
|
||||
|
||||
showResetNew: function() {
|
||||
return this.get('filter') === 'new' && this.get('topics.length') > 0;
|
||||
}.property('filter', 'topics.length'),
|
||||
|
||||
canBulkSelect: Em.computed.alias('currentUser.staff'),
|
||||
hasTopics: Em.computed.gt('topics.length', 0),
|
||||
showTable: Em.computed.or('hasTopics', 'topicTrackingState.hasIncoming'),
|
||||
|
|
|
@ -428,8 +428,13 @@ Discourse.Topic.reopenClass({
|
|||
type: 'PUT',
|
||||
data: { filter: filter, operation: operation }
|
||||
});
|
||||
},
|
||||
|
||||
resetNew: function() {
|
||||
return Discourse.ajax("/topics/reset-new", {type: 'PUT'});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -145,6 +145,15 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
|
|||
.length;
|
||||
},
|
||||
|
||||
resetNew: function() {
|
||||
var self = this;
|
||||
Object.keys(this.states).forEach(function (id) {
|
||||
if (self.states[id].last_read_post_number === null) {
|
||||
delete self.states[id];
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
countUnread: function(category_name){
|
||||
return _.chain(this.states)
|
||||
.where(function(topic){
|
||||
|
|
|
@ -68,6 +68,9 @@
|
|||
{{#if showDismissRead}}
|
||||
<button class='btn dismiss-read' {{action dismissRead}}>{{i18n topics.bulk.dismiss_read}}</button>
|
||||
{{/if}}
|
||||
{{#if showResetNew}}
|
||||
<button class='btn dismiss-read' {{action resetNew}}>{{i18n topics.bulk.mark_seen}}</button>
|
||||
{{/if}}
|
||||
|
||||
<h3>
|
||||
{{#if latest}}
|
||||
|
|
|
@ -21,7 +21,8 @@ class TopicsController < ApplicationController
|
|||
:merge_topic,
|
||||
:clear_pin,
|
||||
:autoclose,
|
||||
:bulk]
|
||||
:bulk,
|
||||
:reset_new]
|
||||
|
||||
before_filter :consider_user_for_promotion, only: :show
|
||||
|
||||
|
@ -281,6 +282,11 @@ class TopicsController < ApplicationController
|
|||
render_json_dump topic_ids: changed_topic_ids
|
||||
end
|
||||
|
||||
def reset_new
|
||||
current_user.user_stat.update_column(:new_since, Time.now)
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def toggle_mute
|
||||
|
|
|
@ -630,6 +630,7 @@ en:
|
|||
bulk:
|
||||
reset_read: "Reset Read"
|
||||
dismiss_read: "Dismiss Read"
|
||||
mark_seen: "Mark Seen"
|
||||
toggle: "toggle bulk selection of topics"
|
||||
actions: "Bulk Actions"
|
||||
change_category: "Change Category"
|
||||
|
|
|
@ -281,6 +281,7 @@ Discourse::Application.routes.draw do
|
|||
put "t/:id" => "topics#update"
|
||||
delete "t/:id" => "topics#destroy"
|
||||
put "topics/bulk"
|
||||
put "topics/reset-new" => 'topics#reset_new'
|
||||
post "topics/timings"
|
||||
get "topics/similar_to"
|
||||
get "topics/created-by/:username" => "list#topics_by", as: "topics_by", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
|
|
|
@ -811,4 +811,25 @@ describe TopicsController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'reset_new' do
|
||||
it 'needs you to be logged in' do
|
||||
lambda { xhr :put, :reset_new }.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
let(:user) { log_in(:user) }
|
||||
|
||||
it "updates the `new_since` date" do
|
||||
old_date = 2.years.ago
|
||||
|
||||
user.user_stat.update_column(:new_since, old_date)
|
||||
|
||||
xhr :put, :reset_new
|
||||
user.reload
|
||||
user.user_stat.new_since.to_date.should_not == old_date.to_date
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue