Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
basic mobile usecases: shows, notes, memes
Browse files Browse the repository at this point in the history
  • Loading branch information
tardate committed Oct 23, 2011
1 parent 2849d00 commit fb4ff53
Show file tree
Hide file tree
Showing 24 changed files with 222 additions and 33 deletions.
6 changes: 5 additions & 1 deletion app/controllers/memes_controller.rb
@@ -1,6 +1,6 @@
class MemesController < InheritedResources::Base class MemesController < InheritedResources::Base
belongs_to :show, :finder => :find_by_number!, :optional => true belongs_to :show, :finder => :find_by_number!, :optional => true
custom_actions :collection => [:stats], :member => [:stat] custom_actions :collection => [:stats,:top], :member => [:stat]
respond_to :html, :json, :xml respond_to :html, :json, :xml


include Navd::Chartable include Navd::Chartable
Expand All @@ -13,4 +13,8 @@ def stat
render :json => to_chartable_structure(resource.stat_over_time,Meme::STAT_CHART_TEMPLATE).to_json render :json => to_chartable_structure(resource.stat_over_time,Meme::STAT_CHART_TEMPLATE).to_json
end end


def top
@memes = Meme.topn
top!
end
end end
5 changes: 3 additions & 2 deletions app/models/meme.rb
Expand Up @@ -3,9 +3,10 @@ class Meme < ActiveRecord::Base
has_many :notes, :dependent => :destroy has_many :notes, :dependent => :destroy
has_many :shows, :through => :notes, :uniq => true, :order => 'number desc' has_many :shows, :through => :notes, :uniq => true, :order => 'number desc'


default_scope order('memes.name')
scope :select_listing, order(:name) scope :select_listing, order(:name)


scope :topn, lambda { |limit=10| scope :topn, lambda { |limit = AppConstants.number_of_trending_memes|
unscoped.where(Meme.arel_table[:id].in(topn_arel(limit))) unscoped.where(Meme.arel_table[:id].in(topn_arel(limit)))
} }


Expand All @@ -15,7 +16,7 @@ class Meme < ActiveRecord::Base
joins(:shows). joins(:shows).
where(Meme.arel_table[:id].in((meme_id ? meme_id : topn_arel))). where(Meme.arel_table[:id].in((meme_id ? meme_id : topn_arel))).
group(:"memes.name", :"shows.number"). group(:"memes.name", :"shows.number").
order('memes.name, shows.number') reorder('memes.name, shows.number')
} }


# Gets the stats over time for the current meme # Gets the stats over time for the current meme
Expand Down
4 changes: 3 additions & 1 deletion app/models/note.rb
Expand Up @@ -2,5 +2,7 @@ class Note < ActiveRecord::Base
belongs_to :show belongs_to :show
belongs_to :meme belongs_to :meme


scope :show_meme_note_order, includes(:show).includes(:meme).order('shows.number desc, memes.name asc, notes.name asc') default_scope order('notes.name')
scope :show_meme_note_order, includes(:show).includes(:meme).reorder('shows.number desc, memes.name asc, notes.name asc')

end end
6 changes: 4 additions & 2 deletions app/models/show.rb
Expand Up @@ -2,7 +2,8 @@ class Show < ActiveRecord::Base
has_many :notes, :dependent => :destroy has_many :notes, :dependent => :destroy
has_many :memes, :through => :notes, :uniq => true, :order => :name has_many :memes, :through => :notes, :uniq => true, :order => :name


scope :select_listing, where(:published => true).order('number desc') default_scope order('shows.number desc')
scope :select_listing, where(:published => true)


# TODO: there's a better query construct possible than this=> # TODO: there's a better query construct possible than this=>
scope :meme_stats, lambda { |show_id=nil| scope :meme_stats, lambda { |show_id=nil|
Expand All @@ -13,7 +14,7 @@ class Show < ActiveRecord::Base
joins(:memes). joins(:memes).
where(n[:meme_id].not_in(Meme.non_trending_arel)). where(n[:meme_id].not_in(Meme.non_trending_arel)).
group(:"memes.name"). group(:"memes.name").
order('count(notes.id)') reorder('count(notes.id)')
} }


class << self class << self
Expand Down Expand Up @@ -52,4 +53,5 @@ def to_param
def meme_stat def meme_stat
self.class.meme_stats(self.id) self.class.meme_stats(self.id)
end end

