From 7c935652fbb6fd7f786c0819fd652852b26aa629 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 3 May 2012 23:23:31 +0200 Subject: [PATCH] make search and feedlist pass --- app/assets/javascripts/tracks.js | 2 +- app/controllers/search_controller.rb | 14 ++++++++------ app/helpers/feedlist_helper.rb | 6 +++--- app/models/todo.rb | 8 ++++---- app/views/layouts/standard.html.erb | 8 ++++---- ...ion.rhtml => _show_results_collection.html.erb} | 0 app/views/search/{index.rhtml => index.html.erb} | 2 +- .../search/{results.rhtml => results.html.erb} | 0 config/routes.rb | 7 +++++++ test/functional/feedlist_controller_test.rb | 12 ++++++++++++ 10 files changed, 40 insertions(+), 19 deletions(-) rename app/views/search/{_show_results_collection.rhtml => _show_results_collection.html.erb} (100%) rename app/views/search/{index.rhtml => index.html.erb} (68%) rename app/views/search/{results.rhtml => results.html.erb} (100%) diff --git a/app/assets/javascripts/tracks.js b/app/assets/javascripts/tracks.js index 077da5c4..3aed5f5f 100644 --- a/app/assets/javascripts/tracks.js +++ b/app/assets/javascripts/tracks.js @@ -1160,7 +1160,7 @@ $.fn.clearDeps = function() { /**************************************/ function generic_get_script_for_list(element, getter, param){ - $(element).load(relative_to_root(getter+'?'+param)); + $(element).load(relative_to_root(getter+'.js?'+param)); } function default_ajax_options_for_submit(ajax_type, element_to_block) { diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 3137c92b..817c9f1e 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -5,23 +5,25 @@ class SearchController < ApplicationController def results @source_view = params['_source_view'] || 'search' @page_title = "TRACKS::Search Results for #{params[:search]}" - terms = '%' + params[:search] + '%' + terms = "%#{params[:search]}%" @found_not_complete_todos = current_user.todos. where("(todos.description LIKE ? OR todos.notes LIKE ?) AND todos.completed_at IS NULL", terms, terms). includes(Todo::DEFAULT_INCLUDES). - reorder("todos.due IS NULL, todos.due ASC, todos.created_at ASC") + reorder("todos.due IS NULL, todos.due ASC, todos.created_at ASC"). + all @found_complete_todos = current_user.todos. where("(todos.description LIKE ? OR todos.notes LIKE ?) AND NOT (todos.completed_at IS NULL)", terms, terms). includes(Todo::DEFAULT_INCLUDES). - reorder("todos.completed_at DESC") + reorder("todos.completed_at DESC"). + all @found_todos = @found_not_complete_todos + @found_complete_todos - @found_projects = current_user.projects.where("name LIKE ? OR description LIKE ?", terms, terms) - @found_notes = current_user.notes.where("body LIKE ?", terms) - @found_contexts = current_user.contexts.where("name LIKE ?", terms) + @found_projects = current_user.projects.where("name LIKE ? OR description LIKE ?", terms, terms).all + @found_notes = current_user.notes.where("body LIKE ?", terms).all + @found_contexts = current_user.contexts.where("name LIKE ?", terms).all # TODO: limit search to tags on todos @found_tags = Tagging.find_by_sql([ diff --git a/app/helpers/feedlist_helper.rb b/app/helpers/feedlist_helper.rb index 6b3a557b..35dbe97e 100644 --- a/app/helpers/feedlist_helper.rb +++ b/app/helpers/feedlist_helper.rb @@ -8,12 +8,12 @@ module FeedlistHelper def text_formatted_link(options = {}) linkoptions = merge_hashes( {:format => 'txt'}, user_token_hash, options) - link_to('TXT', linkoptions, :title => "Plain text feed" ) + link_to(content_tag(:span, 'TXT', {:class => 'feed', :title => "Plain text feed"}, linkoptions)) end def ical_formatted_link(options = {}) linkoptions = merge_hashes( {:format => 'ics'}, user_token_hash, options) - link_to('iCal', linkoptions, :title => "iCal feed" ) + link_to(content_tag(:span, 'iCal', {:class=>"feed", :title => "iCal feed"}, linkoptions)) end def feed_links(feeds, link_options, title) @@ -23,7 +23,7 @@ module FeedlistHelper html << text_formatted_link(link_options)+space if feeds.include?(:txt) html << ical_formatted_link(link_options)+space if feeds.include?(:ical) html << title - return html + return html.html_safe end def all_feed_links_for_project(project) diff --git a/app/models/todo.rb b/app/models/todo.rb index 1c946f4f..9402491a 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -46,10 +46,10 @@ class Todo < ActiveRecord::Base scope :with_tag, lambda { |tag_id| joins("INNER JOIN taggings ON todos.id = taggings.taggable_id").where("taggings.tag_id = ? ", tag_id) } scope :with_tags, lambda { |tag_ids| where("EXISTS(SELECT * from taggings t WHERE t.tag_id IN (?) AND t.taggable_id=todos.id AND t.taggable_type='Todo')", tag_ids) } # scope :of_user, lambda { |user_id| {:conditions => ["todos.user_id = ? ", user_id] } } - # scope :completed_after, lambda { |date| {:conditions => ["todos.completed_at > ?", date] } } - # scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ?", date] } } - # scope :created_after, lambda { |date| {:conditions => ["todos.created_at > ?", date] } } - # scope :created_before, lambda { |date| {:conditions => ["todos.created_at < ?", date] } } + scope :completed_after, lambda { |date| where("todos.completed_at > ?", date) } + scope :completed_before, lambda { |date| where("todos.completed_at < ?", date) } + scope :created_after, lambda { |date| where("todos.created_at > ?", date) } + scope :created_before, lambda { |date| where("todos.created_at < ?", date) } STARRED_TAG_NAME = "starred" DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :pending_successors, :uncompleted_predecessors, :recurring_todo ] diff --git a/app/views/layouts/standard.html.erb b/app/views/layouts/standard.html.erb index 308a5c09..3e80e184 100644 --- a/app/views/layouts/standard.html.erb +++ b/app/views/layouts/standard.html.erb @@ -68,14 +68,14 @@
  • <%= t('layouts.navigation.admin') %>
  • -
  • <%= navigation_link(image_tag("system-search.png", :size => "16X16", :border => 0), {:controller => "search", :action => "index"}, :title => t('layouts.navigation.search')) %>
  • +
  • <%= navigation_link(image_tag("system-search.png", :size => "16X16", :border => 0), search_path, :title => t('layouts.navigation.search')) %>
  • <%= render_flash %> diff --git a/app/views/search/_show_results_collection.rhtml b/app/views/search/_show_results_collection.html.erb similarity index 100% rename from app/views/search/_show_results_collection.rhtml rename to app/views/search/_show_results_collection.html.erb diff --git a/app/views/search/index.rhtml b/app/views/search/index.html.erb similarity index 68% rename from app/views/search/index.rhtml rename to app/views/search/index.html.erb index 392720fd..e2e23440 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.html.erb @@ -1,5 +1,5 @@