* feat: add a hidden tags route + controller + view * refactor: make a re-useable template for hidden_tags and following_tags * chore: add some jsdocs to document/help follow the code * chore: add some jsdocs to document/help follow the code * feat: add soem comment changes * refactor: use more readable string concatenation * refactor: use more readable string concatenation * fix: whoops error in template literal * feat: potential solution to being able to query the paginated hidden tags whilst using the existing following_tags functionality * feat: typo * chore: add comment * update the count for the dashboard sidebar * feat: add the correct count on the mobile action menu * spec: update the request spec to ensure that we have the correct tags being displayed * refactor: query for hidden tags * chore: update initscrolling language in comments * refactor: prioritize readability * refactor: update where clause * chore: add more clarifying comments * feat: make sure that we only rename if action exists in initScrolling * feat: update the styling for the update weights section * feat: include followable on tag page * feat: update points to explicit_points in the followings_controller * feat: abstract out the uncommon UI elements and move them to the top level template * feat: remove unused html * chore: remove the antispam tag * feat: update the tags template and corresponding localization keys * chore: update the comment * feat: update the following_tags spec * spec: update accordingly * refactor: use URLSearchParams * feat: update the follow and antifollow/hidden tags * feat: use a range * fix: use explicit points * Empty commit * feat: update the pagination styles * update localization
54 lines
1.8 KiB
Ruby
54 lines
1.8 KiB
Ruby
class FollowingsController < ApplicationController
|
|
before_action :authenticate_user!
|
|
before_action -> { limit_per_page(default: 80, max: 1000) }
|
|
|
|
ATTRIBUTES_FOR_SERIALIZATION = %i[id followable_id followable_type].freeze
|
|
TAGS_ATTRIBUTES_FOR_SERIALIZATION = [*ATTRIBUTES_FOR_SERIALIZATION, :points, :explicit_points].freeze
|
|
|
|
def users
|
|
relation = current_user.follows_by_type("User")
|
|
.select(ATTRIBUTES_FOR_SERIALIZATION)
|
|
.order(created_at: :desc)
|
|
@follows = load_follows_and_paginate(relation)
|
|
end
|
|
|
|
def tags
|
|
relation = current_user.follows_by_type("ActsAsTaggableOn::Tag").select(TAGS_ATTRIBUTES_FOR_SERIALIZATION)
|
|
relation = if params[:controller_action] == "hidden_tags"
|
|
relation.where(explicit_points: (...0))
|
|
else
|
|
relation.where(explicit_points: (0...))
|
|
end
|
|
relation = relation.order(explicit_points: :desc)
|
|
@followed_tags = load_follows_and_paginate(relation)
|
|
end
|
|
|
|
def organizations
|
|
relation = current_user.follows_by_type("Organization")
|
|
.select(ATTRIBUTES_FOR_SERIALIZATION)
|
|
.order(created_at: :desc)
|
|
@followed_organizations = load_follows_and_paginate(relation)
|
|
end
|
|
|
|
def podcasts
|
|
relation = current_user.follows_by_type("Podcast")
|
|
.select(ATTRIBUTES_FOR_SERIALIZATION)
|
|
.order(created_at: :desc)
|
|
@followed_podcasts = load_follows_and_paginate(relation)
|
|
end
|
|
|
|
private_constant :ATTRIBUTES_FOR_SERIALIZATION
|
|
|
|
private_constant :TAGS_ATTRIBUTES_FOR_SERIALIZATION
|
|
|
|
private
|
|
|
|
def limit_per_page(default:, max:)
|
|
per_page = (params[:per_page] || default).to_i
|
|
@follows_limit = [per_page, max].min
|
|
end
|
|
|
|
def load_follows_and_paginate(relation)
|
|
relation.includes(:followable).page(params[:page]).per(@follows_limit)
|
|
end
|
|
end
|