Skip to content

Commit

Permalink
tried to make the annotations post work
Browse files Browse the repository at this point in the history
lots of failure, some success. rage quitting.
  • Loading branch information
atruskie committed Nov 25, 2012
1 parent 3e83766 commit 8f895ff
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
11 changes: 9 additions & 2 deletions app/assets/javascripts/angular/controllers/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function ListenCtrl($scope, $resource, $routeParams, AudioRecording, AudioEvent)
};

$scope.selectedAnnotation = {
tags: [-1],
audio_event_tags: [-1],
start_time_seconds: 0.05,
end_time_seconds: 15.23,
low_frequency_hertz:1000,
Expand All @@ -70,7 +70,12 @@ function ListenCtrl($scope, $resource, $routeParams, AudioRecording, AudioEvent)
}

$scope.addAnnotation = function createAnnotation() {
var a = this.selectedAnnotation;
var a = angular.copy(this.selectedAnnotation);

// prep tags
a.audio_event_tags_attributes = a.audio_event_tags.map(function (v) {return {tag_id:v};});
delete a.audio_event_tags

a.audio_recording_id = recordingId;

AudioEvent.save({audioEventId:null}, a,
Expand All @@ -79,6 +84,8 @@ function ListenCtrl($scope, $resource, $routeParams, AudioRecording, AudioEvent)

// now update tag-list
$scope.audio_events.push(response);
$scope.selected_Annotation = response;

},
function createAnnotationFailure(response, getResponseHeaders) {
console.error("Annotation creation unsuccessful, response: " + response.status, response.data);
Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/layout.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ footer {
/* General Classes
-----------------------------------------------------------------------------*/
.short-guid {
width: 50px;
width: 70px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
}

.select2-container {
Expand Down
6 changes: 3 additions & 3 deletions app/assets/templates/listen.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ <h3>Audio Controls</h3>
</audio>

<h3>
Tag edit
Annotation edit
</h3>

<form name="annotationEditForm" ng-model="selectedAnnotation">
<label>
<span>Tags</span>
<em>--TODO: support for proper tagging control--</em><br/>
<select ng-multiple="true" tags multiple ui-select2="{allowClear:true}" ng-model="selectedAnnotation.tags" >
<select ng-multiple="true" tags multiple ui-select2="{allowClear:true}" ng-model="selectedAnnotation.audio_event_tags" >
<option ng-repeat="t in tags" value="{{t.id}}" >{{t.text}}<!-- ng-show={{t.type_of_tag}}-->, {{t.type_of_tag}} <!-- --></span></option>
</select>

Expand Down Expand Up @@ -83,7 +83,7 @@ <h3>Annotations</h3>
<tbody>
<tr ng-repeat="ae in audio_events">
<td>{{ae.id}}</td>
<td><a ng-href="/recordings/{{ae.audio_recording.uuid}}" class="short-guid" ></a>{{attr}}</td>
<td><a ng-href="/recordings/{{ae.audio_recording.uuid}}" class="short-guid" >{{ae.audio_recording.uuid}}</a></td>
<td>{{ae.created_at}}</td>
<td>{{ae.creator_id}}</td>
<td>{{ae.deleted_at}}</td>
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def render_csv(filename = nil)
end

private


# temporarily enabled again
#def set_stamper
# current_user is provided by devise
#User.stamper = self.current_user
# current_user is provided by devise
# User.stamper = self.current_user
#end
end
12 changes: 6 additions & 6 deletions app/controllers/audio_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def by_audio_id
.includes(:audio_recording)
.where(:audio_recordings => { :uuid => id })

@stuff = @audio_events.map {|m| m}

#@audio_recording = (AudioRecording.find_by_uuid id)
#@audio_events = AudioEvent.find_all_by_audio_recording_id @audio_recording.id
Expand Down Expand Up @@ -51,7 +50,7 @@ def by_audio_id
# GET /audio_events/1
# GET /audio_events/1.json
def show
@audio_event = AudioEvent.find(params[:id])
@audio_event = AudioEvent.includes(:audio_event_tags).find(params[:id])

respond_to do |format|
format.html # show.html.erb
Expand All @@ -72,20 +71,20 @@ def new

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

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

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
Expand Down Expand Up @@ -121,7 +120,8 @@ def destroy

def download

@formatted_annotations = custom_format AudioEvent.includes(:tags).order(:audio_event => :recorded_date).all
@formatted_annotations =
custom_format AudioEvent.includes(:tags).order(:audio_event => :recorded_date).all

respond_to do |format|
format.xml { render :xml => @formatted_annotations }
Expand Down
9 changes: 5 additions & 4 deletions app/models/audio_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ class AudioEvent < ActiveRecord::Base
# relations
belongs_to :audio_recording

has_many :audio_event_tags, :inverse_of => :audio_event, :dependent => :destroy

has_many :tags, :through => :audio_event_tags
#accepts_nested_attributes_for :tags

accepts_nested_attributes_for :tags, :audio_event_tags
has_many :audio_event_tags, :inverse_of => :audio_event, :dependent => :destroy
accepts_nested_attributes_for :audio_event_tags, :allow_destroy => true

# attr
attr_accessible :audio_recording_id, :end_time_seconds, :high_frequency_hertz, :is_reference,
:low_frequency_hertz, :start_time_seconds
:low_frequency_hertz, :start_time_seconds,
:tags_attributes, :audio_event_tags_attributes

# userstamp
stampable
Expand Down
11 changes: 8 additions & 3 deletions app/models/audio_event_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ class AudioEventTag < ActiveRecord::Base
belongs_to :audio_event
belongs_to :tag

accepts_nested_attributes_for :audio_event

# attr
attr_accessible :audio_event, :tag
attr_accessible :audio_event, :tag,
:tag_id

# userstamp
stampable
belongs_to :user, :class_name => 'User', :foreign_key => :creator_id

# validations
validates :audio_event_id, :presence => true
validates :tag_id, :presence => true
validates_presence_of :audio_event
#validates_presence_of :tag_id

#validates_uniqueness_of :audio_event,
# :scope => [:tag]
end

0 comments on commit 8f895ff

Please sign in to comment.