Skip to content

Commit

Permalink
Added download links for CSV annotation download for details pages on…
Browse files Browse the repository at this point in the history
… Sites and Projects.

Listed links to audio recordings on site details page.

modified:   Gemfile.lock
modified:   app/assets/javascripts/angular/controllers/home.js
modified:   app/assets/javascripts/angular/controllers/projects.js
modified:   app/assets/javascripts/angular/controllers/sites.js
modified:   app/assets/javascripts/angular/services/services.js
modified:   app/assets/templates/project_details.html
modified:   app/assets/templates/site_details.html
modified:   app/controllers/audio_events_controller.rb
modified:   app/controllers/audio_recordings_controller.rb
modified:   app/serializers/site_serializer.rb
modified:   db/development_seeds.rb
  • Loading branch information
atruskie committed Feb 11, 2013
1 parent 3e924ee commit 1cf6b37
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/angular/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function HomeCtrl($scope, $resource, $routeParams, AudioEvent) {

$scope.welcomeMessage = "Welcome to <bar>";

$scope.downloadAnnotationLink = AudioEvent.csvLink;
$scope.downloadAnnotationLink = AudioEvent.csvLink();


}
Expand Down
6 changes: 4 additions & 2 deletions app/assets/javascripts/angular/controllers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ ProjectsCtrl.linkList = function (id) {

ProjectsCtrl.$inject = ['$scope', '$resource', 'Project'];

function ProjectCtrl($scope, $location, $resource, $routeParams, Project, Site, Photo) {
function ProjectCtrl($scope, $location, $resource, $routeParams, Project, Site, Photo, AudioEvent) {

var self = this;

var projectResource = Project; //$resource('/projects/:projectId', {projectId: $routeParams.projectId});
var routeArgs = {projectId: $routeParams.projectId};

$scope.downloadAnnotationLink = AudioEvent.csvLink({projectId: $routeParams.projectId});

this.populateProject = function(){
var p = { "project": {} };

Expand Down Expand Up @@ -165,5 +167,5 @@ function ProjectCtrl($scope, $location, $resource, $routeParams, Project, Site,
$scope.allSites = Site.query();
}

ProjectCtrl.$inject = ['$scope', '$location', '$resource', '$routeParams', 'Project', 'Site', 'Photo'];
ProjectCtrl.$inject = ['$scope', '$location', '$resource', '$routeParams', 'Project', 'Site', 'Photo', 'AudioEvent'];

10 changes: 8 additions & 2 deletions app/assets/javascripts/angular/controllers/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ SitesCtrl.linkList = function (id) {

SitesCtrl.$inject = ['$scope', '$resource', 'Site'];

function SiteCtrl($scope, $resource, $routeParams, Project, Site, AudioRecording) {
function SiteCtrl($scope, $resource, $routeParams, Project, Site, AudioRecording, AudioEvent) {
var siteResource = Site;
var routeArgs = {siteId: $routeParams.siteId};

$scope.downloadAnnotationLink = AudioEvent.csvLink({siteId: $routeParams.siteId});

// download a list of audio recordings belonging to this site
// HACK: GET ALL THE THINGS
$scope.audioRecordings = AudioRecording.query({site_id: $routeParams.siteId, times_only: true});

$scope.editing = $routeParams.editing === "edit";

$scope.site = siteResource.get(routeArgs, function () {
Expand Down Expand Up @@ -63,4 +69,4 @@ function SiteCtrl($scope, $resource, $routeParams, Project, Site, AudioRecording
};
}

SiteCtrl.$inject = ['$scope', '$resource', '$routeParams', 'Project', 'Site', 'AudioRecording'];
SiteCtrl.$inject = ['$scope', '$resource', '$routeParams', 'Project', 'Site', 'AudioRecording', 'AudioEvent'];
37 changes: 36 additions & 1 deletion app/assets/javascripts/angular/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,47 @@
}]);

bawss.factory('AudioEvent', [ '$resource', function ($resource) {
var baseCsvUri = "/audio_events/download.";
function makeCsvLink(options) {
var formattedUrl = baseCsvUri;
if (!angular.isObject(options)) {
// overwrite input then continur to format
options = {};
}

if (options.format) {
formattedUrl += options.format;
}
else {
formattedUrl += "csv"
}

if (options.projectId || options.siteId) {
formattedUrl += "?"
}

if (options.projectId) {
formattedUrl += "project_id=" + options.projectId.toString();
}

if (options.projectId && options.siteId) {
formattedUrl += "&"
}

if (options.siteId) {
formattedUrl += "site_id=" + options.siteId.toString();
}


return formattedUrl;
}

var actions = {
query: { method: 'GET', isArray: true }
};

var resource = resourcePut($resource, '/audio_events/:audioEventId', {audioEventId: '@audioEventId'}, actions);
resource.csvLink = "/audio_events/download.csv";
resource.csvLink = makeCsvLink;
return resource;
}]);

Expand Down
5 changes: 5 additions & 0 deletions app/assets/templates/project_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ <h2>Project</h2>
<div ng-show="isShowing">
<h3 title="{{project.urn}}">{{project.name}}</h3>
<p ng-bind="project.description" ></p>

<p>
<a ng-href="{{downloadAnnotationLink}}" target="_blank" >Download</a> all annotations from this project.
</p>

<pre>{{project.notes}}</pre>

<h4>Sites</h4>
Expand Down
13 changes: 12 additions & 1 deletion app/assets/templates/site_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ <h3>{{site.name}}</h3>
Projects: <span ng-repeat="p in site.projects"> <a ng-href="/projects/{{p.id}}">{{p.name}}</a>{{!$last | boolToWords:', '}}</span>
</p>

<p>
<a ng-href="{{downloadAnnotationLink}}" target="_blank" >Download</a> all annotations from this site.
</p>


<p>
<img src="http://maps.googleapis.com/maps/api/staticmap?center={{site.latitude}},{{site.longitude}}&zoom=12&size=250x250&maptype=hybrid&sensor=false">
</p>
<p ng-bind="site.latitude" ></p>
<p ng-bind="site.longitude" ></p>

<p>Number of recordings: {{site.audioRecordings.length}}</p>
<p>Number of recordings: {{site.audioRecordings.length}}

<ul>
<li ng-repeat="ar in audioRecordings" >
<a ng-href="/listen/{{ar.uuid}}">{{ar.recordedDate}},&nbsp;{{ar.durationSeconds}}</a>
</li>
</ul>

<pre>{{site.notes}}</pre>

Expand Down
25 changes: 24 additions & 1 deletion app/controllers/audio_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,31 @@ def by_audio_id
end

def download

project_id = nil
if params[:project_id]
project_id = Integer(params[:project_id].to_s, 10)
end

site_id = nil
if params[:site_id]
site_id = Integer(params[:site_id].to_s, 10)
end

query = AudioEvent.includes(:tags)

if project_id || site_id

query = query.joins(audio_recording: {site: :projects})

query = query.where(projects: {id: project_id}) if project_id

query = query.where(sites: {id: site_id}) if site_id

end

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

respond_to do |format|
format.xml { render :xml => @formatted_annotations }
Expand Down
13 changes: 12 additions & 1 deletion app/controllers/audio_recordings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ class AudioRecordingsController < ApplicationController
# GET /audio_recordings
# GET /audio_recordings.json
def index
@audio_recordings = AudioRecording.all

site_query_id = (params[:site_id].to_s).to_i

if site_query_id > 0
@audio_recordings = AudioRecording.where(site_id: site_query_id).all

else
@audio_recordings = AudioRecording.all

end



respond_to do |format|
format.json { render json: @audio_recordings }
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/site_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SiteSerializer < CommonAttributesSerializer

has_many :projects, :serializer => ProjectsInSiteSerializer
has_many :photos, :serializer => PhotosInSiteSerializer
has_many :audio_recordings, :serializer => AudioRecordingsInSiteSerializer
#has_many :audio_recordings, :serializer => AudioRecordingsInSiteSerializer

end

Expand Down

0 comments on commit 1cf6b37

Please sign in to comment.