<% title "#{@container.name.titleize} - #{@container.in_fog.name}" %>
<%= stylesheet 'foreman_docker/terminal' %>
<%= container_title_actions(@container) %>
<div id="host-show" class="row">
  <div class="col-md-4">
   <div id="myTabContent" class="tab-content">
      <div class="tab-pane active in">
        <table id="properties_table" class="table table-bordered table-striped">
          <tr><th colspan="2"><%= _('Properties') %></th></tr>
            <tr>
              <td><%= _('Name') %></td>
              <td><%= @container.in_fog.name %></td>
            </tr>
            <tr>
              <td><%= _('Image Repository') %></td>
              <td><%= @container.repository_name %> </td>
            </tr>
            <tr>
              <td><%= _('Image Tag') %></td>
              <td><%= @container.tag %> </td>
            </tr>
            <tr>
              <td><%= _('IP Address') %></td>
              <td><%= @container.in_fog.ipaddress %> </td>
            </tr>
            <tr>
              <td><%= _('CPU shares') %></td>
              <td><%= @container.in_fog.cores %></td>
            </tr>
            <tr>
              <td><%= _('UUID') %></td>
              <td><%= trunc_with_tooltip @container.in_fog.identity %></td>
            </tr>
            <tr>
              <td><%= _('Memory') %></td>
              <td><%= number_to_human_size @container.in_fog.memory %> </td>
            </tr>
            <tr>
              <td><%= _('Command') %></td>
              <td><%= @container.in_fog.command %> </td>
            </tr>
            <tr>
              <td><%= _('Exposed ports') %></td>
              <td>
                <table id="exposed_ports" class="table table-bordered" style="table-layout:fixed; word-wrap: break-word">
                  <% (@container.in_fog.exposed_ports || []).each do |exposed_port| %>
                  <% pair = exposed_port.first.split("/") %>
                    <tr>
                      <td><b><%= pair.first %></b></td>
                      <td><i><%= pair.second %></i></td>
                    </tr>
                  <% end %>
                </table>
              </td>
            </tr>
            <tr>
              <td><%= _('DNS') %></td>
              <td>
                  <% (@container.in_fog.attributes['host_config_dns'] || []).each do |dns| %>
                    <%= dns %><br/>
                  <% end %>
                </td>
            </tr>            
            <tr>
              <td><%= _('Environment Variables') %></td>
              <td>
                <table id="environment_variables" class="table table-bordered" style="table-layout:fixed; word-wrap: break-word">
                  <% (@container.in_fog.attributes['config_env'] || []).each do |environment_variable| %>
                  <% pair = environment_variable.split("=") %>
                    <tr>
                      <td><b><%= pair.first %></b></td>
                      <td><i><%= pair.second %></i></td>
                    </tr>
                  <% end %>
                </table>
              </td>
            </tr>
            <% Taxonomy.enabled_taxonomies.each do |taxonomy| %>
              <tr>
                <td><%= _(taxonomy.humanize) %></td>
                <td><%= link_to_taxonomies(@container.send(:"#{taxonomy}")).html_safe %> </td>
              </tr>
            <% end %>
            <tr>
              <td><%= _('Running on') %></td>
              <td><%= link_to @container.compute_resource,
                              compute_resource_path(@container.compute_resource) %></td>
            </tr>
          </tr>
        </table>
      </div>
    </div>
  </div>
  <div class="col-md-8">
    <% if @container.in_fog.ready? %>
    <ul id="myTab" class="nav nav-tabs">
      <li class="active"><a href="#processes" data-toggle="tab">
        <span class="glyphicon glyphicon-credit-card"></span>
        <%= _('Processes') %>
      </a></li>
      <li><a href="#logs" data-toggle="tab">
        <span class="glyphicon glyphicon-list-alt"></span>
        <%= _('Logs') %>
      </a></li>
    </ul>
    <div id="myTabContent" class="tab-content">
      <div class="tab-pane active in" id="processes">
        <div class='accordion' id='accordion'>
          <% processes(@container).each do |process| %>
          <div>
            <h2>
              <a href='#<%= process['PID'] %>-index'
               class='accordion-toggle'
               data-toggle='collapse'
               data-parent='#accordion'>
               <%= process['CMD'] %>
              </a><br>
              <small><%= process['UID'] %></small>
            </h2>
          </div>
          <div id='<%= process['PID'] %>-index' class='collapse accordion-body'>
            <pre class="prettyprint"><%= JSON.pretty_generate(process) %></pre>
          </div>
        <% end %>
        </div>
      </div>
      <div class="tab-pane" id="logs">
        <pre class="terminal terminal-output pre-scrollable"><code>
          <%= logs(@container, :stdout => true, :tail => 100) %>
        </code></pre>
      </div>
    </div>
    <% else %>
      <div class="alert alert-block alert-warning">
        <p><strong><%= _("Notice") %></strong>
        <hr>
        <%= _("Your container is stopped.") %></p>
        <p><%= _("Please turn on your container to see processes running, logs, and more.") %></p>
      </div>
    <% end %>
  </div>
</div>

<div id="commit-modal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title"><%= _('Commit this container state') %></h4>
      </div>
      <div class="modal-body">
        This will save your current container state to an image.
      <hr/>
      <%= form_tag commit_container_path(:id => @container.id), :id => 'commit-form', :class => 'form-horizontal' do %>
        <div class="form-group">
          <%= label_tag "commit[repo]", _("Repo"), :class=>"col-sm-2 control-label" %>
          <%= text_field :commit, :repo, { :class => "col-sm-8", :focus_on_load => true,
                                           :placeholder => _('docker/my-committed-image') } %>
        </div>
        <div class="form-group">
          <%= label_tag "commit[tag]", _("Tag"), :class=>"col-sm-2 control-label" %>
          <%= text_field :commit, :tag, { :class => "col-sm-8",
                                          :placeholder => _('latest') } %>
        </div>
        <div class="form-group">
          <%= label_tag "commit[author]", _("Author"), :class=>"col-sm-2 control-label" %>
          <%= text_field :commit, :author, { :class => "col-sm-8",
                                             :placeholder => _('Foreman user <foremaner@theforeman.org>') } %>
        </div>
        <div class="form-group">
          <%= label_tag "commit[comment]", _("Comment"), :class=>"col-sm-2 control-label" %>
          <%= text_field :commit, :comment, { :class => "col-sm-8",
                                              :placeholder => _('Description of the commit') } %>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal"><%= _('Cancel') %></button>
          <%= button_tag(:type => 'submit', :class => 'btn btn-primary') do %>
            <%= _('Submit') %> <span class="glyphicon glyphicon-cloud-upload"></span>
          <% end %>
        </div>
        <% end %>
    </div>
  </div>
</div>
