Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework users show #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/assets/images/office.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions app/decorators/application_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
class ApplicationDecorator < Draper::Decorator
def formatted_columns
self.class.column_names.reject { |e| invisible_columns.include? e }.map { |c| [c.gsub("_", " ").capitalize, self.send(c).to_s] }.to_h

def visible_columns
attributes.keys.select { |e| visible_column_list.include? e }
end

def enabled_columns
attributes.keys.select { |e| enabled_column_list.include? e }
end

def invisible_columns
def visible_column_list
raise NotImplementedError
end

def enabled_column_list
raise NotImplementedError
end

end
12 changes: 10 additions & 2 deletions app/decorators/user_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
class UserDecorator < ApplicationDecorator
delegate_all

def invisible_columns
["password_digest", "name", "remember_digest"]
def visible_column_list
["id"]
end

def enabled_column_list
["email", "password"]
end

def posted_months
self.posts.order(created_at: :asc).map { |p| p.created_at.strftime('%B') }
end
end
15 changes: 7 additions & 8 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
<script>sweetLogin();</script>
<% end %>
<h2 class="center"><%= @user.name %></h2>
<% @user.formatted_columns.each_pair do |k, v| %>
<strong><%= k %>: </strong><%= v %><br />
<% end %>

<h2>Posts</h2>
<div class="container">
<%= render '/users/user_sections/profile' %>
</div>
<%= render '/users/user_sections/posts' %>
<div class="row">
<% @posts.each do |post| %>
<div class="col s12 m6 l4"><%= render partial: "/posts/post", locals: {post: post, full_post: false} %></div>
<% end %>
<div class="col s4">
<%= render '/users/user_sections/months' %>
</div>
</div>
13 changes: 13 additions & 0 deletions app/views/users/user_sections/_months.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="card">
<div class="card-image waves-effect waves-block waves-light">
<img class="activator" src="<%= image_url('office.jpg') %>">
</div>
<div class="card-content">
<span class="card-title activator grey-text text-darken-4">Card Title<i class="material-icons right">more_vert</i></span>
<p><a href="#">This is a link</a></p>
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">Card Title<i class="material-icons right">close</i></span>
<p>Here is some more information about this product that is only revealed once clicked on.</p>
</div>
</div>
6 changes: 6 additions & 0 deletions app/views/users/user_sections/_posts.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h2>Posts</h2>
<div class="row">
<% @posts.each do |post| %>
<div class="col s12 m6 l4"><%= render partial: "/posts/post", locals: {post: post, full_post: false} %></div>
<% end %>
</div>
9 changes: 9 additions & 0 deletions app/views/users/user_sections/_profile.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= simple_form_for @user do |u| %>
<% @user.enabled_columns.each do |c| %>
<%= u.input c %>
<% end %>
<% end %>

<% @user.visible_columns.each do |c| %>
<strong><%= c %>: </strong><%= @user.send(c) %><br />
<% end %>