Skip to content

Commit

Permalink
Work done on Saved Search. Added location to Projects, and notes and …
Browse files Browse the repository at this point in the history
…retired to Tags.

Changed the travis script to try to fix build errors.

modified:   .travis.yml
 -- doesn't use sh script, commands are directly in .travis file

modified:   Gemfile.lock
modified:   app/assets/javascripts/angular/controllers/login.js
modified:   app/assets/stylesheets/application.css.scss
 -- added bootstrap css back in

modified:   app/assets/templates/home.html
modified:   app/controllers/api/callbacks_controller.rb
modified:   app/models/audio_recording.rb
modified:   app/models/saved_search/saved_search_store.rb
modified:   app/models/saved_search/saved_search_store_body.rb
modified:   app/models/saved_search/saved_search_store_post.rb
modified:   app/models/saved_search/saved_search_store_pre.rb
modified:   app/views/layouts/application.html.erb
new file:   db/migrate/20130218060415_add_location_to_projects.rb
new file:   db/migrate/20130218060728_add_notes_and_retired_to_tags.rb
 -- added migrations

modified:   spec/controllers/sites_controller_spec.rb
modified:   spec/controllers/users_controller_spec.rb
modified:   spec/factories/audio_recording_factory.rb
modified:   spec/models/progress_spec.rb
 -- had to change, as it left entries in the database

modified:   spec/models/user_spec.rb
modified:   spec/requests/saved_search_request_spec.rb
  • Loading branch information
