Browse files

analyze controller and comment cleanup

  • Loading branch information...
1 parent 12fb709 commit 6d20ca44f5f807d9a8b06cc68dce9e6b91bbb182 @jywarren committed Nov 27, 2012
View
10 webserver/app/controllers/analyze_controller.rb
@@ -0,0 +1,10 @@
+class AnalyzeController < ApplicationController
+
+ def spectrum
+ @spectrum = Spectrum.find(params[:id])
+ @spectrums = Spectrum.find(:all, :limit => 4, :order => "created_at DESC", :conditions => ["id != ?",@spectrum.id])
+ @comment = Comment.new
+ render :layout => "bootstrap"
+ end
+
+end
View
7 webserver/app/controllers/spectrums_controller.rb
@@ -62,13 +62,6 @@ def show
end
end
- def analyze
- @spectrum = Spectrum.find(params[:id])
- @spectrums = Spectrum.find(:all, :limit => 4, :order => "created_at DESC", :conditions => ["id != ?",@spectrum.id])
- @comment = Comment.new
- render :layout => "bootstrap"
- end
-
# non REST
def embed
@spectrum = Spectrum.find(params[:id])
View
2 webserver/app/helpers/analyze_helper.rb
@@ -0,0 +1,2 @@
+module AnalyzeHelper
+end
View
27 webserver/app/views/analyze/_calibrate.html.erb
@@ -0,0 +1,27 @@
+<div class="modal hide fade" id="calibratemodal1">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+ <b>Use a fluorescent bulb spectrum to calibrate your spectrometer</b>
+ </div>
+ <div class="modal-body">
+ <p>You'll need a clear fluorescent spectrum like the one shown here. First, click on the highest peak of the middle blue band:</p>
+ <p style="text-align:center;"><img class="img-rounded" src="/images/calibrate-blue.png"></p>
+ </div>
+ <div class="modal-footer">
+ <a data-dismiss="modal" class="btn" href="javascript:void();">Cancel</a>
+ <a data-dismiss="modal" class="btn btn-primary" href="#calibrationmodal2" onClick="$('#graph').bind('plotclick', function (event, pos, item) { $('#graph').unbind('plotclick');$W.second_calibration(pos.x,435.833);$('#calibratemodal2').modal('show'); })">Begin</a></p>
+ </div>
+</div>
+<div class="modal hide fade" id="calibratemodal2">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+ <b>Complete your calibration</b>
+ </div>
+ <div class="modal-body">
+ <p>Now, click at the peak of the green band as shown here: </p>
+ <p style="text-align:center;"><img class="img-rounded" src="/images/calibrate-green.png"></p>
+ </div>
+ <div class="modal-footer">
+ <a data-dismiss="modal" class="btn btn-primary" href="javascript:void();">Finish</a></p>
+ </div>
+</div>
View
14 webserver/app/views/analyze/_embed.html.erb
@@ -0,0 +1,14 @@
+<div class="modal hide fade" id="embedmodal">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+ <b>Embed this spectrum on your website</b>
+ </div>
+ <div class="modal-body">
+ <p>Copy this code onto your blog to share your spectral data:</p>
+ <textarea id="embedcode" cols="50" rows="4"><iframe width='500px' height='400px' border='0' src='http://spectralworkbench.org/spectra/embed/<%= @spectrum.id %>'></iframe></textarea>
+ <p><a class="btn" href="javascript:void();" id="embed">Custom size</a></p>
+ </div>
+ <div class="modal-footer">
+ <a data-dismiss="modal" href="#" class="btn">Close</a>
+ </div>
+</div>
View
120 webserver/app/views/analyze/spectrum.html.erb
@@ -0,0 +1,120 @@
+<script src="/javascripts/show.js"> </script>
+<script src="/javascripts/analyze.js"> </script>
+<script language="javascript" type="text/javascript" src="/javascripts/flot/jquery.flot.js"></script>
+<script language="javascript" type="text/javascript" src="/javascripts/flot/jquery.flot.crosshair.js"></script>
+
+<div class="container-fluid" style="clear:both;">
+ <div class="row-fluid" id="display">
+
+ <img style="width:95%;height:100px;padding:0 1% 0 4%;background:black;" id="image" src="<%= @spectrum.photo.url(:original) %>" />
+ <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 data-toggle="modal" href="#calibratemodal1" class="btn btn-primary"><i class="icon icon-white icon-screenshot"></i><span class="hidden-phone"> Calibrate</span></a>
+ <%= render :partial => "calibrate" %>
+
+ <a href="#embedmodal" class="btn btn-inverse" data-toggle="modal"><i class="icon icon-white icon-share"></i><span class="hidden-phone"> Embed</span></a>
+ <%= render :partial => "embed" %>
+ <a class="btn btn-inverse" href="javascript:void(0);" onClick="window.location = '/sets/add/'+prompt('Add to which set? (enter an id)')+'?spectrum_id=<%= @spectrum.id %>'"><i class="icon icon-white icon-plus-sign"></i><span class="hidden-phone"> Add to set</span></a>
+ <a class="btn btn-inverse"><i class="icon icon-white icon-align-left"></i><span class="hidden-phone"> Compare</span></a>
+
+ <a rel="popover" data-placement="left" class="pull-right btn btn-inverse" data-content='<ul class="nav nav-list"><li><a onClick="$W.units()">Toggle units</a></li><li><a onClick="$W.toggle_mode()">Toggle RGB</a></li><li><a onClick="$W.extract()"><i class="icon icon-refresh"></i> Re-extract from photo</a></li><li><a onClick="$W.set_sample_row()">Set sample row</a></li></ul>'><i class="icon icon-white icon-briefcase"></i><span class="hidden-phone"> More tools</span></a>
+
+ <form class="hidden-phone navbar-form pull-right" style="margin:0 10px;">
+ <input type="text" class="input-small search-query" data-provide="typeahead">
+ <button type="submit" class="btn btn-inverse"><i class="icon-search icon-white"></i></button>
+ </form>
+ <a style="margin-right:4px;" class="pull-right hidden-desktop btn btn-inverse"><i class="icon icon-white icon-search"></i></a></span>
+
+ </div>
+ </div>
+
+ </div>
+ <div class="row-fluid">
+ <div class="span3">
+ <h3><%= @spectrum.title %></h3>
+ <p><small>uploaded by <a href="/profile/<%= @spectrum.author %>"><%= @spectrum.author %></a></small> <a class="btn btn-mini" href="/spectra/feed/<%= @spectrum.author %>">RSS</a></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 %>
+ <p><%= @spectrum.notes %></p>
+ <% if logged_in? && current_user.login == @spectrum.author %>
+ <div class="btn-group">
+ <a class="btn btn-small btn-link" href="/spectrums/<%= @spectrum.id %>/edit"><i class="icon icon-pencil"></i> Edit</a>
+ <%= link_to '<i class="icon icon-remove-sign"></i> Delete', "/spectrums/destroy/"+@spectrum.id.to_s, :confirm => 'Are you sure?', :class => "btn btn-small btn-link" %>
+ </div>
+ <% end %>
+ <br />
+ <div class="btn-group">
+ <a class="btn btn-small" href="/spectra/show/<%= @spectrum.id %>.json"><b>JSON</b></a>
+ <a class="btn btn-small" href="/spectra/show/<%= @spectrum.id %>.csv"><b>CSV</b></a>
+ <a class="btn btn-small" href="/spectra/show/<%= @spectrum.id %>.xml"><b>XML</b></a>
+ <a rel="tooltip" class="btn btn-small" href="http://publiclaboratory.org/wiki/spectral-workbench-exporting" title="About export formats"><i class="icon icon-question-sign"></i></a>
+ </div>
+
+ <hr />
+
+ <div id="share">
+ <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>
+ <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
+ </div>
+ </div>
+
+ <div class="span9">
+ <a name="comments"></a>
+ <h3>Comments (<%= @spectrum.comments.length %>)</h3>
+
+ <% if @spectrum.comments.length == 0 %><p><i>No comments</i></p><% end %>
+
+ <% @spectrum.comments.each do |comment| %>
+ <div class="comment">
+ <a name="comment_<%= comment.id %>"></a>
+ <b><%= time_ago_in_words(comment.created_at) %> ago,
+ <% if User.find_by_login(comment.author) %><a href="/spectra/author/<%= comment.author %>"><%= comment.author %></a> wrote:</b>
+ <% else %><%=h comment.author %> wrote:</b>
+ <% end %>
+ <p><%=h comment.body %></p>
+ <% if logged_in? && current_user.role == "admin" %><p><a href="/comments/delete/<%= comment.id %>">Delete</a></p><% end %>
+ </div>
+ <% end %>
+
+ <br />
+ <form action="/spectra/comment/<%= @spectrum.id %>" class="well form" id="new_comment" method="post">
+
+ <h3 style="margin-top:0;">Post a comment</h3>
+ <textarea id="body" cols="8" rows="6"></textarea>
+
+ <% if !logged_in? %>
+ <div class="control-group">
+ <input id="email" type="text" placeholder="you@email.com"><br />
+ <input id="author" type="text" placeholder="Your name"><br />
+ </div>
+ <% end %>
+
+ <% if !logged_in? && !APP_CONFIG["local"] %><p><%= recaptcha_tags :display => {:theme => "white"} %></p><% end %>
+
+ <input type='hidden' name='authenticity_token' value="<%= form_authenticity_token %>"/>
+ <input class="btn btn-primary" type="submit" value="Post" />
+
+ </form>
+
+ </div>
+ </div>
+ </div>
+
+</div>
+<script type="text/javascript">
+
+(function () {
+
+ $W.initialize({
+ spectrum_id:<%= @spectrum.id %>,
+ title: "<%= @spectrum.title.gsub('"',"'") %>",
+ form_authenticity_token: "<%= form_authenticity_token %>",
+ spectrum_data: <%= @spectrum.data.gsub('"',"'") %>
+ })
+
+})()
+
+</script>
+
View
2 webserver/config/routes.rb
@@ -41,6 +41,8 @@
map.connect 'spectra/:action/:id', :controller => "spectrums"
map.connect 'spectra/:action/:id.:format', :controller => "spectrums"
+ map.connect 'analyze/:action/:id', :controller => "analyze"
+
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
View
53 webserver/public/javascripts/show.js
@@ -21,16 +21,7 @@ $W = {
var url = "/spectrums/compare/"+$W.spectrum_id+"?q="+$("#searchinput").val()
$("#result").html(ajax_load).load(url)
});
- $('#units').click(function() {
- if (flotoptions.xaxis.tickFormatter == wavenumbers) {
- flotoptions.xaxis.tickFormatter = nanometers
- flotoptions.xaxis.tickSize = 100
- } else {
- flotoptions.xaxis.tickFormatter = wavenumbers
- flotoptions.xaxis.tickSize = wavenumber_tickSize
- }
- $.plot($("#graph"),this.data,flotoptions);
- })
+ $('#units').click($W.units)
$('#createSet').click(function() {
var f = document.createElement('form');
f.style.display = 'none';
@@ -44,19 +35,7 @@ $W = {
f.action = "/sets/new/"+spectra.join(',')
f.submit();
})
- $('#extract').click(function() {
- var f = document.createElement('form');
- f.style.display = 'none';
- $('#graph').append(f);
- f.id = "extractform"
- var i = document.createElement('input');
- i.name = "authenticity_token"
- i.value = $W.form_authenticity_token
- $('#extractform').append(i);
- f.method = 'POST';
- f.action = "/spectrums/extract/"+$W.spectrum_id
- f.submit();
- })
+ $('#extract').click($W.extract)
$('#clone').click(function() {
// use uniq_id as a CSS class, only show those from the same device
$('.cloneCalibration').show()
@@ -263,7 +242,33 @@ $W = {
})
return (left_redness > right_redness)
},
-
+ units: function() {
+ if (flotoptions.xaxis.tickFormatter == wavenumbers) {
+ flotoptions.xaxis.tickFormatter = nanometers
+ flotoptions.xaxis.tickSize = 100
+ } else {
+ flotoptions.xaxis.tickFormatter = wavenumbers
+ flotoptions.xaxis.tickSize = wavenumber_tickSize
+ }
+ $.plot($("#graph"),this.data,flotoptions);
+ },
+ extract: function() {
+ var f = document.createElement('form');
+ f.style.display = 'none';
+ $('#graph').append(f);
+ f.id = "extractform"
+ var i = document.createElement('input');
+ i.name = "authenticity_token"
+ i.value = $W.form_authenticity_token
+ $('#extractform').append(i);
+ f.method = 'POST';
+ f.action = "/spectrums/extract/"+$W.spectrum_id
+ f.submit();
+ },
+ set_sample_row: function() {
+ var rownum = prompt('Enter the pixel row you would like to extract a spectrum from, where row 0 is the top edge of the original image.','100')
+ if (rownum) window.location = '/spectrums/setsamplerow/'+$W.spectrum_id+'?row='+rownum
+ }
}
View
8 webserver/test/functional/analyze_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class AnalyzeControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
View
4 webserver/test/unit/helpers/analyze_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class AnalyzeHelperTest < ActionView::TestCase
+end

0 comments on commit 6d20ca4

Please sign in to comment.