Skip to content

Commit

Permalink
General work for angular client.
Browse files Browse the repository at this point in the history
modified:   Gemfile
modified:   Gemfile.lock
modified:   app/assets/stylesheets/application.css
modified:   app/assets/javascripts/application.js
	-- added jquery-ui gem

modified:   app/assets/javascripts/angular/controllers/listen.js
modified:   app/assets/javascripts/angular/controllers/projects.js
new file:   app/assets/javascripts/angular/controllers/search.js
modified:   app/assets/javascripts/angular/directives/directives.js
modified:   app/assets/javascripts/angular/services/services.js
modified:   app/assets/javascripts/app.js
	-- general front end work. $rootScope refresh method added. Services refactored into services.js

modified:   app/assets/javascripts/controllers.js.erb
	-- removed parts of the file that aren't necessary. this file is kept only as an example

modified:   app/assets/javascripts/functions.js
	-- fixed bug, adding to global protoype caused error in other libraries.

deleted:    app/assets/javascripts/jasmine_examples/Player.js
deleted:    app/assets/javascripts/jasmine_examples/Song.js
	-- not used, removed

deleted:    app/assets/javascripts/bookmarks.js.coffee
deleted:    app/assets/javascripts/progresses.js.coffee
deleted:    app/assets/javascripts/saved_searches.js.coffee
	-- default scaffold stuff not used

modified:   app/assets/templates/home.html
modified:   app/assets/templates/listen.html
new file:   app/assets/templates/search_details.html
new file:   app/assets/templates/searches_index.html

modified:   app/views/layouts/application.html.erb
	-- added reload route link for quick refresh

modified:   config/routes.rb
	-- cleaned up / commented

deleted:    vendor/assets/javascripts/jQuery.jPlayer.2.2.0/Jplayer.swf
deleted:    vendor/assets/javascripts/jQuery.jPlayer.2.2.0/add-on/jplayer.playlist.min.js
deleted:    vendor/assets/javascripts/jQuery.jPlayer.2.2.0/add-on/jquery.jplayer.inspector.js
deleted:    vendor/assets/javascripts/jQuery.jPlayer.2.2.0/jquery.jplayer.min.js
deleted:    vendor/assets/javascripts/jQuery.jPlayer.2.2.0/popcorn/popcorn.jplayer.js
	-- removed jplayer - bot being used

new file:   vendor/assets/javascripts/select2-release-3.2/LICENSE
new file:   vendor/assets/javascripts/select2-release-3.2/README.md
new file:   vendor/assets/javascripts/select2-release-3.2/release.sh
new file:   vendor/assets/javascripts/select2-release-3.2/select2.css
new file:   vendor/assets/javascripts/select2-release-3.2/select2.js
new file:   vendor/assets/javascripts/select2-release-3.2/select2.min
new file:   vendor/assets/javascripts/select2-release-3.2/select2.png
new file:   vendor/assets/javascripts/select2-release-3.2/select2x2.png
new file:   vendor/assets/javascripts/select2-release-3.2/spinner.gif
modified:   app/assets/javascripts/application.js
	-- added select2 library
  • Loading branch information
atruskie committed Nov 22, 2012
1 parent 01473c8 commit 8c914eb
Show file tree
Hide file tree
Showing 34 changed files with 3,511 additions and 1,176 deletions.
33 changes: 18 additions & 15 deletions app/assets/javascripts/angular/controllers/listen.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";
/*
The listen controller. Show a spectrogram, listen to audio, annotate the spectrogram.
*/

