From 343cd2554a7baf8dc21723f3d7efb43b740c6708 Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Thu, 9 Feb 2017 19:38:38 -0800 Subject: [PATCH 001/116] Add domain and clientID and set name and email to localStorage --- client/main/toggle.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/main/toggle.js b/client/main/toggle.js index 0a0a0f8..eb3d1fc 100644 --- a/client/main/toggle.js +++ b/client/main/toggle.js @@ -1,8 +1,8 @@ var app = angular.module('gameMon.toggle', ['auth0']) .config(function(authProvider){ authProvider.init({ - domain: 'towering-cranes.auth0.com', - clientID: 'QfGpmdzDtxUhduPejeKN8P1TadDU8OqG' + domain: 'modern-grasshoppers.auth0.com', + clientID: 'bJt92FUnqvxDiGCEwjp107bav3XB4Ek6' }); }).run(function(auth){ auth.hookEvents(); @@ -12,6 +12,9 @@ app.controller('LoginController', function(auth, $scope, $location, $http, $wind $rootScope.isLoggedIn = localStorage.getItem('profile') ? true : false; $scope.login = function(){ auth.signin({}, function(profile, idToken, accessToken) { + console.log(profile); + localStorage.setItem('name', profile.nickname); + localStorage.setItem('email', profile.email); localStorage.setItem('profile', profile.user_id); localStorage.setItem('token', accessToken); $rootScope.isLoggedIn = true; @@ -28,4 +31,4 @@ app.controller('LoginController', function(auth, $scope, $location, $http, $wind localStorage.removeItem('token'); $window.location.href = 'https://towering-cranes.auth0.com/v2/logout?returnTo=http%3A%2F%2F138.68.224.84'; } -}); \ No newline at end of file +}); From c19b794f24b61e560690423ef123c6905659b8fa Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Thu, 9 Feb 2017 19:40:00 -0800 Subject: [PATCH 002/116] Add auth0 dependencies --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 31921cb..63996e1 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ }, "dependencies": { "angular": "^1.6.1", + "angular-jwt": "^0.1.9", + "angular-lock": "^1.0.5", "angular-materialize": "^0.2.2", "angular-route": "^1.6.1", "body-parser": "^1.16.0", From 547a1bea55a6854e297de6860ff08511a1340282 Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Thu, 9 Feb 2017 19:42:54 -0800 Subject: [PATCH 003/116] Create nickname and email properties to User schema. --- server/database/db.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/database/db.js b/server/database/db.js index 3bd9c4b..7b2a30a 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -2,7 +2,7 @@ //only holds database information var Sequelize = require('sequelize'); -var db = new Sequelize('gamemon', 'root', process.env.DB_PASSWORD, { +var db = new Sequelize('gamemon', 'root', '', { define: { charset: 'utf8mb4' } @@ -10,7 +10,9 @@ var db = new Sequelize('gamemon', 'root', process.env.DB_PASSWORD, { var User = db.define('User', { username: {type: Sequelize.STRING, unique: true}, - password: Sequelize.STRING + password: Sequelize.STRING, + nickname: Sequelize.STRING, + email: Sequelize.STRING }); var Game = db.define('Game', { From c960341f5903004d487e31c9603cd2144e6aa348 Mon Sep 17 00:00:00 2001 From: Brian Hassett Date: Thu, 9 Feb 2017 20:00:17 -0800 Subject: [PATCH 004/116] Create view for someone else's profile --- client/app.js | 13 +- client/main/profile.js | 208 +++++++++++++++++++++++++ client/main/toggle.js | 1 + client/profile/profileview.html | 217 +++++++++++++++++++++++++++ server/database/db.js | 1 + server/giantBomb/giantBombHelpers.js | 2 +- 6 files changed, 437 insertions(+), 5 deletions(-) create mode 100644 client/main/profile.js create mode 100644 client/profile/profileview.html diff --git a/client/app.js b/client/app.js index 7251a6d..3c247e6 100644 --- a/client/app.js +++ b/client/app.js @@ -10,12 +10,17 @@ angular.module('gamemon', [ .when('/', { templateUrl: 'home/home.html' }) - .when('/gamemon', { + .when('/gamemon', { //change this to myprofile? templateUrl: 'main/main.html', controller: 'LoginController' }) - .when('/signup', { - templateUrl: 'user/signup.html' + //this is never used and the template doesn't exist + // .when('/signup', { + // templateUrl: 'user/signup.html' + // }) + .when('/profile/:username', { + templateUrl: 'user/profileview', + controller: 'ForeignViewController' // ?? }) - .otherwise({redirectTo: '/'}); + .otherwise({redirectTo: '/gamemon'}); }); \ No newline at end of file diff --git a/client/main/profile.js b/client/main/profile.js new file mode 100644 index 0000000..1245139 --- /dev/null +++ b/client/main/profile.js @@ -0,0 +1,208 @@ +// controller for game collection +var app = angular.module('gameMon.gameCollection', ['ui.materialize', 'gameMon.selectedGame']); +app.controller('GameCollectionController', function($scope, UserCollection, SelectedGame, $rootScope) { + $scope.data = {}; //stores games + $scope.username = localStorage.profile; + $rootScope.username = localStorage.profile; + //Store games in corresponding objects + $scope.platforms = {}; + $scope.genres = {}; + //Store just names in array + $scope.platformArr = []; + $scope.genreArr = []; + //For filtering + $scope.setFilter = function(val) { + $scope.current = val; + } + $scope.current = ''; + + $scope.selectGame = function(game) { + SelectedGame.setCurrentGameFromCollection(game); + }; + + var getCollection = function() { + UserCollection.getUserCollection($scope.username, function(res) { + //Gets user collection, stores platforms and games in $scope.platforms; + // Brian: based on $scope.username, which comes from localStorage. We should use this same function to access other users' collecions. But we should have a better way to identify them than their username in the database, which is currently an Auth0 hash. We should be able to search by a simple username. + console.log('scope.username', $scope.username); + $scope.data.games = res.data; + for (var i = 0; i < $scope.data.games.length; i++) { + var game = $scope.data.games[i]; + //Platforms + if (game.platforms !== null) { + for (var j = 0; j < game.platforms.length; j++) { + var platform = game.platforms[j].name; + if (!$scope.platforms.hasOwnProperty(platform)) { + $scope.platforms[platform] = [game]; + $scope.platformArr.push(platform); + } else { + $scope.platforms[platform].push(game); + } + } + } + //Genres + if (game.genres !== null) { + for (var k = 0; k < game.genres.length; k++) { + var genre = game.genres[k].name; + if (!$scope.genres.hasOwnProperty(genre)) { + $scope.genres[genre] = [game]; + $scope.genreArr.push(genre); + } else { + $scope.genres[genre].push(game); + } + } + } + } + // console.log($scope.data.games); + }); + }; + + //getCollection(); + UserCollection.addUser({username: $scope.username, password: 'password'}, function(response){ + // console.log('User successfully added', $scope.username, typeof $scope.username); + getCollection(); + }); + + $rootScope.$on('collectionChange', function(event) { + getCollection(); + }); + +}); + +app.factory('UserCollection', ['$http', function($http) { + var db = {}; + + //db.addUser = //make a post request to /users + //call add user with whatever local storage user is + //call it with password is password + //specify a callback + + //db.adduser takes a user object with username password + //make an http post request to /users + db.addUser = function(user, callback){ + $http.post('/users', user).then(function(response){ + callback(response); + }, failCallback); + }; + + db.getUserCollection = function(username, callback) { + $http.get('/users/games/' + username) + .then(function(response) { + callback(response); + }, failCallback); + }; + + // Following 2 functions used in modal + db.addGameToCollection = function(username, gameId, callback) { + // Get game obj from game id + $http.get('/games/search/id/' + gameId) + .then(function(response) { + + // Attach user to game object for back end processing + var game = response.data; + game.username = username; + + $http.post('/games', game) + .then(function(response) { + callback(response); + }, failCallback); + + }, failCallback); + }; + + db.removeGameFromCollection = function(username, gameId, callback) { + $http.get('/games/search/id/' + gameId) + .then(function(response) { + + // Attach user to game object for back end processing + var game = response.data; + game.username = username; + // console.log(game); + + $http({ + url: '/games', + method: 'DELETE', + data: game, + headers: { + 'Content-Type': 'application/json;charset=utf-8' + } + }) + .then(function(response) { + callback(response); + }, failCallback); + + }, failCallback); + }; + + var failCallback = function(response) { + console.log(response); + }; + + return db; +}]); + +//Collection filter +app.filter('collectionFilter', function() { + return function(items, filterOpt) { + if (!items) { + //Do nothing if there are no items + return; + } else if (filterOpt[0] === '' || null) { + //Don't filter if nothing is given in filter options + return items; + } else { + var filtered = []; + for(var i = 0; i < items.length; i++) { + //Input filter + if (filterOpt[1] === 'text' && filterOpt[0]) { + //Check if input matches title or aliases + //Get rid of accent on e for Pokémon case (most common case) and ignore caps + + //Check title match + if (items[i].title.replace(/é/g, 'e').toLowerCase() === filterOpt[0].toLowerCase()){ + filtered.push(items[i]); + } if (items[i].aliases !== null) { + if (items[i].aliases.replace(/é/g, 'e').toLowerCase() === filterOpt[0].toLowerCase()) { + filtered.push(items[i]); + } + } + //Check if matches franchise + if (items[i].franchises) { + for (var j = 0; j < items[i].franchises.length; j++) { + if (items[i].franchises[j].name.toLowerCase() === filterOpt[0].toLowerCase()) { + filtered.push(items[i]); + } + } + } + } //End of input filter + + //Genre filter + if (filterOpt[1] === 'genre') { + var genres = items[i].genres; + //Check if genre matches filter + if (genres !== null) { + for (var j = 0; j < genres.length; j++) { + if(genres[j].name === filterOpt[0]) { + filtered.push(items[i]); + } + } + } + } + //Platform filter + if (filterOpt[1] === 'platform') { + var platforms = items[i].platforms; + //Check if platform matches filter + if (platforms !== null) { + for (var j = 0; j < platforms.length; j++) { + if(platforms[j].name === filterOpt[0]) { + filtered.push(items[i]); + } + } + } + } + } + //If nothing was filtered, return all items + return filtered.length === 0 ? items : filtered; + } + }; +}); \ No newline at end of file diff --git a/client/main/toggle.js b/client/main/toggle.js index eb3d1fc..8780d49 100644 --- a/client/main/toggle.js +++ b/client/main/toggle.js @@ -9,6 +9,7 @@ var app = angular.module('gameMon.toggle', ['auth0']) }); app.controller('LoginController', function(auth, $scope, $location, $http, $window, $rootScope, $route) { + //it looks like auth0 gives you a key in localstorage $rootScope.isLoggedIn = localStorage.getItem('profile') ? true : false; $scope.login = function(){ auth.signin({}, function(profile, idToken, accessToken) { diff --git a/client/profile/profileview.html b/client/profile/profileview.html new file mode 100644 index 0000000..5ab8c0a --- /dev/null +++ b/client/profile/profileview.html @@ -0,0 +1,217 @@ + + +
+
+
+ + +
+ No games currently in this user's collection. + + +
+
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/server/database/db.js b/server/database/db.js index 7b2a30a..a36044c 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -3,6 +3,7 @@ var Sequelize = require('sequelize'); var db = new Sequelize('gamemon', 'root', '', { +//var db = new Sequelize('gamemon', 'root', /*process.env.DB_PASSWORD,*/'', { define: { charset: 'utf8mb4' } diff --git a/server/giantBomb/giantBombHelpers.js b/server/giantBomb/giantBombHelpers.js index 41dbe36..a2f647b 100644 --- a/server/giantBomb/giantBombHelpers.js +++ b/server/giantBomb/giantBombHelpers.js @@ -1,6 +1,6 @@ var request = require('request'); -var giantBombApiKey = process.env.GIANTBOMB_API_KEY; +var giantBombApiKey = '664df4aa2d031a2137758d6d453af45b9b78f80d' //process.env.GIANTBOMB_API_KEY; exports.searchForGames = function(searchTerm, callback) { var options = { From 8af72ebed35fb0ca615465bb99e7beae6fbeef3e Mon Sep 17 00:00:00 2001 From: Brian Hassett Date: Fri, 10 Feb 2017 10:25:35 -0800 Subject: [PATCH 005/116] Add email and nickname to add user post request. Add view and controller for other users' profiles--not yet working. --- client/app.js | 13 +- client/main/gameCollection.js | 10 +- client/main/profile.js | 208 -------------------------------- client/profile/profile.js | 167 +++++++++++++++++++++++++ client/profile/profileview.html | 52 +------- 5 files changed, 181 insertions(+), 269 deletions(-) delete mode 100644 client/main/profile.js create mode 100644 client/profile/profile.js diff --git a/client/app.js b/client/app.js index 3c247e6..f5df3f1 100644 --- a/client/app.js +++ b/client/app.js @@ -3,14 +3,15 @@ angular.module('gamemon', [ 'gameMon.search', 'gameMon.modal', 'gameMon.toggle', + //'gameMon.otherCollection', 'ngRoute' ]) -.config(function($routeProvider) { +.config(function appJS($routeProvider) { $routeProvider .when('/', { templateUrl: 'home/home.html' }) - .when('/gamemon', { //change this to myprofile? + .when('/gamemon', { //change this to myprofile instead of gamemon? templateUrl: 'main/main.html', controller: 'LoginController' }) @@ -18,9 +19,9 @@ angular.module('gamemon', [ // .when('/signup', { // templateUrl: 'user/signup.html' // }) - .when('/profile/:username', { - templateUrl: 'user/profileview', - controller: 'ForeignViewController' // ?? + .when('/profiles/:username', { + templateUrl: 'profile/profileview.html', + controller: 'LoginController' // ?? }) - .otherwise({redirectTo: '/gamemon'}); + .otherwise({redirectTo: '/'}); //gamemon instead? }); \ No newline at end of file diff --git a/client/main/gameCollection.js b/client/main/gameCollection.js index 1b465f3..b9ecb5a 100644 --- a/client/main/gameCollection.js +++ b/client/main/gameCollection.js @@ -1,7 +1,7 @@ // controller for game collection var app = angular.module('gameMon.gameCollection', ['ui.materialize', 'gameMon.selectedGame']); app.controller('GameCollectionController', function($scope, UserCollection, SelectedGame, $rootScope) { - $scope.data = {}; + $scope.data = {}; //stores games $scope.username = localStorage.profile; $rootScope.username = localStorage.profile; //Store games in corresponding objects @@ -21,8 +21,8 @@ app.controller('GameCollectionController', function($scope, UserCollection, Sele }; var getCollection = function() { - UserCollection.getUserCollection($scope.username, function(res) { - //Gets user collection, stores platforms and games in $scope.platforms + UserCollection.getUserCollection($scope.username, function(res) { //rootscope instead? + //Gets user collection, stores platforms and games in $scope.platforms; $scope.data.games = res.data; for (var i = 0; i < $scope.data.games.length; i++) { var game = $scope.data.games[i]; @@ -56,8 +56,8 @@ app.controller('GameCollectionController', function($scope, UserCollection, Sele }; //getCollection(); - UserCollection.addUser({username: $scope.username, password: 'password'}, function(response){ - // console.log('User successfully added', $scope.username, typeof $scope.username); + UserCollection.addUser({username: $scope.username, password: 'password', nickname: localStorage.name, email: localStorage.email}, function(response){ + console.log('User successfully added', $scope.username, localStorage.name, localStorage.email); getCollection(); }); diff --git a/client/main/profile.js b/client/main/profile.js deleted file mode 100644 index 1245139..0000000 --- a/client/main/profile.js +++ /dev/null @@ -1,208 +0,0 @@ -// controller for game collection -var app = angular.module('gameMon.gameCollection', ['ui.materialize', 'gameMon.selectedGame']); -app.controller('GameCollectionController', function($scope, UserCollection, SelectedGame, $rootScope) { - $scope.data = {}; //stores games - $scope.username = localStorage.profile; - $rootScope.username = localStorage.profile; - //Store games in corresponding objects - $scope.platforms = {}; - $scope.genres = {}; - //Store just names in array - $scope.platformArr = []; - $scope.genreArr = []; - //For filtering - $scope.setFilter = function(val) { - $scope.current = val; - } - $scope.current = ''; - - $scope.selectGame = function(game) { - SelectedGame.setCurrentGameFromCollection(game); - }; - - var getCollection = function() { - UserCollection.getUserCollection($scope.username, function(res) { - //Gets user collection, stores platforms and games in $scope.platforms; - // Brian: based on $scope.username, which comes from localStorage. We should use this same function to access other users' collecions. But we should have a better way to identify them than their username in the database, which is currently an Auth0 hash. We should be able to search by a simple username. - console.log('scope.username', $scope.username); - $scope.data.games = res.data; - for (var i = 0; i < $scope.data.games.length; i++) { - var game = $scope.data.games[i]; - //Platforms - if (game.platforms !== null) { - for (var j = 0; j < game.platforms.length; j++) { - var platform = game.platforms[j].name; - if (!$scope.platforms.hasOwnProperty(platform)) { - $scope.platforms[platform] = [game]; - $scope.platformArr.push(platform); - } else { - $scope.platforms[platform].push(game); - } - } - } - //Genres - if (game.genres !== null) { - for (var k = 0; k < game.genres.length; k++) { - var genre = game.genres[k].name; - if (!$scope.genres.hasOwnProperty(genre)) { - $scope.genres[genre] = [game]; - $scope.genreArr.push(genre); - } else { - $scope.genres[genre].push(game); - } - } - } - } - // console.log($scope.data.games); - }); - }; - - //getCollection(); - UserCollection.addUser({username: $scope.username, password: 'password'}, function(response){ - // console.log('User successfully added', $scope.username, typeof $scope.username); - getCollection(); - }); - - $rootScope.$on('collectionChange', function(event) { - getCollection(); - }); - -}); - -app.factory('UserCollection', ['$http', function($http) { - var db = {}; - - //db.addUser = //make a post request to /users - //call add user with whatever local storage user is - //call it with password is password - //specify a callback - - //db.adduser takes a user object with username password - //make an http post request to /users - db.addUser = function(user, callback){ - $http.post('/users', user).then(function(response){ - callback(response); - }, failCallback); - }; - - db.getUserCollection = function(username, callback) { - $http.get('/users/games/' + username) - .then(function(response) { - callback(response); - }, failCallback); - }; - - // Following 2 functions used in modal - db.addGameToCollection = function(username, gameId, callback) { - // Get game obj from game id - $http.get('/games/search/id/' + gameId) - .then(function(response) { - - // Attach user to game object for back end processing - var game = response.data; - game.username = username; - - $http.post('/games', game) - .then(function(response) { - callback(response); - }, failCallback); - - }, failCallback); - }; - - db.removeGameFromCollection = function(username, gameId, callback) { - $http.get('/games/search/id/' + gameId) - .then(function(response) { - - // Attach user to game object for back end processing - var game = response.data; - game.username = username; - // console.log(game); - - $http({ - url: '/games', - method: 'DELETE', - data: game, - headers: { - 'Content-Type': 'application/json;charset=utf-8' - } - }) - .then(function(response) { - callback(response); - }, failCallback); - - }, failCallback); - }; - - var failCallback = function(response) { - console.log(response); - }; - - return db; -}]); - -//Collection filter -app.filter('collectionFilter', function() { - return function(items, filterOpt) { - if (!items) { - //Do nothing if there are no items - return; - } else if (filterOpt[0] === '' || null) { - //Don't filter if nothing is given in filter options - return items; - } else { - var filtered = []; - for(var i = 0; i < items.length; i++) { - //Input filter - if (filterOpt[1] === 'text' && filterOpt[0]) { - //Check if input matches title or aliases - //Get rid of accent on e for Pokémon case (most common case) and ignore caps - - //Check title match - if (items[i].title.replace(/é/g, 'e').toLowerCase() === filterOpt[0].toLowerCase()){ - filtered.push(items[i]); - } if (items[i].aliases !== null) { - if (items[i].aliases.replace(/é/g, 'e').toLowerCase() === filterOpt[0].toLowerCase()) { - filtered.push(items[i]); - } - } - //Check if matches franchise - if (items[i].franchises) { - for (var j = 0; j < items[i].franchises.length; j++) { - if (items[i].franchises[j].name.toLowerCase() === filterOpt[0].toLowerCase()) { - filtered.push(items[i]); - } - } - } - } //End of input filter - - //Genre filter - if (filterOpt[1] === 'genre') { - var genres = items[i].genres; - //Check if genre matches filter - if (genres !== null) { - for (var j = 0; j < genres.length; j++) { - if(genres[j].name === filterOpt[0]) { - filtered.push(items[i]); - } - } - } - } - //Platform filter - if (filterOpt[1] === 'platform') { - var platforms = items[i].platforms; - //Check if platform matches filter - if (platforms !== null) { - for (var j = 0; j < platforms.length; j++) { - if(platforms[j].name === filterOpt[0]) { - filtered.push(items[i]); - } - } - } - } - } - //If nothing was filtered, return all items - return filtered.length === 0 ? items : filtered; - } - }; -}); \ No newline at end of file diff --git a/client/profile/profile.js b/client/profile/profile.js new file mode 100644 index 0000000..34cead2 --- /dev/null +++ b/client/profile/profile.js @@ -0,0 +1,167 @@ +// controller for viewing another user's collection -- currently crashing when you try to load it +var app = angular.module('gameMon.otherCollection', ['ui.materialize', 'gameMon.selectedGame']); +app.controller('OtherCollectionController', function OtherCollectionController($scope, UserCollection, SelectedGame, $rootScope, $routeParams) { + $scope.data = {}; //stores games + $scope.username = //localStorage.profile; + //$rootScope.username = localStorage.profile; + //Store games in corresponding objects + $scope.platforms = {}; + $scope.genres = {}; + //Store just names in array + $scope.platformArr = []; + $scope.genreArr = []; + //For filtering + $scope.setFilter = function(val) { + $scope.current = val; + } + $scope.current = ''; + + $scope.selectGame = function(game) { + SelectedGame.setCurrentGameFromCollection(game); + }; + console.log('hello from profile.js'); + + var getCollection = function() { + UserCollection.getUserCollection($routeParams.username, function(res) { //change to $routeParams.username + //Gets user collection, stores platforms and games in $scope.platforms; + // Brian: based on $scope.username, which comes from localStorage. We should use this same function to access other users' collecions. But we should have a better way to identify them than their username in the database, which is currently an Auth0 hash. We should be able to search by a simple username. + $scope.data.games = res.data; + for (var i = 0; i < $scope.data.games.length; i++) { + var game = $scope.data.games[i]; + //Platforms + if (game.platforms !== null) { + for (var j = 0; j < game.platforms.length; j++) { + var platform = game.platforms[j].name; + if (!$scope.platforms.hasOwnProperty(platform)) { + $scope.platforms[platform] = [game]; + $scope.platformArr.push(platform); + } else { + $scope.platforms[platform].push(game); + } + } + } + //Genres + if (game.genres !== null) { + for (var k = 0; k < game.genres.length; k++) { + var genre = game.genres[k].name; + if (!$scope.genres.hasOwnProperty(genre)) { + $scope.genres[genre] = [game]; + $scope.genreArr.push(genre); + } else { + $scope.genres[genre].push(game); + } + } + } + } + // console.log($scope.data.games); + }); + }; + + getCollection(); + // UserCollection.addUser({username: $scope.username, password: 'password'}, function(response){ + // // console.log('User successfully added', $scope.username, typeof $scope.username); + // getCollection(); + // }); + + $rootScope.$on('collectionChange', function(event) { + getCollection(); + }); + +}); + +// app.factory('UserCollection', ['$http', function($http) { +// var db = {}; + +// //db.addUser = //make a post request to /users +// //call add user with whatever local storage user is +// //call it with password is password +// //specify a callback + +// //db.adduser takes a user object with username password +// //make an http post request to /users +// db.addUser = function(user, callback){ +// $http.post('/users', user).then(function(response){ +// callback(response); +// }, failCallback); +// }; + +// db.getUserCollection = function(username, callback) { +// $http.get('/users/games/' + username) +// .then(function(response) { +// callback(response); +// }, failCallback); +// }; + + +// var failCallback = function(response) { +// console.log(response); +// }; + +// return db; +// }]); + +//Collection filter +// app.filter('collectionFilter', function() { +// return function(items, filterOpt) { +// if (!items) { +// //Do nothing if there are no items +// return; +// } else if (filterOpt[0] === '' || null) { +// //Don't filter if nothing is given in filter options +// return items; +// } else { +// var filtered = []; +// for(var i = 0; i < items.length; i++) { +// //Input filter +// if (filterOpt[1] === 'text' && filterOpt[0]) { +// //Check if input matches title or aliases +// //Get rid of accent on e for Pokémon case (most common case) and ignore caps + +// //Check title match +// if (items[i].title.replace(/é/g, 'e').toLowerCase() === filterOpt[0].toLowerCase()){ +// filtered.push(items[i]); +// } if (items[i].aliases !== null) { +// if (items[i].aliases.replace(/é/g, 'e').toLowerCase() === filterOpt[0].toLowerCase()) { +// filtered.push(items[i]); +// } +// } +// //Check if matches franchise +// if (items[i].franchises) { +// for (var j = 0; j < items[i].franchises.length; j++) { +// if (items[i].franchises[j].name.toLowerCase() === filterOpt[0].toLowerCase()) { +// filtered.push(items[i]); +// } +// } +// } +// } //End of input filter + +// //Genre filter +// if (filterOpt[1] === 'genre') { +// var genres = items[i].genres; +// //Check if genre matches filter +// if (genres !== null) { +// for (var j = 0; j < genres.length; j++) { +// if(genres[j].name === filterOpt[0]) { +// filtered.push(items[i]); +// } +// } +// } +// } +// //Platform filter +// if (filterOpt[1] === 'platform') { +// var platforms = items[i].platforms; +// //Check if platform matches filter +// if (platforms !== null) { +// for (var j = 0; j < platforms.length; j++) { +// if(platforms[j].name === filterOpt[0]) { +// filtered.push(items[i]); +// } +// } +// } +// } +// } +// //If nothing was filtered, return all items +// return filtered.length === 0 ? items : filtered; +// } +// }; +// }); \ No newline at end of file diff --git a/client/profile/profileview.html b/client/profile/profileview.html index 5ab8c0a..9d618c0 100644 --- a/client/profile/profileview.html +++ b/client/profile/profileview.html @@ -1,8 +1,8 @@ - +
-
+
- - - - - - - - From 9d5366e68a3e7f8dc13bb11ddc402d92979f4a33 Mon Sep 17 00:00:00 2001 From: gwynndp Date: Thu, 9 Feb 2017 18:29:04 -0800 Subject: [PATCH 006/116] Enter Database url instead of username & password --- server/database/db.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/database/db.js b/server/database/db.js index 7b2a30a..f8270e2 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -2,7 +2,14 @@ //only holds database information var Sequelize = require('sequelize'); -var db = new Sequelize('gamemon', 'root', '', { + +// var db = new Sequelize('gamemon', 'root', 'process.env.DB_PASSWORD', { +// define: { +// charset: 'utf8mb4' +// } +// }); + +var db = new Sequelize(process.env.DB_URL, { define: { charset: 'utf8mb4' } From cba0958a854da95a537e493ef61aa14e0c8e7ca4 Mon Sep 17 00:00:00 2001 From: gwynndp Date: Thu, 9 Feb 2017 18:52:00 -0800 Subject: [PATCH 007/116] Enter Database url instead of username & password --- server/database/db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/database/db.js b/server/database/db.js index f8270e2..4a9234a 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -9,7 +9,7 @@ var Sequelize = require('sequelize'); // } // }); -var db = new Sequelize(process.env.DB_URL, { +var db = new Sequelize(process.env.CLEARDB_DATABASE_URL, { define: { charset: 'utf8mb4' } From f5bede4ecb745bfa1e7980e8475b5773e93bc39a Mon Sep 17 00:00:00 2001 From: gwynndp Date: Thu, 9 Feb 2017 19:46:12 -0800 Subject: [PATCH 008/116] Revert to username & password; --- server/database/db.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/server/database/db.js b/server/database/db.js index 4a9234a..8c7fba9 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -3,12 +3,6 @@ var Sequelize = require('sequelize'); -// var db = new Sequelize('gamemon', 'root', 'process.env.DB_PASSWORD', { -// define: { -// charset: 'utf8mb4' -// } -// }); - var db = new Sequelize(process.env.CLEARDB_DATABASE_URL, { define: { charset: 'utf8mb4' From 09a66e2fc36b7ede7dc38cb24b47ef78bc9527e8 Mon Sep 17 00:00:00 2001 From: gwynndp Date: Thu, 9 Feb 2017 19:50:23 -0800 Subject: [PATCH 009/116] Update to use ClearDB url --- server/database/db.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/database/db.js b/server/database/db.js index 8c7fba9..4a9234a 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -3,6 +3,12 @@ var Sequelize = require('sequelize'); +// var db = new Sequelize('gamemon', 'root', 'process.env.DB_PASSWORD', { +// define: { +// charset: 'utf8mb4' +// } +// }); + var db = new Sequelize(process.env.CLEARDB_DATABASE_URL, { define: { charset: 'utf8mb4' From e04102cd7d6e3f3318d8234d538718623a56f9f6 Mon Sep 17 00:00:00 2001 From: gwynndp Date: Thu, 9 Feb 2017 20:07:38 -0800 Subject: [PATCH 010/116] Insert GiantBomb API key --- server/giantBomb/giantBombHelpers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/giantBomb/giantBombHelpers.js b/server/giantBomb/giantBombHelpers.js index 41dbe36..4b8780e 100644 --- a/server/giantBomb/giantBombHelpers.js +++ b/server/giantBomb/giantBombHelpers.js @@ -1,6 +1,7 @@ var request = require('request'); -var giantBombApiKey = process.env.GIANTBOMB_API_KEY; +//var giantBombApiKey = process.env.GIANTBOMB_API_KEY; +var giantBombApiKey = '138240b063cac215ab7ed7413514c1456d3fd46d'; exports.searchForGames = function(searchTerm, callback) { var options = { From 50899e05162c70965cfaa90a27ac3f946cecfd5c Mon Sep 17 00:00:00 2001 From: gwynndp Date: Fri, 10 Feb 2017 10:42:38 -0800 Subject: [PATCH 011/116] Add database sync to update tables if schema changes - DEV ONLY --- server/database/db.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/server/database/db.js b/server/database/db.js index 4a9234a..37035bc 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -15,11 +15,18 @@ var db = new Sequelize(process.env.CLEARDB_DATABASE_URL, { } }); +// THIS IS FOR THE LIVE SERVER ON HEROKU +// var db = new Sequelize(process.env.CLEARDB_DATABASE_URL, { +// define: { +// charset: 'utf8mb4' +// } +// }); + var User = db.define('User', { username: {type: Sequelize.STRING, unique: true}, password: Sequelize.STRING, - nickname: Sequelize.STRING, - email: Sequelize.STRING + nickname: {type: Sequelize.STRING, unique: true}, + email: {type: Sequelize.STRING, unique: true}, }); var Game = db.define('Game', { @@ -51,7 +58,16 @@ User.belongsToMany(Game, {through: 'GameLibrary'}); Game.belongsToMany(User, {through: 'GameLibrary'}); // creates tables in mysql if they don't exist -db.sync(); // Sequelize decides what order to avoid errors +//db.sync(); // Sequelize decides what order to avoid errors + +//force the database to update even if there are changes to the schema +//only for development use, other wise comment this out and uncomment the db.sync() above +db.sync({ force: true }) +.then(function(err) { + console.log('It worked!'); + }, function (err) { + console.log('An error occurred while creating the table:', err); + }); //export them for use exports.sequelize = db; From 1f91eb61756c50b48892a409f6cb64c3b685cd09 Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Fri, 10 Feb 2017 12:52:36 -0600 Subject: [PATCH 012/116] Update giantBombHelpers.js --- server/giantBomb/giantBombHelpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/giantBomb/giantBombHelpers.js b/server/giantBomb/giantBombHelpers.js index a2f647b..41dbe36 100644 --- a/server/giantBomb/giantBombHelpers.js +++ b/server/giantBomb/giantBombHelpers.js @@ -1,6 +1,6 @@ var request = require('request'); -var giantBombApiKey = '664df4aa2d031a2137758d6d453af45b9b78f80d' //process.env.GIANTBOMB_API_KEY; +var giantBombApiKey = process.env.GIANTBOMB_API_KEY; exports.searchForGames = function(searchTerm, callback) { var options = { From e86da244ec1c4b7ae4d7bc30716a0521742aa429 Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Fri, 10 Feb 2017 12:57:01 -0600 Subject: [PATCH 013/116] Update giantBombHelpers.js --- server/giantBomb/giantBombHelpers.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/giantBomb/giantBombHelpers.js b/server/giantBomb/giantBombHelpers.js index 4b8780e..41dbe36 100644 --- a/server/giantBomb/giantBombHelpers.js +++ b/server/giantBomb/giantBombHelpers.js @@ -1,7 +1,6 @@ var request = require('request'); -//var giantBombApiKey = process.env.GIANTBOMB_API_KEY; -var giantBombApiKey = '138240b063cac215ab7ed7413514c1456d3fd46d'; +var giantBombApiKey = process.env.GIANTBOMB_API_KEY; exports.searchForGames = function(searchTerm, callback) { var options = { From ab5b67b82752bec9ab990e74cd09c74154a98a3b Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Thu, 9 Feb 2017 22:34:53 -0600 Subject: [PATCH 014/116] Add button and image container div --- client/main/main.html | 10 +++++++--- client/styles/styles.css | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/client/main/main.html b/client/main/main.html index 0bbf51f..c33f7ed 100644 --- a/client/main/main.html +++ b/client/main/main.html @@ -75,9 +75,13 @@

Game Collection

diff --git a/client/styles/styles.css b/client/styles/styles.css index 90c27d4..eff5933 100644 --- a/client/styles/styles.css +++ b/client/styles/styles.css @@ -79,6 +79,17 @@ main { .gameImage:hover, .collection-card:hover { opacity: 0.7; } +.gridImage { + width: 164px; + height: 220px; +} +.im-game-button { + position: absolute; + bottom: 5px; + right: 5px; + background-color: #2196F3; + color: #FFF; +} .searchCard { font-size: 14px; } From ab2f7ebd541d06b7d78d130cbaf79f71198dd83a Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Thu, 9 Feb 2017 23:15:24 -0600 Subject: [PATCH 015/116] Fix button in grid view --- client/main/main.html | 8 +++----- client/styles/styles.css | 9 ++++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/client/main/main.html b/client/main/main.html index c33f7ed..088d134 100644 --- a/client/main/main.html +++ b/client/main/main.html @@ -76,11 +76,9 @@

Game Collection

diff --git a/client/styles/styles.css b/client/styles/styles.css index eff5933..ad75a6d 100644 --- a/client/styles/styles.css +++ b/client/styles/styles.css @@ -79,14 +79,13 @@ main { .gameImage:hover, .collection-card:hover { opacity: 0.7; } -.gridImage { - width: 164px; - height: 220px; +.col .s2 { + position: relative; } .im-game-button { position: absolute; - bottom: 5px; - right: 5px; + top: 190px; + left: 26px; background-color: #2196F3; color: #FFF; } From 540aa099d5366eeed67fd0f2e9536d487ae1cb9b Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Fri, 10 Feb 2017 13:30:10 -0600 Subject: [PATCH 016/116] Add button to list view, change css selectors --- client/main/main.html | 3 ++- client/styles/styles.css | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/main/main.html b/client/main/main.html index 088d134..b1020fe 100644 --- a/client/main/main.html +++ b/client/main/main.html @@ -78,7 +78,7 @@

Game Collection

- I'm Game + I'm Game
@@ -93,6 +93,7 @@

Game Collection

{{game.title}}

{{ game.summary }}

+
I'm Game
diff --git a/client/styles/styles.css b/client/styles/styles.css index ad75a6d..cc22ccf 100644 --- a/client/styles/styles.css +++ b/client/styles/styles.css @@ -82,7 +82,7 @@ main { .col .s2 { position: relative; } -.im-game-button { +.im-game-grid-button { position: absolute; top: 190px; left: 26px; From 1562c4c197bf631a9b52f98bbeba86917cbcf25b Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Thu, 9 Feb 2017 20:19:37 -0800 Subject: [PATCH 017/116] Added Giant Bomb API key --- server/giantBomb/giantBombHelpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/giantBomb/giantBombHelpers.js b/server/giantBomb/giantBombHelpers.js index 41dbe36..9fdbd72 100644 --- a/server/giantBomb/giantBombHelpers.js +++ b/server/giantBomb/giantBombHelpers.js @@ -1,6 +1,6 @@ var request = require('request'); -var giantBombApiKey = process.env.GIANTBOMB_API_KEY; +var giantBombApiKey = '664df4aa2d031a2137758d6d453af45b9b78f80d'; exports.searchForGames = function(searchTerm, callback) { var options = { From fb7d918df9c1a25715e79e9074c7a8cf275fbb25 Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Thu, 9 Feb 2017 20:19:54 -0800 Subject: [PATCH 018/116] Modify user post request to include nickname and email --- server/server.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/server.js b/server/server.js index 50ebb0c..ed2b42c 100644 --- a/server/server.js +++ b/server/server.js @@ -11,6 +11,7 @@ var port = process.env.PORT || 8080; // Add a user to db app.post('/users', function(req, res) { + console.log(req.body); var requestObj = req.body; var newUser = { username: requestObj.username, From 4530c75c28353012519a7893892facfbf72c5dae Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Fri, 10 Feb 2017 12:44:59 -0800 Subject: [PATCH 019/116] Change logout href to localhost --- client/main/toggle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/main/toggle.js b/client/main/toggle.js index 8780d49..51c7198 100644 --- a/client/main/toggle.js +++ b/client/main/toggle.js @@ -30,6 +30,6 @@ app.controller('LoginController', function(auth, $scope, $location, $http, $wind $rootScope.isLoggedIn = false; localStorage.removeItem('profile'); localStorage.removeItem('token'); - $window.location.href = 'https://towering-cranes.auth0.com/v2/logout?returnTo=http%3A%2F%2F138.68.224.84'; + $window.location.href = 'https://localhost:8080'; } }); From d2bc8d542f4aea3f8f77e736549377e63cd6b4e9 Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Fri, 10 Feb 2017 12:45:27 -0800 Subject: [PATCH 020/116] Create server endpoint that calls db helper for gameid --- server/server.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/server.js b/server/server.js index ed2b42c..2be1f38 100644 --- a/server/server.js +++ b/server/server.js @@ -15,7 +15,9 @@ app.post('/users', function(req, res) { var requestObj = req.body; var newUser = { username: requestObj.username, - password: requestObj.password + password: requestObj.password, + nickname: requestObj.nickname, + email: requestObj.email }; dbHelpers.createUser(newUser, function(created) { @@ -42,6 +44,16 @@ app.post('/games', function(req, res) { }); }); +//Adding a gameid to a specific user +app.post('/api/users/:username/:gameid', function (req, res) { + var gameid = req.params.gameid; + var user = req.params.username; + + dbHelpers.findImGameUsers(user, gameId, function(users) { + res.send(users); + }); +}); + app.get('/users/games/:username', function(req, res) { var user = req.params.username; From 9201d0d3127ea3331838d862aaeb031dbb7ddb7b Mon Sep 17 00:00:00 2001 From: gwynndp Date: Fri, 10 Feb 2017 11:15:04 -0800 Subject: [PATCH 021/116] Add imgame field to database --- server/database/db.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/server/database/db.js b/server/database/db.js index 37035bc..329f98f 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -3,13 +3,7 @@ var Sequelize = require('sequelize'); -// var db = new Sequelize('gamemon', 'root', 'process.env.DB_PASSWORD', { -// define: { -// charset: 'utf8mb4' -// } -// }); - -var db = new Sequelize(process.env.CLEARDB_DATABASE_URL, { +var db = new Sequelize('gamemon', 'root', '', { define: { charset: 'utf8mb4' } @@ -27,6 +21,7 @@ var User = db.define('User', { password: Sequelize.STRING, nickname: {type: Sequelize.STRING, unique: true}, email: {type: Sequelize.STRING, unique: true}, + imgame: Sequelize.INTEGER }); var Game = db.define('Game', { From e1f13dfeed1db6ed73183d6102c45bf684c2898d Mon Sep 17 00:00:00 2001 From: gwynndp Date: Fri, 10 Feb 2017 12:46:12 -0800 Subject: [PATCH 022/116] Add database helper to update User imgame value and search for other users by imgame value --- client/app.js | 4 ++++ server/database/databaseHelpers.js | 19 +++++++++++++++++++ server/database/db.js | 1 + server/giantBomb/giantBombHelpers.js | 6 +++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/client/app.js b/client/app.js index f5df3f1..7aab69d 100644 --- a/client/app.js +++ b/client/app.js @@ -23,5 +23,9 @@ angular.module('gamemon', [ templateUrl: 'profile/profileview.html', controller: 'LoginController' // ?? }) + .when('/api/users/imgame', { + templateUrl: '', + controller: 'ImGameController' + }) .otherwise({redirectTo: '/'}); //gamemon instead? }); \ No newline at end of file diff --git a/server/database/databaseHelpers.js b/server/database/databaseHelpers.js index ba87526..961f5c1 100644 --- a/server/database/databaseHelpers.js +++ b/server/database/databaseHelpers.js @@ -76,3 +76,22 @@ exports.removeGameFromCollection = function(user, game, callback) { } }); }; + + +exports.findImGameUsers = function(user, gameId, callback) { + db.User.findOne({where: {username: user}}).then(function(user) { + if (user) { + user.imgame = gameId; + } else { // handle case that user doesn't exist + callback(`${user} doesn't exist or couldn't be found`); + } + }); + // Find users with same imgame + db.User.findAll({where: {imgame: gameId}}).then(function(users) { + if (users) { + callback(users); + } else { // handle case that there are no matching users + callback(null); + } + }); +}; diff --git a/server/database/db.js b/server/database/db.js index 329f98f..245bdc0 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -3,6 +3,7 @@ var Sequelize = require('sequelize'); +// THIS IS FOR LOCAL DEV var db = new Sequelize('gamemon', 'root', '', { define: { charset: 'utf8mb4' diff --git a/server/giantBomb/giantBombHelpers.js b/server/giantBomb/giantBombHelpers.js index 41dbe36..fa36317 100644 --- a/server/giantBomb/giantBombHelpers.js +++ b/server/giantBomb/giantBombHelpers.js @@ -1,6 +1,10 @@ var request = require('request'); -var giantBombApiKey = process.env.GIANTBOMB_API_KEY; +// THIS IS FOR LOCAL DEV +var giantBombApiKey = '138240b063cac215ab7ed7413514c1456d3fd46d'; + +// THIS IS FOR THE LIVE SERVER ON HEROKU +// var giantBombApiKey = process.env.GIANTBOMB_API_KEY; exports.searchForGames = function(searchTerm, callback) { var options = { From a8a376694c450b1bf17a29ad807a1ff6803f73a7 Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Thu, 9 Feb 2017 23:20:09 -0600 Subject: [PATCH 023/116] Create imgame.html --- client/imgame/imgame.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 client/imgame/imgame.html diff --git a/client/imgame/imgame.html b/client/imgame/imgame.html new file mode 100644 index 0000000..e69de29 From cff9f5ef8edccfd1aec01db328e7ecb3b4d0fded Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Thu, 9 Feb 2017 23:36:32 -0600 Subject: [PATCH 024/116] Add a route for imgame, create page --- client/app.js | 4 ++-- client/imgame/imgame.html | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/app.js b/client/app.js index 7aab69d..3b7e14e 100644 --- a/client/app.js +++ b/client/app.js @@ -23,8 +23,8 @@ angular.module('gamemon', [ templateUrl: 'profile/profileview.html', controller: 'LoginController' // ?? }) - .when('/api/users/imgame', { - templateUrl: '', + .when('/imgame/:gametitle', { + templateUrl: 'imgame/imgame.html', controller: 'ImGameController' }) .otherwise({redirectTo: '/'}); //gamemon instead? diff --git a/client/imgame/imgame.html b/client/imgame/imgame.html index e69de29..f4d5d0c 100644 --- a/client/imgame/imgame.html +++ b/client/imgame/imgame.html @@ -0,0 +1,2 @@ + +
From 7c58684b3097ad979d020a6cbd8e531443114961 Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Fri, 10 Feb 2017 13:57:01 -0600 Subject: [PATCH 025/116] Add userCollection css selector --- client/imgame/imgame.html | 4 +++- client/styles/styles.css | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/client/imgame/imgame.html b/client/imgame/imgame.html index f4d5d0c..3479908 100644 --- a/client/imgame/imgame.html +++ b/client/imgame/imgame.html @@ -1,2 +1,4 @@ -
+
+ +
\ No newline at end of file diff --git a/client/styles/styles.css b/client/styles/styles.css index cc22ccf..7772e68 100644 --- a/client/styles/styles.css +++ b/client/styles/styles.css @@ -22,7 +22,12 @@ main { margin-right:auto; min-height: 500px; } - +#userCollection { + max-width: 95%; + margin-left: auto; + margin-right:auto; + min-height: 500px; +} .views { margin-right: 10px; } From 41305b136e5afbbf6db5043c3f795a3ef718e93e Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Fri, 10 Feb 2017 17:27:40 -0600 Subject: [PATCH 026/116] Create imgame controller file --- client/imgame/imgame.js | 0 client/index.html | 1 + 2 files changed, 1 insertion(+) create mode 100644 client/imgame/imgame.js diff --git a/client/imgame/imgame.js b/client/imgame/imgame.js new file mode 100644 index 0000000..e69de29 diff --git a/client/index.html b/client/index.html index 1a137a9..e1789f5 100644 --- a/client/index.html +++ b/client/index.html @@ -56,6 +56,7 @@ + From abc0539a5a8559c9c47cbc2b1314992fb84fde4c Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Fri, 10 Feb 2017 18:14:21 -0600 Subject: [PATCH 027/116] Create divs/styling and ng-repeat for users in imgame page --- client/imgame/imgame.html | 15 +++++++++++++-- client/styles/styles.css | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/client/imgame/imgame.html b/client/imgame/imgame.html index 3479908..9ac4905 100644 --- a/client/imgame/imgame.html +++ b/client/imgame/imgame.html @@ -1,4 +1,15 @@ - +
- +
+

Now viewing users wanting to play {{ gameTitle }}

+
+
+
+

{{ user.nickname }}

+

View {{ user.nickname }}'s Profile

+

{{ user.email }}

+
+
+
+
\ No newline at end of file diff --git a/client/styles/styles.css b/client/styles/styles.css index 7772e68..e273f45 100644 --- a/client/styles/styles.css +++ b/client/styles/styles.css @@ -94,6 +94,12 @@ main { background-color: #2196F3; color: #FFF; } +.imgameUser { + border-style: solid; + border-color: #fff; + width: 145px; + height: 200px; +} .searchCard { font-size: 14px; } From 89d2867c5c68cc5d3c4a9ffbc8db15f576dccd45 Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Fri, 10 Feb 2017 18:19:04 -0600 Subject: [PATCH 028/116] Fix styling for imgame page --- client/imgame/imgame.html | 2 +- client/styles/styles.css | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/imgame/imgame.html b/client/imgame/imgame.html index 9ac4905..95bf6cc 100644 --- a/client/imgame/imgame.html +++ b/client/imgame/imgame.html @@ -1,7 +1,7 @@
-

Now viewing users wanting to play {{ gameTitle }}

+

Now viewing users wanting to play {{ gameTitle }}

diff --git a/client/styles/styles.css b/client/styles/styles.css index e273f45..b13ff78 100644 --- a/client/styles/styles.css +++ b/client/styles/styles.css @@ -100,6 +100,9 @@ main { width: 145px; height: 200px; } +.imgameTitle { + color: #fff; +} .searchCard { font-size: 14px; } From d1f7849b92e381138977e9316e504463a24eed1f Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Fri, 10 Feb 2017 16:14:00 -0800 Subject: [PATCH 029/116] Implement update user with game and find users with game db helper functions; function to implement user's collection by nickname --- server/database/databaseHelpers.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/server/database/databaseHelpers.js b/server/database/databaseHelpers.js index 961f5c1..9ea3c65 100644 --- a/server/database/databaseHelpers.js +++ b/server/database/databaseHelpers.js @@ -77,17 +77,20 @@ exports.removeGameFromCollection = function(user, game, callback) { }); }; - -exports.findImGameUsers = function(user, gameId, callback) { +//Updates user to associate with game title +exports.updateImGameUser = function(user, gameTitle, callback) { db.User.findOne({where: {username: user}}).then(function(user) { if (user) { - user.imgame = gameId; + user.updateAttributes({imgame: gameTitle}); } else { // handle case that user doesn't exist callback(`${user} doesn't exist or couldn't be found`); } - }); +}); + +//Finds all users associated with game title +exports.findImGameUsers = function(gameTitle, callback) { // Find users with same imgame - db.User.findAll({where: {imgame: gameId}}).then(function(users) { + db.User.findAll({where: {imgame: gameTitle}}).then(function(users) { if (users) { callback(users); } else { // handle case that there are no matching users @@ -95,3 +98,20 @@ exports.findImGameUsers = function(user, gameId, callback) { } }); }; + +//Getting user's collection by nickname +exports.getPublicUserCollection = function(nickname, callback) { + db.sequelize.query(`SELECT Users.nickname,Games.* FROM Users INNER JOIN GameLibraries ON UserId=Users.id INNER JOIN Games ON GameId=Games.id WHERE Users.nickname="${nickname}";`).spread(function(games) { + games.forEach(function(game) { + game.genres = JSON.parse(game.genres); + game.platforms = JSON.parse(game.platforms); + game.franchises = JSON.parse(game.franchises); + game.publishers = JSON.parse(game.publishers); + game.developers = JSON.parse(game.developers); + game.similarGames = JSON.parse(game.similarGames); + game.videos = JSON.parse(game.videos); + }) + + callback(games); + }); +} From 682044e1ea240747eced4f744b2fe71373992dac Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Fri, 10 Feb 2017 16:15:21 -0800 Subject: [PATCH 030/116] Added imgame attribute to User schema --- server/database/db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/database/db.js b/server/database/db.js index 245bdc0..3e1067e 100644 --- a/server/database/db.js +++ b/server/database/db.js @@ -22,7 +22,7 @@ var User = db.define('User', { password: Sequelize.STRING, nickname: {type: Sequelize.STRING, unique: true}, email: {type: Sequelize.STRING, unique: true}, - imgame: Sequelize.INTEGER + imgame: Sequelize.STRING }); var Game = db.define('Game', { From 6ba53be911e64e82d8819daa22426955393bc540 Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Fri, 10 Feb 2017 16:16:13 -0800 Subject: [PATCH 031/116] Implement post and get requests on server-side for game title --- server/server.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/server/server.js b/server/server.js index 2be1f38..f142f57 100644 --- a/server/server.js +++ b/server/server.js @@ -44,16 +44,29 @@ app.post('/games', function(req, res) { }); }); -//Adding a gameid to a specific user -app.post('/api/users/:username/:gameid', function (req, res) { - var gameid = req.params.gameid; - var user = req.params.username; +//Getting all the users associated with a specific game +app.get('/api/users/:gameTitle', function (req, res) { + var gameTitle = req.params.gameTitle; - dbHelpers.findImGameUsers(user, gameId, function(users) { + dbHelpers.findImGameUsers(gameTitle, function(users) { res.send(users); }); }); +//Adding a gameTitle to a specific user +app.post('/api/users/:username/:gameTitle', function (req, res) { + var gameTitle = req.params.gameTitle; + var user = req.params.username; + + dbHelpers.updateImGameUsers(user, gameTitle, function(created) { + if (created) { + res.send('Game Title added to user'); + } else { + res.send('User was not updated'); + } + }); +}); + app.get('/users/games/:username', function(req, res) { var user = req.params.username; From 6723fa298fe95859cda3192bc10ea385ab444603 Mon Sep 17 00:00:00 2001 From: Brian Hassett Date: Fri, 10 Feb 2017 16:34:36 -0800 Subject: [PATCH 032/116] Update server.js --- server/server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/server.js b/server/server.js index f142f57..b61903f 100644 --- a/server/server.js +++ b/server/server.js @@ -54,8 +54,8 @@ app.get('/api/users/:gameTitle', function (req, res) { }); //Adding a gameTitle to a specific user -app.post('/api/users/:username/:gameTitle', function (req, res) { - var gameTitle = req.params.gameTitle; +app.post('/api/users/:username', function (req, res) { + var gameTitle = req.body.gameTitle; var user = req.params.username; dbHelpers.updateImGameUsers(user, gameTitle, function(created) { From 7e664c81312c07a6333677dae5d694285a5c88c8 Mon Sep 17 00:00:00 2001 From: Brian Hassett Date: Fri, 10 Feb 2017 12:57:42 -0800 Subject: [PATCH 033/116] Implement foreign profile view. But need to modify get request to use nickname instead of auth0 hash --- client/app.js | 2 +- client/index.html | 1 + client/profile/profile.js | 52 ++++++++++++--------------------- client/profile/profileview.html | 2 +- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/client/app.js b/client/app.js index 3b7e14e..3ea34c3 100644 --- a/client/app.js +++ b/client/app.js @@ -3,7 +3,7 @@ angular.module('gamemon', [ 'gameMon.search', 'gameMon.modal', 'gameMon.toggle', - //'gameMon.otherCollection', + 'gameMon.otherCollection', 'ngRoute' ]) .config(function appJS($routeProvider) { diff --git a/client/index.html b/client/index.html index e1789f5..617dac4 100644 --- a/client/index.html +++ b/client/index.html @@ -61,6 +61,7 @@ + + From 0ecdf57681b36fbe39d08147b9a35e5713633bb3 Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Fri, 10 Feb 2017 20:11:34 -0800 Subject: [PATCH 036/116] Add socket.io as dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 63996e1..864095d 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "mysql": "^2.13.0", "nodemon": "^1.11.0", "request": "^2.79.0", - "sequelize": "^3.30.0" + "sequelize": "^3.30.0", + "socket.io": "^1.7.2" } } From 46c731a0df376f8a6840178e4ec7dff65e9fa4c6 Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Fri, 10 Feb 2017 20:11:51 -0800 Subject: [PATCH 037/116] Fix syntax errors --- server/database/databaseHelpers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/database/databaseHelpers.js b/server/database/databaseHelpers.js index 9ea3c65..0a5a169 100644 --- a/server/database/databaseHelpers.js +++ b/server/database/databaseHelpers.js @@ -85,7 +85,8 @@ exports.updateImGameUser = function(user, gameTitle, callback) { } else { // handle case that user doesn't exist callback(`${user} doesn't exist or couldn't be found`); } -}); + }); +} //Finds all users associated with game title exports.findImGameUsers = function(gameTitle, callback) { @@ -97,7 +98,7 @@ exports.findImGameUsers = function(gameTitle, callback) { callback(null); } }); -}; +} //Getting user's collection by nickname exports.getPublicUserCollection = function(nickname, callback) { @@ -110,8 +111,7 @@ exports.getPublicUserCollection = function(nickname, callback) { game.developers = JSON.parse(game.developers); game.similarGames = JSON.parse(game.similarGames); game.videos = JSON.parse(game.videos); - }) - + }); callback(games); }); } From 6bd3f60cf948812704423e32f2f575fe8a2eab9e Mon Sep 17 00:00:00 2001 From: Michael Chiang Date: Fri, 10 Feb 2017 20:12:35 -0800 Subject: [PATCH 038/116] Attach express app and socket.io server to same HTTP server and listens for socket connections --- server/server.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server/server.js b/server/server.js index b61903f..ea5212b 100644 --- a/server/server.js +++ b/server/server.js @@ -4,10 +4,23 @@ var bodyParser = require('body-parser'); var db = require('./database/db.js'); var dbHelpers = require('./database/databaseHelpers.js'); var giantBombHelpers = require('./giantBomb/giantBombHelpers.js'); -var app = express(); + +var port = process.env.PORT || 8080; +var app = require('express')(); +var server = app.listen(port, function() { + console.log('Running on port: ', port); +}); app.use(express.static(__dirname + "/../client")); app.use(bodyParser.json({limit: '5mb'})); -var port = process.env.PORT || 8080; + +//Socket.io +var io = require('socket.io')(server); +io.on('connection', function(socket) { + socket.emit('news', {hello: 'world'}); + socket.on('my other event', function (data) { + console.log(data); + }); +}); // Add a user to db app.post('/users', function(req, res) { @@ -126,6 +139,3 @@ app.get('/games/search/id/:id', function(req, res) { }); }); -var server = app.listen(port, function() { - console.log('Running on port: ', port); -}); From b3ad55de5e2026cc15285f7dd48f01e1a79e8a3e Mon Sep 17 00:00:00 2001 From: gwynndp Date: Fri, 10 Feb 2017 16:40:06 -0800 Subject: [PATCH 039/116] Refine endpoints & new ImGameController --- client/main/ImGameController.js | 11 +++++++++++ server/giantBomb/giantBombHelpers.js | 2 ++ 2 files changed, 13 insertions(+) create mode 100644 client/main/ImGameController.js diff --git a/client/main/ImGameController.js b/client/main/ImGameController.js new file mode 100644 index 0000000..d9c7e8a --- /dev/null +++ b/client/main/ImGameController.js @@ -0,0 +1,11 @@ +// module with factory to pass game info +var app = angular.module('ImGameController'); + +app.factory('', ['$http', 'giantBomb', '$rootScope', function($http, giantBomb, $rootScope) { + + }; + + return { + + }; +}]); \ No newline at end of file diff --git a/server/giantBomb/giantBombHelpers.js b/server/giantBomb/giantBombHelpers.js index 08e504a..fa36317 100644 --- a/server/giantBomb/giantBombHelpers.js +++ b/server/giantBomb/giantBombHelpers.js @@ -1,5 +1,7 @@ var request = require('request'); +// THIS IS FOR LOCAL DEV +var giantBombApiKey = '138240b063cac215ab7ed7413514c1456d3fd46d'; // THIS IS FOR THE LIVE SERVER ON HEROKU // var giantBombApiKey = process.env.GIANTBOMB_API_KEY; From 03bbf287c1fe2c7d1a4458d212aaf911c979c2e4 Mon Sep 17 00:00:00 2001 From: gwynndp Date: Sat, 11 Feb 2017 10:02:04 -0800 Subject: [PATCH 040/116] Add basic socket.io chat to index page --- client/index.html | 56 +++++++++++++++++++++++++++--- server/database/databaseHelpers.js | 2 +- server/server.js | 21 ++++++++++- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/client/index.html b/client/index.html index 3fd5043..df6be86 100644 --- a/client/index.html +++ b/client/index.html @@ -43,14 +43,60 @@
+ + + + + + +
+
+
+

Online Users

+
+
+
+
+ + + +
+
+
+
+ + + + + + + + diff --git a/server/database/databaseHelpers.js b/server/database/databaseHelpers.js index 0a5a169..b1d61f4 100644 --- a/server/database/databaseHelpers.js +++ b/server/database/databaseHelpers.js @@ -91,7 +91,7 @@ exports.updateImGameUser = function(user, gameTitle, callback) { //Finds all users associated with game title exports.findImGameUsers = function(gameTitle, callback) { // Find users with same imgame - db.User.findAll({where: {imgame: gameTitle}}).then(function(users) { + db.User.findAll({attributes: { exclude: ['username'] }}, {where: {imgame: gameTitle}}).then(function(users) { if (users) { callback(users); } else { // handle case that there are no matching users diff --git a/server/server.js b/server/server.js index ea5212b..4442c65 100644 --- a/server/server.js +++ b/server/server.js @@ -13,15 +13,34 @@ var server = app.listen(port, function() { app.use(express.static(__dirname + "/../client")); app.use(bodyParser.json({limit: '5mb'})); -//Socket.io +////////////////////Socket.io + +var connections = []; var io = require('socket.io')(server); io.on('connection', function(socket) { socket.emit('news', {hello: 'world'}); socket.on('my other event', function (data) { console.log(data); }); + + connections.push(socket); + console.log('Connected: %s sockets connected', connections.length); + + socket.on('disconnect', function(data) { + connections.splice(connections.indexOf(socket), 1); + console.log('Disconnected: %s sockets connected', connections.length); + }); + + socket.on('send message', function(data) { + console.log(data); + io.sockets.emit('new message', {msg: data}); + }); + }); + +////////////////////////////// + // Add a user to db app.post('/users', function(req, res) { console.log(req.body); From efa5ecc37365adb8928302a3cf66f8856665971f Mon Sep 17 00:00:00 2001 From: Brian Hassett Date: Sat, 11 Feb 2017 10:16:10 -0800 Subject: [PATCH 041/116] Complete imgame controller --- client/app.js | 1 + client/imgame/imgame.html | 2 +- client/imgame/imgame.js | 34 +++++++++++++++++------------- client/index.html | 1 + client/profile/profile.js | 2 +- server/database/databaseHelpers.js | 5 +++-- server/server.js | 11 +++++++++- 7 files changed, 36 insertions(+), 20 deletions(-) diff --git a/client/app.js b/client/app.js index 3ea34c3..9dae6b0 100644 --- a/client/app.js +++ b/client/app.js @@ -4,6 +4,7 @@ angular.module('gamemon', [ 'gameMon.modal', 'gameMon.toggle', 'gameMon.otherCollection', + 'gameMon.imGame', 'ngRoute' ]) .config(function appJS($routeProvider) { diff --git a/client/imgame/imgame.html b/client/imgame/imgame.html index 95bf6cc..f78b4fe 100644 --- a/client/imgame/imgame.html +++ b/client/imgame/imgame.html @@ -6,7 +6,7 @@

Now viewing users wanting to play {{ gameTitle }}

diff --git a/client/imgame/imgame.js b/client/imgame/imgame.js index 69d81e7..c99b6b9 100644 --- a/client/imgame/imgame.js +++ b/client/imgame/imgame.js @@ -4,25 +4,28 @@ app.controller('ImGameController', function OtherCollectionController($scope, Fo $scope.username = localStorage.profile; $rootScope.username = localStorage.profile; //Store games in corresponding objects + console.log('whats gameTitle?', $routeParams.gametitle); $scope.gameTitle = $routeParams.gametitle; //get all users function var getUsers = function() { + console.log('getting users'); ImGameFactory.getGamers($scope.gameTitle, function(res) { $scope.data.users = res.data; + console.log($scope.data.users); }); } //update i'm game status, calls get users on success var updateImGameStatus = function() { - ImGameFactory.postImGame($scope.username) { - function(res) { - console.log('user is game!') - getUsers(); - } - } + console.log('updating status', $scope.username, $scope.gameTitle) + ImGameFactory.postImGame($scope.username, $scope.gameTitle, function(res) { + console.log('user is game!') + }) } //call update, which will call getUsers updateImGameStatus(); + getUsers(); + //post request for leaving room... @@ -38,24 +41,25 @@ app.factory('ImGameFactory', ['$http', function($http) { output.postImGame = function(user, gametitle, callback) { $http({ - method: 'GET', url: '/users/imgame/' + user, - data: JSON.stringify({name: gametitle}) + method: 'POST', + url: '/api/users/' + user, + data: JSON.stringify({gameTitle: gametitle}) }).then(function(response){ callback(response); }, failCallback); - }; + } output.getGamers = function(title, callback) { - $http.get('/users/imgame/' + title) // + $http.get('api/users/' + title) // .then(function(response) { callback(response); - }, failCallback); - } - }; + }, failCallback); + } + var failCallback = function(response) { - console.log(response); + console.log('err: ', response); }; - return db; + return output; }]); diff --git a/client/index.html b/client/index.html index 617dac4..fef2f93 100644 --- a/client/index.html +++ b/client/index.html @@ -63,6 +63,7 @@ + + \ No newline at end of file diff --git a/client/index.html b/client/index.html index d6b5786..325e635 100644 --- a/client/index.html +++ b/client/index.html @@ -44,59 +44,6 @@
- - - - - -
-
-
-

Online Users

-
-
-
-
- - - -
-
-
-
- - - - - - - - - - From 62bc677c4ca20d48a49859a0b3b62af9a8578cfc Mon Sep 17 00:00:00 2001 From: Brian Hassett Date: Sat, 11 Feb 2017 11:27:43 -0800 Subject: [PATCH 044/116] Add $destroy listener to imgame controller, open link to profiles in imgame to new tab, tweak db helper. --- client/imgame/imgame.html | 2 +- client/imgame/imgame.js | 5 +++++ server/database/databaseHelpers.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/imgame/imgame.html b/client/imgame/imgame.html index 1d48c15..53c49b6 100644 --- a/client/imgame/imgame.html +++ b/client/imgame/imgame.html @@ -6,7 +6,7 @@

Now viewing users wanting to play {{ gameTitle }}

diff --git a/client/imgame/imgame.js b/client/imgame/imgame.js index c99b6b9..dfd3ca2 100644 --- a/client/imgame/imgame.js +++ b/client/imgame/imgame.js @@ -26,6 +26,11 @@ app.controller('ImGameController', function OtherCollectionController($scope, Fo updateImGameStatus(); getUsers(); + $scope.$on('$destroy', function() { + ImGameFactory.postImGame($scope.username, null, function(res) { + console.log('destroyed'); + }) + }); //post request for leaving room... diff --git a/server/database/databaseHelpers.js b/server/database/databaseHelpers.js index 89194f2..6910cef 100644 --- a/server/database/databaseHelpers.js +++ b/server/database/databaseHelpers.js @@ -91,7 +91,7 @@ exports.updateImGameUser = function(user, gameTitle, callback) { //Finds all users associated with game title exports.findImGameUsers = function(gameTitle, callback) { // Find users with same imgame - db.User.findAll({attributes: { exclude: ['username'] }}, {where: {imgame: gameTitle}}).then(function(users) { + db.User.findAll({attributes: { exclude: ['username'] }, where: {imgame: gameTitle}}).then(function(users) { if (users) { callback(users); } else { // handle case that there are no matching users From 2a9c94d406de85878a0ce0537303f17b56f276cd Mon Sep 17 00:00:00 2001 From: Daniel Ritchie Date: Sat, 11 Feb 2017 13:42:48 -0600 Subject: [PATCH 045/116] Change app styling --- client/index.html | 8 ++++---- client/main/main.html | 8 ++++++-- client/profile/profileview.html | 2 +- client/styles/styles.css | 10 ++++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/client/index.html b/client/index.html index 325e635..c177e56 100644 --- a/client/index.html +++ b/client/index.html @@ -2,7 +2,7 @@ - GameMon + I'm Game @@ -20,8 +20,8 @@