FEATURE: Read Faq badge

This commit is contained in:
Sam 2014-07-11 17:32:29 +10:00
parent 167a2a68e6
commit 833c50c460
7 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,22 @@
export default Discourse.View.extend({
didInsertElement: function() {
var path = this.get('controller.model.path');
if(path === "faq" || path === "guidelines"){
var $window = $(window);
$window.on('scroll.faq', function(){
if($window.scrollTop() + $window.height() > $(document).height() - 10) {
if(!this._notifiedBottom){
this._notifiedBottom = true;
Discourse.ajax("/users/read-faq", {
method: "POST"
});
}
}
});
}
},
willDestroyElement: function(){
$(window).off('scroll.faq');
}
});

View File

@ -411,6 +411,15 @@ class UsersController < ApplicationController
render json: success_json
end
def read_faq
if(user = current_user)
user.user_stat.read_faq = 1.second.ago
user.user_stat.save
end
render json: success_json
end
private
def honeypot_value

View File

@ -12,12 +12,19 @@ class Badge < ActiveRecord::Base
FirstFlag = 13
FirstLink = 14
FirstQuote = 15
ReadFaq = 16
# other consts
AutobiographerMinBioLength = 10
module Queries
ReadFaq = <<SQL
SELECT user_id, read_faq
WHERE read_faq IS NOT NULL
SQL
FirstQuote = <<SQL
SELECT l.user_id, l.post_id, l.created_at granted_at
FROM

View File

@ -1996,3 +1996,6 @@ en:
first_quote:
name: First Quote
description: Quoted a user
read_faq:
name: Read Faq
description: Read the community guidelines

View File

@ -181,6 +181,7 @@ Discourse::Application.routes.draw do
get "privacy" => "static#show", id: "privacy"
get "signup" => "list#latest"
post "users/read-faq" => "users#read_faq"
get "users/search/users" => "users#search_users"
get "users/password-reset/:token" => "users#password_reset"
put "users/password-reset/:token" => "users#password_reset"

View File

@ -18,6 +18,15 @@ trust_level_badges.each do |spec|
end
end
Badge.seed do |b|
b.id = Badge::ReadFaq
b.name = "Read Faq"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = false
b.query = Badge::Queries::ReadFaq
end
Badge.seed do |b|
b.id = Badge::FirstLink
b.name = "First Link"

View File

@ -0,0 +1,5 @@
class AddReadFaqToUserStats < ActiveRecord::Migration
def change
add_column :user_stats, :read_faq, :datetime
end
end