Skip to content

Commit

Permalink
Changes to serializers. Work on Projects page. Page styling work.
Browse files Browse the repository at this point in the history
modified:   app/assets/javascripts/angular/controllers/projects.js
modified:   app/assets/javascripts/angular/directives/directives.js
modified:   app/assets/javascripts/angular/services/angularjs-rails-resource.js
modified:   app/assets/javascripts/angular/services/services.js
modified:   app/assets/stylesheets/_layout.css.scss
modified:   app/assets/templates/listen.html
modified:   app/assets/templates/project_details.html
modified:   app/controllers/api/callbacks_controller.rb
modified:   app/controllers/projects_controller.rb
modified:   app/models/project.rb
modified:   app/serializers/analysis_item_serializer.rb
modified:   app/serializers/analysis_job_serializer.rb
modified:   app/serializers/analysis_script_serializer.rb
modified:   app/serializers/audio_event_serializer.rb
modified:   app/serializers/audio_event_tag_serializer.rb
modified:   app/serializers/audio_recording_serializer.rb
modified:   app/serializers/common_attributes.rb
new file:   app/serializers/project_serializer.rb
new file:   app/serializers/site_serializer.rb
  • Loading branch information
Mark Cottman-Fields committed Dec 19, 2012
1 parent e7aa3d3 commit c4d227f
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 31 deletions.
10 changes: 7 additions & 3 deletions app/assets/javascripts/angular/controllers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function ProjectCtrl($scope, $resource, $routeParams, Project) {
});



$scope.links = {};

$scope.delete = function() {
Expand All @@ -61,9 +60,14 @@ function ProjectCtrl($scope, $resource, $routeParams, Project) {
p.urn = this.project.urn;
p.description = this.project.description;
p.notes = this.project.notes;
p.site_ids = (this.project.sites || []).map(function(value) {return {id: value.id}});
p.site_ids = (this.project.sites || []).map(function(value) {return value.id} );

// validation
if(!p.name){

}

projectResource.update(routeArgs, p, (function() {console.log("success update")}));
projectResource.update(routeArgs, p, function() {console.log("success update")}, function() { console.log("failed update")} );
};

}
Expand Down
15 changes: 14 additions & 1 deletion app/assets/javascripts/angular/directives/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,25 @@

