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

Random projects page #132

Merged
merged 8 commits into from
Apr 8, 2015
Merged
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
15 changes: 15 additions & 0 deletions app/assets/javascripts/zoomed.application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs

6 changes: 6 additions & 0 deletions app/assets/stylesheets/zoomed.application.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$font-size-base: 32px;

@import "strap-on";
@import "font-awesome";

@import "zoomed";
6 changes: 6 additions & 0 deletions app/assets/stylesheets/zoomed.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.page-header #play-pause-button {
display: none;
}
.page-header:hover #play-pause-button {
display: block;
}
8 changes: 8 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ def delete_episode
redirect_to project_path(nil, @project), notice: "Removed hackweek #{@episode.name}"
end

# GET /projects/random
def random
projects = Project.current(@episode).active
# I can do this with a single query, but that won't be testable or database-agnostic
@project = projects.offset(Kernel.rand(projects.size)).first
render layout: 'zoomed'
end

private

def project_params
Expand Down
24 changes: 24 additions & 0 deletions app/views/layouts/zoomed.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%html{xmlns: 'http://www.w3.org/1999/html'}
%head
%title
- if content_for?(:title)
Hack Week:
= yield :title
-else
Hack Week
%meta{charset: 'utf-8'}
%meta{name: 'viewport', content: 'width=device-width, initial-scale=1.0'}
= favicon_link_tag 'favicon.gif'
= stylesheet_link_tag 'zoomed.application', media: 'all'
%meta{property: 'og:title', content: 'SUSE Hack Week'}
%meta{property: 'og:image', content: 'http://hackweek.suse.com/images/hackweek-logo-10.png'}
%meta{property: 'og:site_name', content: 'SUSE Hack Week'}
%meta{property: 'og:description', content: 'Hack Week is the week where SUSE engineers can experiment without limits. This is the opportunity to innovate, collaborate across teams and learn.'}
= javascript_include_tag 'zoomed.application'
= csrf_meta_tags
%body
.container-fluid
#content
= yield

= yield :script
63 changes: 63 additions & 0 deletions app/views/projects/random.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
- content_for :title do
= @project.title

.row
.col-md-12
.page-header.media
.pull-left
%h3
= @project.title
%br
%small
= render :partial => "projects/state_name", :locals => {:project => @project }
by
= link_to @project.originator.name, @project.originator
.pull-right
%button.btn.btn-default#play-pause-button{ data: { running: :true } }
=fa_icon :pause, id: 'play-pause-icon'
.row
.col-sm-8
:markdown
#{@project.description}
.col-sm-4
.row
.col-sm-12
%h5
- if @project.users.empty?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misreading this, but isn't this missing an else? Wouldn't this display 'No Hackers:' if there are no project participants?

No hackers.
-else
Hackers:
.well.well-sm#hackers
- @project.users.each do |user|
= link_to user_path(user) do
= image_tag user.gravatar_url(:size => "64"), alt: user.name, title: user.name, class: "img-thumbnail", id: "user#{user.id}-gravatar"
.clearfix

.row
.col-sm-12
%h5
Activity:
%ul
- @project.updates.last(5).reverse.each do |update|
%li
= render :partial => "updates/show", :locals => { :update => update }

- content_for :script do
:javascript
$(function() {
$('#play-pause-button').click(function() {
var button = $('#play-pause-button');
var icon = $('#play-pause-icon');
var running = Boolean(button.data("running"));

button.data("running", !running);
icon.toggleClass('fa-play fa-pause');
});

window.setInterval(function() {
var running = Boolean($('#play-pause-button').data("running"));
if (running) {
location.reload();
}
}, 30000);
});
5 changes: 3 additions & 2 deletions app/views/updates/_show.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
= "#{time_ago_in_words update.created_at} ago:"
%em
%small= "#{time_ago_in_words update.created_at} ago:"
= link_to "#{update.author.name}", user_path(update.author)
= " #{update.text}"
%small= " #{update.text}"
= link_to "#{update.project.title}", project_path(update.project)
7 changes: 4 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
get 'newest', to: 'projects#index'
get 'popular'
get 'biggest'
get 'random'
end
member do
get 'like'
Expand All @@ -48,7 +49,7 @@

resources :announcements do
member do
get "enroll"
get "enroll"
end
end

Expand All @@ -59,14 +60,14 @@
end

get "keyword/tokens"
post "api/import", to: "api#import"
post "api/import", to: "api#import"
get "gallery", to: "gallery#index"
get "search", to: "search#result", as: "search"

get "howto", to: "application#howto"
get "news", to: "announcements#index"
get "about", to: "announcements#about"

root 'projects#index'

end
18 changes: 18 additions & 0 deletions spec/controllers/projects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,22 @@
end
end
end

describe 'GET /:episode/projects/random' do
it 'should render special zoomed template' do
get :random
expect(response).to render_template(layout: 'zoomed')
end

it 'assigns random project on each request' do
project = create :project
9.times { create :project }

expect(Kernel).to receive(:rand).with(10).and_return(0)
get :random

expect(assigns(:project)).to eq project
end
end

end