function ListenCtrl($scope, $resource, $routeParams) {

var recordingResource = $resource('/audio_recordings/:recordingId', {recordingId: '@recordingId'}, {
get: { method:'GET', params:{recordingId: '@recordingId'}, isArray: false }
});
/**
* The listen controller. Show a spectrogram, listen to audio, annotate the spectrogram.
* @param $scope
* @param $resource
* @param $routeParams
* @param AudioRecording
* @param AudioEvent
* @constructor
*/
function ListenCtrl($scope, $resource, $routeParams, AudioRecording, AudioEvent) {

var recordingResource = AudioRecording
$scope.recording = recordingResource.get($routeParams);

// HACK:
Expand All @@ -20,12 +23,12 @@ function ListenCtrl($scope, $resource, $routeParams) {
$scope.spectrogram = spectrogramResource.get($routeParams);

// HACK:
$scope.spectrogram.url = "/media/1bd0d668-1471-4396-adc3-09ccd8fe949a_0_120_0_11025_512_g.png"
$scope.spectrogram.url = "/media/1bd0d668-1471-4396-adc3-09ccd8fe949a_0_120_0_11025_512_g.png";

var audioEventResource = $resource('/audio_events?by_audio_id=:recordingId', {recordingId: '@recordingId'}, {
get: { method:'GET', params:{recordingId: '@recordingId'}, isArray: true }
});
$scope.audio_events = audioEventResource.get($routeParams);
// var audioEventResource = $resource('/audio_events?by_audio_id=:recordingId', {recordingId: '@recordingId'}, {
// get:
// });
$scope.audio_events = AudioEvent.query({by_audio_id:$routeParams.recordingId});
$scope.event_keys = function () {
return Object.keys($scope.audio_events[0]);
}
Expand All @@ -40,4 +43,4 @@ function ListenCtrl($scope, $resource, $routeParams) {

}

ListenCtrl.$inject = ['$scope', '$resource', '$routeParams']
ListenCtrl.$inject = ['$scope', '$resource', '$routeParams', 'AudioRecording', 'AudioEvent'];
2 changes: 1 addition & 1 deletion app/assets/javascripts/angular/controllers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function ProjectCtrl($scope, $resource, $routeParams, Project) {
p.urn = this.project.urn;
p.description = this.project.description;
p.notes = this.project.notes;
p.sites = (this.project.sites || []).map(function(value) {return {id: value.id}});
p.site_ids = (this.project.sites || []).map(function(value) {return {id: value.id}});

projectResource.update(routeArgs, p, (function() {console.log("success update")}));
};
Expand Down
37 changes: 37 additions & 0 deletions app/assets/javascripts/angular/controllers/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";

function SearchesCtrl($scope, $resource, Search) {
// $scope.sitesResource = $resource('/sites', {}, { get: { method:'GET', params:{}, isArray: true }});
// $scope.sites = $scope.sitesResource.get();
}

SearchesCtrl.$inject = ['$scope', '$resource'];


function SearchCtrl($scope, $resource, Search) {
// $scope.sitesResource = $resource('/sites', {}, { get: { method:'GET', params:{}, isArray: true }});
// $scope.sites = $scope.sitesResource.get();

$scope.projects = [ {name: "demo", id: 6}, {name: "dddemo", id: 7}, {name: "ddaademo", id: 1}, {name: "desssdmo", id: 12}];
$scope.selectedProjects = [$scope.projects[0].id];

$scope.sites = [ {name: "fffff", id: 425}, {name: "ddddd", id: 587}, {name: "ssss", id: 374}, {name: "aaaaa", id: 175}];
$scope.selectedSites= [$scope.sites[0].id];

// $scope.tags = ...
$scope.selectedTags =[];

$scope.jobAnnotations = "Include";
$scope.referenceAnnotations = "Include";

$scope.startDate = undefined;
$scope.endDate = undefined;

// $scope.tags = ...
// $scope.audioRecordings = ...
$scope.selectedAudioRecordings =[];


}

SearchCtrl.$inject = ['$scope', '$resource'];
35 changes: 35 additions & 0 deletions app/assets/javascripts/angular/directives/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,41 @@
};
});

