diff --git a/app/assets/javascripts/angular/controllers/listen.js b/app/assets/javascripts/angular/controllers/listen.js index 68c19a46..c040cbc5 100644 --- a/app/assets/javascripts/angular/controllers/listen.js +++ b/app/assets/javascripts/angular/controllers/listen.js @@ -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: @@ -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]); } @@ -40,4 +43,4 @@ function ListenCtrl($scope, $resource, $routeParams) { } -ListenCtrl.$inject = ['$scope', '$resource', '$routeParams'] \ No newline at end of file +ListenCtrl.$inject = ['$scope', '$resource', '$routeParams', 'AudioRecording', 'AudioEvent']; \ No newline at end of file diff --git a/app/assets/javascripts/angular/controllers/projects.js b/app/assets/javascripts/angular/controllers/projects.js index 81a1ef31..36fce88a 100644 --- a/app/assets/javascripts/angular/controllers/projects.js +++ b/app/assets/javascripts/angular/controllers/projects.js @@ -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")})); }; diff --git a/app/assets/javascripts/angular/controllers/search.js b/app/assets/javascripts/angular/controllers/search.js new file mode 100644 index 00000000..3631bbce --- /dev/null +++ b/app/assets/javascripts/angular/controllers/search.js @@ -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']; diff --git a/app/assets/javascripts/angular/directives/directives.js b/app/assets/javascripts/angular/directives/directives.js index a8180317..2839ffcc 100644 --- a/app/assets/javascripts/angular/directives/directives.js +++ b/app/assets/javascripts/angular/directives/directives.js @@ -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() { diff --git a/app/assets/javascripts/angular/services/services.js b/app/assets/javascripts/angular/services/services.js index 9dc9bcfd..cd26e1a1 100644 --- a/app/assets/javascripts/angular/services/services.js +++ b/app/assets/javascripts/angular/services/services.js @@ -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); + }); + })(); \ No newline at end of file diff --git a/app/assets/javascripts/app.js b/app/assets/javascripts/app.js index 3cdb8893..4ef7438b 100644 --- a/app/assets/javascripts/app.js +++ b/app/assets/javascripts/app.js @@ -2,7 +2,34 @@ /* 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 */ @@ -10,17 +37,21 @@ var bawApp = angular.module('baw', '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 }). @@ -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"]; @@ -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" + + }; + + }]); + +})(); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f4a040d6..54a3815e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -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 diff --git a/app/assets/javascripts/bookmarks.js.coffee b/app/assets/javascripts/bookmarks.js.coffee deleted file mode 100644 index 76156794..00000000 --- a/app/assets/javascripts/bookmarks.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/controllers.js.erb b/app/assets/javascripts/controllers.js.erb index b8c703f3..e39b3b6b 100644 --- a/app/assets/javascripts/controllers.js.erb +++ b/app/assets/javascripts/controllers.js.erb @@ -21,45 +21,3 @@ // {template: '<%= asset_path("photos.html") %>', controller: PhotosCtrl}); // // $route.otherwise({redirectTo: '/photographers'}); -//} -//PhotoGalleryCtrl.$inject = ['$route', '$http']; -// -//function PhotographersCtrl(Photographers) { -// this.photographers = Photographers.index(); -//} -//PhotographersCtrl.$inject = ['Photographers']; -// -//function GalleriesCtrl(Galleries, Photographers, $routeParams) { -// this.photographer = Photographers.get({ photographer_id: $routeParams.photographer_id }); -// this.galleries = Galleries.index({ photographer_id: $routeParams.photographer_id }); -//} -//GalleriesCtrl.$inject = ['Galleries', 'Photographers', '$routeParams']; -// -//function PhotosCtrl(Photos, Galleries, Photographers, SelectedPhotos, $routeParams) { -// var self = this; -// -// self.photographer = Photographers.get({ photographer_id: $routeParams.photographer_id }); -// self.gallery = Galleries.get({ photographer_id: $routeParams.photographer_id, gallery_id: $routeParams.gallery_id }); -// self.photos = Photos.index({ photographer_id: $routeParams.photographer_id, gallery_id: $routeParams.gallery_id }); -// self.selected_photos = SelectedPhotos.index(); -// -// -// self.selectPhoto = function(photo) { -// var selected_photo = new SelectedPhotos({ selected_photo: { photo_id: photo.id } }); -// selected_photo.$create(function() { -// self.selected_photos.push(selected_photo); -// }); -// } -// -// self.deleteSelectedPhoto = function(selected_photo) { -// angular.Array.remove(self.selected_photos, selected_photo); -// selected_photo.$destroy({ selected_photo_id: selected_photo.id }); -// } -// -// self.saveSelectedPhoto = function(selected_photo) { -// selected_photo.$update({ selected_photo_id: selected_photo.id }); -// $('input').blur(); -// } -// -//} -//PhotosCtrl.$inject = ['Photos', 'Galleries', 'Photographers', 'SelectedPhotos', '$routeParams']; diff --git a/app/assets/javascripts/functions.js b/app/assets/javascripts/functions.js index 1fbaafb7..e1a57eb4 100644 --- a/app/assets/javascripts/functions.js +++ b/app/assets/javascripts/functions.js @@ -1,9 +1,9 @@ -/* - - http://www.isurinder.com/blog/post/2011/04/02/StringFormat-In-JavaScript.aspx#.UKWRyvgzpQs +/** + * String format function + * http://www.isurinder.com/blog/post/2011/04/02/StringFormat-In-JavaScript.aspx#.UKWRyvgzpQs + * @type {Function} */ - String.format = String.prototype.format = function() { var i=0; var string = (typeof(this) == "function" && !(i++)) ? arguments[0] : this; @@ -12,4 +12,23 @@ String.format = String.prototype.format = function() { string = string.replace(/\{\d+?\}/, arguments[i]); return string; -} \ No newline at end of file +}; + +/** + * Chainable if statement + * @param test - the test that is evaluated + * @param {Function} truthyAction - the function to run if the test is truthy + * @param {Function} falseyAction - the function to run if the test id falsey + * @returns {Object} returns 'this' + */ +function fluidIf(test, truthyAction, falseyAction){ + if (test) { + return truthyAction.call(this) || this; + } + + if (falseyAction) { + return falseyAction.call(this) || this; + } + + return this; +}; \ No newline at end of file diff --git a/app/assets/javascripts/jasmine_examples/Player.js b/app/assets/javascripts/jasmine_examples/Player.js deleted file mode 100644 index fcce8268..00000000 --- a/app/assets/javascripts/jasmine_examples/Player.js +++ /dev/null @@ -1,22 +0,0 @@ -function Player() { -} -Player.prototype.play = function(song) { - this.currentlyPlayingSong = song; - this.isPlaying = true; -}; - -Player.prototype.pause = function() { - this.isPlaying = false; -}; - -Player.prototype.resume = function() { - if (this.isPlaying) { - throw new Error("song is already playing"); - } - - this.isPlaying = true; -}; - -Player.prototype.makeFavorite = function() { - this.currentlyPlayingSong.persistFavoriteStatus(true); -}; \ No newline at end of file diff --git a/app/assets/javascripts/jasmine_examples/Song.js b/app/assets/javascripts/jasmine_examples/Song.js deleted file mode 100644 index a8a3f2dd..00000000 --- a/app/assets/javascripts/jasmine_examples/Song.js +++ /dev/null @@ -1,7 +0,0 @@ -function Song() { -} - -Song.prototype.persistFavoriteStatus = function(value) { - // something complicated - throw new Error("not yet implemented"); -}; \ No newline at end of file diff --git a/app/assets/javascripts/progresses.js.coffee b/app/assets/javascripts/progresses.js.coffee deleted file mode 100644 index 76156794..00000000 --- a/app/assets/javascripts/progresses.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/saved_searches.js.coffee b/app/assets/javascripts/saved_searches.js.coffee deleted file mode 100644 index 76156794..00000000 --- a/app/assets/javascripts/saved_searches.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 15aca45c..bedbbd18 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -9,5 +9,7 @@ * compiled file, but it's generally better to create a new file per style scope. * *= require_self + *= require jquery.ui.all + *= require_tree ../../../vendor/assets/javascripts/. *= require_tree . */ \ No newline at end of file diff --git a/app/assets/templates/home.html b/app/assets/templates/home.html index 953833f7..8025251e 100644 --- a/app/assets/templates/home.html +++ b/app/assets/templates/home.html @@ -11,5 +11,10 @@

Welcome

Listen Listen2 +

+ New search + Saved searches +

+ \ No newline at end of file diff --git a/app/assets/templates/listen.html b/app/assets/templates/listen.html index 52a7f9e1..ee46c1e6 100644 --- a/app/assets/templates/listen.html +++ b/app/assets/templates/listen.html @@ -13,8 +13,8 @@

Spectrogram

Audio Controls

-