From 923827d374330aa52c193cd0e1a3748e8fef3d7e Mon Sep 17 00:00:00 2001 From: Alice Sheng Date: Tue, 21 Apr 2015 20:37:04 -0700 Subject: [PATCH] load 4 random photos on homepage --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/assets/stylesheets/home.css.erb | 16 ---------------- app/controllers/home_controller.rb | 24 +++++++++++++++++++++++- app/views/home/index.html.erb | 8 ++++---- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index df0c8566..3d0bbe60 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gem 'activerecord-session_store' gem 'authlogic' gem 'd3js-rails', '~> 3.1.6' gem 'exception_notification', '~> 4' +gem 'flickraw' gem 'haml-rails' gem 'jquery-rails', '~> 2.1.4' gem 'mechanize' @@ -25,6 +26,7 @@ gem 'will_paginate', '~> 3.0' gem 'yaml_db' gem 'rubycas-client', :git => 'git://github.com/rubycas/rubycas-client.git' + group :development, :test do gem 'autotest-standalone' gem 'rspec-rails' diff --git a/Gemfile.lock b/Gemfile.lock index f157bc97..f3992767 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,6 +67,7 @@ GEM ffi-compiler (0.1.3) ffi (>= 1.0.0) rake + flickraw (0.9.8) haml (4.0.5) tilt haml-rails (0.5.3) @@ -204,6 +205,7 @@ DEPENDENCIES autotest-standalone d3js-rails (~> 3.1.6) exception_notification (~> 4) + flickraw haml-rails jquery-rails (~> 2.1.4) mechanize diff --git a/app/assets/stylesheets/home.css.erb b/app/assets/stylesheets/home.css.erb index c6d43746..ebc49de3 100644 --- a/app/assets/stylesheets/home.css.erb +++ b/app/assets/stylesheets/home.css.erb @@ -78,22 +78,6 @@ background: #f7e26b; } -#main #what_sec{ - background: url(<%= asset_path 'site/hkn_members.png' %>); -} - -#main #student-services_sec{ - background: url(<%= asset_path 'site/hkn_tutoring.png' %>); -} - -#main #ind_rel_sec{ - background: url(<%= asset_path 'site/hkn_faculty.png' %>); -} - -#main #membership_sec{ - background: url(<%= asset_path 'site/hkn_banquet.png' %>); -} - /*Tutoring Calendar*/ #daily_tutoring_schedule th{ border: none; diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index cf160b6e..782de261 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,6 @@ class HomeController < ApplicationController helper EventsHelper - + require 'flickraw' def index @events = Event.upcoming_events(0, @current_user) @show_searcharea = true @@ -18,6 +18,28 @@ def index else @tutoring_message = prop.tutoring_message end + + FlickRaw.api_key="bb6eccbf731a58f02b4acacfcb36e85d" + FlickRaw.shared_secret="aa8d976469254029" + default_photos = [ActionController::Base.helpers.asset_path('site/hkn_members.png'), ActionController::Base.helpers.asset_path('site/hkn_tutoring.png'), ActionController::Base.helpers.asset_path('site/hkn_faculty.png'), ActionController::Base.helpers.asset_path('site/hkn_banquet.png')] + @photo_links = [] + photo_indices = [] + for i in 0..3 + photo_index = rand(1000) + while photo_indices.include? photo_index + photo_index = rand(1000) + end + photo = flickr.people.getPublicPhotos(:user_id => '121225723@N05', :per_page => '1', :page => photo_index.to_s) + break if photo.nil? + photo_id = photo[0].id + sizes = flickr.photos.getSizes(:photo_id => photo_id) + link = sizes[5].source + photo_indices << photo_index + @photo_links << link + end + if @photo_links.length < 4 + @photo_links = default_photos + end end def factorial diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 4b4de31f..d6b24276 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -41,7 +41,7 @@

What is HKN?

-
+
Eta Kappa Nu (HKN) is the national Electrical and Computer Engineering honor society. @@ -54,7 +54,7 @@

Student Services

-
+

Tutoring

@@ -72,7 +72,7 @@

Industrial Relations

-
+
HKN has strong ties with industry, linking students with companies by setting up <%= link_to "info sessions", infosessions_path %> where companies can give a presentation about themselves and provide a forum for students to talk to industry and find out more about the work environment. Additionally, we sell <%= link_to "resume books", resume_books_about_path %> containing the resumes of our members. @@ -83,7 +83,7 @@

Membership

-
+

Membership in Eta Kappa Nu is extended to undergraduates in the top fourth of the junior class and the top third of the senior class in EECS, and all continuing EE graduate students. Interested students should watch for the list of eligible names, which is posted around Cory Hall and Soda Hall about a month after the beginning of each semester.