<commit_before>module Qadmin  
  module Helper    

    def admin_controls(name, options = {}, &block)
      return if respond_to?(:overlay?) && overlay?
      controller     = options[:controller] || name.to_s.tableize
      assumed_object = self.instance_variable_get "@#{name}"
      logger.debug "= admin_controls: name : #{name}, assumed_object: #{assumed_object.inspect}"
      obj            = options[:object] || assumed_object || nil
      parent         = options[:parent] || false

      parent_link_attributes = parent ? {parent.class.to_s.foreign_key => parent.id} : {}
      general_link_attributes = {:controller => controller}.merge(parent_link_attributes)

      control_links = {
        :index      => link_to(image_tag('admin/icon_list.png') + " Back to List", general_link_attributes.merge(:action => 'index')),
        :new        => link_to(image_tag('admin/icon_new.png') + " New", general_link_attributes.merge(:action => 'new')),
        :edit       => link_to(image_tag('admin/icon_edit.png') + " Edit", general_link_attributes.merge({:action => 'edit', :id => obj.id})),
        :show       => link_to(image_tag('admin/icon_show.png') + " View", general_link_attributes.merge({:action => 'show', :id => obj.id})),
        :destroy    => link_to(image_tag('admin/icon_destroy.png') + " Delete", general_link_attributes.merge({:action => 'destroy', :id => obj.id}), :confirm => 'Are you sure?', :method => :delete),
        :ports      => link_to(image_tag('admin/icon_export.png') + " Import/Export", general_link_attributes.merge(:action => 'ports')),
        :export     => link_to(image_tag('admin/icon_export.png') + " Export", general_link_attributes.merge(:action => 'export')),
        :preview    => link_to(image_tag('admin/icon_find.png') + " Preview", general_link_attributes.merge({:action => 'preview', :id => obj.id}))
      }

      control_sets = {
        :index => [:new],
        :new   => [:index],
        :edit  => [:index,:new,:show,:destroy],
        :show  => [:index,:new,:edit,:destroy]
      }
      
      control_set = (options[:controls] || []).dup
      control_set.unshift(control_sets[options[:for]]) if options[:for]
      control_set << :ports if options[:ports]
      controls = [control_set].flatten.collect {|c| control_links[c] }.compact

      html = ""
      html << %{<ul class="admin_controls">}
      controls.each {|control| html << li(control) }
      if block_given?
        html << capture(&block)
        html << %{</ul>}
        concat(html)
      else
        html << %{</ul>}
        html
      end
    end
    
    def sortable_column_header(attribute_name, text = nil, options = {})
      link_text = text || self.qadmin_configuration.on_index.column_headers[attribute_name] || attribute_name.to_s.humanize
      return link_text unless qadmin_configuration.model_klass.can_query?
      query_parser = model_restful_query_parser(options)
      query_param = options[:query_param] || :query
      logger.warn 'params:' +  self.params[query_param].inspect<commit_msg>Controls are now lambdas!<commit_after>module Qadmin  
  module Helper    

    def admin_controls(name, options = {}, &block)
      return if respond_to?(:overlay?) && overlay?
      controller     = options[:controller] || name.to_s.tableize
      assumed_object = self.instance_variable_get "@#{name}"
      logger.debug "= admin_controls: name : #{name}, assumed_object: #{assumed_object.inspect}"
      obj            = options[:object] || assumed_object || nil
      parent         = options[:parent] || false

      parent_link_attributes = parent ? {parent.class.to_s.foreign_key => parent.id} : {}
      general_link_attributes = {:controller => controller}.merge(parent_link_attributes)

      control_links = {
        :index      => lambda { link_to(image_tag('admin/icon_list.png') + " Back to List", general_link_attributes.merge(:action => 'index')) },
        :new        => lambda { link_to(image_tag('admin/icon_new.png') + " New", general_link_attributes.merge(:action => 'new')) },
        :edit       => lambda { link_to(image_tag('admin/icon_edit.png') + " Edit", general_link_attributes.merge({:action => 'edit', :id => obj.id})) },
        :show       => lambda { link_to(image_tag('admin/icon_show.png') + " View", general_link_attributes.merge({:action => 'show', :id => obj.id})) },
        :destroy    => lambda { link_to(image_tag('admin/icon_destroy.png') + " Delete", general_link_attributes.merge({:action => 'destroy', :id => obj.id}), :confirm => 'Are you sure?', :method => :delete) },
        :ports      => lambda { link_to(image_tag('admin/icon_export.png') + " Import/Export", general_link_attributes.merge(:action => 'ports')) },
        :export     => lambda { link_to(image_tag('admin/icon_export.png') + " Export", general_link_attributes.merge(:action => 'export')) },
        :preview    => lambda { link_to(image_tag('admin/icon_find.png') + " Preview", general_link_attributes.merge({:action => 'preview', :id => obj.id})) }
      }

      control_sets = {
        :index => [:new],
        :new   => [:index],
        :edit  => [:index,:new,:show,:destroy],
        :show  => [:index,:new,:edit,:destroy]
      }
      
      control_set = (options[:controls] || []).dup
      control_set.unshift(control_sets[options[:for]]) if options[:for]
      control_set << :ports if options[:ports]
      controls = [control_set].flatten.collect {|c| control_links[c] }.compact

      html = ""
      html << %{<ul class="admin_controls">}
      controls.each do |control| 
        control_html = control.respond_to?(:call) ? control.call : control
        html << li(control_html) 
      end
      if block_given?
        html << capture(&block)
        html << %{</ul>}
        concat(html)
      else
        html << %{</ul>}
        html
      end
    end
    
    def sortable_column_header(attribute_name, text = nil, options = {})
      link_text = text || self.qadmin_configuration.on_index.column_headers[attribute_name] || attribute_name.to_s.humanize
      return link_text unless qadmin_configuration.model_klass.can_query?
      query_parser = model_restful_query_parser(options)
      query_param = options[:query_param] || :query
      logger.warn 'params:' +  self.params[query_param].inspect
{'fraction_non_alphanumeric': 0.15983476326660312, 'fraction_numerical': 0.0, 'mean_word_length': 3.2533783783783785, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3177461', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1922, 'n_words': 338}