unepwcmc/SAPI

View on GitHub
app/views/admin/api_usage/index.html.erb

Summary

Maintainability
Test Coverage
<div class="row">
  <div class="span12">
    <div class="page-header">
      <h1>API Usage</h1>
    </div>

    <div class="page-header">
      <h4>Last <%= ApiRequest::RECENT_MONTHS %> Months Requests by Response Status</h4>
    </div>

    <%= line_chart sanitise_hash_for_line_graph(@recent_requests),
      library: {
      title: 'Requests by HTTP Status',
      titlePosition: 'out',
      colors: ['#4AC948', '#EE3B3B']
      }
    %>
  </div>
</div>

<div class="row">
  <div class="span6">
    <div class="page-header">
      <h4>All Requests by Response Status</h4>
    </div>
    <%= pie_chart ApiRequest.requests_by_response_status, library: { legend: 'left', colors: status_colours } %>
  </div>

  <div class="span6">
    <div class="page-header">
      <h4>All Requests by Endpoint</h4>
    </div>
    <%= pie_chart ApiRequest.requests_by_controller, library: { legend: 'left', colors: controller_colours } %>
  </div>
</div>

<div class="row">
  <div class="span12">
    <div class="page-header">
      <h4>Top 50 Most Active Users in the last <%= ApiRequest::RECENT_MONTHS %> months</h4>
    </div>
    <table class="table">
      <thead>
        <tr>
          <th>Name</th>
          <th>Email</th>
          <th>Organisation</th>
          <th>Country</th>
          <th>Successful Requests</th>
          <th>Failed Requests</th>
          <th>View User Data</th>
        </tr>
      </thead>
      <tbody>
        <% unless @users_by_activity.blank? %>
          <% @users_by_activity.each do |r| %>
            <tr>
              <th><%= r.user.try(:name) %></th>
              <th><%= r.user.try(:email) %></th>
              <th><%= r.user.try(:organisation) %></th>
              <th><%= r.user.try(:geo_entity).try(:name_en) %></th>
              <th><%= r.success_cnt %></th>
              <th><%= r.failure_cnt %></th>
              <th><%= link_to 'View', api_user_usage_path(r.user) %></th>
            </tr>
          <% end %>
        <% end %>
      </tbody>
    </table>
  </div>
</div>