publiclab/spectral-workbench

View on GitHub
app/views/spectrums/_sets.html.erb

Summary

Maintainability
Test Coverage
<% row = 1 if row.nil? %>
<div id="sets" class="row-fluid">

<% @sets.each_with_index do |set,index| %>
<div class="span<%= 12/row %>">
    <a class="graph_set" id="graph_set_<%= set.id %>" style="height:100px;width:250px;display:block;"></a>
    <div class="text">
      <h3><a href="/sets/show/<%= set.id %>"><%= set.title.truncate(30) %></a></h3>
      <p><a href="<%= user_path(set.user.login) %>"><%= set.author %></a> | <%= set.spectrums.length %> spectra |
        <a href="/sets/show/<%= set.id %>#comments"><i class="fa fa-comment"></i> <%= set.comments.length %></a>
      </p>
      <% if !set.notes.blank? %>
      <p class="notes"><%= set.notes.truncate(200) %></p>
      <% end %>
    </div>

<script type="text/javascript">
  (function(){
  data_set_<%= set.id %> = []

  <% set.spectrums.each do |spectrum| %>
  <% if spectrum.data == "" || spectrum.data.nil? %>
    spectrum = <%=raw spectrum.extract_data %>
  <% else %>
    spectrum = <%=raw spectrum.data.chomp(",") %>
  <% end %>
    data_set_<%= set.id %>.push({data:[]})
    scaled = true
    $.each(spectrum.lines,function(index,line) {
      if (line.wavelength == null) {
        line.wavelength = index
        scaled = false
      }
      data_set_<%= set.id %>[data_set_<%= set.id %>.length-1].data.push([line.wavelength,line.average/2.55])
    })
  <% end %>
  $.plot($("#graph_set_<%= set.id %>"),data_set_<%= set.id %>,flotoptions_minimal);
  })()
</script>

</div>
<% if ((index+1.00)/row).to_i == ((index+1.00)/row) %>
</div>
<hr />
<div class="row-fluid">
<% end %>
<% end %>
</div>