Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

revamped sets page, much nicer, see for example: http://bit.ly/WkBCFN

  • Loading branch information...
commit 896266bf144e3a6f75ab878353606f1f3a092394 1 parent 26b75ed
@jywarren authored
View
11 webserver/app/controllers/sessions_controller.rb
@@ -17,6 +17,17 @@ def destroy
redirect_back_or_default('/')
end
+ # only on local installations, to bypass OpenID; add "local: true" to config/config.yml
+ def local
+ if APP_CONFIG["local"] == true && @user = User.find_by_login(params[:login])
+ self.current_user = @user
+ successful_login
+ else
+ flash[:error] = "Forbidden"
+ redirect_to "/"
+ end
+ end
+
protected
def successful_login
View
3  webserver/app/controllers/sets_controller.rb
@@ -10,6 +10,7 @@ def show
@set = SpectraSet.find params[:id]
@spectrums = Spectrum.find(:all, :limit => 4, :order => "created_at DESC")
@comment = Comment.new
+ render :template => "sets/show-bootstrap", :layout => "bootstrap"
end
def find_match
@@ -88,7 +89,7 @@ def comment
:email => params[:comment][:email]})
@comment.author = current_user.login if logged_in?
@comment.email = current_user.email if logged_in?
- if (logged_in? || verify_recaptcha(:model => @comment, :message => "ReCAPTCHA thinks you're not a human!")) && @comment.save
+ if (logged_in? || APP_CONFIG['local'] || verify_recaptcha(:model => @comment, :message => "ReCAPTCHA thinks you're not a human!")) && @comment.save
flash[:notice] = "Comment saved."
redirect_to "/sets/show/"+params[:id]+"#comment_"+@comment.id.to_s
else
View
2  webserver/app/controllers/spectrums_controller.rb
@@ -20,7 +20,7 @@ def index
respond_to do |format|
format.html {
- render :template => "spectrums/index-bootstrap.html.erb", :layout => "bootstrap"
+ render :template => "spectrums/index.html.erb", :layout => "bootstrap"
} # show.html.erb
format.xml { render :xml => @spectrums }
end
View
14 webserver/app/views/sets/_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 set 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='200px' border='0' src='http://spectralworkbench.org/sets/embed/<%= @set.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
9 webserver/app/views/sets/_spectra.html.erb
@@ -1,7 +1,10 @@
<% @set.spectra.each do |spectrum| %>
-<div id="spectrum_<%= spectrum.id %>" class="spectrum comparison">
-<a href="/spectra/show/<%= spectrum.id %>"><img width="100px" src="<%= spectrum.photo.url(:thumb) %>" /></a>
-<p><b><a href="/spectra/show/<%= spectrum.id %>"><%= spectrum.title %></a></b> | <%= spectrum.created_at.to_s(:short) %></p>
+<div id="spectrum_<%= spectrum.id %>">
+<a href="/analyze/spectrum/<%= spectrum.id %>"><img style="height:50px;width:100%" class="img" src="<%= spectrum.photo.url(:thumb) %>" /></a>
+<p>
+ <b><a href="/analyze/spectrum/<%= spectrum.id %>"><%= spectrum.title %></a></b>
+ <br />
+ by <a href="/profile/<%= spectrum.author %>"><%= spectrum.author %></a>, <%= spectrum.created_at.to_s(:short) %>
</p>
</div>
<% end %>
View
11 webserver/app/views/sets/index-bootstrap.html.erb
@@ -0,0 +1,11 @@
+<div id="index">
+
+<%= render :partial => "spectrums/sidebar" %>
+
+<div id="maincolumn">
+
+<h2>// RECENT SETS</h2>
+<%= render :partial => 'spectrums/sets' %>
+
+</div>
+</div>
View
195 webserver/app/views/sets/show-bootstrap.html.erb
@@ -0,0 +1,195 @@
+<script src="/javascripts/analyze.js"> </script>
+
+<div class="container-fluid" style="clear:both;">
+
+ <ul class="breadcrumb">
+ <li><a href="/">Home</a> <span class="divider">/</span></li>
+ <li><a href="/sets/">Sets</a></li>
+ </ul>
+
+ <div class="row-fluid" id="display">
+
+ <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 href="#embedmodal" class="btn btn-inverse hidden-phone" 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="/capture/match/<%= @set.id %>">Match to this set</a>
+
+ <b class="pull-right" style="padding-top:10px;margin-right:10px;"><span id="wavelength"></span> <span id="#unit_label">nm</span></b>
+
+ </div>
+ </div>
+
+ </div>
+
+ <div class="row-fluid">
+ <div class="span3">
+ <h3 style="margin-bottom:0px;"><%= @set.title %></h3>
+ <p>uploaded by <a href="/profile/<%= @set.author %>"><%= @set.author %></a></p>
+
+ <hr />
+ <h4>Spectra in this set</h4>
+ <%= render :partial => "spectra" %>
+ <hr />
+
+ <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 @set.author.url %><a rel="dct:publisher" href="http://publiclaboratory.org"><%# end %>
+ <span property="dct:title"><%= @set.author %></span><%# if @set.author.url %></a><%# end %>
+ has waived all copyright and related or neighboring rights to
+ "<span property="dct:title"><%= @set.title %></span>".
+ </small></p>
+ </div>
+ </div>
+
+ <div class="span9">
+ <% if logged_in? && current_user.login == @set.author %>
+ <div class="btn-group pull-right" style="margin-top:10px;">
+ <a class="btn btn-small" href="/set/<%= @set.id %>/edit"><i class="icon icon-pencil"></i> Edit</a>
+ <%= link_to '<i class="icon icon-remove-sign"></i> Delete', "/set/destroy/"+@set.id.to_s, :confirm => 'Are you sure?', :class => "btn btn-small" %>
+ </div>
+ <% end %>
+
+ <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>
+ <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>
+
+ <h3>Notes</h3>
+
+ <p><%= @set.notes %></p>
+
+ <a name="comments"></a>
+ <h3>Comments (<%= @set.comments.length %>)</h3>
+
+ <% if @set.comments.length == 0 %><p><i>No comments</i></p><% end %>
+
+ <% @set.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="/sets/comment/<%= @set.id %>" class="well form" id="new_comment" method="post">
+
+ <h3 style="margin-top:0;">Post a comment</h3>
+ <textarea name="comment[body]" id="body" cols="8" rows="6"></textarea>
+
+ <% if !logged_in? %>
+ <div class="control-group">
+ <input name="comment[email]" id="email" type="text" placeholder="you@email.com"><br />
+ <input name="comment[author]" id="author" type="text" placeholder="Your name"><br />
+ </div>
+ <% end %>
+ <% if !logged_in? && !APP_CONFIG["local"] %><p><%= recaptcha_tags :display => {:theme => "white"} %></p><% end %>
+
+ <br />
+ <input type='hidden' name='authenticity_token' value="<%= form_authenticity_token %>"/>
+ <input type='hidden' name='goto' value="analyze"/>
+ <input class="btn btn-primary" type="submit" value="Post" />
+
+ </form>
+
+ </div>
+ </div>
+ </div>
+
+</div>
+<script type="text/javascript">
+
+(function () {
+
+$W = {
+ updateLegend: function() {
+ $W.updateLegendTimeout = null;
+
+ var pos = $W.latestPosition;
+
+ var axes = $W.plot.getAxes();
+ if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max ||
+ pos.y < axes.yaxis.min || pos.y > axes.yaxis.max)
+ return;
+
+ var i, j, dataset = $W.plot.getData();
+ for (i = 0; i < dataset.length; ++i) {
+ var series = dataset[i];
+
+ // find the nearest points, x-wise
+ for (j = 0; j < series.data.length; ++j)
+ if (series.data[j][0] > pos.x)
+ break;
+
+ // now interpolate
+ var y, p1 = series.data[j - 1], p2 = series.data[j];
+ if (p1 == null)
+ y = p2[1];
+ else if (p2 == null)
+ y = p1[1];
+ else
+ y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);
+
+ $('#wavelength').html(parseInt(pos.x))
+ legends.eq(i).html(series.label.replace(/=.*%/, "= " + parseInt(y) + "%"));
+ }
+ }
+}
+
+$("#graph").bind("plothover", function (event, pos, item) {
+ $W.latestPosition = pos;
+ if (!$W.updateLegendTimeout)
+ $W.updateLegendTimeout = setTimeout($W.updateLegend, 50);
+});
+
+data = []
+<% @set.spectra.each do |spectrum| %>
+<% if spectrum.data == "" || spectrum.data.nil? %>
+ spectrum = <%= spectrum.extract_data %>
+<% else %>
+ spectrum = <%= spectrum.data.chomp(",") %>
+<% end %>
+ data.push({label: "<%= spectrum.title %> = 0% ",data:[]})
+ scaled = true
+ $.each(spectrum.lines,function(index,line) {
+ if (line.wavelength == null) {
+line.wavelength = index
+scaled = false
+ }
+ data[data.length-1].data.push([line.wavelength,line.average/(2.55)])
+ })
+<% end %>
+flotoptions.xaxis.show = scaled
+$W.plot = $.plot($("#graph"),data,flotoptions);
+ $('#embedcode').click(function() {
+ this.focus()
+ this.select()
+ })
+ $('#embed').click(function() {
+ var size = prompt("What size, in WIDTHxHEIGHT?","500x150")
+ var width = size.split('x')[0]
+ var height = size.split('x')[1]
+ $('#embedcode').val("<iframe width='"+width+"px' height='"+height+"px' border='0' src='http://spectralworkbench.org/sets/embed/<%= @set.id %>?width="+width+"&height="+height+"'></iframe>")
+ $('#embedcode').focus()
+ $('#embedcode').select()
+ })
+})()
+
+$('#wavenumber').click(function() {
+ flotoptions.xaxis.tickFormatter = wavenumbers
+ flotoptions.xaxis.tickSize = wavenumber_tickSize
+ $W.plot($("#graph"),data,flotoptions);
+})
+
+</script>
View
72 webserver/app/views/spectrums/index-bootstrap.html.erb
@@ -1,72 +0,0 @@
-<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">
- <iframe class="span4" height="240px;" src="http://www.youtube.com/embed/idg10MiceEI" frameborder="0" allowfullscreen></iframe>
- <div class="span8">
- <div class="jumbotron">
- <h2>DIY material analysis</h2>
- <p class="lead">Use a homemade spectrometer to scan different materials, and contribute to an open source database.</p>
- <a class="btn btn-large btn-success" href="http://publiclaboratory.org/tool/spectrometer"><i class="icon icon-wrench icon-white hidden-phone"></i> Build one</a>
- <a class="btn btn-large btn-primary" href="http://shop.breadpig.com/products/desktop-spectrometry-kit"><i class="icon icon-shopping-cart icon-white"></i> Preorder<span class="hidden-phone"> one </span> &raquo;</a>
- <a class="btn btn-large" href="http://publiclaboratory.org/tool/spectrometer"><i class="icon icon-book hidden-phone"></i> Learn<span class="hidden-phone"> more</span></a>
- </div>
- </div>
- </div>
-
- <hr />
-
- <div id="spectra" class="row-fluid">
-
- <div class="span4">
-
- <%= render :partial => "search" %>
-
- <h3>Recent authors</h3>
- <ul class="nav">
- <% User.find_all_by_login(@spectrums.collect(&:author).uniq).each do |user| %>
- <li><a href="/profile/<%= user.login %>"><i class="icon icon-user"></i> <%= user.login %></a></li>
- <% end %>
- </ul>
-
- <hr />
- <h3>Recent sets</h3>
- <%= render :partial => 'sets' %>
-
- <hr />
- </div>
-
- <style>._row { clear:left;} </style>
-
- <div class="span8">
- <h2>Recently uploaded spectra <small class="hidden-phone">by contributors like you</small></h2>
-
- <div class="_row">
- <% @spectrums.each_with_index do |spectrum,i| %>
- <div class="span3 clearfix">
- <a class="image" href="/spectra/show/<%= spectrum.id %>"><img src="<%= spectrum.photo.url(:thumb) %>" class="image" style="background:#ccc;"></a>
- <h4><a data-transition="slide" href="/spectra/show/<%= spectrum.id %>"><%=h truncate(spectrum.title,:length => 18) %></a></h4>
- <p><a data-transition="slide" href="/profile/<%=h spectrum.author %>"><%=h spectrum.author %></a> | <%= time_ago_in_words(spectrum.created_at) %> ago</p>
- </div>
- <% if ((i+1)/4.0).to_i == ((i+1)/4.0) %>
- </div>
- <hr />
- <div class="_row">
- <% end %>
- <% end %>
- </div>
- </div>
-
-</div>
-<script type="text/javascript">
-
-(function () {
-
-
-
-})()
-
-</script>
-
View
73 webserver/app/views/spectrums/index-mobile.html.erb
@@ -1,73 +0,0 @@
-<style>
-
-h1 {
- font-family: georgia;
- font-weight:normal;
-}
-.spectrum {
- clear:both;
-}
-li.spectrum {
- padding-right:8px;
-}
-li.spectrum .text {
- float:right;
- margin-right:30px;
-}
-
-</style>
-
-<div data-role="page" id="page1">
- <div data-theme="d" data-role="header">
- <a data-role="button" data-transition="fade" data-theme="b" href="/capture">Capture</a>
- <h3>
- <img src="/images/spectralworkbench.png" />
- SpectralWorkbench
- </h3>
- </div>
-
- <div data-role="content" style="padding: 15px">
-
- <p style="background:#fcc;padding:8px;" class="notice"><b>Warning: The latest Opera Mobile has a bug which breaks mobile capture. <a href="http://publiclaboratory.org/wiki/opera-mobile">Download the previous version</a>.</p>
-
- <h1>SpectralWorkbench</h1>
-
- <p><i>Affordable, DIY, open source spectral analysis from your desktop or Android phone (<a href="javascript:void();" onClick="$('#readmore').toggle()">Read more</a>)</i></p>
- <p id="readmore" style="display:none;">Spectrometry can reveal the composition of unknown materials -- either from samples you take from a site, or (with more difficulty) from a distance. It is used by NASA to identify substances on other planets. Typically, full-spectrum light (such as the sun) shines through a thin slice of the sample, which filters (absorbs) certain colors and allows others to pass through. This light can be split up by color using a prism, and the missing (absorbed) colors can be identified. Finally, the brightness of all the colors is compared to a database of known samples to find a match.</p>
-
- <p><a href="https://www.wepay.com/stores/publiclaboratory/item/hd-video-spectrometer-kit-885355"><img src="/images/cart.png" /></a> <a href="https://www.wepay.com/stores/publiclaboratory/item/hd-video-spectrometer-kit-885355">Purchase a DIY spectrometer kit &raquo;</a></p>
- <p>Or, <a href="http://publiclaboratory.org/wiki/video-spectrometer-construction">learn how to make one yourself</a> as part of an open-source research effort of the <a href="http://publiclaboratory.org">Public Laboratory</a> community.</p>
-
- <% if APP_CONFIG['local'] != "true" %>
- <div id="video" style="display:none">
- <iframe width="610" height="370" src="http://www.youtube.com/embed/_yqRZLxcecs" frameborder="0" allowfullscreen></iframe>
- </div>
- <% end %>
-
-<h3>RECENT SETS <a class="right" href="/sets/">view all &raquo;</a></h3>
-<%= render :partial => 'sets' %>
-
-<h3>RECENT SPECTRA</h3>
-
-<ul data-role="listview" data-divider-theme="" data-inset="true">
-<% @spectrums.each do |spectrum| %>
-
-<li data-theme="c" class="spectrum">
- <div class="text">
- <h3><a data-transition="slide" href="/spectra/show/<%= spectrum.id %>"><%=h truncate(spectrum.title,:length => 18) %></a></h3>
- <p><a data-transition="slide" href="/profile/<%=h spectrum.author %>"><%=h spectrum.author %></a> | <%= time_ago_in_words(spectrum.created_at) %> ago</p>
- </div>
- <a class="image" href="/spectra/show/<%= spectrum.id %>"><img width="100px;" height="100px;" src="<%= spectrum.photo.url(:thumb) %>" class="image" style="background:#ccc;"></a>
-</li>
-
-<% end %>
-</ul>
-
-<br style="clear:both;" />
-<%= will_paginate @spectrums %>
-
-</div>
-
-<%= render :partial => "layouts/footer" %>
-
-</div>
View
79 webserver/app/views/spectrums/index.html.erb 100755 → 100644
@@ -1,23 +1,72 @@
-<div id="index">
+<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>
-<%= render :partial => "sidebar" %>
+<div class="container-fluid" style="clear:both;">
+
+ <div class="row-fluid">
+ <iframe class="span4" height="240px;" src="http://www.youtube.com/embed/idg10MiceEI" frameborder="0" allowfullscreen></iframe>
+ <div class="span8">
+ <div class="jumbotron">
+ <h2>DIY material analysis</h2>
+ <p class="lead">Use a homemade spectrometer to scan different materials, and contribute to an open source database.</p>
+ <a class="btn btn-large btn-success" href="http://publiclaboratory.org/tool/spectrometer"><i class="icon icon-wrench icon-white hidden-phone"></i> Build one</a>
+ <a class="btn btn-large btn-primary" href="http://shop.breadpig.com/products/desktop-spectrometry-kit"><i class="icon icon-shopping-cart icon-white"></i> Preorder<span class="hidden-phone"> one </span> &raquo;</a>
+ <a class="btn btn-large" href="http://publiclaboratory.org/tool/spectrometer"><i class="icon icon-book hidden-phone"></i> Learn<span class="hidden-phone"> more</span></a>
+ </div>
+ </div>
+ </div>
-<div id="maincolumn">
+ <hr />
-<% if APP_CONFIG['local'] != "true" %>
-<div id="video">
-<iframe width="611" height="458" src="http://www.youtube.com/embed/idg10MiceEI" frameborder="0" allowfullscreen></iframe>
-</div>
-<% end %>
+ <div id="spectra" class="row-fluid">
-<h2>// RECENT SETS <a class="right" href="/sets/">view all &raquo;</a></h2>
-<%= render :partial => 'sets' %>
+ <div class="span4">
-<h2>// RECENT ANONYMOUS SPECTRA (<a href="/spectra/anonymous">view all &raquo;</a>)</h2>
-<%= render :partial => 'anon_list' %>
+ <%= render :partial => "search" %>
-<h2>// RECENT SPECTRA (<a href="/spectra/feed">RSS</a>)</h2>
-<%= render :partial => 'list' %>
+ <h3>Recent authors</h3>
+ <ul class="nav">
+ <% User.find_all_by_login(@spectrums.collect(&:author).uniq).each do |user| %>
+ <li><a href="/profile/<%= user.login %>"><i class="icon icon-user"></i> <%= user.login %></a></li>
+ <% end %>
+ </ul>
+
+ <hr />
+ <h3>Recent sets</h3>
+ <%= render :partial => 'sets' %>
+
+ <hr />
+ </div>
+
+ <style>._row { clear:left;} </style>
+
+ <div class="span8">
+ <h2>Recently uploaded spectra <small class="hidden-phone">by contributors like you</small></h2>
+
+ <div class="_row">
+ <% @spectrums.each_with_index do |spectrum,i| %>
+ <div class="span3 clearfix">
+ <a class="image" href="/spectra/show/<%= spectrum.id %>"><img src="<%= spectrum.photo.url(:thumb) %>" class="image" style="background:#ccc;"></a>
+ <h4><a data-transition="slide" href="/spectra/show/<%= spectrum.id %>"><%=h truncate(spectrum.title,:length => 18) %></a></h4>
+ <p><a data-transition="slide" href="/profile/<%=h spectrum.author %>"><%=h spectrum.author %></a> | <%= time_ago_in_words(spectrum.created_at) %> ago</p>
+ </div>
+ <% if ((i+1)/4.0).to_i == ((i+1)/4.0) %>
+ </div>
+ <hr />
+ <div class="_row">
+ <% end %>
+ <% end %>
+ </div>
+ </div>
</div>
-</div>
+<script type="text/javascript">
+
+(function () {
+
+
+
+})()
+
+</script>
+
View
1  webserver/config/routes.rb
@@ -1,4 +1,5 @@
ActionController::Routing::Routes.draw do |map|
+ map.local '/local/:login', :controller => 'sessions', :action => 'local'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.login '/login', :controller => 'sessions', :action => 'new'
map.register '/register', :controller => 'users', :action => 'create'
Please sign in to comment.
Something went wrong with that request. Please try again.