<% title _("Puppet classes") %>

<% title_actions import_proxy_select(hash_for_import_environments_puppetclasses_path),
                 documentation_button('4.2.2Classes') %>

<table class="table table-bordered table-striped">
  <thead>
    <tr>
      <th><%= sort :name, :as => s_("Puppetclass|Name") %></th>
      <th><%= sort :environment, :as => _("Environments and documentation") %></th>
      <th><%= _('Host groups') %></th>
      <th><%= sort :total_hosts, :as => _('Hosts'), :default => "DESC" %></th>
      <th><%= sort :params_count, :as => _('Parameters'), :default => "DESC" %></th>
      <th><%= sort :variables_count, :as => _('Variables'), :default => "DESC" %></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <% for puppetclass in @puppetclasses %>
      <tr>
        <td><%=link_to_if_authorized trunc_with_tooltip(puppetclass.name), hash_for_edit_puppetclass_path(:id => puppetclass).merge(:auth_object => puppetclass, :authorizer => authorizer) %></td>
        <td>
          <% puppetclass.environments.uniq.each do |environment| %>
            <%= link_to_function environment, 'show_rdoc(this)', :'data-url' => rdoc_classes_path(environment, puppetclass.name) %>
          <% end %>
        </td>
        <td><%= puppetclass.all_hostgroups(false).map {|hg| link_to_if_authorized trunc_with_tooltip(hg), hash_for_edit_hostgroup_path(:id=>hg).merge(:auth_object => hg, :authorizer => @hostgroups_authorizer)}.to_sentence.html_safe %></td>
        <td> <%= link_to puppetclass.total_hosts, hosts_path(:search => "class = #{puppetclass.name}")%></td>
        <td><%= puppetclass.global_class_params_count %> </td>
        <td><%= puppetclass.lookup_keys_count %> </td>
        <td><%
          links = [display_delete_if_authorized(hash_for_puppetclass_path(:id => puppetclass).merge(:auth_object => puppetclass, :authorizer => authorizer), :data => { :confirm => _("Delete %s?") % puppetclass.name }, :action => :delete)]
          links.push(display_link_if_authorized(_('Override all parameters'), hash_for_override_puppetclass_path(:enable => true, :id => puppetclass), :method => :post, :data => { :confirm => _("This will set all parameters of the class %s as overridden. Continue?") % puppetclass.name })) if puppetclass.class_params.present? && !overridden?(puppetclass)
          links.push(display_link_if_authorized(_('Set parameters to defaults'), hash_for_override_puppetclass_path(:enable => false, :id => puppetclass), :method => :post, :data => { :confirm => _("This will reset parameters of the class %s to their default values. Continue?") % puppetclass.name })) if puppetclass.class_params.present? && overridden?(puppetclass)
          %>
          <%= action_buttons(*links) %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<%= will_paginate_with_info @puppetclasses %>
