publiclab/spectral-workbench

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

Summary

Maintainability
Test Coverage
<%= render :partial => "spectrums/show/clone" %>
<%= render :partial => "spectrums/show/set" %>
<%= render :partial => "spectrums/show/macros" %>
<%= render :partial => "spectrums/show/calibrate" %>
<%= render :partial => "spectrums/show/select_row" %>
<%= render :partial => "spectrums/show/compare" %>

<div class="container-fluid" style="clear:both;">

  <% if logged_in? %>
    <% if @spectrum.author == current_user.login %>
      <% if @spectrum.has_operations %>
        <div class="alert alert-warning">
          This spectrum has been edited in the new Spectral Workbench 2.0 interface. <a href="/spectrums/show2/<%= @spectrum.id %>">Continue working with it there</a> or you may encounter compatibility issues.
        </div>
      <% end %>
      <% if !@spectrum.calibrated %>
        <div class="alert alert-warning"><button type="button" class="close" data-dismiss="alert">×</button>
          This spectrum is not yet calibrated. <a class="btn btn-primary btn-small" data-toggle="modal" href="#calibratemodal1" onClick="$('calibrate-begin').focus()">Calibrate</a>
          <a class="btn btn-small" href="http://publiclab.org/wiki/spectral-workbench-calibration">Learn more</a>
        </div>
      <% elsif @spectrum.tags.length == 0 %>
        <div class="alert"><button type="button" class="close" data-dismiss="alert">×</button>
          This spectrum is not tagged. <a onClick="$('#tagform .input-prepend').addClass('control-group info');$('#taginput').css('background','#eff')" href="#tags">Add descriptive tags</a> to help categorize your data and build a comprehensive open source library of spectra.
        </div>
      <% end %>
    <% end %>
  <% end %>

  <% if mobile? && !@spectrum.calibrated %>
    <div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>
      <i class="fa fa-exclamation-circle"></i> Calibration is easiest <b>from a computer</b>, after which you can use it from your phone.
    </div>
  <% end %>

  <div class="row-fluid" id="display">

    <a id="imagelink" rel="tooltip" title="Click to expand vertically." href="javascript:void();" onClick="$('#image').css('height','300px');$('#imagelink').tooltip('destroy')"><img style="width:95%;height:100px;padding:0 1% 0 4%;background:black;" id="image" src="<%= @spectrum.photo.url(:original) %>?<%= DateTime.now.to_i %>" /></a>
    <div id="graph" style="width:98%;height:200px;"></div>

    <div class="navbar navbar-inverse navbar-static-bottom" style="margin:0;">
      <div class="navbar-inner">
        <a id="$('#calibrate-begin').focus()" data-toggle="modal" href="#calibratemodal1" class="btn btn-primary"><i class="fa fa-white fa-crosshairs"></i><span class="hidden-phone"> Calibrate</span></a>

        <a href="#embed-modal" class="btn btn-inverse hidden-phone" data-toggle="modal"><i class="fa fa-white fa-share"></i><span class="hidden-phone"> Embed</span></a>
        <%= render partial: "embed/modal", locals: { datum: @spectrum, type: :spectrum } %>
        <a class="btn btn-inverse" data-toggle="modal" href="#setmodal"><i class="fa fa-white fa-plus-circle"></i><span class="hidden-phone"> Add to set</span></a>
        <a class="btn btn-inverse hidden-phone" id="createSet" href="javascript:void(0);"><i class="fa fa-white fa-list"></i><span class="hidden-phone"> Save as set</span></a>
        <a data-toggle="modal" class="btn btn-inverse" href="#comparemodal"><i class="fa fa-white fa-align-left"></i><span class="hidden-phone"> Compare</span></a>
        <a class="btn btn-inverse" href="/match/search/<%= @spectrum.id %>">Find similar</a>
        <% if logged_in? && current_user.id == 1 && @spectrum.calibrated %><a href="/key/<%= @spectrum.id %>" class="btn btn-inverse">Make key</a><% end %>
        <a href="/spectrums/show2/<%= @spectrum.id %>" class="btn btn-inverse">Preview 2.0 beta</a>

        <%= render :partial => "spectrums/show/tools" %>
        <b class="pull-right" style="padding-top:10px;margin-right:10px;color:#ffffff;"><span id="wavelength"></span> <span id="#unit_label">nm</span></b>

      </div>
    </div>

  </div>
  <div class="row-fluid">
    <div class="span4">
      <h3 style="margin-bottom:0px;"><%= @spectrum.title %></h3>
      <p>uploaded by <a href="<%= user_path(@spectrum.author) %>"><%= @spectrum.author %></a> | <%= @spectrum.created_at.to_s(:long) %></p>
      <% if @spectrum.lat != 0 && @spectrum.lon != 0 %><p>Collected at: Lat: <%= @spectrum.lat %>, Lon: <%= @spectrum.lon %> (<a href="http://www.openstreetmap.org/?lat=<%= @spectrum.lat %>&lon=<%= @spectrum.lon %>&zoom=10&layers=M">View in OpenStreetMap</a>)</p><% end %>

      <%= render :partial => "tags/tagging", locals: { datum: @spectrum, type: @spectrum.class.name.downcase, legacy: true } %>

      <div class="btn-group hidden-phone">
        <hr />
        <a class="btn btn-small" href="/spectrums/latest/<%= @spectrum.id %>.json"><b>JSON</b></a>
        <a class="btn btn-small" href="/spectrums/latest/<%= @spectrum.id %>.csv"><b>CSV</b></a>
        <a class="btn btn-small" href="/spectrums/latest/<%= @spectrum.id %>.xml"><b>XML</b></a>
        <a rel="tooltip" class="btn btn-small" href="http://publiclab.org/wiki/spectral-workbench-exporting" title="About export formats"><i class="fa fa-question-circle"></i></a>
      </div>

      <div class="hidden-phone">

        <hr />

        <% if @spectrum.reversed %><p><small>This spectrum was reversed from its original orientation at the time of capture. <a href="http://publiclab.org/wiki/spectral-workbench-calibration#Reversed+spectra">Read more &raquo;</a></small></p><% end %>
        <p rel="tooltip" title="The pixel row from the captured image used to sample data from."><b>Sample row:</b> <%= @spectrum.sample_row %></p>
        <p rel="tooltip" title="The pixel row from the webcam used to sample data from."><b>Video row:</b> <%= @spectrum.video_row %></p>

      </div>

      <div xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
        <p><a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/"><img src="http://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" /></a></p>
        <p class="hidden-phone"><small>
        To the extent possible under law,
        <%# if @spectrum.author.url %><a rel="dct:publisher" href="http://publiclab.org"><%# end %>
        <span property="dct:title"><%= @spectrum.author %></span><%# if @spectrum.author.url %></a><%# end %>
        has waived all copyright and related or neighboring rights to
        "<span property="dct:title"><%= @spectrum.title %></span>".
        </small></p>
      </div>

      <hr />

      <h4>Sets with this spectrum</h4>
      <%= render :partial => "spectrums/sets" %>
      <hr />
    </div>

    <div class="span8">
      <% if logged_in? && current_user.login == @spectrum.author %>
        <div class="btn-group pull-right" style="margin-top:10px;margin-left:10px;">
          <a class="btn btn-small" href="/spectrums/<%= @spectrum.id %>/edit"><i class="fa fa-pencil"></i> Edit</a>
          <%= link_to '<i class="fa fa-trash"></i> Delete'.html_safe, "/spectrums/destroy/"+@spectrum.id.to_s, :confirm => 'Are you sure?', :class => "btn btn-small" %>
        </div>
      <% end %>

        <div style="margin-top:10px;margin-left:10px;" class="pull-right btn-group">
          <%= render partial: "likes/buttons", locals: { datum: @spectrum } %>
        </div>

        <div id="share" class="pull-right" style="margin-top:14px;">
          <div class="fb-like" data-send="false" data-layout="button_count" data-width="50" data-show-faces="false" style="vertical-align:top;zoom:1;*display:inline"></div>
          <a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
        </div>
       
        <h3>Notes</h3>
       
        <% if @spectrum.has_powertag('calibration') %>
          <p>This spectrum used the calibration from <a href="/spectrums/<%= @spectrum.powertag('calibration') %>"><%= @spectrum.calibration.title %></a>.</p>
        <% end %>
       
        <p><% if @spectrum.notes %><%=raw RDiscount.new(@spectrum.notes).to_html %><% end %></p>
       
        <a name="comments"></a>
        <h3>Comments (<%= @spectrum.comments.length %>)</h3>
       
        <div class="row-fluid">
       
          <div class="span8">
            <%= render partial: 'comments/list', locals: { datum: @spectrum, comments: @spectrum.comments } %>
          </div>
       
        </div>

      </div>
    </div>
  </div>

</div>
<script type="text/javascript">

jQuery(document).ready(function() {
  $W.initialize({
    spectrum_id:<%= @spectrum.id %>,
    sample_row:<%= @spectrum.sample_row %>, // this is not the same as capture row!
    calibrated:<%= @spectrum.calibrated == true %>,
    interface:"analyze",
    mode:"combined",
    title: "<%= @spectrum.title.gsub('"',"'") %>",
    form_authenticity_token: "<%= form_authenticity_token %>",
    spectrum_data: <%=raw Spectrum.find(@spectrum.id).data.gsub('"',"'") %>
  })
})

</script>