Skip to content

Commit

Permalink
updated gems, merged routes.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
cofiem committed Oct 31, 2012
2 parents 1f83232 + 6dc002a commit 6f01984
Show file tree
Hide file tree
Showing 25 changed files with 580 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ before_script:
- sh vendor/bin/install_console_audio_tools.sh
script:
- ls -la
- RAILS_ENV=test bundle exec rake --trace db:migrate
- RAILS_ENV=test bundle exec rake db:migrate --trace
- RAILS_ENV=test bundle exec rake --trace
notifications:
webhooks: http://build.ecosounds.org/build
3 changes: 3 additions & 0 deletions app/assets/javascripts/audio_events.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/javascripts/audio_recordings.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/audio_events.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the AudioEvents controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/audio_recordings.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the AudioRecordings controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
5 changes: 3 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class ApplicationController < ActionController::Base
private

def set_stamper
# current_user is from devise
User.stamper = self.current_user #User.first()
# BUG: I expect this to fail
# TODO: hack while we have no authentication
User.stamper = User.first() #self.current_user
end
end
83 changes: 83 additions & 0 deletions app/controllers/audio_events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class AudioEventsController < ApplicationController
# GET /audio_events
# GET /audio_events.json
def index
@audio_events = AudioEvent.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @audio_events }
end
end

# GET /audio_events/1
# GET /audio_events/1.json
def show
@audio_event = AudioEvent.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @audio_event }
end
end

# GET /audio_events/new
# GET /audio_events/new.json
def new
@audio_event = AudioEvent.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @audio_event }
end
end

# GET /audio_events/1/edit
def edit
@audio_event = AudioEvent.find(params[:id])
end

# POST /audio_events
# POST /audio_events.json
def create
@audio_event = AudioEvent.new(params[:audio_event])

respond_to do |format|
if @audio_event.save
format.html { redirect_to @audio_event, notice: 'Audio event was successfully created.' }
format.json { render json: @audio_event, status: :created, location: @audio_event }
else
format.html { render action: "new" }
format.json { render json: @audio_event.errors, status: :unprocessable_entity }
end
end
end

# PUT /audio_events/1
# PUT /audio_events/1.json
def update
@audio_event = AudioEvent.find(params[:id])

respond_to do |format|
if @audio_event.update_attributes(params[:audio_event])
format.html { redirect_to @audio_event, notice: 'Audio event was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @audio_event.errors, status: :unprocessable_entity }
end
end
end

# DELETE /audio_events/1
# DELETE /audio_events/1.json
def destroy
@audio_event = AudioEvent.find(params[:id])
@audio_event.destroy

respond_to do |format|
format.html { redirect_to audio_events_url }
format.json { head :no_content }
end
end
end
83 changes: 83 additions & 0 deletions app/controllers/audio_recordings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class AudioRecordingsController < ApplicationController
# GET /audio_recordings
# GET /audio_recordings.json
def index
@audio_recordings = AudioRecording.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @audio_recordings }
end
end

# GET /audio_recordings/1
# GET /audio_recordings/1.json
def show
@audio_recording = AudioRecording.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @audio_recording }
end
end

# GET /audio_recordings/new
# GET /audio_recordings/new.json
def new
@audio_recording = AudioRecording.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @audio_recording }
end
end

# GET /audio_recordings/1/edit
def edit
@audio_recording = AudioRecording.find(params[:id])
end

# POST /audio_recordings
# POST /audio_recordings.json
def create
@audio_recording = AudioRecording.new(params[:audio_recording])

respond_to do |format|
if @audio_recording.save
format.html { redirect_to @audio_recording, notice: 'Audio recording was successfully created.' }
format.json { render json: @audio_recording, status: :created, location: @audio_recording }
else
format.html { render action: "new" }
format.json { render json: @audio_recording.errors, status: :unprocessable_entity }
end
end
end

# PUT /audio_recordings/1
# PUT /audio_recordings/1.json
def update
@audio_recording = AudioRecording.find(params[:id])

respond_to do |format|
if @audio_recording.update_attributes(params[:audio_recording])
format.html { redirect_to @audio_recording, notice: 'Audio recording was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @audio_recording.errors, status: :unprocessable_entity }
end
end
end

# DELETE /audio_recordings/1
# DELETE /audio_recordings/1.json
def destroy
@audio_recording = AudioRecording.find(params[:id])
@audio_recording.destroy

respond_to do |format|
format.html { redirect_to audio_recordings_url }
format.json { head :no_content }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/audio_events_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AudioEventsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/audio_recordings_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AudioRecordingsHelper
end
32 changes: 32 additions & 0 deletions app/models/audio_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class AudioEvent < ActiveRecord::Base
belongs_to :audio_recording

attr_accessible :end_time_seconds, :high_frequency_hertz, :is_reference, :low_frequency_hertz, :start_time_seconds

# userstamp
stampable
belongs_to :user
acts_as_paranoid

# validation
validates :start_time_seconds, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }
validates :end_time_seconds, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }
validates :start_time_must_be_less_than_end_time, :presence => true

