Changeset 8411

Show
Ignore:
Timestamp:
03/26/08 23:15:09 (5 years ago)
Author:
damegane
Message:

/lang/ruby/fastladder_mobile .

Location:
lang/ruby/fastladder_mobile/trunk/app
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/fastladder_mobile/trunk/app/controllers/mobile_controller.rb

    r7589 r8411  
    22  verify :session => :member, :redirect_to => "/mobile/login", :except => :login 
    33  after_filter OutputCompressionFilter 
     4 
     5  # 一度に表示するフィード/記事の上限に関する設定 
     6  MAX_FEED_COUNT = 20 # フィードの件数 
     7  # 合計の件数とサイズは越えた時点でループを止めるため設定値=上限ではない 
     8  MAX_TOTAL_ITEM_COUNT = 20 # 記事の件数の合計、0なら無制限 
     9  MAX_TOTAL_ITEM_SIZE = 30000 # 記事本文のHTMLとしての文字数の合計、0なら無制限 
    410 
    511  def login 
     
    2127 
    2228  def index 
    23     conditions = ["has_unread = ?", true] 
    24     @subs = member.subscriptions.find(:first, :conditions => conditions, 
    25                                   :order => "subscriptions.rate DESC, subscriptions.id ASC", 
    26                                   :include => [:folder, { :feed => :crawl_status }]) 
    27     @items = get_items @subs 
     29    feed_count = 0 
     30    item_count = 0 
     31    item_size = 0 
     32    @subs = get_unread_subs 
     33    @items = Array.new 
     34 
     35    if @subs.size > 0 
     36      for feed in @subs 
     37        items = get_items(feed) 
     38        item_count += items.length 
     39        item_size += items.inject(0) {|t, i| t + i.body.size } 
     40        @items << items 
     41        feed_count += 1 
     42 
     43        if item_count >= MAX_TOTAL_ITEM_COUNT || 
     44           item_size >= MAX_TOTAL_ITEM_SIZE 
     45          break 
     46        end 
     47      end 
     48    else 
     49      render :text => "No unread feeds." 
     50      return 
     51    end 
     52 
     53    if @subs.size > feed_count 
     54      @subs = @subs.slice(0, feed_count) 
     55    end 
     56    @dbg = {:f => feed_count, :i => item_count, :s => item_size } 
    2857  end 
    2958 
     
    3160    # set pins 
    3261    if params[:pins] 
    33       params[:pins].each { | p | 
     62      params[:pins].each { |p| 
    3463        a = p.split("##") 
    3564        set_pin(a[0], a[1]) 
    3665      } 
    3766    end 
     67 
    3868    # set readed 
    39     touch params[:subs_id] 
     69    if params[:subs_ids] 
     70      params[:subs_ids].each { |id| 
     71        touch id 
     72      } 
     73    end 
     74 
    4075    # redirect or end 
    4176    if params[:next_feed] 
     
    5994 
    6095  private 
     96  def get_unread_subs 
     97    conditions = ["has_unread = ?", true] 
     98    limit = MAX_FEED_COUNT >= 1 ? MAX_FEED_COUNT : 0 
     99    return member.subscriptions.find(:all, :conditions => conditions, 
     100                                     :order => "subscriptions.rate DESC, subscriptions.id ASC", 
     101                                     :include => [:folder, { :feed => :crawl_status }], 
     102                                     :limit => limit) 
     103  end 
     104 
    61105  def get_items(subs) 
    62106    conditions = subs.viewed_on ? ["stored_on >= ?", subs.viewed_on] : nil 
    63     items = subs.feed.items.find(:all, :conditions => conditions, :order => "created_on DESC, id DESC", :limit => MAX_UNREAD_COUNT) 
    64     result = { 
    65       :subscribe_id => @id, 
    66       :channel => subs.feed, 
    67       :items => items, 
    68     } 
    69     if items.length > 0 
    70       result[:last_stored_on] = items.max { |a, b| a.stored_on <=> b.stored_on }.stored_on 
    71     end 
    72     result[:ignore_notify] = 1 if subs.ignore_notify 
    73     return result 
     107    return subs.feed.items.find(:all, :conditions => conditions, :order => "created_on DESC, id DESC", :limit => MAX_UNREAD_COUNT) 
    74108  end 
    75109 
  • lang/ruby/fastladder_mobile/trunk/app/views/mobile/_item.rhtml

    r7412 r8411  
    88      <tr> 
    99        <td> 
    10           <label for="chk_<%= item_counter %>"> 
    11             <input id="chk_<%= item_counter %>" type="checkbox" name="pins[]" value="<%=h item.link + "##" + item.title%>"> 
     10          <label for="chk_<%= subs_id %>-<%= item_counter %>"> 
     11            <input id="chk_<%= subs_id %>-<%= item_counter %>" type="checkbox" name="pins[]" value="<%=h item.link + "##" + item.title%>"> 
    1212            Pin 
    1313          </label> 
  • lang/ruby/fastladder_mobile/trunk/app/views/mobile/index.rhtml

    r7412 r8411  
    11<% form_tag('/mobile/next', :method => :post) do %> 
    2   <div class="title"> 
    3     <h1><%= link_to @subs.feed.title, @subs.feed.link %></h1> 
    4     <p> 
    5       <%= @items[:items].size %> new item(s). 
    6       Rate : <%= @subs.rate %> 
    7       <%= submit_tag 'Go Next Feed', {:id => "next_feed", :name => "next_feed"}%> 
    8       <%= submit_tag 'Send Pin Only', {:id => "send_pin", :name => "send_pin"}%> 
    9     </p> 
    10   </div> 
    112 
    12   <%= render(:partial => "item", :collection => @items[:items]) %> 
    13   <%= hidden_field_tag 'subs_id', @subs.id %> 
     3  <% @subs.each_index {|i| %> 
     4    <%= render(:partial => "subs", :object => @subs[i], :locals => {:item_count => @items[i].length}) %> 
     5 
     6    <%= render(:partial => "item", :collection => @items[i], :locals => {:subs_id => @subs[i].id}) %> 
     7  <% } %> 
    148 
    159  <div class="navi"> 
    16     <%= submit_tag 'Go Next Feed', {:id => "next_feed", :name => "next_feed"}%> 
    17     <%= submit_tag 'Send Pin Only', {:id => "send_pin", :name => "send_pin"}%> 
     10    <%= submit_tag 'Next Feed', {:id => "next_feed", :name => "next_feed"}%> 
     11    <%= submit_tag 'Pin Only', {:id => "send_pin", :name => "send_pin"}%> 
     12    <br> 
     13    Feeds:<%= @dbg[:f] %> 
     14    Items:<%= @dbg[:i] %> 
     15    Size:<%= @dbg[:s] %> 
    1816  </div> 
    1917<% end %>