diff --git a/app/helpers/mezuro_ranges_helper.rb b/app/helpers/mezuro_ranges_helper.rb new file mode 100644 index 0000000..07e96ea --- /dev/null +++ b/app/helpers/mezuro_ranges_helper.rb @@ -0,0 +1,6 @@ +module MezuroRangesHelper + + def readings_options(reading_group) + reading_group.readings.map { |reading| [reading.label, reading.id] } + end +end \ No newline at end of file diff --git a/app/models/mezuro_range.rb b/app/models/mezuro_range.rb index 35632b6..8a881f1 100644 --- a/app/models/mezuro_range.rb +++ b/app/models/mezuro_range.rb @@ -7,5 +7,6 @@ class MezuroRange < KalibroGem::Entities::Range validates :beginning, presence: true, beginning_uniqueness: true validates :end, presence: true #TODO: Validates numeracy + validates :reading_id, presence: true end \ No newline at end of file diff --git a/app/views/mezuro_ranges/_form.html.erb b/app/views/mezuro_ranges/_form.html.erb index fc7b3f9..5f6dc00 100644 --- a/app/views/mezuro_ranges/_form.html.erb +++ b/app/views/mezuro_ranges/_form.html.erb @@ -14,6 +14,18 @@ <%= f.label :comments, class: 'control-label' %>
<%= f.text_area :comments, class: 'form-control' %> + + <% if @reading_group.readings.size == 0 %> + <%= render partial: 'no_readings' %> + <% else %> +
+ <%= f.label :reading_id, 'Reading', class: 'control-label' %> + <%= f.select( :reading_id, readings_options(@reading_group), {class: 'form-control'} ) %> +

+ <% end %> + + + <%= f.submit 'Save', class: 'btn btn-primary' %> diff --git a/app/views/mezuro_ranges/_no_readings.html.erb b/app/views/mezuro_ranges/_no_readings.html.erb index ba3fda6..0e3d203 100644 --- a/app/views/mezuro_ranges/_no_readings.html.erb +++ b/app/views/mezuro_ranges/_no_readings.html.erb @@ -1,4 +1,23 @@ - - <% col_number = reading_groups_owner?(@reading_group.id) ? 5 : 3 %> - There are no readings yet! - +
+ +

There is not reading yet!

+

+ You need to create reading in your associeated reading group before create a range +

+

+ <% if reading_groups_owner? @reading_group.id %> + + <%= link_to 'Create New Reading', new_reading_group_reading_path(@reading_group,), class: 'btn btn-danger' %> + + <% else %> + +

+
+ +

You are not allowed to do this operation, your reading belongs to another person.

+
+ + <% end %> +

+ + \ No newline at end of file diff --git a/app/views/mezuro_ranges/_reading.html.erb b/app/views/mezuro_ranges/_reading.html.erb deleted file mode 100644 index 9bb9963..0000000 --- a/app/views/mezuro_ranges/_reading.html.erb +++ /dev/null @@ -1,5 +0,0 @@ - - <%= reading.label %> - <%= reading.grade %> -   - \ No newline at end of file diff --git a/app/views/mezuro_ranges/new.html.erb b/app/views/mezuro_ranges/new.html.erb index 4188389..5a8f9b5 100644 --- a/app/views/mezuro_ranges/new.html.erb +++ b/app/views/mezuro_ranges/new.html.erb @@ -4,22 +4,4 @@ @mezuro_range.metric_configuration_id)) do |f| %> <%= render partial: 'form', locals: {f: f} %> <% end %> - - - - - - - - - - - - <% if @reading_group.readings.size == 0 %> - <%= render partial: 'no_readings' %> - <% else %> - <%= render partial: 'reading', collection: @reading_group.readings, as: :reading %> - <% end %> - - -
LabelGradeColor
+<%= raise mezuro_range.inspect %> -- libgit2 0.21.2