Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added commands to update on a user page, table + command options refa…

…ctorin

git-svn-id: https://monoquery.googlecode.com/svn/trunk@217 cf6fe662-2141-0410-9b27-09d17ba8d87b
  • Loading branch information...
commit 263c587793e7b0f07071df9c6d50ff0b9a6812cb 1 parent bb5a919
@cldwalker authored
View
1  app/controllers/users_controller.rb
@@ -35,6 +35,7 @@ def show
@tags = @user.tags
@users = User.find_top_users
+ @commands_to_update = @user.user_commands.out_of_date if current_user?
end
def opensearch
View
44 app/helpers/all_commands_helper.rb
@@ -1,4 +1,4 @@
-#for methods used both by commands and user commands
+#global methods used both by commands and/or user commands
module AllCommandsHelper
def whose_commands(command)
command.user == current_user ? "Your" : "#{@user.login}'s public"
@@ -42,4 +42,46 @@ def option_metadata(option, options={})
metadata.map {|e| content_tag(:li, e, :style=>'margin: 0px 0px 2px 0px')}.join("\n")
end
end
+
+ def url_status(user_command, html_options={})
+ html_options.reverse_merge(:status_length=>100)
+ content_tag(:span, {:id=>'url_status'}.update(html_options)) do
+ if user_command.command_url_changed?
+ if user_command_owner?(user_command)
+ %[Not up to date.<br/>
+ The command's url has changed to: #{truncate_with_more(h(user_command.command.url), html_options[:status_length], :tag_type=>'span')}<br/>] +
+ link_to_remote('Click to update url and options', :url=>update_url_user_command_path(user_command),
+ :before=>"$('url_status_spinner').show()", :complete=>"$('url_status_spinner').hide()") + ajax_spinner('url_status')
+ else
+ "Not up to date"
+ end
+ else
+ "Up to date"
+ end
+ end
+ end
+
+ def command_actions(ucommand, options={})
+ options.reverse_merge!(:class=>'options')
+ content_tag(:ul, :class=>options[:class]) do
+ if ucommand.owned_by?(current_user)
+ if options[:with_words]
+ content_tag(:li, link_to("Edit", edit_user_command_path(ucommand)), :class=>'edit') +
+ content_tag(:li, link_to("Delete", user_command_path(ucommand),
+ :confirm => "Are you sure you want to delete this command?", :method=>:delete), :class=>'delete')
+ else
+ content_tag(:li, link_to(image_tag("icons/edit.png"), edit_user_command_path(ucommand)), :class=>'no_icon') +
+ content_tag(:li, link_to(image_tag("icons/delete.png"), user_command_path(ucommand),
+ :confirm => "Are you sure you want to delete this command?", :method=>:delete), :class=>'no_icon')
+ end
+ elsif logged_in?
+ body = ''
+ if options[:with_copy]
+ body += content_tag(:li, link_to('Copy', copy_user_command_path(ucommand)), :class=>'add')
+ end
+ body += content_tag(:li, link_to('Subscribe', subscribe_user_command_path(ucommand)), :class=>'add')
+ body
+ end
+ end
+ end
end
View
4 app/helpers/shared_helper.rb
@@ -21,8 +21,8 @@ def can_view_queries?
user_command_owner? || @user_command.public_queries?
end
- def user_command_owner?
- @user_command.owned_by?(current_user)
+ def user_command_owner?(user_command=@user_command)
+ user_command.owned_by?(current_user)
end
def user_command_owner_or_admin?
View
12 app/helpers/table_helper.rb
@@ -8,6 +8,14 @@ def user_command_column_value(user_command, column)
user_command_link(user_command)
when :queries_count
user_command.queries_count
+ when :url_status
+ url_status(user_command, :status_length=>25)
+ when :command
+ basic_command_link user_command.command
+ when :keyword
+ user_command.keyword
+ when :command_actions
+ command_actions(user_command)
else
''
end
@@ -16,7 +24,7 @@ def user_command_column_value(user_command, column)
def user_command_table(user_commands, options={})
options = {:columns=>[:user, :name, :queries_count]}.merge(options)
default_headers = {:user=>'User', :name=>'User Command', :queries_count=>'Queries'}
- options[:headers] = options[:columns].map {|c| default_headers[c] || c.humanize }
+ options[:headers] ||= options[:columns].map {|c| default_headers[c] || c.to_s.humanize }
active_record_table(user_commands, options)
end
@@ -36,7 +44,7 @@ def query_column_value(query, column)
def query_table(queries, options={})
options.reverse_merge! :columns=>[:query_string, :created_at]
default_headers = {:query_string=>'Query', :created_at=>'Date', :user=>'User', :user_command=>'User Command'}
- options[:headers] = options[:columns].map {|c| default_headers[c] || c.to_s.humanize }
+ options[:headers] ||= options[:columns].map {|c| default_headers[c] || c.to_s.humanize }
active_record_table(queries, options)
end
View
19 app/helpers/user_commands_helper.rb
@@ -58,22 +58,5 @@ def option_type_specific_fields(option_type, form, options={})
end
end
fields
- end
-
- def url_status(user_command, html_options={})
- content_tag(:span, {:id=>'url_status'}.update(html_options)) do
- if user_command.command_url_changed?
- if user_command_owner?
- %[Not up to date.<br/>
- The command's url has changed to: #{truncate_with_more(h(user_command.command.url), 100, :tag_type=>'span')}<br/>] +
- link_to_remote('Click to update url and options', :url=>update_url_user_command_path(user_command),
- :before=>"$('url_status_spinner').show()", :complete=>"$('url_status_spinner').hide()") + ajax_spinner('url_status')
- else
- "Not up to date"
- end
- else
- "Up to date"
- end
- end
- end
+ end
end
View
1  app/models/user_command.rb
@@ -30,6 +30,7 @@ class UserCommand < ActiveRecord::Base
named_scope :shortcuts, :conditions => ["commands.kind ='shortcut' AND commands.bookmarklet=0"], :include=>:command
named_scope :non_bootstrap, :conditions=>["commands.id NOT IN (1,2,3,4,5,6,7,8,645)"], :include=>:command
named_scope :search, lambda {|v| {:conditions=>["user_commands.keyword REGEXP ? OR user_commands.url REGEXP ?", v, v]} }
+ named_scope :out_of_date, :conditions=>["commands.url != user_commands.url"], :include=>:command
named_scope :any
#fields which are passed from creating user_command to command on create + updates
View
40 app/views/commands/_command_summary_table.html.erb
@@ -1,35 +1,9 @@
<h1><%= title %></h1>
-<table>
- <tr>
- <th>User Command</th>
- <th width="100">Command</th>
- <th width="70">Keyword</th>
- <th width="30">Queries</th>
- <th>Options</th>
- </tr>
-
-
-<% for ucommand in commands %>
- <tr <%= cycle('class="offset"', '') -%>>
- <td>
- <%= user_command_link ucommand %>
- </td>
- <td>
- <%= basic_command_link ucommand.command %>
- </td>
- <td><%= ucommand.keyword %></td>
- <td><%= ucommand.queries_count %></td>
- <td>
- <ul class="options">
- <% if current_user? %>
- <li class="no_icon"><%= link_to image_tag("icons/edit.png"), edit_user_command_path(ucommand) %></li>
- <li class="no_icon"><%= link_to image_tag("icons/delete.png"), user_command_path(ucommand), :confirm => "Are you sure you want to delete this command?", :method=>:delete %></li>
- <% elsif logged_in? %>
- <li class="add"><%= link_to 'Subscribe', subscribe_user_command_path(ucommand) %></li>
- <% end %>
- </ul>
- </td>
- </tr>
-<% end %>
-</table>
+<%- columns = [:name, :command, :keyword, :queries_count]
+headers = ['User Command', ["Command", {:width=>100}], ["Keyword", {:width=>70}], ["Queries", {:width=>30}]]
+if logged_in?
+ columns += [:command_actions]; headers += ['Options']
+end
+-%>
+<%= user_command_table commands, :columns=>columns, :headers =>headers %>
View
11 app/views/user_commands/index.html.erb
@@ -92,16 +92,7 @@
<%= time_ago_in_words_or_date(uc.created_at) %>
</td>
<td>
- <% if logged_in? %>
- <ul class="options">
- <% if uc.owned_by?(current_user) %>
- <li class="no_icon"><%= link_to image_tag("icons/edit.png"), edit_user_command_path(uc) %></li>
- <li class="no_icon"><%= link_to image_tag("icons/delete.png"), user_command_path(uc), :confirm => "Are you sure you want to delete this command?", :method => :delete %></li>
- <% else %>
- <li class="add"><%= link_to 'Subscribe', subscribe_user_command_path(uc) %></li>
- <% end %>
- </ul>
- <% end %>
+ <%= command_actions(uc)%>
</td>
</tr>
<% end %>
View
10 app/views/user_commands/show.html.erb
@@ -4,15 +4,7 @@
</h1>
<% if logged_in? %>
- <ul class="options header">
- <% if user_command_owner? %>
- <li class="edit"><%= link_to 'Edit', edit_user_command_path(@user_command) %></li>
- <li class="delete"><%= link_to 'Delete', user_command_path(@user_command), :confirm => "Are you sure you want to delete this command?", :method=>:delete %></li>
- <% else %>
- <li class="add"><%= link_to 'Copy', copy_user_command_path(@user_command) %></li>
- <li class="add"><%= link_to 'Subscribe', subscribe_user_command_path(@user_command) %></li>
- <% end %>
- </ul>
+ <%= command_actions @user_command, :with_copy=>true, :class=>'options header', :with_words=>true%>
<% end %>
<hr />
View
17 app/views/users/show.html.erb
@@ -52,8 +52,23 @@
<% end %>
<li class="command"><%= link_to "View all #{whose} commands", specific_user_commands_path(@user) %></li>
<li class="search"><%= link_to "View all #{whose} queries", user_queries_path(@user) %></li>
+ <% if current_user? %>
+ <li class="refresh">
+ <%= link_to_function "View Commands to Update (#{@commands_to_update.size})", "$('commands_to_update_table').toggle()" %>
+ </li>
+ <% end %>
</ul>
-
+
+ <% if current_user? %>
+ <div id="commands_to_update_table" style="display:none">
+ <p style="font-size: 10px"><%= image_tag "icons/information.png"%> Updating your commands is optional.
+ However, the command owner or admin has probably modified the command for a good reason. You should look at the
+ new version of a command before updating.
+ </p>
+ <%= user_command_table @commands_to_update, :columns=>[:name, :url_status], :headers=>[['User Command', {:width=>25}],['Url Status', {:width=>50}]]%>
+ </div>
+ <% end %>
+
<h1>Tags</h1>
<%= tag_cloud_or_list @tags %>
View
4 public/stylesheets/text.css
@@ -353,6 +353,10 @@ ul.options li.search {
background: url(../images/icons/search.png) no-repeat left center;
}
+ul.options li.refresh {
+ background: url(../images/icons/arrow_refresh.png) no-repeat left center;
+}
+
ul.options li.command {
background: url(../images/icons/cog.png) no-repeat left center;
}
Please sign in to comment.
Something went wrong with that request. Please try again.