# BioCatalogue: app/views/soap_operations/index.xml.builder
#
# Copyright (c) 2010, University of Manchester, The European Bioinformatics 
# Institute (EMBL-EBI) and the University of Southampton.
# See license.txt for details

# <?xml>
xml.instruct! :xml

# <soapOperations>
xml.tag! "soapOperations", 
         xlink_attributes(uri_for_collection("soap_operations", :params => params)), 
         xml_root_attributes,
         :resourceType => "SoapOperations" do
  
  # <parameters>
  xml.parameters do 
    
    # Filtering parameters
    render :partial => "api/filtering/parameters", :locals => { :parent_xml => xml, :resource_type => "SoapOperations" }
    
    # <query>
    xml.query params[:q], :urlKey => "q"
    
    # Sorting parameters
    render :partial => "api/sorting/parameters", :locals => { :parent_xml => xml, :sort_by => @sort_by, :sort_order => @sort_order }
    
    # Pagination parameters
    render :partial => "api/pagination/parameters", :locals => { :parent_xml => xml, :page => @page, :per_page => @per_page }
    
  end
  
  # <statistics>
  xml.statistics do
    
    # <pages>
    xml.pages @soap_operations.total_pages
    
    # <results>
    xml.results @soap_operations.total_entries
    
    # <total>
    xml.total SoapOperation.count
    
  end
  
  # <results>
  xml.results do
    
    # <soapOperation> *
    @soap_operations.each do |s_op|
      render :partial => "soap_operations/api/result_item", :locals => { :parent_xml => xml, :soap_operation => s_op }
    end
    
  end
  
  # <related>
  xml.related do
    
    params_clone = BioCatalogue::Util.duplicate_params(params)
    
    # Pagination previous next links
    render :partial => "api/pagination/previous_next_links", 
           :locals => { :parent_xml => xml,
                        :resource_type => "SoapOperations",
                        :page => @page,
                        :total_pages => @soap_operations.total_pages,
                        :params_clone => params_clone,
                        :resource_url_lambda => lambda { |params| uri_for_collection("soap_operations", :params => params) } }
    
    # <filters>
    xml.filters xlink_attributes(uri_for_collection("soap_operations/filters"), 
                                 :title => xlink_title("Filters for the SOAP operations index")),
                :resourceType => "Filters"
    
    # <filtersOnCurrentResults>
    xml.filtersOnCurrentResults xlink_attributes(uri_for_collection("soap_operations/filters", :params => params_clone.reject{|k,v| k.to_s.downcase == "page" }), 
                                 :title => xlink_title("Filters for the SOAP operations index that will be applied on top of the current results set")),
                :resourceType => "Filters"
    
  end
  
end