forked from e621ng/e621ng
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:
parent
01418903aa
commit
25f8222d2c
@ -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?
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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|
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,3 +1,3 @@
|
||||
<script>
|
||||
var ___deferred_posts = <%= DeferredPosts.dump.as_json %>;
|
||||
var ___deferred_posts = <%= raw DeferredPosts.dump.to_json %>;
|
||||
</script>
|
@ -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" %>
|
||||
|
5
db/migrate/20190430120155_add_user_avatar_id.rb
Normal file
5
db/migrate/20190430120155_add_user_avatar_id.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddUserAvatarId < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :users, :avatar_id, :integer
|
||||
end
|
||||
end
|
@ -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');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user