var GUID_REGEXP = /^\{?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}?$/i;
bawds.directive('isGuid', function() {
return {

require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
var isList = typeof attrs.ngList !== "undefined";

// push rather than unshift... we want to test last
ctrl.$parsers.push(function(viewValue) {
var valid = true;
if (isList) {
for(var i = 0; i < viewValue.length && valid; i++) {
valid = GUID_REGEXP.test(viewValue[i]);
}
}
else {
valid = GUID_REGEXP.test(viewValue);
}

if (valid) {
// it is valid
ctrl.$setValidity('isGuid', true);
return viewValue;
} else {
// it is invalid, return undefined (no model update)
ctrl.$setValidity('isGuid', false);
return undefined;
}
});
}
};
});


})();

//bawApp.directive('nsDsFade', function() {
Expand Down
59 changes: 24 additions & 35 deletions app/assets/javascripts/angular/services/services.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
/* http://docs.angularjs.org/#!angular.service */

//angular.service('Photographers', function($resource) {
// return $resource('photographers/:photographer_id', {},
// { 'index': { method: 'GET', isArray: true }});
//});
//
//angular.service('Galleries', function($resource) {
// return $resource('photographers/:photographer_id/galleries/:gallery_id', {},
// { 'index': { method: 'GET', isArray: true }});
//});
//
//angular.service('Photos', function($resource) {
// return $resource('photographers/:photographer_id/galleries/:gallery_id/photos', {},
// { 'index': { method: 'GET', isArray: true }});
//});
//
//angular.service('SelectedPhotos', function($resource) {
// return $resource('selected_photos/:selected_photo_id', {},
// { 'create': { method: 'POST' },
// 'index': { method: 'GET', isArray: true },
// 'update': { method: 'PUT' },
// 'destroy': { method: 'DELETE' }});
//});


(function() {
/**
* Helper method for adding a put request onto the standard angular resource service
* @param $resource - the stub resource
* @param {string} path - the webserver path
* @param {Object} paramDefaults
* @param {Object} [actions] a set of actions to also add (extend)
* @return {*}
*/
function resourcePut($resource, path, paramDefaults, actions) {
var a = actions || {};
a.update = {method: 'PUT'};
a.update = a.update || {method: 'PUT'};
return $resource(path, paramDefaults, a);
}

var bawss = angular.module("baw.services", ['ngResource']);

//function addPut

/**
*
*/
bawss.factory('Project', function($resource) {
return resourcePut($resource, '/projects/:projectId', {projectId: "@projectId"});
});

// var projectResource = $resource('/projects/:projectId', {projectId: '@id'}, {
// get: { method:'GET', params:{projectId: '@id'}, isArray: false }
// });
//
// baws.factory('projects', function(){
// var projectsService;
//
// return projectsService;
// });
bawss.factory('AudioRecording', function($resource) {
return resourcePut($resource, '/audio_recordings/:recordingId', {recordingId: '@recordingId'});
});

bawss.factory('AudioEvent', function($resource) {
var actions = {
query: { method:'GET', isArray: true }
};
return resourcePut($resource, '/audio_events', actions);
});


})();
84 changes: 70 additions & 14 deletions app/assets/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,56 @@

/* App Module */

