Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#134209539 view game log #61

Open
wants to merge 8 commits into
base: staging
Choose a base branch
from
20 changes: 11 additions & 9 deletions app/controllers/api/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const GameServices = {
const game = new Game({
game_id: gameId,
creator: req.body.creator,
winner: '',
winner: {username: 'No winner'},
rounds: 0,
friends: req.body.friends,
date_created: new Date(),
completed: 'false'
completed: false
});
game.save((err) => {
if (err) {
console.log(err);
return res.status(500).json({
message: 'An error occured while trying to save',
error: err
Expand All @@ -33,18 +34,19 @@ const GameServices = {
const gameCreator = req.body.creator;
const gameId = req.params.id;
const query = { $and: [
{ game_id: gameId }, { creator: gameCreator }
{ game_id: gameId }, { 'creator.id': gameCreator.id }
] };
Game.update(query, {
winner: req.body.winner,
completed: req.body.status,
rounds: req.body.rounds
rounds: req.body.rounds,
friends: req.body.friends
}, (err, result) => {
if (err) return res.status(500).json({ message: 'An error occured while updating this data', error: err });
return res.status(200).json({ message: 'Game updated sucessfully' });
});
},
viewOne(req, res) {
gameDetails(req, res) {
const userId = req.params.userid;
const gameId = req.params.gameid;
Game.findOne({ _id: gameId })
Expand All @@ -59,13 +61,13 @@ const GameServices = {
});
});
},
viewAll(req, res) {
gameLog(req, res) {
const userId = req.params.userid;
Game.find({
$or: [
{ creator: userId }, { friends: userId }
{ 'creator.id': userId }, { 'friends.id': userId }
]
})
}).sort({_id: -1})
.exec((err, result) => {
if (err) {
return res.status(500).json({
Expand All @@ -77,4 +79,4 @@ const GameServices = {
}
};

module.exports = GameServices;
module.exports = GameServices;
8 changes: 4 additions & 4 deletions app/models/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const GameSchema = new Schema({
required: true
},
creator: {
type: String,
type: Object,
required: true
},
winner: {
type: String,
default: ''
type: Object,
default: {}
},
rounds: {
type: Number,
Expand All @@ -32,7 +32,7 @@ const GameSchema = new Schema({
},
completed: {
type: String,
default: ''
default: false
},
friends: Array,
});
Expand Down
1 change: 1 addition & 0 deletions app/views/includes/foot.jade
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ script(type='text/javascript', src='/js/services/datafactory.js')
script(type='text/javascript', src='/js/controllers/index.js')
script(type='text/javascript', src='/js/controllers/header.js')
script(type='text/javascript', src='/js/controllers/game.js')
script(type='text/javascript', src='/js/controllers/dashboard.js')
script(type='text/javascript', src='/js/controllers/game-tour.js')
script(type='text/javascript', src='/js/init.js')

Expand Down
4 changes: 2 additions & 2 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ const routes = (app, passport) => {
app.put('/api/games/:id/start', users.authenticate, game.update);

// Get game history
app.get('/api/:userid/:gameid/history', users.authenticate, game.viewOne);
app.get('/api/:userid/games/history', users.authenticate, game.viewAll);
app.get('/api/games/history/:userid/:gameid', users.authenticate, game.gameDetails);
app.get('/api/games/history/:userid', users.authenticate, game.gameLog);

// Invite users with nodemailer
app.post('/api/users/email-invite', users.authenticate, invite.emailinvite);
Expand Down
38 changes: 36 additions & 2 deletions public/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ body:after {
padding: 0;
}

.player-list-holder{
max-height: 150px
}

.player-list .player-name {
font-size: 1.2em;
padding-top: 10%;
Expand Down Expand Up @@ -602,12 +606,17 @@ body:after {
min-height: 50px;
max-height: 70px;
padding-top: 3%;
margin-top: -80px;
}

.play-wrapper .player-invited-friends {
overflow-y: scroll;
max-height: 160px;
min-height: 160px;
max-height: 120px;
min-height: 120px;
}

.send-invite-input{
padding: 0;
}

.player-invited-friends li {
Expand Down Expand Up @@ -757,3 +766,28 @@ body:after {
.facebook-visit {
padding: 0;
}

.game-log-wrapper {
padding-left: 5%;
padding-right: 5%;
padding-top: 8%;
}

.player-star {
margin-bottom: 50px;
}

.player-name-log{
color: #FFF;
}

.game-log-table {
overflow-y: scroll;
max-height: 400px;
padding-right: 0;
padding-left: 5%;
}

.game-log {
background: #ccc;
}
50 changes: 50 additions & 0 deletions public/js/controllers/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
angular.module('mean.system').
controller('DashboardController', ['$scope', 'dataFactory', '$modal', function($scope, dataFactory, $modal) {
function showModal(result, template) {
$scope.animationsEnabled = true;
$scope.messageBody = result;
$scope.modalInstance = $modal.open({
animation: $scope.animationsEnabled,
ariaLabelledBy: 'modal-title',
scope: $scope,
ariaDescribedBy: 'modal-body',
templateUrl: template,
controller: 'DashboardController',
size: 'sm',
appendTo: angular.element(document).find('#game-log-button'),
resolve: {
items: function () {
return $scope.messageBody;
}
}
});
}
$scope.closeModal = () => {
$scope.modalInstance.close();
};

$scope.viewGameLog = () => {
if (!$scope.showGameLog) {
const link = `/api/games/history/${window.user._id}`;
$scope.result = dataFactory.getGameHistory(link).success((response) => {
$scope.data = response;
})
.error((response) => {
$scope.data = "An error occurred when trying to get game log";
});
$scope.showGameLog = true;
} else {
$scope.showGameLog = false;
}
};
$scope.singleLog = (game_id) => {
const link = `/api/games/history/${window.user._id}/${game_id}`;
$scope.single = dataFactory.getSingleHistory(link)
.success((response) => {
showModal(response, '/views/dashboard-modal.html');
})
.error((response) => {
showModal('An error occurred', '/views/dashboard-modal.html');
});
};
}]);
41 changes: 26 additions & 15 deletions public/js/controllers/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ angular.module('mean.system')
const gameId = $location.search().game;
const link = `/api/games/${gameId}/start`;
const data = {
creator: game.players[0].id,
creator: game.players[0],
friends: game.players
}
dataFactory.saveGameHistory(link, data)
Expand All @@ -169,35 +169,40 @@ angular.module('mean.system')
});
};

$scope.closeModal = function () {
$scope.modalInstance.close();
};
const gameID = $location.search().game;
const isCustom = $scope.isCustomGame();

$scope.$watch('game.state', function () {
if (game.state === 'game ended' && $scope.isCustomGame()) {
const gameId = $location.search().game;
if (game.state === 'game ended' && isCustom && game.players[0].id === window.user._id) {
const gameId = gameID;
const link = `/api/games/${gameId}/start`;
const data = {
creator: game.players[0].id,
winner: game.players[game.gameWinner].id,
status: 'true',
rounds: game.round
creator: game.players[0],
winner: game.players[game.gameWinner],
status: true,
rounds: game.round,
friends: game.players
}
dataFactory.updateGameHistory(link, data)
.success(function (response) {
$scope.model = 'Game updated';
$scope.model = response.message;
})
.error(function (response) {
$scope.message = 'Could not update game';
$scope.message = response.message;
});
}
});

$scope.abandonGame = function () {
$scope.chat.removeChatHistory();
game.leaveGame();
$location.path('/');
};

$scope.closeModal = function () {
$scope.modalInstance.close();
};

// Catches changes to round to update when no players pick card
// (because game.state remains the same)
$scope.$watch('game.round', function () {
Expand Down Expand Up @@ -285,12 +290,15 @@ angular.module('mean.system')
}
dataFactory.sendInvites(mode, form)
.success(function (response) {
$scope.message = 'Invite has been sent';
$scope.inviteList.push($scope.email);
$scope.message = 'Invite has been sent';
})
.error(function (response) {
$scope.message = 'Could not send invite';
});
$timeout(()=> {
$scope.message = '';
}, 4000);
}
}
};
Expand All @@ -306,8 +314,11 @@ angular.module('mean.system')
})
.error(function (response) {
$scope.friendMessage = response.message;
})
}
});
$timeout(()=> {
$scope.friendMessage = '';
}, 4000);
};

function showModal(message, template) {
$scope.animationsEnabled = true;
Expand Down
4 changes: 3 additions & 1 deletion public/js/services/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ angular.module('mean.system')
}
return this.unreadMessageCount;
}

removeChatHistory(){
this.firebase.child(this.chatGroup).remove();
}
}
const chat = new Chat();
return chat;
Expand Down
15 changes: 12 additions & 3 deletions public/js/services/datafactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ angular.module('mean.system')

dataFactory.updateGameHistory = function(route, form) {
return $http({
method: 'POST',
method: 'PUT',
url: route,
headers: { 'Content-Type': 'application/json' },
data: {
gameDataId: form.gameKey,
creator: form.creator,
winner: form.winner,
status: form.status,
rounds: form.rounds
rounds: form.rounds,
friends: form.friends
}
});
};
Expand Down Expand Up @@ -82,5 +83,13 @@ angular.module('mean.system')
return $http.get(route);
};

dataFactory.getGameHistory = function(route) {
return $http.get(route);
};

dataFactory.getSingleHistory = function(route) {
return $http.get(route);
};

return dataFactory;
}]);
22 changes: 22 additions & 0 deletions public/views/dashboard-modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="modal-dialog {{size ? 'modal-' + size : ''}}">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="modal-title">Game Information for {{messageBody.result.game_id}}</h3>
</div>
<div class="modal-body" id="modal-body">
<div ng-repeat = "(key, value) in messageBody">
<p>Creator: {{value.creator.username}}</p>
<p>Winner: {{value.winner.username}}</p>
<p>Rounds: {{value.rounds}}</p>
<p>Players:
<ul ng-repeat = "friend in value.friends">
<li>{{friend.username}}</li>
</ul>
</p>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="closeModal()">OK</button>
</div>
</div>
</div>
Loading