diff --git a/app/assets/javascripts/discourse/views/static.js.es6 b/app/assets/javascripts/discourse/views/static.js.es6 new file mode 100644 index 00000000000..d65778a69dc --- /dev/null +++ b/app/assets/javascripts/discourse/views/static.js.es6 @@ -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'); + } +}); diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f5725f6280d..9af380f2ffa 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/badge.rb b/app/models/badge.rb index f8b7d600d14..3ab65f2e2b6 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -12,12 +12,19 @@ class Badge < ActiveRecord::Base FirstFlag = 13 FirstLink = 14 FirstQuote = 15 + ReadFaq = 16 # other consts AutobiographerMinBioLength = 10 module Queries + + ReadFaq = < "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" diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index a8cb34eccf0..ba984b57a90 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -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" diff --git a/db/migrate/20140711063215_add_read_faq_to_user_stats.rb b/db/migrate/20140711063215_add_read_faq_to_user_stats.rb new file mode 100644 index 00000000000..90b6ce6efd6 --- /dev/null +++ b/db/migrate/20140711063215_add_read_faq_to_user_stats.rb @@ -0,0 +1,5 @@ +class AddReadFaqToUserStats < ActiveRecord::Migration + def change + add_column :user_stats, :read_faq, :datetime + end +end