Changeset 1591

Show
Ignore:
Timestamp:
07/05/08 18:55:15 (3 months ago)
Author:
jm3
Message:

sorting is working

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • agitator/TODO

    r1590 r1591  
     1 
    12NEXT 
    2   sort tags by usage 
     3  print list of tags in browser 
    34  everything next is in reminder controller (persistence for reminders) 
    4   print list of tags in browser 
    55 
    66NICETOHAVE 
     
    99 
    1010DONE 
    11   get basic login and logout working 
    12   set up db alias 
    13   hide login form if already logged in  
     11DONE sort tags by usage 
     12DONE get basic login and logout working 
     13DONE set up db alias 
     14DONE hide login form if already logged in  
     15 
  • agitator/app/controllers/reminder_controller.rb

    r1590 r1591  
    2121      @message = "Ordinarily you would see your (cached) #{BOOKMARKING_NAME} tags here but Rails is being a bitch about it." 
    2222    end 
     23 
     24   session[:sort_tags_by] = (params[:sort_tags_by] == "alpha") ? "alpha" : "usage" 
    2325     
    2426    # FIXME: sort the tags by most prevalent and show the top ten 
     
    4143    logger.debug( "..................................." ) 
    4244    logger.debug( "* found " + tags.length.to_s + " tags") 
    43     sorted_tags = [tags.length] 
    44     c = 0 
    45     tags.each{ |t| 
    46       sorted_tags[c] = t.attributes['count'] + " " + t.attributes['tag'] 
    47       sorted_tags.sort!.reverse! 
    48       logger.debug( t.to_s ) 
    49       c += 1 
    50     } 
    51     sorted_tags.each{ |t| 
    52       logger.debug( t ) 
    53     } 
     45 
     46    # hashify them briefly so we can sort them by usage: 
     47    tag_hash = Hash.new 
     48    tags.each{ |t| tag_hash[ t.attributes['tag']] =  t.attributes['count'].to_i } 
     49    sorted_tags = tag_hash.sort {|a,b| a[1] <=> b[1]}.reverse 
     50 
     51    #sorted_tags.each{ |t| logger.debug( t[0].to_s + ":" + t[1].to_s ) } 
     52    #return sorted_tags 
    5453  end 
    5554 
  • agitator/app/helpers/application_helper.rb

    r1590 r1591  
    55  end 
    66 
    7   def get_tag_as_html( tag_string, user ) 
    8     return '<a href="http://' +  BOOKMARKING_NAME + '/' + user + '/' + tag_string.split[1] + '">' + tag_string.split[1] + '(' + tag_string.split[0] + ')</a>' 
     7  def get_tag_as_html( tag, user ) 
     8    if user == nil or tag == nil 
     9      return "" 
     10    end 
     11    return '<a href="http://' +  BOOKMARKING_NAME + '/' + user + '/'  + tag[0] + '">' + tag[0] + '(' + tag[1].to_s + ')</a>' 
    912  end 
    1013   
  • agitator/app/views/widgets/_home_guts.rhtml

    r1590 r1591  
    1 <h2>HOME</h2> 
    21<% 
    3 if u and u != "" and @tags 
     2  if u and u != "" and @tags and @tags != nil and @tags.length > 0 
     3    sort = session[:sort_tags_by] 
    44%> 
    55 
     6Hi, <%= u %>! 
    67 
    7 Hi, <%= u %>, 
     8<form name="sneaky_form" id="sneaky_form" action="/i/have/no/fucking/idea"> 
     9  <input type="hidden" name="reminder_tags" value="<%= DEFAULT_REMINDER_TAGS %>" /> 
     10</form> 
    811 
    9 your most-used tag is <%= get_tag_as_html @tags[0], u %>. 
     12<h3> 
     13  Your personal email will include links that are tagged: 
     14</h3> 
     15 
     16<div id="reminder_tags_preview"> 
     17</div> 
     18 
     19<h3> 
     20  Here are <%= @tags.length > 50 ? "your top 50" : "all your" %> <%=  BOOKMARKING_NAME %> tags,<br /> 
     21  sorted  
     22  <%= sort== "alpha" ? "alphabetically" : "from most-used to least-used" %>. 
     23</h3> 
     24<p> 
     25  To include a tag in your personal reminder email, click it! 
     26</p> 
     27<form> 
     28 
     29<div id="tags_by_usage" style="<%= sort == 'alpha' ? 'display: none;' : '' %>"> 
     30<div class="tag_sort_toggle"> 
     31  <a href="javascript:sort_tags_by_alpha();">sort alphabetically?</a> 
     32</div> 
     33<%  
     34  c = 0 
     35  @tags.each{ |t| 
     36  if c < 50 
     37-%> 
     38  <label> <input type="checkbox" name="tag_<%= t[0] %>" value="<%= t[0] %>" onClick="toggle_tag(this);" /> <%= t[0] %> </label> &nbsp; 
     39<%  
     40    end 
     41    c += 1 
     42  }  
     43%> 
     44</div> 
     45</form> 
     46 
     47<div id="tags_by_alpha" style="<%= sort == 'alpha' ? '' : 'display: none;' %>"> 
     48<div class="tag_sort_toggle"> 
     49  <a href="javascript: sort_tags_by_usage();">sort by most-frequently used?</a> 
     50</div> 
     51<%  
     52  c = 0 
     53  @tags = @tags.sort{ |a,b| a[0].downcase <=> b[0].downcase } 
     54  @tags.each{ |t| 
     55  if c < 50 
     56-%> 
     57  <label> <input type="checkbox" name="tag_<%= t[0] %>" value="<%= t[0] %>" onClick="toggle_tag(this);" /> <%= t[0] %> </label> &nbsp; 
     58<%  
     59    end 
     60    c += 1 
     61  }  
     62%> 
     63</div> 
     64 
    1065 
    1166<p> 
  • agitator/config/environment.rb

    r1585 r1591  
    1414BOOKMARKING_API_USERNAME     = "agitator_test" 
    1515BOOKMARKING_API_PASSWORD     = "6f1482c1e50d0de7763a5bcd858006e3" 
     16DEFAULT_REMINDER_TAGS        = "todo" 
    1617 
    1718BOOKMARKING_API_CREDS_URL    = "/v1/posts/update" 
  • agitator/public/javascripts/application.js

    r1575 r1591  
    11// Place your application-specific JavaScript functions and classes here 
    22// This file is automatically included by javascript_include_tag :defaults 
     3 
     4function sort_tags_by_alpha() { 
     5  $('tags_by_usage').setStyle('display', 'none'); 
     6  $('tags_by_alpha').setStyle('display', 'block'); 
     7} 
     8 
     9function sort_tags_by_usage() { 
     10  $('tags_by_usage').setStyle('display', 'block'); 
     11  $('tags_by_alpha').setStyle('display', 'none'); 
     12} 
     13 
     14function toggle_tag( checkbox ) { 
     15  if( checkbox.checked ) 
     16    alert( checkbox.value ); 
     17} 
    318 
    419// form validation: 
  • agitator/public/stylesheets/screen.css

    r1581 r1591  
    159159        display: inline; 
    160160} 
     161 
     162div#reminder_tags_preview { 
     163  border: 1px solid gray; 
     164  padding: 2.0em; 
     165  width: 20em; 
     166  text-align: center; 
     167  font-size: 1.6em; 
     168}