Skip to content

Commit

Permalink
modified: .gitignore
Browse files Browse the repository at this point in the history
deleted:    .idea/.generators
deleted:    .idea/.name
deleted:    .idea/codeStyleSettings.xml
deleted:    .idea/dictionaries/n6330274.xml
deleted:    .idea/encodings.xml
deleted:    .idea/misc.xml
deleted:    .idea/modules.xml
deleted:    .idea/scopes/scope_settings.xml
deleted:    .idea/vcs.xml
	-- removed .idea folder from git - it should not be hosted publically anyway

new file:   app/assets/javascripts/tags.js.coffee
new file:   app/assets/stylesheets/tags.css.scss
new file:   app/controllers/tags_controller.rb
new file:   app/helpers/tags_helper.rb
new file:   app/models/tag.rb
new file:   app/views/tags/_form.html.erb
new file:   app/views/tags/edit.html.erb
new file:   app/views/tags/index.html.erb
new file:   app/views/tags/new.html.erb
new file:   app/views/tags/show.html.erb
modified:   config/routes.rb
new file:   db/migrate/20121031055154_create_tags.rb
new file:   test/fixtures/tags.yml
new file:   test/functional/tags_controller_test.rb
new file:   test/unit/helpers/tags_helper_test.rb
new file:   test/unit/tag_test.rb
	-- scaffolding for tags

modified:   test/test_helper.rb
	-- seeds.rb will be now be executed when running tests!

modified:   app/models/audio_event.rb
new file:   app/models/audio_event_tag.rb
modified:   app/models/audio_recording.rb
modified:   app/models/permission.rb
modified:   app/models/photo.rb
modified:   app/models/project.rb
modified:   app/models/site.rb
modified:   app/models/user.rb
modified:   db/migrate/20121030060408_create_audio_events.rb
modified:   db/migrate/20121031023244_create_permissions.rb
new file:   db/migrate/20121031060534_add_many_to_many_for_events_and_tags.rb
	-- added all the validation and relationships for all model elements and cleaned up files

modified:   db/schema.rb
	-- autogened by migration runner
  • Loading branch information
atruskie committed Nov 1, 2012
1 parent b997480 commit 819aa3e
Show file tree
Hide file tree
Showing 28 changed files with 351 additions and 151 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,4 @@ doc/
/.project

# rubymine stuff
/.idea/workspace.xml
/.idea/qubar.site.iml
/.idea/dataSources.xml
/.idea/dataSources.ids
/.idea/.rakeTasks
/.idea
63 changes: 0 additions & 63 deletions .idea/.generators

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

13 changes: 0 additions & 13 deletions .idea/codeStyleSettings.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/dictionaries/n6330274.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/encodings.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/misc.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/modules.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/scopes/scope_settings.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/vcs.xml

This file was deleted.

3 changes: 3 additions & 0 deletions app/assets/javascripts/tags.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/tags.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Tags controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
83 changes: 83 additions & 0 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class TagsController < ApplicationController
# GET /tags
# GET /tags.json
def index
@tags = Tag.all

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

# GET /tags/1
# GET /tags/1.json
def show
@tag = Tag.find(params[:id])

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

# GET /tags/new
# GET /tags/new.json
def new
@tag = Tag.new

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

# GET /tags/1/edit
def edit
@tag = Tag.find(params[:id])
end

# POST /tags
# POST /tags.json
def create
@tag = Tag.new(params[:tag])

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

# PUT /tags/1
# PUT /tags/1.json
def update
@tag = Tag.find(params[:id])

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

# DELETE /tags/1
# DELETE /tags/1.json
def destroy
@tag = Tag.find(params[:id])
@tag.destroy

respond_to do |format|
format.html { redirect_to tags_url }
format.json { head :no_content }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/tags_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module TagsHelper
end
26 changes: 19 additions & 7 deletions app/models/audio_event.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
class AudioEvent < ActiveRecord::Base
# relations
belongs_to :audio_recording
has_many :audio_event_tags
has_many :tags, :through => :audio_event_tags

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

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

# userstamp
stampable
belongs_to :user
acts_as_paranoid
validates_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 :end_time_seconds, :numericality => { :greater_than_or_equal_to => 0 }
validate :start_time_must_be_lte_end_time

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
validates :high_frequency_hertz, :numericality => { :greater_than_or_equal_to => 0 }
validate :low_frequency_must_be_lte_high_frequency

# custom validation methods
def start_time_must_be_less_than_or_equal_to_end_time
def start_time_must_be_lte_end_time
return unless end_time_seconds

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
def low_frequency_must_be_lte_high_frequency
return unless high_frequency_hertz

if low_frequency_hertz > high_frequency_hertz then
errors.add(:start_time_seconds, "must be lower than high frequency")
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/audio_event_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AudioEventTag < ActiveRecord::Base
belongs_to :audio_event
belongs_to :tag

# userstamp
stampable
belongs_to :user

end
29 changes: 21 additions & 8 deletions app/models/audio_recording.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
require 'timeliness'

class AudioRecording < ActiveRecord::Base
# flex store
store :notes
belongs_to :user

# relations
belongs_to :site
has_many :audio_events

# attr
attr_accessible :bit_rate_bps, :channels, :data_length_bytes,
:duration_seconds, :hash, :media_type, :notes,
:recorded_date, :sample_rate_hertz, :status

# userstamp
stampable
belongs_to :user
acts_as_paranoid
validates_as_paranoid

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

validates :recorded_date, :presence => true, :on_or_before => :now
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 :sample_rate_hertz, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }

# the channels field encodes our special version of a bit flag. 0 (no bits flipped) represents
# a mix down option - we don't store mix downs (if we did they would be stored as single channel / mono (value = 1))
validates :channels, :presence => true, :numericality => { :only_integer => true, :greater_than => 0 }
validates :bit_rate_bps, :numericality => { :only_integer => true, :greater_than => 0 }
validates :bit_rate_bps, :numericality => { :only_integer => true, :greater_than_or_equal_to => 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

private

# default values
def default_values
# empty
end
end
35 changes: 34 additions & 1 deletion app/models/permission.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
class Permission < ActiveRecord::Base
extend Enumerize

# relations
belongs_to :user
attr_accessible :level
belongs_to :permissionable, :polymorphic => true

# attr
attr_accessible :level, :permissionable_type, :permissionable_id

# userstamp
stampable
# belongs_to :user

# enumerations
enumerize :level, :in => [:owner, :write, :read, :none], :default => :none, predicates: true

# validation
validates :level, :presence => true
validate :anonymous_permission_can_only_be_read_or_none


# custom validation methods
def anonymous_permission_can_only_be_read_or_none
return unless self.user_id.nil?

return if self.read? || self.none?

errors.add(:level, "The permission level can only be 'read' or 'none' for anonymous permissions")
end

# methods
def anonymous?
self.user.nil?
end

end
Loading

0 comments on commit 819aa3e

Please sign in to comment.