Skip to content

Commit

Permalink
view links don't use hash now, some progress on media controller
Browse files Browse the repository at this point in the history
  • Loading branch information
cofiem committed Nov 7, 2012
1 parent ec2090b commit fd8a98a
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 66 deletions.
18 changes: 9 additions & 9 deletions app/assets/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ var bawApp = angular.module('baw', ['ngResource'], function($routeProvider, $loc

// routes
$routeProvider.
when('/home', {templateUrl: 'assets/home.html', controller: HomeCtrl}).
when('/home', {templateUrl: '/assets/home.html', controller: HomeCtrl}).

when('/projects', {templateUrl: 'assets/projects.html', controller: ProjectCtrl}).
when('/project/:projectId', {templateUrl: 'assets/project.html', controller: ProjectsCtrl}).
when('/projects', {templateUrl: '/assets/projects.html', controller: ProjectCtrl}).
when('/projects/:projectId', {templateUrl: '/assets/project.html', controller: ProjectsCtrl}).

when('/sites', {templateUrl: 'assets/sites.html', controller: SitesCtrl }).
when('/site/:siteId', {templateUrl: 'assets/site.html', controller: SiteCtrl }).
when('/sites', {templateUrl: '/assets/sites.html', controller: SitesCtrl }).
when('/sites/:siteId', {templateUrl: '/assets/site.html', controller: SiteCtrl }).

when('/photos', {templateUrl: 'assets/photos.html', controller: PhotosCtrl }).
when('/photo/:photoId', {templateUrl: 'assets/photo.html', controller: PhotoCtrl }).
when('/photos', {templateUrl: '/assets/photos.html', controller: PhotosCtrl }).
when('/photos/:photoId', {templateUrl: '/assets/photo.html', controller: PhotoCtrl }).

when('/recordings', {templateUrl: 'assets/recordings.html', controller: RecordingsCtrl }).
when('/recording/:recordingId', {templateUrl: 'assets/recording.html', controller: RecordingCtrl }).
when('/recordings', {templateUrl: '/assets/recordings.html', controller: RecordingsCtrl }).
when('/recordings/:recordingId', {templateUrl: '/assets/recording.html', controller: RecordingCtrl }).

//when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
otherwise({redirectTo: '/home'});
Expand Down
14 changes: 8 additions & 6 deletions app/assets/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<h2>Welcome</h2>
<div id="content" data-ng-controller="HomeCtrl">
<h2>Welcome</h2>

<p>{{welcomeMessage}}</p>
<p>{{welcomeMessage}}</p>

<a href="#/projects">Projects</a>
<a href="#/sites">Sites</a>
<a href="#/photos">Photos</a>
<a href="#/recordings">Audio Recordings</a>
<a href="/projects">Projects</a>
<a href="/sites">Sites</a>
<a href="/photos">Photos</a>
<a href="/recordings">Audio Recordings</a>
</div>
6 changes: 3 additions & 3 deletions app/assets/templates/photo.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ <h2>Photo</h2>

<p>The details for a site.</p>

<a href="#/photos" >Photos</a>
<a href="#" >Home</a>
<a href="/photos" >Photos</a>
<a href="/" >Home</a>

<h3><a data-ng-href="#/photo/{{id}}" title="source: {{photo.uri}}">{{photo.name}}</a></h3>
<h3><a data-ng-href="/photos/{{id}}" title="source: {{photo.uri}}">{{photo.name}}</a></h3>
<p data-ng-bind="photo.description" ></p>
<p data-ng-bind="photo.copyright" ></p>
<small>{{photo.updated_at}}</small>
Expand Down
4 changes: 2 additions & 2 deletions app/assets/templates/photos.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ <h1>Photo List</h1>

<p>These are the available photos.</p>

<a href="#/">Home</a>
<a href="/">Home</a>

<ul>
<li data-ng-repeat="photo in photos">
<div>
<h3><a data-ng-href="#/photo/{{id}}" title="source: {{photo.uri}}">{{photo.name}}</a></h3>
<h3><a data-ng-href="/photos/{{photo.id}}" title="source: {{photo.uri}}">{{photo.name}}</a></h3>
<p data-ng-bind="photo.description" ></p>
<p data-ng-bind="photo.copyright" ></p>
<small>{{photo.updated_at}}</small>
Expand Down
11 changes: 9 additions & 2 deletions app/assets/templates/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ <h2>Project</h2>

<p>The details for a project.</p>

<a href="#/projects">Projects</a>
<a href="#/">Home</a>
<a href="/projects">Projects</a>
<a href="/">Home</a>

<h3><a ng-href="{{project.urn}}">{{project.name}}</a></h3>
<p ng-bind="project.description" ></p>
<pre>{{project.notes}}</pre>
<small>{{updated_at}}</small>
<ul>
<li data-ng-repeat="site in project.sites">
{{site.id}}
{{site.latitude}}
{{site.longitude}}
</li>
</ul>
</div>
5 changes: 3 additions & 2 deletions app/assets/templates/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ <h1>Project List</h1>

<p>These are the available projects.</p>

<a href="#/">Home</a>
<a href="/">Home</a>

<ul>
<li data-ng-repeat="project in projects">
<div>
<h3><a data-ng-href="#/project/{{id}}" title="urn: {{project.urn}}">{{project.name}}</a></h3>
<h3><a data-ng-href="/projects/{{project.id}}" title="urn: {{project.urn}}">{{project.name}}</a></h3>
<p data-ng-bind="project.description" ></p>
<small>{{project.updated_at}}</small>
<p ng-bind="project.sites.length" ></p>
</div>
</li>

Expand Down
4 changes: 2 additions & 2 deletions app/assets/templates/recording.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ <h2>Audio Recording</h2>

<p>The details for an audio recording.</p>

<a href="#/recordings">Audio Recordings</a>
<a href="#/">Home</a>
<a href="/recordings">Audio Recordings</a>
<a href="/">Home</a>
<h3>Audio Recording {{recording.id}}</h3>
<img src="/media/{{recording.uuid}}_0_10_0_11025_256_g.png" />
<a data-ng-href="/media/{{recording.uuid}}_0_10_0_11025.webm">audio</a>
Expand Down
4 changes: 2 additions & 2 deletions app/assets/templates/recordings.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ <h1>Audio Recording List</h1>

<p>These are the available audio recordings.</p>

<a href="#/">Home</a>
<a href="/">Home</a>

<ul>
<li data-ng-repeat="recording in recordings">
<h3><a data-ng-href="#/recording/{{recording.id}}">{{recording.id}} ({{recording.uuid}})</a></h3>
<h3><a data-ng-href="/recordings/{{recording.id}}">{{recording.id}} ({{recording.uuid}})</a></h3>
<p>{{recording.duration_seconds}} seconds '{{recording.media_type}}'</p>
</li>

Expand Down
7 changes: 4 additions & 3 deletions app/assets/templates/site.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ <h2>Site</h2>

<p>The details for a site.</p>

<a href="#/sites">Sites</a>
<a href="#/">Home</a>
<a href="/sites">Sites</a>
<a href="/">Home</a>

<h3>{{site.name}}</h3>
<p ng-bind="site.latitude" ></p>
<p ng-bind="site.longitude" ></p>
<pre>{{site.notes}}</pre>
<small>{{updated_at}}</small>
<small>{{site.updated_at}}</small>
<p>{{site.audio_recordings.length}}</p>
</div>
5 changes: 3 additions & 2 deletions app/assets/templates/sites.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ <h1>Site List</h1>

<p>These are the available sites.</p>

<a href="#/">Home</a>
<a href="/">Home</a>

<ul>
<li data-ng-repeat="site in sites">
<div>
<h3><a data-ng-href="#/site/{{site.id}}">{{site.name}}</a></h3>
<h3><a data-ng-href="/sites/{{site.id}}">{{site.name}}</a></h3>
<p><span data-ng-bind="site.latitude"></span></p>
<p><span data-ng-bind="site.longitude"></span></p>
<p>{{site.notes}}</p>
<p>{{site.projects}}</p>
<p>{{site.audio_recordings.length}}</p>
</div>
</li>

Expand Down
59 changes: 40 additions & 19 deletions app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MediaController < ApplicationController
include FileCacher

respond_to :xml, :json, :html, :png, :ogg, :oga, :webm, :webma, :mp3
#respond_to :xml, :json, :html, :png, :ogg, :oga, :webm, :webma, :mp3

def index
# index page for media files
Expand All @@ -25,40 +25,61 @@ def item

final_format_requested = requested_media_type

image_media_types = [ Mime['image/png'] ]
audio_media_types = [ Mime['audio/webm'], Mime['audio/webma'],
Mime['audio/ogg'], Mime['audio/oga'],
Mime['audio/mp3'], Mime['audio/mpeg'] ]
text_media_types = [ Mime['application/json'], Mime['text/html'],
Mime['application/xhtml+xml'], Mime['application/xml'],
Mime['application/x-javascript'], Mime['text/javascript'],
Mime['text/x-javascript'],Mime['text/x-json'] ]
image_media_types = [ Mime::Type.lookup('image/png')
]
audio_media_types = [ Mime::Type.lookup('audio/webm'), Mime::Type.lookup('audio/webma'),
Mime::Type.lookup('audio/ogg'), Mime::Type.lookup('audio/oga'),
Mime::Type.lookup('audio/mp3'), Mime::Type.lookup('audio/mpeg')
]
text_media_types = [ Mime::Type.lookup('application/json'), Mime::Type.lookup('text/html'),
Mime::Type.lookup('application/xhtml+xml'), Mime::Type.lookup('application/xml'),
Mime::Type.lookup('application/x-javascript'), Mime::Type.lookup('text/javascript'),
Mime::Type.lookup('text/x-javascript'), Mime::Type.lookup('text/x-json')
]

all_media_types = image_media_types.concat(audio_media_types).concat(text_media_types)

# if the format is a supported image format, locate a cached spectrogram or generate it, then stream it back.
#if image_media_types.include? final_format_requested

recording = AudioRecording.find_by_uuid(@file_info[:id])
@file_info[:date] = recording.recorded_date.strftime "%Y%m%d"
@file_info[:time] = recording.recorded_date.strftime "%H%M%S"
@file_info[:original_format] = Mime::Type.file_extension_of recording.media_type
@file_info[:requested_media_type] =requested_media_type
@file_info[:requested_extension] =requested_extension


full_path = FileCacher::generate_spectrogram @file_info
send_file full_path, :stream => true, :buffer_size => 4096, :disposition => 'inline', :type => final_format_requested, :content_type => final_format_requested
#full_path = Cache::

#send_file full_path, :stream => true, :buffer_size => 4096, :disposition => 'inline', :type => final_format_requested, :content_type => final_format_requested

if image_media_types.include? final_format_requested
full_path = FileCacher::generate_spectrogram @file_info
download_file full_path, final_format_requested
end

=begin
elsif audio_media_types.include? final_format_requested
if audio_media_types.include? final_format_requested
full_path = FileCacher::create_audio_segment @file_info
send_file full_path, :stream => true, :buffer_size => 4096, :disposition => 'inline', :type => final_format_requested, :content_type => final_format_requested
download_file full_path, final_format_requested
end

elsif text_media_types.include? final_format_requested
respond_with @file_info
if text_media_types.include? final_format_requested
respond_to do |format|
format.xml {render :xml => @file_info}
format.json {render :json => @file_info}
end
end

else
unless all_media_types.include? final_format_requested
# respond with a bad request
respond_with nil, { :head => :bad_request }
head :bad_request
end
=end

end

def download_file(full_path, media_type)
send_file full_path, :stream => true, :buffer_size => 4096, :disposition => 'inline', :type => media_type, :content_type => media_type
end

def update
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ class ProjectsController < ApplicationController
# GET /projects
# GET /projects.json
def index
@projects = Project.all
@projects = Project.includes(:sites)

respond_to do |format|
format.html # index.html.erb
format.json { render json: @projects }
format.json { render :json => @projects.to_json(:include => { :sites => { :only => [ :id, :name ] }}) }
end
end

# GET /projects/1
# GET /projects/1.json
def show
@project = Project.find(params[:id])
@project = Project.find(params[:id], :include => :sites)

respond_to do |format|
format.html # show.html.erb
format.json { render json: @project }
format.json { render :json => @project.to_json(:include => :sites) }
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ class SitesController < ApplicationController
# GET /sites
# GET /sites.json
def index
@sites = Site.all
@sites = Site.includes(:audio_recordings)

respond_to do |format|
format.html # index.html.erb
format.json { render json: @sites }
format.json { render json: @sites.to_json(:include => { :audio_recordings => { :only => [ :id ] }}) }
end
end

Expand Down
12 changes: 11 additions & 1 deletion lib/modules/audio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@ def self.info(source)
# parameters in modify_parameters. Possible options:
# :start_offset :end_offset :channel :sample_rate :format
def self.modify(source, target, modify_parameters)
raise ArgumentError, "Source does not exist: #{File.basename(source)}" unless File.exists? source
raise ArgumentError, "Target exists: #{File.basename(target)}" unless !File.exists? source
raise ArgumentError "Source and Target are the same file." unless source != target

modify_wavpack(source, target, modify_parameters)
if source.match(/\.wv$/)
# wav pack can only be converted to wav

target_file = Cache::cached_audio_file modify_parameters
target_possible_paths = Cache::possible_paths(Cache::cached_audio_storage_paths,target_file)

AudioWavpack::modify_wavpack(source, target, modify_parameters)
end
end

end
18 changes: 14 additions & 4 deletions lib/modules/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Cache

# get the file name for an original audio file
def self.original_audio_file(modify_parameters = {})
file_name = self.build_parameters [ :id, :date, :time, :format ], modify_parameters
file_name = self.build_parameters [ :id, :date, :time, :original_format ], modify_parameters
file_name
end

Expand Down Expand Up @@ -47,7 +47,9 @@ def self. cached_spectrogram_defaults()

# get the file name for a cached spectrogram
def self.cached_spectrogram_file(modify_parameters = {})
file_name = self.build_parameters [ :id, :start_offset, :end_offset, :channel, :sample_rate, :window, :colour, :format ], modify_parameters
# don't use format here, as we know that spectrograms will be cached in png
file_name = self.build_parameters [ :id, :start_offset, :end_offset, :channel, :sample_rate, :window, :colour ], modify_parameters
file_name += '.png'
file_name
end

Expand All @@ -59,7 +61,8 @@ def self.cached_spectrogram_storage_paths()

# get all possible full paths for a file
def self.possible_paths(storage_paths, file_name)
possible_paths = storage_paths.collect { |path| File.join(path,file_name) }

possible_paths = storage_paths.collect { |path| File.join(path, build_subfolder(file_name), file_name) }
possible_paths
end

Expand All @@ -70,7 +73,12 @@ def self.existing_paths(storage_paths, file_name)
end

private


def self.build_subfolder(file_name)
# assume that the file name starts with the uuid, get the first two chars as the sub folder
file_name[0,2]
end

def self.build_parameters(parameter_names = {}, modify_parameters = {})
file_name = ''

Expand All @@ -79,6 +87,8 @@ def self.build_parameters(parameter_names = {}, modify_parameters = {})
file_name += get_parameter(:id, modify_parameters, false)
elsif param == :format
file_name += '.'+get_parameter(:format, modify_parameters, false).reverse.chomp('.').reverse
elsif param == :original_format
file_name += '.'+get_parameter(:original_format, modify_parameters, false).reverse.chomp('.').reverse
else
file_name += get_parameter(param, modify_parameters)
end
Expand Down
Loading

0 comments on commit fd8a98a

Please sign in to comment.