Skip to content

Commit

Permalink
New homepage design (#6497)
Browse files Browse the repository at this point in the history
* start to new front page

* node.authors with test

* home tweaks

* added fixtures, padding, sizing

* Update node.rb

* Add files via upload

* Delete IMG_20191021_100218_039.jpg

* Add files via upload

* move missing.png

* authors length fix

* alternating color rows

* hiding people until that features is completed

* Update home.html.erb

* Update home_controller.rb

* Update style.css

* Update home.html.erb

* Update home_controller.rb
  • Loading branch information
jywarren authored Nov 20, 2019
1 parent b32ffdf commit 39115b4
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ a .fa-white,
color: #666;
clear:both;
margin-top: 40px;
padding: 30px;
padding: 30px !important;
border-top: 1px solid #E5E5E5;
background-color: #f8f8f8;
}
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ def home
if current_user
redirect_to '/dashboard'
else
blog
@projects = Tag.find_nodes_by_type('project:featured', 'page')
.sample(3) # random sampling
@title = I18n.t('home_controller.science_community')
render template: 'home/home'
end
end

# route for seeing the front page even if you are logged in
def front
blog
@projects = Tag.find_nodes_by_type('project:featured', 'page')
.sample(3) # random sampling
@title = I18n.t('home_controller.environmental_investigation')
render template: 'home/home'
@unpaginated = true
Expand Down
13 changes: 8 additions & 5 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,14 @@ def author
User.find(uid)
end

def coauthors
User.where(username: power_tags('with')) if has_power_tag('with')
end

# for wikis:
def authors
revisions.collect(&:author).uniq
end

def coauthors
User.where(username: power_tags('with')) if has_power_tag('with')
end

# tag- and node-based followers
def subscribers(conditions = false)
users = TagSelection.where(tid: tags.collect(&:tid))
Expand Down Expand Up @@ -312,6 +311,10 @@ def body
latest&.body
end

def summary
body.split('\n')&.first
end

# was unable to set up this relationship properly with ActiveRecord associations
def drupal_main_image
DrupalMainImage.order('vid')
Expand Down
121 changes: 111 additions & 10 deletions app/views/home/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,119 @@
<div class="container">

<% cache('feature_home-intro', skip_digest: true) do %>
<%= feature("home-intro") %>
<% end %>

<div class="dashboard">
<% cache('home-blog', expires_in: 60.minutes, skip_digest: true) do %>
<div class="tab-pane active" id="notes">
<% unless @notes.nil? || @notes.length == 0 %>
<%= render partial: "notes/notes", locals: { paginated: false } %>
<p><center><a class="btn btn-outline-secondary" href="/blog">Read more</a></center></p>
<div class="container">

<div class="projects">
<% #cache('home-blog', expires_in: 60.minutes, skip_digest: true) do %>
<% unless @projects.nil? || @projects.length == 0 %>
<% @projects.each_with_index do |project, index| %>
<div class="row px-lg-5<%= " odd" if index.odd? %>">
<div class="col-6 col-xs-12 project-image <%= index.odd? ? " odd pr-lg-5 order-2" : " pl-lg-5" %>">
<a href="<%= project.path %>"><img src="<%= project.main_image %>" /</a>
</div>
<div class="col-6 col-xs-12<%= index.odd? ? " pl-lg-5" : " pr-lg-5" %>">
<h3><a href="<%= project.path %>"><%= project.title %></a></h3>
<p><%= project.summary %></p>
<p><a href="<%= project.path %>">Read more &raquo;</a></p>
<div class="people">
<!-- people most associated with it? editors? pinnable? -->
<!-- replace authors with 'featured people' or something? -->
<!--
<% project.authors[0..2].each do |author| %>
<% if author.photo %>
<a class="person" href="/profile/<%= author.username %>">
<img class="person-image" src="<%= author.photo %>" />
</a>
<% end %>
<% end %>
<% if project.authors.length > 2 %>
<span class="person person-text">
<span class="text"><%= [project.authors.length - 2, 1].max %> more</span>
</span>
<% end %>
-->
</div>
</div>
</div>
<% end %>
</div>
<% end %>
<p><center><a class="btn btn-outline-secondary" href="/projects">More projects</a></center></p>
<% end %>
<% # end %>
</div>
</div>
<style>
.projects {
width: 100%;
position: absolute;
left: 0;
padding: 40px 20px;
}
.projects .row {
padding: 50px 20px;
color: #222;
background: #ffe8c8;
}
.projects .row.odd {
background: white;
}
.projects .row .project-image img {
background: #ccc;
}
.projects .row h3 {
color: #333;
padding-bottom: 10px;
}
.projects .row h3 a {
color: #333;
text-decoration: none;
}
.projects .row a {
color: #333;
text-decoration: underline;
}
.projects .person {
background: #efc997;
float: left;
display: inline-block;
border-radius: 20px;
min-width: 40px;
height: 40px;
margin-right: 5px;
}
.projects .person-image {
border-radius: 20px;
height: 40px;
width: 40px;
}
.projects .person-text {
padding: 5px;
}
.projects .person .text {
color: #884d05;
padding: 3px 8px;
display: inline-block;
}
</style>
<% cache('feature_home-footer', skip_digest: true) do %>
<%= feature("home-footer") %>
<% end %>

Binary file added public/photos/original/missing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test/fixtures/node_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,13 @@ test3_lon:
uid: 16
nid: 25
date: <%= DateTime.now.to_i %>

project:
tid: 28
uid: 1
nid: 13

project2:
tid: 28
uid: 1
nid: 7
4 changes: 4 additions & 0 deletions test/fixtures/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ balloon:
place:
tid: 27
name: place

project:
tid: 28
name: project
9 changes: 9 additions & 0 deletions test/unit/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def setup
assert_equal 1, node.status
assert !node.answered
assert_equal [], node.location_tags
assert node.body
assert node.summary
end

test 'basic question attributes' do
Expand Down Expand Up @@ -513,6 +515,13 @@ def setup
# assert_equal wiki, graph_wiki.values.sum
end

# node.authors should be anyone who's written a revision for this node (a wiki, presumably)
test 'authors' do
authors = Node.last.authors
assert authors
assert_equal 1, authors.length
end

test 'find by tagname and user id' do
# Should test for each type of node: wiki, notes, questions
assert_equal 'Chicago', Node.find_by_tag_and_author('chapter', 1, 'wiki').first.title
Expand Down

0 comments on commit 39115b4

Please sign in to comment.