Skip to content

Commit 8a5a981

Browse files
authored
Merge pull request #72 from indentlabs/polish-profiles
Author page polish
2 parents 58992ae + 6d08285 commit 8a5a981

File tree

10 files changed

+58
-21
lines changed

10 files changed

+58
-21
lines changed

app/assets/javascripts/admin.js.coffee

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/assets/javascripts/content.js.coffee

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
$(document).ready ->
22
$('.tab').click ->
3-
btn_href = $('.card-action a').attr('href').split('#')[0];
4-
tab_anchor = $(this).find('a').attr('href')
5-
$('.card-action a').attr('href', btn_href + tab_anchor);
3+
if $('.card-action a').attr('href')
4+
btn_href = $('.card-action a').attr('href').split('#')[0];
5+
tab_anchor = $(this).find('a').attr('href')
6+
$('.card-action a').attr('href', btn_href + tab_anchor);
67
if location.hash?
78
setTimeout ( ->
89
window.scrollTo(0, 0);

app/assets/javascripts/users.js.coffee

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/models/character.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Character < ActiveRecord::Base
3333
# Items
3434
relates :favorite_items, with: :ownerships, where: { favorite: true }
3535

36-
scope :is_public, -> { joins(:universe).where('universes.privacy = ? OR characters.privacy = ?', 'public', 'public') }
36+
scope :is_public, -> { eager_load(:universe).where('characters.privacy = ? OR universes.privacy = ?', 'public', 'public') }
3737

3838
def description
3939
role

app/models/item.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Item < ActiveRecord::Base
2121
relates :current_owners, with: :current_ownerships
2222
relates :makers, with: :maker_relationships
2323

24-
scope :is_public, -> { joins(:universe).where('universes.privacy = ? OR items.privacy = ?', 'public', 'public') }
24+
scope :is_public, -> { eager_load(:universe).where('universes.privacy = ? OR items.privacy = ?', 'public', 'public') }
2525

2626
def self.color
2727
'amber'

app/models/location.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Location < ActiveRecord::Base
2727
relates :largest_cities, with: :largest_cities_relationships
2828
relates :notable_cities, with: :notable_cities_relationships
2929

30-
scope :is_public, -> { joins(:universe).where('universes.privacy = ? OR locations.privacy = ?', 'public', 'public') }
30+
scope :is_public, -> { eager_load(:universe).where('universes.privacy = ? OR locations.privacy = ?', 'public', 'public') }
3131

3232
def self.icon
3333
'terrain'

app/models/universe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Universe < ActiveRecord::Base
1616
has_many :items
1717
has_many :locations
1818

19-
scope :is_public, -> { where(privacy: "public") }
19+
scope :is_public, -> { where(privacy: 'public') }
2020

2121
def content_count
2222
[

app/models/user.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ def content_count
5757
].sum
5858
end
5959

60+
def public_content_count
61+
[
62+
characters.is_public.length,
63+
items.is_public.length,
64+
locations.is_public.length,
65+
universes.is_public.length
66+
].sum
67+
end
68+
6069
def image_url(size=80)
6170
email_md5 = Digest::MD5.hexdigest(email.downcase)
6271
# 80px is Gravatar's default size

app/views/content/form/_actions_dropdown.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
<% end %>
66

77
<ul id='options-menu' class='dropdown-content'>
8-
<%# TODO: something with these %>
8+
<!-- Broken on content edit pages
99
<li><a href="#!" class="share">Share this <%= content.class.to_s.downcase %></a></li>
1010
<li class="divider"></li>
11+
-->
1112
<% if content.persisted? %>
1213
<li>
1314
<%= link_to "Delete this #{content.class.to_s.downcase} forever", content,
1415
:class => 'red-text',
1516
:method => :delete,
16-
:confirm => 'Are you sure? This action cannot be undone!' %>
17+
:data => { :confirm => 'Are you sure? This action cannot be undone!' } %>
1718
</li>
1819
<% end %>
1920
</ul>

app/views/users/show.html.erb

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ content_jsonld = {
2525
%>
2626

2727
<div class="row">
28-
<div class="col s12 m3 l4">
28+
<div class="col s12 m3 l2">
2929

3030
<div class="hoverable card">
3131
<div class="card-image waves-effect waves-block waves-light">
@@ -45,6 +45,7 @@ content_jsonld = {
4545
<% end %>
4646
</div>
4747

48+
<% if @user.public_content_count > 0 %>
4849
<div class="row">
4950
<%= pie_chart({
5051
universes: @user.universes.is_public.count,
@@ -55,6 +56,7 @@ content_jsonld = {
5556
colors: [Universe.color, Character.color, Location.color, "yellow"],
5657
) %>
5758
</div>
59+
<% end %>
5860

5961
</div>
6062
<div class="card-reveal">
@@ -70,19 +72,49 @@ content_jsonld = {
7072
</div>
7173
</div>
7274

73-
<div class="card col s12 m9 l8">
75+
<div class="card col s12 m9 l10">
7476
<div>
7577
<ul class="tabs">
7678
<% tabs.each do |tab| %>
77-
<li class="tab col s3 <%= "disabled" if tab_content_list[tab].empty? %>"><%= link_to pluralize(tab_content_list[tab].length, tab.singularize), "\##{tab}" %></li>
79+
<li class="tab col s3" id="js-<%= tab %>-tab"><%= link_to pluralize(tab_content_list[tab].length, tab.singularize), "\##{tab}" %></li>
7880
<% end %>
7981
</ul>
8082
</div>
8183

8284
<% tabs.each do |tab| %>
83-
<div id="<%= tab %>" class="col s12">
84-
<%= render partial: 'content/list/list', locals: { content_list: tab_content_list[tab], title: '', clean: true } %>
85-
</div>
85+
<% if tab_content_list[tab].any? %>
86+
<div id="<%= tab %>" class="col s12">
87+
<%= render partial: 'content/list/list', locals: { content_list: tab_content_list[tab], title: '', clean: true } %>
88+
</div>
89+
<% elsif tab_content_list[tab].empty? %>
90+
<% tab_class = tab.singularize.titleize.constantize %>
91+
<div id="<%= tab %>" class="col s12">
92+
<div class="center <%= tab_class.color %>-text" style="margin-top: 40px;">
93+
<i class="material-icons" style="font-size: 500%"><%= tab_class.icon %></i>
94+
</div>
95+
<p class="center">
96+
It looks like <%= @user.name %> isn't sharing any public <%= tab %> yet.
97+
</p>
98+
</div>
99+
<% end %>
86100
<% end %>
87101
</div>
88102
</div>
103+
104+
<%
105+
# Default to showing the first tab with content in it (left-first)
106+
tabs.each do |tab|
107+
if tab_content_list[tab].any?
108+
%>
109+
110+
<script type="text/javascript">
111+
$(document).ready(function () {
112+
$('#js-<%= tab %>-tab').find('a')[0].click();
113+
})
114+
</script>
115+
116+
<%
117+
break # Only do this for the first tab with content we see
118+
end
119+
end
120+
%>

0 commit comments

Comments
 (0)