var bawApp = angular.module('baw',
// global definition
var bawApp = (function() {
// Helper function


function whenDefaults(resourceName, singularResourceName, id, controllerMany, controllerOne, addManageView) {
var path = "/" + resourceName;
var detailsPath = path + "/" + id;
var asset = "/assets/" + resourceName + "_index.html";
var asset_details ="/assets/" + singularResourceName + "_details.html";

return this
// many
.when(path, {templateUrl: asset, controller: controllerMany})
// manage
.fluidIf(addManageView, function(){
this.when(path + "/manage", {templateUrl: asset.replace("index.html", "manager.html"), controller: controllerMany})
})
// details
.when(detailsPath, {templateUrl: asset_details, controller: controllerOne})
// create
.when(path + "/create", {templateUrl: asset_details, controller: controllerOne})
// edit
.when(detailsPath + "/:editing" , {templateUrl: asset_details, controller: controllerOne})
;
}

var app = angular.module('baw',
[
'ngResource',
'ui.directives', /* angular-ui project */
'ui.filters', /* angular-ui project */
'bawApp.directives', /* our directives.js */
'bawApp.filters', /* our filters.js */
'baw.services' /* our services.js */
],
function ($routeProvider, $locationProvider) {
]);

app.config(function ($routeProvider, $locationProvider) {
$routeProvider.whenDefaults = whenDefaults;
$routeProvider.fluidIf = fluidIf;

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

when('/projects', {templateUrl: '/assets/projects_index.html', controller: ProjectCtrl}).
when('/projects/manage', {templateUrl: '/assets/projects_manager.html', controller: ProjectsCtrl}).
when('/projects/:projectId', {templateUrl: '/assets/project_details.html', controller: ProjectsCtrl}).
when('/projects/:projectId/:editing', {templateUrl: '/assets/project_details.html', controller: ProjectsCtrl}).
// when('/projects', {templateUrl: '/assets/projects_index.html', controller: ProjectCtrl}).
// when('/projects/manage', {templateUrl: '/assets/projects_manager.html', controller: ProjectsCtrl}).
// when('/projects/:projectId', {templateUrl: '/assets/project_details.html', controller: ProjectsCtrl}).
// when('/projects/:projectId/:editing', {templateUrl: '/assets/project_details.html', controller: ProjectsCtrl}).
whenDefaults("projects", "project", ":projectId", ProjectsCtrl, ProjectCtrl, true).

when('/sites', {templateUrl: '/assets/sites.html', controller: SitesCtrl }).
when('/sites/:siteId', {templateUrl: '/assets/site.html', controller: SiteCtrl }).
Expand All @@ -34,17 +65,26 @@ var bawApp = angular.module('baw',
when('/listen', {templateUrl: '/assets/listen.html', controller: ListenCtrl}).
when('/listen/:recordingId', {templateUrl: '/assets/listen.html', controller: ListenCtrl}).

whenDefaults("searches", "search", ":searchId", SearchesCtrl, SearchCtrl, true).
when('/search', {templateUrl: '/assets/search_details.html', controller: SearchCtrl}).

//when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
when('/', {templateUrl: '/assets/home.html', controller: HomeCtrl}).
when('/404',{controller : ErrorCtrl}).
otherwise({redirectTo: '/404'});
when('/404?path=:errorPath',{controller : ErrorCtrl}).
otherwise(
{redirectTo: function(params, location, search) {
return '/404?path=' + location;
}
});

// location config
$locationProvider.html5Mode(true);


})
.run(['$rootScope','$location', function ($rootScope) {
});

app.run(['$rootScope','$location', '$route', function ($rootScope, $location, $route) {
$rootScope.print = function () {
var seen = [];
var badKeys = ["$digest", "$$watchers", "$$childHead", "$$childTail", "$$listeners", "$$nextSibling", "$$prevSibling", "$root", "this", "$parent"];
Expand Down Expand Up @@ -79,10 +119,26 @@ var bawApp = angular.module('baw',
};

$rootScope.$on("$routeChangeError", function (event, current, previous, rejection) {
console.warn("route changing has failed... handle me some how")
console.warn("route changing has failed... handle me some how");
//change this code to handle the error somehow
$location.path('/404').replace();
$location.path('/404/' + $location.path);
});

}])
;
// reload a view and controller (shortcut for full page refresh)
$rootScope.$reloadView = function(){
$route.reload();
};

// STANDARD DATE FORMAT
$rootScope.dateOptions = {
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd",
duration: "fast",
yearRange: "1800:3000"

};

}]);

})();
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.ui.datepicker
//= require angular.js
//= require angular-resource.js
//= require angular-ui.js
//= require angular-ui-ieshiv.js
//= require_tree .
//= require_tree ../../../vendor/assets/javascripts/.
//= require app

3 changes: 0 additions & 3 deletions app/assets/javascripts/bookmarks.js.coffee

This file was deleted.

Loading

0 comments on commit 8c914eb

Please sign in to comment.