From 75beec91a8526fbbc0a90134140b9dff6af15c0c Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Sun, 28 Dec 2014 12:24:22 +0000 Subject: Initial frontend work --- static/scripts/app/app.js | 63 ++++++++++++++++ static/scripts/app/controllers.js | 148 ++++++++++++++++++++++++++++++++++++++ static/scripts/app/filters.js | 48 +++++++++++++ static/scripts/app/services.js | 97 +++++++++++++++++++++++++ 4 files changed, 356 insertions(+) create mode 100644 static/scripts/app/app.js create mode 100644 static/scripts/app/controllers.js create mode 100644 static/scripts/app/filters.js create mode 100644 static/scripts/app/services.js (limited to 'static/scripts') diff --git a/static/scripts/app/app.js b/static/scripts/app/app.js new file mode 100644 index 0000000..b0d3738 --- /dev/null +++ b/static/scripts/app/app.js @@ -0,0 +1,63 @@ +var mach2App = angular.module( + 'mach2App', + [ + 'ui.router', + 'mach2Services', + 'mach2Controllers', + 'mach2Filters', + 'ui.bootstrap', + 'angularMoment' + ] +); + +mach2App.config( + [ + '$stateProvider', + '$urlRouterProvider', + function($stateProvider, $urlRouterProvider) { + $stateProvider.state('artists', { + url: '/artists', + templateUrl: 'static/partials/artists/list.html', + controller: 'ArtistCtrl', + }); + + $stateProvider.state('artistdetail', { + url: '/artists/{artistId:int}', + templateUrl: 'static/partials/artists/detail.html', + controller: 'ArtistDetailCtrl', + resolve: { + artistId: ['$stateParams', function($stateParams) { + return $stateParams.artistId; + }] + }, + }); + + $stateProvider.state('artistdetail.tracks', { + url: '/tracks', + templateUrl: 'static/partials/artists/tracks.html', + controller: 'ArtistTracksCtrl' + }); + + $stateProvider.state('albums', { + url: '/albums', + templateUrl: 'static/partials/albums/list.html', + controller: 'AlbumCtrl' + }); + + $stateProvider.state('albums.detail', { + url: '/{albumId:int}', + templateUrl: 'static/partials/album/detail.html', + controller: 'AlbumDetailCtrl' + }); + + $urlRouterProvider.otherwise('/artists'); + } + ] +); + +mach2App.constant( + 'angularMomentConfig', + { + timezone: 'utc' + } +); \ No newline at end of file diff --git a/static/scripts/app/controllers.js b/static/scripts/app/controllers.js new file mode 100644 index 0000000..35340e6 --- /dev/null +++ b/static/scripts/app/controllers.js @@ -0,0 +1,148 @@ +var mach2Controllers = angular.module( + 'mach2Controllers', + [ + 'ui.bootstrap', + 'angularMoment' + ] +); + +mach2Controllers.controller('NavCtrl', ['$scope', function($scope) { +}]); + +mach2Controllers.controller( + 'ArtistCtrl', + [ + '$scope', + 'ArtistSearch', + function($scope, ArtistSearch) { + $scope.totalArtists = ArtistSearch.query(); + $scope.indices = [ + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + '0-9', + 'Other' + ]; + $scope.selectedIndex = $scope.indices[0]; + } + ] +); + +mach2Controllers.controller( + 'ArtistDetailCtrl', + [ + '$scope', + '$stateParams', + 'Artist', + 'ArtistAlbums', + 'ArtistTracks', + function( + $scope, + $stateParams, + Artist, + ArtistAlbums, + ArtistTracks + ) { + console.log('Am I here?'); + $scope.artist = Artist.query({ + artistId: $stateParams.artistId + }); + + $scope.albums = ArtistAlbums.query({ + artistId: $stateParams.artistId + }); + + $scope.tracks = ArtistTracks.query({ + artistId: $stateParams.artistId + }); + } + ] +); + +mach2Controllers.controller( + 'ArtistTracksCtrl', + [ + '$scope', + '$stateParams', + 'Artist', + 'ArtistTracks', + function($scope, $stateParams, Artist, ArtistTracks) { + $scope.artist = Artist.query({ + artistId: $stateParams.artistId + }); + + $scope.tracks = ArtistTracks.query({ + artistId: $stateParams.artistId + }); + } + ] +); + +mach2Controllers.controller( + 'AlbumCtrl', + [ + '$scope', + 'AlbumArtists', + 'AlbumSearch', + function($scope, AlbumArtists, AlbumSearch) { + // horrible way of calculating decades + var currentYear = moment().format('YYYY'); + var startDecade = 1940; + + var decades = []; + + for (i = (startDecade/10); i <= (currentYear/10); i++) { + decades.push(i * 10); + } + + $scope.albums = AlbumSearch.query(); + $scope.indices = decades; + $scope.selectedIndex = $scope.indices[0]; + $scope.albumArtists = AlbumArtists; + } + ] +); + +mach2Controllers.controller( + 'AlbumDetailCtrl', + [ + '$scope', + '$stateParams', + 'Album', + 'AlbumTracks', + function( + $scope, + $stateParams, + Album, + AlbumTracks + ) { + + } + ] +); + +mach2Controllers.controller('TrackCtrl', ['$scope', function($scope) { +}]); diff --git a/static/scripts/app/filters.js b/static/scripts/app/filters.js new file mode 100644 index 0000000..ed1f537 --- /dev/null +++ b/static/scripts/app/filters.js @@ -0,0 +1,48 @@ +var mach2Filters = angular.module('mach2Filters',[]); + +mach2Filters.filter('alphabetFilter', function() { + return function(items, search) { + if (!search) { + return items; + } + + return items.filter(function(element, index, array) { + var searchTerm = search.param; + var searchAttrs = search.attrs; + var regexp = new RegExp(searchTerm, 'i'); + + var searchString = null; + + for(i = 0; i < searchAttrs.length; i++) { + if (element[searchAttrs[i]]) { + searchString = element[searchAttrs[i]]; + break; + } + } + + if (searchTerm === '0-9') { + regexp = /[0-9]/; + } else if (searchTerm === 'Other') { + regexp = /\W/; + } + + if (searchString.charAt(0).match(regexp) !== null) { + return true; + } else { + return false; + } + }); + }; +}); + +mach2Filters.filter('dateFilter', function() { + return function(items, search) { + return items.filter(function(element, index, array) { + var albumDate = moment(element.date, 'YYYY-MM-DD'); + var compDate = moment(search, 'YYYY'); + var compNextDate = moment((parseInt(search) + 10), 'YYYY'); + + return (albumDate.isAfter(compDate) && albumDate.isBefore(compNextDate)); + }); + }; +}); \ No newline at end of file diff --git a/static/scripts/app/services.js b/static/scripts/app/services.js new file mode 100644 index 0000000..c7cd92b --- /dev/null +++ b/static/scripts/app/services.js @@ -0,0 +1,97 @@ +var mach2Services = angular.module('mach2Services', ['ngResource']); + +mach2Services.factory('Artist', ['$resource', function($resource) { + return $resource('artists/:artistId', {}, { + query: { + method: 'GET' + } + }); +}]); + +mach2Services.factory('ArtistAlbums', ['$resource', function($resource) { + return $resource('artists/:artistId/albums', {}, { + query: { + method: 'GET', + isArray: true + } + }); +}]); + +mach2Services.factory('ArtistSearch', ['$resource', function($resource) { + return $resource('artists/:name', {}, { + query: { + method: 'GET', + isArray: true + } + }); +}]); + +mach2Services.factory('ArtistTracks', ['$resource', function($resource) { + return $resource('artists/:artistId/tracks', {}, { + query: { + method: 'GET', + isArray: true + } + }); +}]); + +mach2Services.factory('Album', ['$resource', function($resource) { + return $resource('albums/:albumId', {}, { + query: { + method: 'GET' + } + }); +}]); + +mach2Services.factory('AlbumArtists', ['$resource', function($resource) { + return $resource('albums/:albumId/artists', {}, { + query: { + method: 'GET', + isArray: true + } + }); +}]); + +mach2Services.factory('AlbumSearch', ['$resource', function($resource) { + return $resource('albums/:name', {}, { + query: { + method: 'GET', + isArray: true, + } + }); +}]); + +mach2Services.factory('AlbumTracks', ['$resource', function($resource) { + return $resource('albums/:albumId/tracks', {}, { + query: { + method: 'GET', + isArray: true + } + }); +}]); + +mach2Services.factory('Track', ['$resource', function($resource) { + return $resource('tracks/:trackId', {}, { + query: { + method: 'GET' + } + }); +}]); + +mach2Services.factory('TrackArtists', ['$resource', function($resource) { + return $resource('tracks/:trackId/artists', {}, { + query: { + method: 'GET' + } + }); +}]); + + +mach2Services.factory('TrackSearch', ['$resource', function($resource) { + return $resource('tracks/:name', {}, { + query: { + method: 'GET', + isArray: true + } + }); +}]); -- cgit v1.2.3