bawds.directive('bawJsonBinding', function () {



return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attr, ngModel) {

ngModel.$parsers.push(angular.fromJson);
function catchParseErrors(viewValue){
try{
var result = angular.fromJson(viewValue);
}catch(e){
ngModel.$setValidity('bawJsonBinding',false);
return '';
}
ngModel.$setValidity('bawJsonBinding',true);
return result;
}

ngModel.$parsers.push(catchParseErrors);
ngModel.$formatters.push(angular.toJson)
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ angular.module('rails', [])

if ((headers()["Accept"] || "").indexOf("application/json") >= 0) {

if (data === undefined || data === null || !angular.isObject(data)) {
if (data === undefined || data === null){
return;
}

if (!angular.isObject(data)) {
return data;
}

transformObject(data, underscore);

stampObject(data, "camelCased->underscore");
Expand All @@ -103,7 +107,7 @@ angular.module('rails', [])
function (response) {
console.log("rails field naming interceptor, promise failed function", response);

return p.reject(response);
return response;//p.reject(response);
});
return p;
});
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/angular/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
function resourcePut($resource, path, paramDefaults, actions) {
var a = actions || {};
a.update = a.update || {method: 'PUT'};
a.update = a.update || { method: 'PUT' };
return $resource(path, paramDefaults, a);
}

Expand Down
20 changes: 19 additions & 1 deletion app/assets/stylesheets/_layout.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ header {
& ul {
list-style-type: none;
float: right;
line-height:60px;
line-height:40px;
margin: 0 15px 0 0;
& li {
display: inline-block;
Expand Down Expand Up @@ -251,4 +251,22 @@ body:before {

.select2-container {
min-width: 150px;
}

/* Validation Styles
--------------------------------------------------------------------------------*/
input.ng-invalid.ng-dirty, textarea.ng-invalid.ng-dirty {
background-color: #FA787E;
}

input.ng-valid.ng-dirty, textarea.ng-valid.ng-dirty {
background-color: #78FA89;
}

input.ng-pristine.ng-valid, textarea.ng-pristine.ng-valid {
background-color: #e4e4e4;
}

input.ng-pristine.ng-invalid, textarea.ng-pristine.ng-invalid {
background-color: #f7c0c0;
}
8 changes: 4 additions & 4 deletions app/assets/templates/listen.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ <h3>

<label>
<span>Duration (seconds)</span></label>
<input type="text" min="{{limits.timeMin}}" max="{{limits.timeMax}}" required
<input type="number" min="{{limits.timeMin}}" max="{{limits.timeMax}}" required
ng-model="selectedAnnotation.startTimeSeconds"/>
&nbsp;to&nbsp;
<input type="text" min="{{limits.timeMin}}" max="{{limits.timeMax}}" required
<input type="number" min="{{limits.timeMin}}" max="{{limits.timeMax}}" required
ng-model="selectedAnnotation.endTimeSeconds"/>

<label>
<span>Frequency</span> </label>
<input type="text" min="{{limits.freqMin}}" max="{{limits.freqMax}}" required
<input type="number" min="{{limits.freqMin}}" max="{{limits.freqMax}}" required
ng-model="selectedAnnotation.lowFrequencyHertz"/>
&nbsp;to&nbsp;
<input type="text" min="{{limits.freqMin}}" max="{{limits.freqMax}}" required
<input type="number" min="{{limits.freqMin}}" max="{{limits.freqMax}}" required
ng-model="selectedAnnotation.highFrequencyHertz"/>


Expand Down
5 changes: 2 additions & 3 deletions app/assets/templates/project_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ <h3>Sites</h3>
</div>
<div ng-show="editing">
<form id="project_edit_form">

<label>
<span>Name</span>
<input type="text" ng-model="project.name">
<input type="text" ng-model="project.name" required maxlength="50">
</label>
<label>
<span>Urn</span>
<span ng-bind="project.urn"></span>
</label>
<label>
<span>Description</span>
<textarea spellcheck ng-model="project.description" ></textarea>
<textarea spellcheck ng-model="project.description"></textarea>
</label>
<label>
<span>Notes</span>
Expand Down
1 change: 0 additions & 1 deletion app/controllers/api/callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def failure
def success_complete(canonical_data)
displayed_data = '<p>Login successful. Please <a href="#" onclick="javascript:closeWindow();return false;">close</a> this window.</p>'


user = store_provider_info(canonical_data, current_user)

sign_in(user, :event => :authentication)
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ class ProjectsController < ApplicationController
# GET /projects
# GET /projects.json
def index
@projects = Project.includes(:sites, :photos)
@projects = Project.all

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

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

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

# GET /projects/new
# GET /projects/new.json
def new
@project = Project.new
@project.sites.build
@all_sites = Site.all
@project.sites.build
@all_sites = Site.all

respond_to do |format|
format.html # new.html.erb
Expand Down
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Project < ActiveRecord::Base

# validation
validates :name, :presence => true, :uniqueness => { :case_sensitive => false }
validates :urn, :presence => true
validates :urn, :presence => true, :uniqueness => { :case_sensitive => false }

# commonly used queries (these return
# ActiveRecord::Relation object which will allow for
Expand Down
7 changes: 5 additions & 2 deletions app/serializers/analysis_item_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'common_attributes'

class AnalysisItemSerializer < ActiveModel::Serializer
attributes :id, :worker_info, :worker_started_utc, :worker_run_details, :status, :offset_start_seconds, :offset_end_seconds
class AnalysisItemSerializer < CommonAttributesSerializer
attributes :id, :worker_info, :worker_started_utc,
:worker_run_details, :status, :offset_start_seconds,
:offset_end_seconds

#has_one :audio_recording

Expand Down
7 changes: 5 additions & 2 deletions app/serializers/analysis_job_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'common_attributes'

class AnalysisJobSerializer < ActiveModel::Serializer
attributes :id, :name, :description, :notes, :script_name, :script_version, :script_description, :script_settings, :script_display_name, :script_extra_data, :data_set_identifier
class AnalysisJobSerializer < CommonAttributesSerializer
attributes :id, :name, :description, :notes, :script_name,
:script_version, :script_description, :script_settings,
:script_display_name, :script_extra_data, :data_set_identifier

#has_one :saved_search

Expand Down
3 changes: 2 additions & 1 deletion app/serializers/analysis_script_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'common_attributes'

class AnalysisScriptSerializer < ActiveModel::Serializer
class AnalysisScriptSerializer < CommonAttributesSerializer
attributes :id, :name, :version, :description, :settings, :display_name, :extra_data

end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/audio_event_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'common_attributes'
require 'audio_event_serializer'

class AudioRecordingIdsSerializer < ActiveModel::Serializer
class AudioRecordingIdsSerializer < CommonAttributesSerializer
attributes :id, :uuid
end

Expand Down
1 change: 1 addition & 0 deletions app/serializers/audio_event_tag_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'common_attributes'

class AudioEventTagSerializer < CommonAttributesSerializer
attributes :audio_event_id, :tag_id
Expand Down
2 changes: 0 additions & 2 deletions app/serializers/audio_recording_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
require 'common_attributes'


class AudioRecordingSerializer < CommonAttributesSerializer
attributes :bit_rate_bps, :channels, :data_length_bytes,
:duration_seconds, :file_hash, :media_type, :notes,
:recorded_date, :sample_rate_hertz, :status, :uploader_id,
:site_id, :uuid, :id


end


16 changes: 16 additions & 0 deletions app/serializers/common_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,21 @@ def include_deleted_at?
def include_deleter_id?
object.respond_to? :deleted_id
end

def include_updated_at?
object.respond_to? :updated_at
end

def include_updater_id?
object.respond_to? :updater_id
end

def include_created_at
object.respond_to? :created_at
end

def include_creator_id?
object.respond_to? :creator_id
end
end

16 changes: 16 additions & 0 deletions app/serializers/project_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'common_attributes'

class SitesInProjectSerializer < CommonAttributesSerializer
attributes :id, :name
end

class PhotosInProjectSerializer < CommonAttributesSerializer
attributes :id, :description, :uri, :copyright
end

class ProjectSerializer < CommonAttributesSerializer
attributes :id, :name, :description, :urn, :notes

has_many :sites, :serializer => SitesInProjectSerializer
has_many :photos, :serializer => PhotosInProjectSerializer
end
6 changes: 6 additions & 0 deletions app/serializers/site_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'common_attributes'

class SiteSerializer < CommonAttributesSerializer
attributes :id, :name, :latitude, :longitude, :notes

end

0 comments on commit c4d227f

Please sign in to comment.