<commit_before>module TypusHelper

  ##
  # Applications list on the dashboard
  #
  def applications

    html = "<div id=\"list\">"

    if Typus.applications.size == 0
      return display_error("There are not defined applications in config/typus.yml")
    end

    Typus.applications.each do |module_name|

      enabled = false

      html_module = <<-HTML
        <table>
          <tr>
            <th colspan="2">#{module_name}</th>
          </tr>
      HTML

      Typus.modules(module_name).each do |model|
        if @current_user.models.include? model
          html_module << <<-HTML
            <tr class="#{cycle('even', 'odd')}">
              <td>#{link_to model.titleize.pluralize, "/admin/#{model.tableize}"}<br /></td>
              <td align="right" valign="bottom"><small>#{link_to 'Add', "/admin/#{model.tableize}/new"}</small></td>
            </tr>
          HTML
          enabled = true
        end
      end
      html_module << <<-HTML
        </table>
        <br />
        <div style="clear"></div>
      HTML
      
      html << html_module if enabled
      
    end

    html << "</div>"

#  rescue Exception => error
#    display_error(error)
  end

  def typus_block(name)
    render :partial => "typus/#{params[:model]}/#{name}" rescue nil
  end

  def display_error(error)
    "<div id=\"flash\" class=\"error\"><p>#{error}</p></div>"
  end

  def page_title
    crumbs = []
    crumbs << Typus::Configuration.options[:app_name]
    crumbs << params[:model] << params[:action]
    return crumbs.compact.map { |x| x.titleize }.join(" &rsaquo; ")
  end

  def header
    "<h1>#{Typus::Configuration.options[:app_name]} <small>#{link_to "View site", '/', :target => 'blank'}</small></h1>"
  end

  def login_info
    html = <<-HTML
      <ul>
        <li>Logged as #{link_to @current_user.full_name, :controller => 'typus', :model => 'typus_users', :action => 'edit', :id => @current_user.id}</li>
        <li>#{link_to "Logout", typus_logout_url}</li>
      </ul>
    HTML
    return html
  end

  def display_flash_message
    flash_types = [ :error, :warning, :notice ]
    flash_type = flash_types.detect{ |a| flash.keys.include?(a) } || flash.keys.first
    if flash_type
      "<div id=\"flash\" class=\"%s\"><p>%s</p></div>" % [flash_type.to_s, flash[flash_type]]
    end
  end

  def display_error(error)
    log_error error
    "<div id=\"flash\" class=\"error\"><p>#{error}</p></div>"
  end

  ##
  #
  #
  def log_error(exception)
    ActiveSupport::Deprecation.silence do
        logger.fatal(<commit_msg>Fixed direct link to TypusUser edition<commit_after>module TypusHelper

  ##
  # Applications list on the dashboard
  #
  def applications

    html = "<div id=\"list\">"

    if Typus.applications.size == 0
      return display_error("There are not defined applications in config/typus.yml")
    end

    Typus.applications.each do |module_name|

      enabled = false

      html_module = <<-HTML
        <table>
          <tr>
            <th colspan="2">#{module_name}</th>
          </tr>
      HTML

      Typus.modules(module_name).each do |model|
        if @current_user.models.include? model
          html_module << <<-HTML
            <tr class="#{cycle('even', 'odd')}">
              <td>#{link_to model.titleize.pluralize, "/admin/#{model.tableize}"}<br /></td>
              <td align="right" valign="bottom"><small>#{link_to 'Add', "/admin/#{model.tableize}/new"}</small></td>
            </tr>
          HTML
          enabled = true
        end
      end
      html_module << <<-HTML
        </table>
        <br />
        <div style="clear"></div>
      HTML
      
      html << html_module if enabled
      
    end

    html << "</div>"

#  rescue Exception => error
#    display_error(error)
  end

  def typus_block(name)
    render :partial => "typus/#{params[:model]}/#{name}" rescue nil
  end

  def display_error(error)
    "<div id=\"flash\" class=\"error\"><p>#{error}</p></div>"
  end

  def page_title
    crumbs = []
    crumbs << Typus::Configuration.options[:app_name]
    crumbs << params[:model] << params[:action]
    return crumbs.compact.map { |x| x.titleize }.join(" &rsaquo; ")
  end

  def header
    "<h1>#{Typus::Configuration.options[:app_name]} <small>#{link_to "View site", '/', :target => 'blank'}</small></h1>"
  end

  def login_info
    html = <<-HTML
      <ul>
        <li>Logged as #{link_to @current_user.full_name, :controller => 'admin/typus_users', :action => 'edit', :id => @current_user.id}</li>
        <li>#{link_to "Logout", typus_logout_url}</li>
      </ul>
    HTML
    return html
  end

  def display_flash_message
    flash_types = [ :error, :warning, :notice ]
    flash_type = flash_types.detect{ |a| flash.keys.include?(a) } || flash.keys.first
    if flash_type
      "<div id=\"flash\" class=\"%s\"><p>%s</p></div>" % [flash_type.to_s, flash[flash_type]]
    end
  end

  def display_error(error)
    log_error error
    "<div id=\"flash\" class=\"error\"><p>#{error}</p></div>"
  end

  ##
  #
  #
  def log_error(exception)
    ActiveSupport::Deprecation.silence do
        logger.fatal(
{'fraction_non_alphanumeric': 0.1697265625, 'fraction_numerical': 0.0015625, 'mean_word_length': 2.5123456790123457, 'pattern_counts': {'":': 0, '<': 131, '<?xml version=': 0, '>': 100, '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': '6171369', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1713, 'n_words': 358}