diff --git a/app/assets/javascripts/initializers/initializeFetchFollowedArticles.js.erb b/app/assets/javascripts/initializers/initializeFetchFollowedArticles.js.erb index e8b6927a2..40a8051ce 100644 --- a/app/assets/javascripts/initializers/initializeFetchFollowedArticles.js.erb +++ b/app/assets/javascripts/initializers/initializeFetchFollowedArticles.js.erb @@ -31,7 +31,14 @@ function insertNewArticles(user){ var articlePoints = 0 var containsUserID = findOne([article.user_id], user.followed_user_ids || []) var containsOrganizationID = findOne([article.organization_id], user.followed_organization_ids || []) - articlePoints = articlePoints + (intersect_arrays(user.followed_tag_names, article.cached_tag_list_array).length*2) + article.positive_reactions_count + var intersectedTags = intersect_arrays(user.followed_tag_names, article.cached_tag_list_array) + var followedPoints = 1 + JSON.parse(user.followed_tags).map(function(tag) { + if (intersectedTags.includes(tag.name)) { + followedPoints = followedPoints + tag.points + } + }) + articlePoints = articlePoints + (followedPoints*2) + article.positive_reactions_count if (containsUserID || article.user_id === user.id) { articlePoints = articlePoints + 16 } @@ -61,7 +68,14 @@ function insertTopArticles(user){ var articlePoints = 0 var containsUserID = findOne([article.user_id], user.followed_user_ids || []) var containsOrganizationID = findOne([article.organization_id], user.followed_organization_ids || []) - articlePoints = articlePoints + intersect_arrays(user.followed_tag_names, article.cached_tag_list_array).length + var intersectedTags = intersect_arrays(user.followed_tag_names, article.cached_tag_list_array) + var followedPoints = 1 + JSON.parse(user.followed_tags).map(function(tag) { + if (intersectedTags.includes(tag.name)) { + followedPoints = followedPoints + tag.points + } + }) + articlePoints = articlePoints + followedPoints if (containsUserID) { articlePoints = articlePoints + 1 } diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index ae329bb66..912ccd846 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -164,7 +164,7 @@ } h2{ font-weight:500; - margin-bottom:5px; + margin-bottom:10px; margin-top:8px; font-size:22px; @media screen and ( min-width: 800px ) { @@ -182,6 +182,30 @@ font-size: 0.6em; vertical-align:0.16em; } + form { + background: $light-gray; + padding: 8px 15px; + margin-bottom: 10px; + border-radius: 3px; + @media screen and ( min-width: 750px ) { + display: inline-block; + float: right; + } + input { + font-size: 16px; + border-radius: 3px; + padding: 3px 8px; + width: 50px; + border: 1px solid $black; + font-weight: bold; + &[type="submit"] { + width: auto; + background: $green; + font-family: $helvetica-condensed; + margin-left: 5px; + } + } + } } h4{ margin-top:0px; diff --git a/app/controllers/async_info_controller.rb b/app/controllers/async_info_controller.rb index 8a14d3caf..b749cea2a 100644 --- a/app/controllers/async_info_controller.rb +++ b/app/controllers/async_info_controller.rb @@ -38,7 +38,7 @@ class AsyncInfoController < ApplicationController username: @user.username, profile_image_90: ProfileImage.new(@user).get(90), followed_tag_names: @user.cached_followed_tag_names, - followed_tags: @user.cached_followed_tags.to_json(only: %i[id name bg_color_hex text_color_hex]), + followed_tags: @user.cached_followed_tags.to_json(only: %i[id name bg_color_hex text_color_hex], methods: [:points]), followed_user_ids: @user.cached_following_users_ids, followed_organization_ids: @user.cached_following_organizations_ids, reading_list_ids: ReadingList.new(@user).cached_ids_of_articles, diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index 92c470239..34237a93a 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -10,9 +10,11 @@ class DashboardsController < ApplicationController current_user end authorize (@user || User), :dashboard_show? - if params[:which] == "following_users" + if params[:which] == "following" || params[:which] == "following_users" @follows = @user.follows_by_type("User"). order("created_at DESC").includes(:followable).limit(80) + @followed_tags = @user.follows_by_type("ActsAsTaggableOn::Tag"). + order("points DESC").includes(:followable).limit(80) elsif params[:which] == "user_followers" @follows = Follow.where(followable_id: @user.id, followable_type: "User"). includes(:follower).order("created_at DESC").limit(80) diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index 255837509..c18df0503 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -37,4 +37,18 @@ class FollowsController < ApplicationController current_user.touch render json: { outcome: @result } end + + def update + @follow = Follow.find(params[:id]) + authorize @follow + if @follow.update(follow_params) + redirect_to "/dashboard/following" + end + end + + private + + def follow_params + params.require(:follow).permit(policy(Follow).permitted_attributes) + end end diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 3510d1c1b..3d5f6f197 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -107,7 +107,7 @@ class StoriesController < ApplicationController def handle_base_index @home_page = true @page = (params[:page] || 1).to_i - num_articles = 15 + num_articles = 25 @stories = article_finder(num_articles) add_param_context(:page, :timeframe) diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index 7bad166c2..39e488faa 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -2,8 +2,14 @@ class UserDecorator < ApplicationDecorator delegate_all def cached_followed_tags - Rails.cache.fetch("user-#{id}-#{updated_at}/followed_tags", expires_in: 20.hours) do - Tag.where(id: Follow.where(follower_id: id, followable_type: "ActsAsTaggableOn::Tag").pluck(:followable_id)).order("hotness_score DESC") + Rails.cache.fetch("user-#{id}-#{updated_at}/followed_tags_11-30", expires_in: 20.hours) do + follows_query = Follow.where(follower_id: id, followable_type: "ActsAsTaggableOn::Tag").pluck(:followable_id, :points) + tags = Tag.where(id: follows_query.map { |f| f[0] }).order("hotness_score DESC") + tags.each do |t| + follow_query_item = follows_query.detect{|f| f[0] == t.id} + t.points = follow_query_item[1] + end + tags end end diff --git a/app/models/tag.rb b/app/models/tag.rb index 2a4b84241..53cc4e855 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,4 +1,7 @@ class Tag < ActsAsTaggableOn::Tag + + attr_accessor :points + include AlgoliaSearch acts_as_followable resourcify diff --git a/app/policies/follow_policy.rb b/app/policies/follow_policy.rb index b86c86f91..4b1256f14 100644 --- a/app/policies/follow_policy.rb +++ b/app/policies/follow_policy.rb @@ -2,4 +2,18 @@ class FollowPolicy < ApplicationPolicy def create? !user_is_banned? end + + def update? + user_is_follower? + end + + def permitted_attributes + %i[points] + end + + private + + def user_is_follower? + record.follower_id == user.id && record.follower_type == "User" + end end diff --git a/app/views/dashboards/show.html.erb b/app/views/dashboards/show.html.erb index cb5631d38..ac426ad07 100644 --- a/app/views/dashboards/show.html.erb +++ b/app/views/dashboards/show.html.erb @@ -10,9 +10,9 @@ FOLLOWERS (<%= @user.followers_count %>) - " href="/dashboard/following_users"> + " href="/dashboard/following"> FOLLOWING - (<%= @user.following_users_count %>) + (<%= @user.following_users_count + @user.following_tags_count %>) <% if @user.org_admin && @user.organization && (params[:which].blank? || params[:which] == "organization") %> @@ -32,7 +32,31 @@ <%= render "dashboard_article", article: article, org_admin: true %> <% end %> - <% elsif params[:which] == "user_followers" || params[:which] == "following_users" || params[:which] == "organization_user_followers" %> + <% elsif params[:which] == "user_followers" || params[:which] == "following_users" || params[:which] == "following" || params[:which] == "organization_user_followers" %> + <% if @followed_tags %> +
Adjust Follow Weight to make a tag show up less or more in your feed (default 1.0)
+ <% @followed_tags.each do |follow| %> + <% tag = follow.followable %> + <% if tag %> + <% color = HexComparer.new([tag.bg_color_hex || "#0000000",tag.text_color_hex || "#ffffff"]).brightness(0.8) %> +