Add avatar to user class

This also updates the supporting code to enable dumping deferred
post information to the page, which was partially broken in a
previous commit.
This commit is contained in:
Kira 2019-04-30 06:50:43 -07:00
parent 01418903aa
commit 25f8222d2c
9 changed files with 25 additions and 7 deletions

View File

@ -97,7 +97,7 @@ class UsersController < ApplicationController
]
permitted_params += [dmail_filter_attributes: %i[id words]]
permitted_params += [:profile_about, :profile_artinfo, :email] if CurrentUser.is_member? # Prevent editing when blocked
permitted_params += [:profile_about, :profile_artinfo, :email, :avatar_id] if CurrentUser.is_member? # Prevent editing when blocked
permitted_params += [:name, :email] if context == :create
permitted_params << :level if CurrentUser.is_admin?

View File

@ -239,6 +239,11 @@ module ApplicationHelper
[:"#{prefix}-#{name}", value]
end.to_h
end
def user_avatar(post_id)
DeferredPosts.add(post_id) if post_id
tag.div (tag.img class: 'thumb-img placeholder', src: '/images/thumb-preview.png', height: 100, width: 100), class: 'thumbnail placeholder', id: "tp-#{post_id}"
end
protected
def nav_link_match(controller, url)

View File

@ -2,7 +2,7 @@ class DeferredPosts
KEY = :deferred_posts
def self.add(post_id)
raise ArgumentError.new "post id must be a number" if post_id.nil? || !post_id.respond_to?(:to_id)
raise ArgumentError.new "post id must be a number" if post_id.nil? || !post_id.respond_to?(:to_i)
posts = RequestStore[KEY] || []
posts << post_id.to_i
RequestStore[KEY] = posts
@ -20,6 +20,7 @@ class DeferredPosts
def self.dump
post_ids = RequestStore[KEY] || []
post_ids.uniq!
return {} if post_ids.size == 0
post_hash = {}
posts = Post.where(id: post_ids)
posts.find_each do |p|

View File

@ -1545,10 +1545,12 @@ class Post < ApplicationRecord
def minimal_attributes
hash = {
'status': status,
'flags': status_flags,
'file_ext': file_ext,
'id': id,
'rating': rating,
'width': width,
'height': height,
'width': image_width,
'height': image_height,
'tags': tag_string,
'score': score,
'uploader_id': uploader_id

View File

@ -109,6 +109,7 @@ class User < ApplicationRecord
has_many :post_sets, -> {order(name: :asc)}, foreign_key: :creator_id
has_many :favorites, ->(rec) {where("user_id % 100 = #{rec.id % 100} and user_id = #{rec.id}").order("id desc")}
belongs_to :inviter, class_name: "User", optional: true
belongs_to :avatar, class_name: 'Post', optional: true
accepts_nested_attributes_for :dmail_filter
module BanMethods

View File

@ -1,3 +1,3 @@
<script>
var ___deferred_posts = <%= DeferredPosts.dump.as_json %>;
var ___deferred_posts = <%= raw DeferredPosts.dump.to_json %>;
</script>

View File

@ -36,6 +36,8 @@
</p>
</div>
<%= f.input :avatar_id, type: :number, label: 'Avatar Post ID' %>
<%= f.input :profile_about, label: "About Me" %>
<%= f.input :profile_artinfo, label: "Commission Info" %>

View File

@ -0,0 +1,5 @@
class AddUserAvatarId < ActiveRecord::Migration[5.2]
def change
add_column :users, :avatar_id, :integer
end
end

View File

@ -2462,7 +2462,8 @@ furry -rating:s'::text,
unread_dmail_count integer DEFAULT 0 NOT NULL,
set_count integer DEFAULT 0 NOT NULL,
profile_about text,
profile_artinfo text
profile_artinfo text,
avatar_id integer
);
@ -4883,6 +4884,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20190418093745'),
('20190427163107'),
('20190427181805'),
('20190428132152');
('20190428132152'),
('20190430120155');