Commit 3c46a3a0dc763e1216bf1e45f8b5cc0153a257dc

Authored by Fellipe Souto Sampaio
Committed by Rafael Manzo
1 parent 4d27b784

New view

Pending unit and acceptance test
app/helpers/mezuro_ranges_helper.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +module MezuroRangesHelper
  2 +
  3 + def readings_options(reading_group)
  4 + reading_group.readings.map { |reading| [reading.label, reading.id] }
  5 + end
  6 +end
0 7 \ No newline at end of file
... ...
app/models/mezuro_range.rb
... ... @@ -7,5 +7,6 @@ class MezuroRange < KalibroGem::Entities::Range
7 7  
8 8 validates :beginning, presence: true, beginning_uniqueness: true
9 9 validates :end, presence: true #TODO: Validates numeracy
  10 + validates :reading_id, presence: true
10 11  
11 12 end
12 13 \ No newline at end of file
... ...
app/views/mezuro_ranges/_form.html.erb
... ... @@ -14,6 +14,18 @@
14 14 <%= f.label :comments, class: 'control-label' %><br>
15 15 <%= f.text_area :comments, class: 'form-control' %>
16 16 </div>
  17 +
  18 + <% if @reading_group.readings.size == 0 %>
  19 + <%= render partial: 'no_readings' %>
  20 + <% else %>
  21 + <div class="form-group">
  22 + <%= f.label :reading_id, 'Reading', class: 'control-label' %>
  23 + <%= f.select( :reading_id, readings_options(@reading_group), {class: 'form-control'} ) %>
  24 + </div></br>
  25 + <% end %>
  26 +
  27 +
  28 +
17 29  
18 30 <%= f.submit 'Save', class: 'btn btn-primary' %>
19 31  
... ...
app/views/mezuro_ranges/_no_readings.html.erb
1   -<tr>
2   - <% col_number = reading_groups_owner?(@reading_group.id) ? 5 : 3 %>
3   - <td colspan="<%= col_number %>">There are no readings yet!</td>
4   -</tr>
  1 +<div class="alert alert-error alert-dismissable">
  2 + <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
  3 + <h4 class="alert-heading">There is not reading yet!</h4>
  4 + <p>
  5 + You need to create reading in your associeated reading group before create a range
  6 + </p>
  7 + <p>
  8 + <% if reading_groups_owner? @reading_group.id %>
  9 +
  10 + <%= link_to 'Create New Reading', new_reading_group_reading_path(@reading_group,), class: 'btn btn-danger' %>
  11 +
  12 + <% else %>
  13 +
  14 + </p></div>
  15 + <div class="alert alert-error alert-dismissable">
  16 + <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
  17 + <p> You are not allowed to do this operation, your reading belongs to another person. </p>
  18 + </div>
  19 +
  20 + <% end %>
  21 + </p>
  22 +
  23 +</div>
5 24 \ No newline at end of file
... ...
app/views/mezuro_ranges/_reading.html.erb
... ... @@ -1,5 +0,0 @@
1   -<tr>
2   - <td><%= reading.label %></td>
3   - <td><%= reading.grade %></td>
4   - <td style="background-color: #<%= reading.color %>; width: 20%;">&nbsp;</td>
5   -</tr>
6 0 \ No newline at end of file
app/views/mezuro_ranges/new.html.erb
... ... @@ -4,22 +4,4 @@
4 4 @mezuro_range.metric_configuration_id)) do |f| %>
5 5 <%= render partial: 'form', locals: {f: f} %>
6 6 <% end %>
7   -
8   -<table class="table table-hover">
9   - <thead>
10   - <tr>
11   - <th>Label</th>
12   - <th>Grade</th>
13   - <th>Color</th>
14   - </tr>
15   - </thead>
16   -
17   - <tbody>
18   - <% if @reading_group.readings.size == 0 %>
19   - <%= render partial: 'no_readings' %>
20   - <% else %>
21   - <%= render partial: 'reading', collection: @reading_group.readings, as: :reading %>
22   - <% end %>
23   - </tbody>
24   -
25   -</table>
  7 +<%= raise mezuro_range.inspect %>
... ...