end end
14 changes: 13 additions & 1 deletion app/stylesheets/mobile/_base.scss
Expand Up @@ -3,4 +3,16 @@ body {
.clearpanel { .clearpanel {
clear: both; clear: both;
height: 15px; height: 15px;
} }
.content {
.name {
font-weight: bold;
}
.cover_art {
width: 100px;
margin: 10px auto 0;
img {
height: 100px;
}
}
}
6 changes: 3 additions & 3 deletions app/views/dashboards/menu.mobile.haml
Expand Up @@ -4,17 +4,17 @@
%h2= t('site.short_title') %h2= t('site.short_title')
%ul.rounded %ul.rounded
%li %li
%a %a.touch_load{'data-url' => top_memes_path, 'data-transition' => 'pop-in'}
%img.icon.greenbox{ :src => "/images/mobile/tabs/flag.png" } %img.icon.greenbox{ :src => "/images/mobile/tabs/flag.png" }
= t('stats.top_memes.title', :n => AppConstants.number_of_trending_memes) = t('stats.top_memes.title', :n => AppConstants.number_of_trending_memes)
%span.arrow %span.arrow
%li %li
%a %a.touch_load{'data-url' => memes_path, 'data-transition' => 'slide-left'}
%img.icon.greenbox{ :src => "/images/mobile/tabs/aim.png" } %img.icon.greenbox{ :src => "/images/mobile/tabs/aim.png" }
= t('memes.index.title') = t('memes.index.title')
%span.arrow %span.arrow
%li %li
%a %a.touch_load{'data-url' => shows_path, 'data-transition' => 'slide-left'}
%img.icon.greenbox{ :src => "/images/mobile/tabs/note.png" } %img.icon.greenbox{ :src => "/images/mobile/tabs/note.png" }
= t('shows.index.title') = t('shows.index.title')
%span.arrow %span.arrow
Expand Down
6 changes: 6 additions & 0 deletions app/views/memes/_table.mobile.haml
@@ -0,0 +1,6 @@
%ul.rounded
- collection.each do |item|
%li
%a.touch_load{'data-url' => polymorphic_path([item,:notes]), 'data-transition' => 'slide-left'}
= item.name
%span.count= item.notes.count
12 changes: 3 additions & 9 deletions app/views/memes/index.mobile.haml
@@ -1,11 +1,5 @@
.toolbar .toolbar
%h1 %h1= t('.title')
Memes %a.button.back.touch_load{'data-url' => menu_dashboard_path, 'data-transition' => 'pop-out' }= t(:done)
.content .content
%h2 = render :partial => 'memes/table'
Main Menu
%ul.rounded
%li
%a
%img.icon.greenbox{ :src => "/images/mobile/tabs/flag.png" }
%span.arrow
5 changes: 5 additions & 0 deletions app/views/memes/top.mobile.haml
@@ -0,0 +1,5 @@
.toolbar
%h1= t('stats.top_memes.short_title', :n => AppConstants.number_of_trending_memes)
%a.button.back.touch_load{'data-url' => menu_dashboard_path, 'data-transition' => 'pop-out' }= t(:done)
.content
= render :partial => 'memes/table'
6 changes: 6 additions & 0 deletions app/views/notes/_table.mobile.haml
@@ -0,0 +1,6 @@
%ul.rounded
- collection.each do |item|
%li
%a.touch_load{'data-url' => polymorphic_path([item]), 'data-transition' => 'slide-left'}
= item.name
%span.arrow
5 changes: 5 additions & 0 deletions app/views/notes/index.mobile.haml
@@ -0,0 +1,5 @@
.toolbar
%h1= t('.title')
%a.button.back.touch_load{'data-url' => menu_dashboard_path, 'data-transition' => 'pop-out' }= t(:done)
.content
= render :partial => 'notes/table'
23 changes: 23 additions & 0 deletions app/views/notes/show.mobile.haml
@@ -0,0 +1,23 @@
.toolbar
%h1= t('.title')
%a.button.back.touch_load{'data-url' => menu_dashboard_path, 'data-transition' => 'pop-out' }= t(:done)
.content
.name= resource.name
%ul.rounded
- if resource.url?
%li
%a.touch_load{'data-url' => resource.url, 'data-transition' => 'slide-left'}
%img.icon.greenbox{ :src => "/images/mobile/tabs/aim.png" }
= t(:link)
%span.arrow
%li
%a.touch_load{'data-url' => polymorphic_path([resource.meme,:notes]), 'data-transition' => 'slide-left'}
%img.icon.greenbox{ :src => "/images/mobile/tabs/aim.png" }
= resource.meme.name
%span.arrow
%li
%a.touch_load{'data-url' => polymorphic_path([resource.show]), 'data-transition' => 'slide-left'}
%img.icon.greenbox{ :src => "/images/mobile/tabs/note.png" }
= resource.show.short_title
%span.arrow
.description= resource.description
4 changes: 2 additions & 2 deletions app/views/pages/_technoexperts.html.haml
Expand Up @@ -3,8 +3,8 @@
%h2 TECHNO EXPERTS!! %h2 TECHNO EXPERTS!!
%p %p
The NoAgenda Dashboard works best on late model Chrome/Firefox/Safari/IE browsers The NoAgenda Dashboard works best on late model Chrome/Firefox/Safari/IE browsers
It also works pretty darn good on the iPad. A special version for Android and iPhone devices It also works pretty darn good on the iPad. If you are using an Android or iPhone
is in the works. device, it serves a special mobile-friendly version.
%p %p
We're currently only loading show details since show number We're currently only loading show details since show number
= AppConstants.earliest_show_to_load = AppConstants.earliest_show_to_load
Expand Down
6 changes: 5 additions & 1 deletion app/views/pages/technoexperts.mobile.haml
@@ -1 +1,5 @@
= render :partial => 'pages/technoexperts.html' .toolbar
%h1= t('pages.technoexperts.title')
%a.button.touch_load{'data-url' => menu_dashboard_path, 'data-transition' => 'flip-right' }= t(:done)
.content
= render :partial => 'pages/technoexperts.html'
6 changes: 6 additions & 0 deletions app/views/shows/_table.mobile.haml
@@ -0,0 +1,6 @@
%ul.rounded
- collection.each do |item|
%li
%a.touch_load{'data-url' => polymorphic_path([item]), 'data-transition' => 'slide-left'}
= item.short_title
%span.count= item.notes.count
13 changes: 3 additions & 10 deletions app/views/shows/index.mobile.haml
@@ -1,12 +1,5 @@
.toolbar .toolbar
%h1 %h1= t('.title')
Shows %a.button.back.touch_load{'data-url' => menu_dashboard_path, 'data-transition' => 'pop-out' }= t(:done)
.content .content
%h2 = render :partial => 'shows/table'
Main Menu
%ul.rounded
%li
%a
%img.icon.greenbox{ :src => "/images/mobile/tabs/flag.png" }
%span.arrow
.clearpanel
21 changes: 21 additions & 0 deletions app/views/shows/show.mobile.haml
@@ -0,0 +1,21 @@
.toolbar
%h1= resource.short_title
%a.button.back.touch_load{'data-url' => menu_dashboard_path, 'data-transition' => 'pop-out' }= t(:done)
.content
%h2= resource.name
- if resource.cover_art_url?
.cover_art= image_tag(resource.cover_art_url)
%ul.rounded
%li
%a.touch_load{'data-url' => polymorphic_path([resource,:memes]), 'data-transition' => 'slide-left'}
%img.icon.greenbox{ :src => "/images/mobile/tabs/aim.png" }
= t('memes.index.title')
%span.arrow
%li
%a.touch_load{'data-url' => polymorphic_path([resource,:notes]), 'data-transition' => 'slide-left'}
%img.icon.greenbox{ :src => "/images/mobile/tabs/note.png" }
= t('notes.index.title')
%span.arrow
- if resource.credits?
%h2= resource_class.human_attribute_name(:credits)
%div= raw resource.credits
5 changes: 5 additions & 0 deletions config/locales/en.yml
Expand Up @@ -41,8 +41,10 @@ en:
show: Episode show: Episode
back: Back back: Back
book_of_knowledge: Book of Knowledge book_of_knowledge: Book of Knowledge
done: Done
donor: donor:
title: Be a Donor not a Boner! title: Be a Donor not a Boner!
link: On the web..
memes: memes:
index: index:
title: Memes title: Memes
Expand All @@ -51,6 +53,8 @@ en:
notes: notes:
index: index:
title: Show Notes title: Show Notes
show:
title: Show Note
pages: pages:
technoexperts: technoexperts:
title: TECHNO EXPERTS title: TECHNO EXPERTS
Expand All @@ -67,3 +71,4 @@ en:
stats: stats:
top_memes: top_memes:
title: 'Top %{n} Trending Memes' title: 'Top %{n} Trending Memes'
short_title: 'Top %{n} Memes'
5 changes: 4 additions & 1 deletion config/routes.rb
Expand Up @@ -8,7 +8,10 @@
resources :notes, :only => [:index,:show] resources :notes, :only => [:index,:show]
resources :memes, :only => [:index,:show] do resources :memes, :only => [:index,:show] do
resources :notes, :only => [:index,:show] resources :notes, :only => [:index,:show]
get :stats, :on => :collection collection do
get :stats
get :top
end
get :stat, :on => :member get :stat, :on => :member
end end
resources :shows, :only => [:index,:show] do resources :shows, :only => [:index,:show] do
Expand Down
12 changes: 12 additions & 0 deletions public/javascripts/application.js
Expand Up @@ -38,6 +38,7 @@ var NAVD = {
$(document.body).append('<div id="mobileMain" class="jsTouchPanel" style="position: absolute; left: 0px; top: 0px; border-left: 0px !important;"></div>'); $(document.body).append('<div id="mobileMain" class="jsTouchPanel" style="position: absolute; left: 0px; top: 0px; border-left: 0px !important;"></div>');
NAVD.mobileMain = jsTouch.init('mobileMain', { width: 320, page: '/dashboard/menu' } ); NAVD.mobileMain = jsTouch.init('mobileMain', { width: 320, page: '/dashboard/menu' } );
NAVD.mobile_resize(); NAVD.mobile_resize();
NAVD.enableSmartphonePageLoad();
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('orientationchange', NAVD.mobile_resize, false); document.addEventListener('orientationchange', NAVD.mobile_resize, false);
window.addEventListener('resize', NAVD.mobile_resize, false); window.addEventListener('resize', NAVD.mobile_resize, false);
Expand All @@ -54,6 +55,17 @@ var NAVD = {
jsTouch.resize(); jsTouch.resize();
}, },


enableSmartphonePageLoad: function() {
$('.touch_load').live('click', function() {
var url = $(this).data('url') || $(this).attr('href');
var transition = $(this).data('transition') || 'slide-left';
if (url != "") {
jsTouch.loadPage(url, { transition: transition });
}
return false;
});
},

enableScroller: function() { enableScroller: function() {
if ( NAVD.config.mobile ) { if ( NAVD.config.mobile ) {
NAVD.mainScroller = new iScroll('container'); NAVD.mainScroller = new iScroll('container');
Expand Down
14 changes: 14 additions & 0 deletions public/stylesheets/compiled/mobile.css
Expand Up @@ -923,3 +923,17 @@ div.jsTouch div.content input {
clear: both; clear: both;
height: 15px; height: 15px;
} }

/* line 8, ../../../app/stylesheets/mobile/_base.scss */
.content .name {
font-weight: bold;
}
/* line 11, ../../../app/stylesheets/mobile/_base.scss */
.content .cover_art {
width: 100px;
margin: 10px auto 0;
}
/* line 14, ../../../app/stylesheets/mobile/_base.scss */
.content .cover_art img {
height: 100px;
}
23 changes: 23 additions & 0 deletions spec/controllers/memes/mobile_spec.rb
@@ -0,0 +1,23 @@
require 'spec_helper'

describe MemesController do
render_views
let!(:show) { Factory(:show) }
let!(:meme) { Factory(:meme) }
let!(:note) { Factory(:note, :meme => meme, :show => show) }

before do
Browser.any_instance.stub(:iphone?).and_return(true)
end

describe "GET index" do
subject { get :index }
it { should be_success }
end

describe "GET top" do
subject { get :top }
it { should be_success }
end

end
24 changes: 24 additions & 0 deletions spec/controllers/notes/mobile_spec.rb
@@ -0,0 +1,24 @@
require 'spec_helper'

describe NotesController do
render_views
let!(:show) { Factory(:show) }
let!(:meme) { Factory(:meme) }
let!(:note) { Factory(:note, :meme => meme, :show => show) }
let(:resource) { note }

before do
Browser.any_instance.stub(:iphone?).and_return(true)
end

describe "GET index" do
subject { get :index }
it { should be_success }
end

describe "GET show" do
subject { get :show, :id => resource.id }
it { should be_success }
end

end

0 comments on commit fb4ff53

Please sign in to comment.