Permalink
Browse files

The ALL page is working now.

  • Loading branch information...
1 parent 351d03f commit 72f48af2c1248a9e627aaa5f754d187bb3dba2ab weshays committed May 17, 2012
Showing with 144 additions and 12 deletions.
  1. +3 −0 .pryrc
  2. +2 −0 Gemfile
  3. +7 −0 Gemfile.lock
  4. +18 −6 app.rb
  5. +93 −0 helpers/plaza_collection.rb
  6. +15 −0 helpers/routes_helper.rb
  7. +6 −6 views/all.haml
View
3 .pryrc
@@ -0,0 +1,3 @@
+Pry.commands.alias_command 'c', 'continue'
+Pry.commands.alias_command 's', 'step'
+Pry.commands.alias_command 'n', 'next'
View
2 Gemfile
@@ -17,6 +17,8 @@ gem 'haml'
group :development, :test do
gem 'sqlite3'
gem 'pry'
+ gem 'pry-remote'
+ gem 'pry-nav'
gem 'shotgun'
end
View
7 Gemfile.lock
@@ -45,6 +45,11 @@ GEM
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
+ pry-nav (0.2.1)
+ pry (~> 0.9.9)
+ pry-remote (0.1.4)
+ pry (~> 0.9.9)
+ slop (~> 2.1)
rack (1.4.1)
rack-protection (1.2.0)
rack
@@ -87,6 +92,8 @@ DEPENDENCIES
koala
pg
pry
+ pry-nav
+ pry-remote
shotgun
sinatra
sinatra-activerecord
View
24 app.rb
@@ -15,12 +15,16 @@
require 'koala'
require 'json'
-require 'pry' if development?
+if development?
+ require 'pry'
+ require 'pry-remote'
+ require 'pry-nav'
+end
# Require the Plaza-Ruby library
# https://github.com/thecity/plaza-ruby
-require File.expand_path( File.dirname(__FILE__) + '/lib/plaza-ruby/the_city.rb')
+require File.expand_path( File.dirname(__FILE__) + '/lib/plaza-ruby/lib/the_city.rb')
# Load Initializers
Dir["./config/initializers/**/*"].each { |i| require i }
@@ -57,6 +61,10 @@
end
+ @subdomain = 'livingstones'
+ @the_city = TheCity.new(@subdomain, false)
+ @fb_page_id = '0'
+
if @facebook_entry
@facebook_entry.update_attribute(:deleted_at, DateTime.now)
@fb_page_id = @facebook_entry.fb_page_id
@@ -93,6 +101,8 @@
post '/authorize/?' do
+ @show_nav = false
+
if params[:tabs_added].nil?
@url_to_use = FACEBOOK_PAGE_TAB_URL
@@ -114,6 +124,8 @@
post '/deauthorize/?' do
+ @show_nav = false
+
if params[:signed_request]
oauth = Koala::Facebook::OAuth.new(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, FACEBOOK_APP_URL)
fb_params = oauth.parse_signed_request(params[:signed_request])
@@ -130,6 +142,7 @@
get_or_post '/plaza/edit/?' do
+ @show_nav = false
@show_form = false
@error = nil
@success = nil
@@ -148,18 +161,17 @@
end
else
- @error = 'Facebook ID not specified or found'
+ @error = 'Facebook ID not specified or not found'
end
haml :edit
end
get_or_post '/plaza/?' do
- #redirect FACEBOOK_PAGE_TAB_URL
@all_tab = 'active'
- @topics = @the_city.topics(8) unless @the_city.nil?
- haml @topics.nil? ? :nothing_to_load : :all
+ @plaza_display = PlazaCollection.new(@the_city, 8);
+ haml @plaza_display.nil? ? :nothing_to_load : :all
end
View
93 helpers/plaza_collection.rb
@@ -0,0 +1,93 @@
+# Project:: Plaza-Facebook
+# File:: plaza_collection.rb
+#
+# Author:: Wes Hays <wes@onthecity.org>
+
+
+class PlazaCollection < Plaza
+
+
+ # Constructor
+ #
+ # @param TheCity the_city An initialzed TheCity object.
+ # @param integer items_to_display The number of items to display. Default is 5.
+ def initialize(the_city, items_to_display = 5)
+ # Holds the data.
+ @plaza_data = []
+
+ @topics = the_city.topics(2)
+ @events = the_city.events(items_to_display)
+ @prayers = the_city.prayers(items_to_display)
+ @needs = the_city.needs(items_to_display)
+ @albums = the_city.albums(items_to_display)
+
+ temp = {}
+
+ i = 0
+ while( !(topic = @topics.select(i)).nil? )
+ key = _build_time_key( topic.created_at )
+ temp[key] = topic
+ i += 1
+ end
+
+ i = 0
+ while( !(event = @events.select(i)).nil? ) do
+ key = _build_time_key( event.created_at )
+ temp[key] = event
+ i += 1
+ end
+
+ i = 0
+ while( !(prayer = @prayers.select(i)).nil? ) do
+ key = _build_time_key( prayer.created_at )
+ temp[key] = prayer
+ i += 1
+ end
+
+ i = 0
+ while( !(need = @needs.select(i)).nil? ) do
+ key = _build_time_key( need.created_at )
+ temp[key] = need
+ i += 1
+ end
+
+ i = 0
+ while( !(album = @albums.select(i)).nil? ) do
+ key = _build_time_key( album.created_at )
+ temp[key] = album
+ i += 1
+ end
+
+ temp = temp.sort.reverse.collect{ |t| t[1] }
+
+ @plaza_data = temp[0...items_to_display]
+ end
+
+
+ # All titles in list.
+ #
+ # @return array of item titles.
+ def all_titles
+ @plaza_data.collect { |item| items << item.title }
+ end
+ alias :titles :all_titles
+
+
+
+ # Get the specified plaza item.
+ #
+ # @param index The index of the item to get.
+ #
+ # @return Mixed (Topic, Need, Prayer, Event, Album).
+ def select(index)
+ @plaza_data[index] if @plaza_data[index]
+ end
+
+
+ private
+
+ def _build_time_key(created_at_str)
+ DateTime.parse(created_at_str).to_i
+ end
+
+end
View
15 helpers/routes_helper.rb
@@ -30,4 +30,19 @@ def albums_url(subdomain, id)
return '#' if subdomain.nil? or id.nil?
"http://#{subdomain}.onthecity.org/plaza/albums/#{id}"
end
+
+ def mixed_item_url(subdomain, item)
+ if item.class == Topic
+ topics_url(subdomain, item.id)
+ elsif item.class == Event
+ events_url(subdomain, item.id)
+ elsif item.class == Prayer
+ prayers_url(subdomain, item.id)
+ elsif item.class == Need
+ needs_url(subdomain, item.id)
+ elsif item.class == Album
+ albums_url(subdomain, item.id)
+ end
+ end
+
end
View
12 views/all.haml
@@ -1,15 +1,15 @@
- i = 0
-- while( (topic = @topics.select(i)) != nil)
+- while( (item = @plaza_display.select(i)) != nil)
- i+= 1
-
- %article.feed_item.clearfix.topic
+
+ %article.feed_item.clearfix{:class => item.class.to_s.downcase}
%h1
- %a{:href => topics_url(@subdomain, topic.id), :target => '_blank'}= topic.title
+ %a{:href => mixed_item_url(@subdomain, item), :target => '_blank'}= item.title
.col_left
.body
- = blurbize(topic.content)
+ = blurbize(item.content)
- = haml(:_posted_by, :locals => {:item => topic})
+ = haml(:_posted_by, :locals => {:item => item})
%i.indicator

0 comments on commit 72f48af

Please sign in to comment.