summaryrefslogtreecommitdiff
path: root/app/views/workouts/index.html.erb
blob: 4bddd151a3d2b8c08c4e9f7668861d93e2af55ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<div class="container">
  <div class="columns">
    <div class="column is-12">
      <nav class="level">
        <!-- Left side -->
        <div class="level-left">
          <div class="level-item">
            <%= search_form %>
          </div>
          <div class="level-item">
            <p class="subtitle is-5">
            <strong><%= @workouts.count %></strong> workouts
            </p>
          </div>
          <div class="level-item">
            <%= form_tag workouts_path(filter_params_hash), method: :get do %>
              <p class="control">
                <% filter_params_hash.each do |key, value| %>
                  <%= hidden_field_tag key, value %>
                <% end %>
                <span class="select">
                  <%= select_tag :since, options_for_select(@ranges.map { |x| [time_ago_in_words(x.ago), x.to_i] }, params[:since]), include_blank: true  %>
                </span>
              </p>
            <% end %>
          </div>
        </div>

        <!-- Right side -->
        <div class="level-right">
          <p class="level-item">
          <% if @exercise.nil? %>
            <strong> <%= link_to 'All', workouts_path(filter_params_hash(exercise: nil)) %> </strong>
          <% else %>
            <%= link_to 'All', workouts_path(filter_params_hash(exercise: nil)) %>
          <% end %>
          </p>
          <% @primary_exercises.each do |exercise| %>
            <p class="level-item">
            <% if exercise == @exercise %>
              <strong><%= link_to exercise.name, workouts_path(filter_params_hash(exercise: exercise)) %></strong>
            <% else %>
              <%= link_to exercise.name, workouts_path(filter_params_hash(exercise: exercise)) %>
            <% end %>
            </p>
          <% end %>
          <p class="level-item"><%= link_to "New", new_workout_path, class: 'button is-success' %></p>
        </div>
      </nav>
    </div>
  </div>
  <div class="columns">
    <div class="column is-12">
      <%= line_chart charts_path(filter_params_hash), download: true %>
    </div>
  </div>

  <div class="columns">
    <div class="column is-12">
      <p class="has-text-right"><%= link_to t(".calendar"), calendar_workouts_path %></p>
      <table class="table is-bordered is-striped is-narrow">
        <thead>
          <tr>
            <th><abbr title="Routine">R</abbr></th>
            <th><abbr title="Date">Date</abbr></th>
            <th><abbr title="Body weight">BW</abbr></th>
            <% @primary_exercises.each do |exercise| %>
              <th><%= exercise.name %></th>
            <% end %>
          </tr>
        </thead>
        <tbody>
          <%= cache @workouts do %>
            <% @workouts.each do |workout| %>
              <tr>
                <td> <%= workout.name %> </td>
                <td> <%= I18n.l workout.occurred_at, format: :short %> </td>
                <td> <%= workout.body_weight.to(:lbs) %> lbs </td>
                <% @primary_exercises.each do |exercise| %>
                  <td> <%= workout.display_status_for(exercise) %> </td>
                <% end %>
              </tr>
            <% end %>
          <% end %>
        </tbody>
      </table>
    </div>
  </div>
  <div class="columns">
    <div class="column is-12">
      <%# paginate @workouts, remote: false %>
    </div>
  </div>
</div>

<% content_for :javascript do %>
  $('.select').on('change', function(event) {
    $(event.target).parents('form:first').submit();
  });
<% end %>