Mark Cottman-Fields committed Feb 18, 2013
1 parent 27df1a3 commit 69c42dd
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 26 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ branches:
gemfile:
- Gemfile
before_install:
- sh vendor/bin/install_console_audio_tools.sh
- echo "Installing audio tools."
- sudo apt-get update -qq
- sudo apt-get install -qq ffmpeg mp3splt sox wavpack --fix-missing
- echo "Testing for audio tools."
- ffmpeg -version
- mp3splt -version
- sox --version
- wvunpack
- echo "Before install done."
script:
# - ls -la
- RAILS_ENV=test bundle exec rake db:migrate --trace
Expand Down
6 changes: 2 additions & 4 deletions app/assets/javascripts/angular/controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ function LoginCtrl($scope, $http, $location, authService, AuthenticationProvider

$scope.$watch('$root.loggedIn', function (){
if ($scope.loggedIn) {
$scope.displayName = $scope.userData.friendlyName;
$scope.email = $scope.userData.email;
$scope.friendlyName = $scope.userData.friendlyName;
}
else{
$scope.userName = "";
$scope.email = "";
$scope.friendlyName = "";
}
});

Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*= require_tree ../images/.
*= require vendor
* require_tree .
* require_tree bootstrap
*= require_tree ./bootstrap
* depend_on "_base"
*/

Expand Down
32 changes: 27 additions & 5 deletions app/assets/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<div id="content" data-ng-controller="HomeCtrl">
<div id="content" data-ng-controller="HomeCtrl" style="position:relative;">
<h2>Home</h2>

<p>
Welcome to a place where you can listen, learn, share your discoveries and help out the environment!
The Bioacoustic Workbench is a repository for audio recordings of the environment and tools that aid in
analysing the sounds.
</p>

<p>
We gather recordings from a wide range of environments, find practical ways to annotate
the sounds with information about what's going on in them, and then enable that
information to be put to use by ecologists and other parties interested in conservation.
</p>

<p ng-show="loggedIn">
Welcome back to the Bioacoustic Workbench, <span>{{$scope.userData.friendly_name}}</span>! We're glad you're here.
Welcome back to the Bioacoustic Workbench, <span>{{$scope.userData.friendly_name}}</span>! We're glad you're
here.
</p>

<p ng-hide="loggedIn" ng-controller="LoginCtrl">
Time to get started! You can <a href ng-click="login()">sign in</a> using an account you have at an external website.
Time to get started! You can <a href ng-click="login()">sign in</a> using an account you have at an external
website.
</p>

<p>
Expand All @@ -24,6 +30,7 @@ <h2>Home</h2>
</p>

<h3>Audio Recordings and Annotations</h3>

<p>
<a href="/recordings">Audio Recordings</a>

Expand All @@ -32,8 +39,23 @@ <h3>Audio Recordings and Annotations</h3>
</p>

<h3>Download annotations</h3>

<p>
Download all annotations on site (temporary). In
<a ng-href="{{downloadAnnotationLink}}" target="_blank" >csv</a> format.
<a ng-href="{{downloadAnnotationLink}}" target="_blank">csv</a> format.
</p>
</div>

<div id="map_canvas" style="width:100%; height:600px;z-index:2;"></div>

<script type="text/javascript">
$(document).ready(function () {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
});
</script>
</div>
15 changes: 12 additions & 3 deletions app/controllers/api/callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ def failure
# returneddata = 0; dataitem = window.open('/security/auth/open_id/callback', 'dataitem'); dataitem.returneddata = returneddata;
# to access the object: dataitem.returneddata

Rails.logger.warn("Log in failed. Data: #{window_data.as_json}; Params: #{params}")

respond_to do |format|
format.json { render :json => window_data.as_json, :status => :unauthorized }
format.js { render :json => window_data.as_json, :status => :unauthorized }
format.xml { render :xml => window_data.to_xml, :status => :unauthorized }
format.any { render :text => window_content(displayed_data, window_data), :status => :unauthorized }
end
Expand All @@ -55,11 +58,17 @@ def success_complete(canonical_data)

sign_in(user, :event => :authentication)

current_user.reset_authentication_token!
unless current_user.blank?
current_user.reset_authentication_token!
end

content = Api::SessionsController.login_info(current_user, user, canonical_data[:authorization][:provider])

Rails.logger.debug("Log in succeeded. Data: #{content.as_json}; Params: #{params}")

respond_to do |format|
format.json { render :json => content.as_json, :status => :ok }
format.js { render :json => content.as_json, :status => :ok }
format.xml { render :xml => content.to_xml, :status => :ok }
format.any { render :text => window_content(displayed_data, content), :status => :ok }
end
Expand Down Expand Up @@ -233,7 +242,7 @@ def twitter_info(raw)

# create a unique, dummy email, since twitter doesn't provide one
# set dummy email to true, so that this email is never shown
fake_email = raw['uid'].gsub(/[^0-9a-zA-Z]/,'_')+'[email protected]'
fake_email = raw['uid'].gsub(/[^0-9a-zA-Z]/, '_')+'[email protected]'

{
authorization:
Expand Down Expand Up @@ -370,7 +379,7 @@ def create_or_update_user(canonical_data, user=nil)

new_user_name = canonical_data[:user][:user_name].blank? ?
-1 * Random.rand(100000) :
canonical_data[:user][:user_name].gsub(/[^0-9a-zA-Z]/,'_')+'_'+canonical_data[:authorization][:provider]
canonical_data[:user][:user_name].gsub(/[^0-9a-zA-Z]/, '_')+'_'+canonical_data[:authorization][:provider]

# HACK: for users created by external providers, dummy the user name with the .... field
user = User.create!(
Expand Down
11 changes: 11 additions & 0 deletions app/models/audio_recording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,22 @@ class AudioRecording < ActiveRecord::Base

validates :file_hash, :presence => true

validate :is_uuid

# uuid stuff
attr_protected :uuid
include UUIDHelper

def is_uuid
unless self.uuid.blank?
begin
UUIDTools::UUID.parse(self.uuid)
rescue
self.errors.add(:uuid, "must be a valid UUID, given #{self.uuid.class} with value #{self.uuid}.")
end
end
end

# http://stackoverflow.com/questions/11569940/inclusion-validation-fails-when-provided-a-symbol-instead-of-a-string
# this lets a symbol be set, and it all still works
def status=(new_status)
Expand Down
4 changes: 4 additions & 0 deletions app/models/saved_search/saved_search_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,8 @@ def execute_query
to_return = {:search => self, :query => the_query, :items => results}
OpenStruct.new(to_return)
end

def to_s
self.to_json
end
end
32 changes: 23 additions & 9 deletions app/models/saved_search/saved_search_store_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,45 @@ def initialize(args)

validate :time_start_before_end

validate :tags_is_array, :tags_are_strings
validate :tags_are_strings, :is_uuid

def date_start_before_end
if !self.date_start.blank? && !self.date_end.blank? && self.date_start >= self.date_end
self.errors.add(:date_start, "must be before end date")
self.errors.add(:date_start, "must be before date_end")
end
end

def time_start_before_end
if !self.time_start.blank? && !self.time_end.blank? && self.time_start >= self.time_end
self.errors.add(:time_start, "must be before end time")
self.errors.add(:time_start, "must be before time_end")
end
end

def tags_is_array
self.errors.add(:tags, "must be an array, given #{self.tags.class} with value #{self.tags}.") unless self.tags.is_a?(Array) || self.tags.blank?
def is_uuid
unless self.audio_recording_uuid.blank?
begin
UUIDTools::UUID.parse(self.audio_recording_uuid)
rescue
self.errors.add(:audio_recording_uuid, "must be a valid UUID, given #{self.audio_recording_uuid.class} with value #{self.audio_recording_uuid}.")
end
end
end

def tags_are_strings
unless self.tags.blank?
self.tags.each do |tag|
unless tag.is_a?(String)
errors.add(:tags, "#{tag} of type #{tag.class} is not valid.")
if self.tags.is_a?(Array)
unless self.tags.blank?
self.tags.each do |tag|
unless tag.is_a?(String)
self.errors.add(:tags, "#{tag} of type #{tag.class} is not valid.")
end
end
end
else
self.errors.add(:tags, "must be an array, given #{self.tags.class} with value #{self.tags}.") unless self.tags.blank?
end
end

def to_s
self.to_json
end
end
4 changes: 4 additions & 0 deletions app/models/saved_search/saved_search_store_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ class SavedSearchStorePost
:display_tags_looks_like, :display_tags_sounds_like,
:display_tags_reference, :display_tags_auto

def to_s
self.to_json
end

end
17 changes: 16 additions & 1 deletion app/models/saved_search/saved_search_store_pre.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
class SavedSearchStorePre
include ActiveModel::Validations

attr_accessor :created_by_id, :is_temporary

validates :created_by_id, numericality: {only_integer: true, greater_than_or_equal_to: 1}, allow_nil: true
validates :is_temporary, :inclusion => { :in => [true, false] }, allow_nil: true
validates :is_temporary, :inclusion => {:in => [true, false]}, allow_nil: true

def to_s
self.to_json
=begin
msg = 'Saved Search Store Pre'
unless @created_by_id.blank?
msg = msg + " created by user with id #@created_by_id"
end
unless @is_temporary.blank?
msg = msg + " is #{@is_temporary ? '' : 'not'} temporary"
end
msg
=end
end
end
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<script src="https://login.persona.org/include.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAWT_qg_GDQVSlQB9O_1CEQf8l4bErP5Ek&sensor=false"></script>
<%= csrf_meta_tags %>
<%= yield(:head) %>

Expand All @@ -28,10 +29,9 @@

<h1><a href="/">Bioacoustic Workbench</a></h1>
<ul>
<li><a href="/projects">Browse Projects</a></li>
<li ng-controller="LoginCtrl">
<span ng-show="loggedIn">
Welcome <a href="/user/{{userData.user_id}}" title="{{friendly_name}}: {{email}}">{{email}}</a>&nbsp;&nbsp;<a href ng-click="logout()">Sign Out</a>
Welcome <a href="/user/{{userData.userId}}" title="{{friendlyName}}">{{friendlyName}}</a>&nbsp;&nbsp;<a href ng-click="logout()">Sign Out</a>
</span>
<span ng-hide="loggedIn">
<a href ng-click="login()">Sign In</a>
Expand Down

0 comments on commit 69c42dd

Please sign in to comment.