Permalink
Browse files

clean up search handling (errors, duplication, etc)

  • Loading branch information...
1 parent a8957fd commit 71d03faf7564a2252e2066cd250d7ed7bdaf167c @ethn ethn committed Mar 29, 2013
@@ -393,7 +393,10 @@ body#wagn .card-slot.recent-changes h2 {
margin-right: 4px;
}
.closed-content,
+.closed-content table,
+.closed-content tbody,
.closed-content tr,
+.closed-content th,
.closed-content td,
.closed-content p,
.closed-content h1,
@@ -540,6 +543,12 @@ ul.pointer {
.search-no-results:after {
content:'0 results';
}
+.closed-content .search-no-results:after {
+ content:'';
+}
+
+
+
.search-count {
float: right;
color: #bbc;
View
@@ -168,15 +168,16 @@ def set_const
end
def get_method_key
- tkls_key = self.class.method_key
- return tkls_key if tkls_key
- return self.class.method_key if self.class.anchorless?
- opts = {}
- self.class.opt_keys.each_with_index do |key, index|
- return nil unless opt_vals[index]
- opts[key] = opt_vals[index]
+ if self.class.anchorless?
+ self.class.method_key
+ else
+ opts = {}
+ self.class.opt_keys.each_with_index do |key, index|
+ return nil unless opt_vals[index]
+ opts[key] = opt_vals[index]
+ end
+ self.class.method_key_from_opts opts
end
- self.class.method_key_from_opts opts
end
def opt_vals
View
@@ -376,23 +376,6 @@ def path opts={}
query = opts.empty? ? '' : "?#{opts.to_param}"
wagn_path( base + query )
end
-
- def search_params
- @search_params ||= begin
- p = self.respond_to?(:paging_params) ? paging_params : { :default_limit=> 100 }
- p[:vars] = {}
- if self == @root
- params.each do |key,val|
- case key.to_s
- when '_wql' ; p.merge! val
- when /^\_(\w+)$/ ; p[:vars][$1.to_sym] = val
- end
- end
- end
- p
- end
- end
-
#
# ------------ LINKS ---------------
#
@@ -6,96 +6,79 @@ module Set::Type::SearchType
format :base
define_view :core, :type=>:search_type do |args|
- error=nil
- results = begin
- card.item_cards( search_params )
- rescue Exception=>e
- error = e; nil
- end
- @itemview = args[:item] || card.spec[:view]
-
+ set_search_vars args
case
- when results.nil?
- Rails.logger.debug " no result? #{error.backtrace}"
- %{No results? #{error.class.to_s}: #{error&&error.message}<br/>#{card.content}}
- when card.spec[:return] =='count'
- results.to_s
+ when @error
+ Rails.logger.debug " no result? #{@error.backtrace}"
+ %{No results? #{@error.class.to_s} :: #{@error && @error.message} :: #{card.content}}
+ when @search_spec[:return] =='count'
+ @results.to_s
else
- _render_card_list args.merge( :results=>results )
+ _render_card_list args
end
end
define_view :card_list, :type=>:search_type do |args|
@itemview ||= :name
- if args[:results].empty?
+ if @results.empty?
'no results'
else
- args[:results].map do |c|
+ @results.map do |c|
process_inclusion c, :view=>@itemview
end.join "\n"
end
end
format :html
-
- define_view :editor, :type=>:search_type do |args|
- form.text_area :content, :rows=>10
- end
-
- define_view :closed_content, :type=>:search_type do |args|
- return "..." if @depth > 2
- search_params[:limit] = 10 #not quite right, but prevents massive invisible lists.
- # really needs to be a hard high limit but allow for lower ones.
-
- results= begin
- card.item_cards( search_params )
- rescue Exception=>e
- error = e; nil
- end
-
- @itemview = args[:item] || card.spec[:view]
-
- if results.nil?
- %{"#{error.class.to_s}: #{error.message}"<br/>#{card.content}}
- elsif card.spec[:return] =='count'
- results.to_s
- elsif results.length==0
- '<span class="search-count">(0)</span>'
- else
- %{<span class="search-count">(#{ card.count })</span>
- <div class="search-result-list">
- #{results.map do |c|
- %{<div class="search-result-item">#{@itemview == 'name' ? c.name : link_to_page( c.name ) }</div>}
- end*"\n"}
- </div>}
- end
- end
-
+
define_view :card_list, :type=>:search_type do |args|
@itemview ||= :closed
paging = _optional_render :paging, args
_render_search_header +
- if args[:results].empty?
+ if @results.empty?
%{<div class="search-no-results"></div>}
else
%{
- #{paging}
- <div class="search-result-list"> #{
- args[:results].map do |c|
- %{<div class="search-result-item item-#{ @itemview }">
- #{ process_inclusion c, :view=>@itemview, :size=>args[:size] }
- </div>}
- end.join }
- </div>
- #{ paging if args[:results].length > 10 }
+ #{paging}
+ <div class="search-result-list">
+ #{
+ @results.map do |c|
+ %{
+ <div class="search-result-item item-#{ @itemview }">
+ #{ process_inclusion c, :view=>@itemview, :size=>args[:size] }
+ </div>
+ }
+ end.join
+ }
+ </div>
+ #{ paging if @results.length > 10 }
}
end
end
+
+ define_view :closed_content, :type=>:search_type do |args|
+ if @depth > 2
+ "..."
+ else
+ search_params[:limit] = 10 #not quite right, but prevents massive invisible lists.
+ # really needs to be a hard high limit but allow for lower ones.
+
+ set_search_vars args
+ @itemview = :link unless @itemview == :name #FIXME - probably want other way to specify closed_view ok...
+
+ _render_core args.merge( :hide=>:paging )
+ end
+ end
+
+ define_view :editor, :type=>:search_type do |args|
+ form.text_area :content, :rows=>10
+ end
+
define_view :search_header do |args|
''
end
@@ -106,11 +89,10 @@ module Set::Type::SearchType
end
define_view :card_list, :name=>:recent do |args|
- cards = args[:results]
@itemview ||= :change
cards_by_day = Hash.new { |h, day| h[day] = [] }
- cards.each do |card|
+ @results.each do |card|
begin
stamp = card.updated_at
day = Date.new(stamp.year, stamp.month, stamp.day)
@@ -151,7 +133,7 @@ module Set::Type::SearchType
s = card.spec search_params
offset, limit = s[:offset].to_i, s[:limit].to_i
return '' if limit < 1
- return '' if offset==0 && limit > offset + args[:results].length #avoid query if we know there aren't enough results to warrant paging
+ return '' if offset==0 && limit > offset + @results.length #avoid query if we know there aren't enough results to warrant paging
total = card.count search_params
return '' if limit >= total # should only happen if limit exactly equals the total
@@ -204,13 +186,13 @@ module Set::Type::SearchType
define_view :card_list, :type=>:search_type do |args|
@itemview ||= :name
- if args[:results].empty?
+ if @results.empty?
'no results'
else
# simpler version gives [{'card':{the card stuff}, {'card' ...} vs.
- # args[:results].map do |c| process_inclusion c, :view=>@itemview end
+ # @results.map do |c| process_inclusion c, :view=>@itemview end
# This which converts to {'cards':[{the card suff}, {another card stuff} ...]} we may want to support both ...
- {:cards => args[:results].map do |c|
+ {:cards => @results.map do |c|
inc = process_inclusion c, :view=>@itemview
(!(String===inc) and inc.has_key?(:card)) ? inc[:card] : inc
end
@@ -270,7 +252,36 @@ def get_spec params={}
end
end
- class Renderer::Html < Renderer
+ class Renderer
+ def set_search_vars args
+ @search_vars_set ||= begin
+ @search_spec = card.spec search_params
+ @itemview = args[:item] || @search_spec[:view]
+ @results = card.item_cards search_params
+ rescue Exception=>e
+ @error = e; nil
+ end
+ end
+
+ def search_params
+ @search_params ||= begin
+ p = self.respond_to?(:paging_params) ? paging_params : { :default_limit=> 100 }
+ p[:vars] = {}
+ if self == @root
+ params.each do |key,val|
+ case key.to_s
+ when '_wql' ; p.merge! val
+ when /^\_(\w+)$/ ; p[:vars][$1.to_sym] = val
+ end
+ end
+ end
+ p
+ end
+ end
+ end
+
+ class Renderer::Html
+
def page_link text, page
@paging_path_args[:offset] = page * @paging_limit
" #{link_to raw(text), path(@paging_path_args), :class=>'card-paging-link slotter', :remote => true} "
@@ -294,5 +305,6 @@ def paging_params
end
end
end
+
end
View
@@ -3,7 +3,7 @@ module Set::Type
module Set
include Sets
- format :base
+ format :html
define_view :core , :type=>:set do |args|
body = card.setting_codes_by_group.map do |group_name, data|
@@ -53,7 +53,9 @@ module Set
end
end
- alias_view(:closed_content , {:type=>:search_type}, {:type=>:set})
+ define_view :closed_content, :type=>:set do |args|
+ ''
+ end
module Model
View
@@ -126,6 +126,7 @@ def define_view view, opts={}, &final
a = [{}] if a.empty?
if final_method = view_method(view)
with_inclusion_mode view do
+ #Rails.logger.info( warn "rendering final method: #{final_method}" )
send final_method, *a
end
else
@@ -167,7 +168,7 @@ def alias_view view, opts={}, *aliases
raise "Bad view #{alias_view.inspect}"
end
- #Rails.logger.warn "def view final_alias #{alias_view_key}, #{view_key}"
+ #Rails.logger.info( warn "def view final_alias #{alias_view_key}, #{view_key}" )
Renderer.renderer.class_eval do
define_method "_final_#{alias_view_key}".to_sym do |*a|
send "_final_#{view_key}", *a

0 comments on commit 71d03fa

Please sign in to comment.