validates :low_frequency_hertz, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }
validates :high_frequency_hertz, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }
validates :low_frequency_must_be_less_than_or_equal_to_high_frequency, :presence => true

# custom validation methods
def start_time_must_be_less_than_or_equal_to_end_time
if start_time_seconds > end_time_seconds then
errors.add(:start_time_seconds, "must be lower than end time")
end
end

def low_frequency_must_be_less_than_or_equal_to_high_frequency
if low_frequency_hertz > high_frequency_hertz then
errors.add(:start_time_seconds, "must be lower than high frequency")
end
end
end
36 changes: 36 additions & 0 deletions app/models/audio_recording.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class AudioRecording < ActiveRecord::Base
store :notes
belongs_to :user
belongs_to :site
attr_accessible :bit_rate_bps, :channels, :data_length_bytes,
:duration_seconds, :hash, :media_type, :notes,
:recorded_date, :sample_rate_hertz, :status

stampable
acts_as_paranoid

# validation
validates :uuid, :presence => true, :length => {:is => 36}
validates :user, :presence => true

validates :recorded_date, :presence => true, :on_or_before => :today
validates :site, :presence => true
validates :duration_seconds, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }

validates :sample_rate_hertz, :numericality => { :only_integer => true, :greater_than => 0 }
validates :channels, :presence => true, :numericality => { :only_integer => true, :greater_than => 0 }
validates :bit_rate_bps, :numericality => { :only_integer => true, :greater_than => 0 }
validates :media_type, :presence => true
validates :data_length_bytes, :presence => true, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }

validates :hash, :presence => true


# uuid stuff
attr_protected :uuid
validates_presence_of :uuid
validates_uniqueness_of :uuid

include UUIDHelper

end
4 changes: 3 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ class Project < ActiveRecord::Base
has_many :photos, :as => :imageable
has_many :project_sites
has_many :sites, :through => :project_sites

accepts_nested_attributes_for :sites

# userstamp
stampable
belongs_to :user

validates :name, :presence => true
end
3 changes: 2 additions & 1 deletion app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Site < ActiveRecord::Base

# userstamp
stampable

belongs_to :user

validates :name, :presence => true, :length => { :minimum => 2 }
validates :latitude, :presence => true, :numericality => true
validates :longitude, :presence => true, :numericality => true
Expand Down
41 changes: 41 additions & 0 deletions app/views/audio_events/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<%= form_for(@audio_event) do |f| %>
<% if @audio_event.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@audio_event.errors.count, "error") %> prohibited this audio_event from being saved:</h2>

<ul>
<% @audio_event.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :audio_recording %><br />
<%= f.text_field :audio_recording %>
</div>
<div class="field">
<%= f.label :start_time_seconds %><br />
<%= f.text_field :start_time_seconds %>
</div>
<div class="field">
<%= f.label :end_time_seconds %><br />
<%= f.text_field :end_time_seconds %>
</div>
<div class="field">
<%= f.label :low_frequency_hertz %><br />
<%= f.text_field :low_frequency_hertz %>
</div>
<div class="field">
<%= f.label :high_frequency %><br />
<%= f.text_field :high_frequency %>
</div>
<div class="field">
<%= f.label :is_reference %><br />
<%= f.text_field :is_reference %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/audio_events/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing audio_event</h1>

<%= render 'form' %>

<%= link_to 'Show', @audio_event %> |
<%= link_to 'Back', audio_events_path %>
33 changes: 33 additions & 0 deletions app/views/audio_events/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h1>Listing audio_events</h1>

<table>
<tr>
<th>Audio recording</th>
<th>Start time seconds</th>
<th>End time seconds</th>
<th>Low frequency hertz</th>
<th>High frequency</th>
<th>Is reference</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @audio_events.each do |audio_event| %>
<tr>
<td><%= audio_event.audio_recording %></td>
<td><%= audio_event.start_time_seconds %></td>
<td><%= audio_event.end_time_seconds %></td>
<td><%= audio_event.low_frequency_hertz %></td>
<td><%= audio_event.high_frequency %></td>
<td><%= audio_event.is_reference %></td>
<td><%= link_to 'Show', audio_event %></td>
<td><%= link_to 'Edit', edit_audio_event_path(audio_event) %></td>
<td><%= link_to 'Destroy', audio_event, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Audio event', new_audio_event_path %>
5 changes: 5 additions & 0 deletions app/views/audio_events/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New audio_event</h1>

<%= render 'form' %>

<%= link_to 'Back', audio_events_path %>
Loading

0 comments on commit 6f01984

Please sign in to comment.