Skip to content

Commit

Permalink
Merge branch 'integration_pagination_with_unified_search' of 0xb5.org…
Browse files Browse the repository at this point in the history
…:digitalgazette into integration_pagination_with_unified_search
  • Loading branch information
chris committed Oct 7, 2010
2 parents cd08934 + d9cd44b commit bc192ee
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 49 deletions.
1 change: 1 addition & 0 deletions mods/digitalgazette/app/controllers/maps_controller.rb
Expand Up @@ -12,6 +12,7 @@ class MapsController < PagesController # TODO < ExternalPagesController
include PagesHelper
# FIXME: do we really need that "all" action?
def index
@page_type = "map"
render :template => 'pages/index'
end

Expand Down
39 changes: 2 additions & 37 deletions mods/digitalgazette/app/controllers/search_controller.rb
Expand Up @@ -45,7 +45,6 @@ def render_search_results
handle_rss(:title => full_url, :link => full_url,
:image => (@user ? avatar_url(:id => @user.avatar_id||0, :size => 'huge') : nil))


unless send_pages! # send the pages to the browser
# museum during refactoring
# if request.xhr?
Expand Down Expand Up @@ -151,6 +150,7 @@ def send_pages!
page[dom_id].replace_html(:partial => (partial = list_partial_for(:page_type => page_type)),
:locals => {
:pages => pages,
:page_type => page_type,
:title => I18n.t("page_search_title".to_sym,
:type => I18n.t("dg_#{page_type}".to_sym)),
:no_top_pagination => true
Expand All @@ -165,8 +165,6 @@ def send_pages!
end
end



#
#
# OPTIONS & FILTERS
Expand All @@ -191,7 +189,7 @@ def prefix_path
# but used for iterative partial resolving of a group of page types
def list_partial_for(options={ })
ret =
if options[:wrapper] ||= @wrapper
if options[:wrapper] ||= @wrapper
LEGAL_PARTIALS[options[:wrapper].to_s]
elsif options[:widget] ||= @widget
BOX_PARTIALS[options[:widget].to_s] || ""
Expand Down Expand Up @@ -282,39 +280,6 @@ def get_page_types
@page_type = @page_types.first if @page_types.size == 1
end

# general update method
# sends the right partials to the browser
# therefore takes the Hash in @pages an resolves it
# to the pages/list or the widget/panel - specific partials
#
# TODO implement non-xhr fallback by passing
# the relevant widget-tree
# down to clever partials/helpers
#
def send_pages!
if request.xhr?
# Update every widget as one, if existing
render :update do |page|
@page_store.to_hash.each_pair do |page_type,options|
dom_id = options[:dom_id]
pages = options[:pages]
page[dom_id].replace_html(:partial => (partial = list_partial_for(:page_type => page_type)),
:locals => {
:pages => pages,
:title => I18n.t("page_search_title".to_sym,
:type => I18n.t("dg_#{page_type}".to_sym)),
:no_top_pagination => true
} )
page[dom_id].insert( { :after => panel_pagination_at(:bottom, options)})
logger.debug("REPLACING '#{dom_id}' WITH PARTIAL '#{partial}'. HAVE #{pages.size} PAGES OF TYPE '#{page_type}'. CURRENT PAGE #{params[:page].inspect} PER PAGE #{params[:per_page].inspect}")
end
if @panel && params[:pagination]
page["#{@panel}_pagination_bottom"].replace_html(panel_pagination_at(:bottom, { :pagination => params[:pagination], :path => @path.to_param}))
end
end
end
end


# the @page_store is our widget tree
def setup_page_store
Expand Down
14 changes: 10 additions & 4 deletions mods/digitalgazette/app/helpers/application_helper.rb
@@ -1,7 +1,4 @@
module ApplicationHelper



def page_line page, &block
"<li class='small_icon #{page.icon}%>_16'>#{yield}</li>"
end
Expand All @@ -15,13 +12,22 @@ def pagination_for(things, options={})
else
defaults = {:renderer => LinkRenderer::Dispatch, :previous_label => "&laquo; %s" % I18n.t(:pagination_previous), :next_label => "%s &raquo;" % I18n.t(:pagination_next), :inner_window => 2}
end
# if a @page_type is given, we only want to render this, so we have to overwrite
# the current path, to exclue other page_types
if options[:page_type]
# if we pass a path option to will paginate, it will use it for creating the url
# see lib/digital_gazette/will_paginate_ajax_link_renderer.rb
options[:params] ||= {}
options[:params][:path] = @naked_path.dup
options[:params][:path].add_types!(options[:page_type])
options[:params][:path].flatten!
end
will_paginate(things, defaults.merge(options))
end

# i had problems, this does exactly, what i want
def better_hidden_field group, name, value
"<input type='hidden' id='#{group}_#{name}' name='#{group}[#{name}]' value='#{value}' />"

end

def clean_javascript_string(string, quote)
Expand Down
7 changes: 3 additions & 4 deletions mods/digitalgazette/app/views/pages/_list.html.haml
Expand Up @@ -3,17 +3,16 @@
- # it basically adds logic to handel @maps seperated from pages
- pages ||= @pages
= render(:partial => heading_partial) if local_assigns[:heading_partial]

%section#pages{:class=> local_assigns[:full_width] ? 'full' : ''}
%header
- if local_assigns[:title] && !title.blank?
%h2
= title
%div.right
= render(:partial => pages_dropdown) if local_assigns[:pages_dropdown]
= pagination_for(pages, :method => 'get') unless local_assigns[:no_top_pagination]
= pagination_for(pages, :method => 'get', :page_type => local_assigns[:page_type]) unless local_assigns[:no_top_pagination]
- else
= pagination_for(pages, :method => 'get') unless local_assigns[:no_top_pagination]
= pagination_for(pages, :method => 'get', :page_type => local_assigns[:page_type]) unless local_assigns[:no_top_pagination]

- if pages && pages.any?
= render(:partial => block_above_pages_list_partial) if local_assigns[:block_above_pages_list_partial]
Expand All @@ -25,4 +24,4 @@
- if defined?(pagination_link) && pagination_link.present?
%span.pagination
- else
= pagination_for(pages, :method => 'get')
= pagination_for(pages, :method => 'get', :page_type => local_assigns[:page_type])
2 changes: 1 addition & 1 deletion mods/digitalgazette/app/views/pages/_tags.html.erb
@@ -1,5 +1,5 @@
<ul class="bullet_indent">
<%- tags.each do |tag| -%>
<li><a href="/<%=@page_type == 'asset' ? 'reports' : 'wiki' %>/search/tag/<%= tag.downcase %>"><%= tag %></a></li>
<li><a href="/search/type/<%= @page_type.to_s %>/tag/<%= tag.downcase %>"><%= tag %></a></li>
<%- end -%>
</ul>
2 changes: 0 additions & 2 deletions mods/digitalgazette/app/views/pages/_topics.html.haml
@@ -1,7 +1,5 @@
-tags ||= {:politics => ["Conflict","Judicial System","Law Enforcement" ,"Military","Public Administration","Political Parties"], :society => ["Gender","Livelihoods and Land Use","Non-Pakhtuns","Pakhtuns","Socio-economic Classes","Youth"], :religion => ["Other Religious Sects","Religious Political Movements","Shia Belief and Practice","Sufi Belief and Practice","Sunni Belief and Practice"], :development => ["Agriculture","Civil Society","Communication","Economy","Education","Energy","Health","Housing","Humanitarian Response","Natural Resources","Transport","Social Welfare","Water Supply and Sanitation"]}



%div#browse_topics
%div.political_topics
= render :partial => "/pages/tag_category", :locals => {:asset_type => page_type, :category => "Politics", :tags => tags[:politics]}
Expand Down
1 change: 0 additions & 1 deletion mods/digitalgazette/app/views/pages/index.html.haml
@@ -1,7 +1,6 @@
= render :partial => "pages/#{@page_type.underscore}/header"
= render :partial => 'search/banner', :locals => {:page_type => @page_type}
/= render :partial => 'pages/search', :locals => {:users => @user.friends, :groups => @user.groups}
%div#browse
%h4= "... or Browse #{@page_type.pluralize} by Topic"
= render :partial => 'pages/topics', :locals => { :page_type => (@page_type || "WikiPage") }
Expand Down
@@ -0,0 +1,16 @@
module DigitalGazette
module PagesControllerExtension
def self.included(base)
base.instance_eval do
skip_before_filter :login_required
before_filter :public_or_login_required, :except => [:search]
end
end

def public_or_login_required
return true unless @pages
!(@pages.collect {|p| p.public? }.include?(false)) or login_required
end
end
end
xx

0 comments on commit bc192ee

Please sign in to comment.