Skip to content

Commit

Permalink
added feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ezraroi committed Jul 5, 2024
1 parent b19dd97 commit de6e765
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 203 deletions.
7 changes: 4 additions & 3 deletions Mundialito/Client/src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ angular.module('mundialitoApp').constant('Constants',
rowTemplate: '<div ng-click="grid.appScope.goToUser(row)" style="cursor: pointer" ng-class="{\'text-primary\':row.entity.Username===grid.appScope.security.user.Username }"><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader }" ui-grid-cell></div></div>',
columnDefs: [
{ field: 'Place', displayName: '', resizable: false, maxWidth: 30 },
{ field: 'Name', displayName: 'Name', resizable: true, minWidth: 120 },
{ field: 'Points', displayName: 'Points', resizable: true, minWidth: 45 },
{ field: 'Name', displayName: 'Name', resizable: true, minWidth: 115 },
{ field: 'Points', displayName: 'Points', resizable: true, minWidth: 45, maxWidth: 75},
{ field: 'GeneralBet.WinningTeam', displayName: 'Team', resizable: false, maxWidth: 45, cellTemplate: '<div class="ui-grid-cell-contents text-center" title="TOOLTIP"><i ng-class="[\'flag\',\'flag-fifa-{{grid.appScope.teamsDic[row.entity.GeneralBet.WinningTeamId].ShortName | lowercase}}\']" tooltip="{{grid.appScope.teamsDic[row.entity.GeneralBet.WinningTeamId].Name}}"></i></div>' },
{ field: 'GeneralBet.GoldenBootPlayer', displayName: 'Player', resizable: false, minWidth: 50, maxWidth: 50 },
{ field: 'TotalMarks', displayName: 'Total Marks', resizable: true },
{ field: 'Results', displayName: 'Results', resizable: true },
{ field: 'Marks', displayName: 'Marks', resizable: true },
{ field: 'YellowCards', displayName: 'Yellow Cards Marks', resizable: true },
{ field: 'Corners', displayName: 'Corners Marks', resizable: true },
{ field: 'PlaceDiff', displayName: '', resizable: false, maxWidth: 45, cellTemplate: '<div ng-class="{\'text-success\': COL_FIELD.indexOf(\'+\') !== -1, \'text-danger\': (COL_FIELD.indexOf(\'+\') === -1) && (COL_FIELD !== \'0\')}"><div class="ngCellText">{{::COL_FIELD}}</div></div>' }
Expand Down
43 changes: 5 additions & 38 deletions Mundialito/Client/src/Dashboard/Dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,50 +186,16 @@
<div class="row" ng-show="!generalBetsAreOpen">
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading"><i class="fa-solid fa-money-bill"></i> General Bets - Team</div>
<div class="panel-heading"><i class="fa-solid fa-money-bill"></i> General Bets</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-6 col-md-offset-3 col-xs-12">
<div class="col-md-6 col-xs-12">
<div google-chart chart="chart">
</div>
</div>
</div>
<div class="row">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<th>Name</th>
<th>Winning Team</th>
<th>Golden Boot Player</th>
</thead>
<tbody>
<tr ng-repeat="bet in generalBets">
<td>{{bet.OwnerName}}</td>
</td>
<td>{{teamsDic[bet.WinningTeamId].Name}}</td>
<td>{{playersDic[bet.GoldenBootPlayerId].Name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row" ng-show="!generalBetsAreOpen">
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading"><i class="fa-solid fa-money-bill"></i> General Bets - Golden Boot Player</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-6 col-md-offset-3 col-xs-12">
<div class="col-md-6 col-xs-12">
<div google-chart chart="playersChart">
</div>
</div>
Expand All @@ -239,13 +205,14 @@
<table class="table table-striped">
<thead>
<th>Name</th>
<th>Points</th>
<th>Winning Team</th>
<th>Golden Boot Player</th>
</thead>
<tbody>
<tr ng-repeat="bet in generalBets">
<td>{{bet.OwnerName}}</td>
</td>
<td>{{usersDic[bet.OwnerId].Points}}</td>
<td>{{teamsDic[bet.WinningTeamId].Name}}</td>
<td>{{playersDic[bet.GoldenBootPlayerId].Name}}</td>
</tr>
Expand Down
19 changes: 16 additions & 3 deletions Mundialito/Client/src/Dashboard/DashboardCtrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
angular.module('mundialitoApp').controller('DashboardCtrl', ['$scope', '$log', 'Constants', '$location', '$timeout', 'GamesManager', 'UsersManager', 'GeneralBetsManager', 'teams', 'players', 'BetsManager',
function ($scope, $log, Constants, $location, $timeout, GamesManager, UsersManager, GeneralBetsManager, teams, players, BetsManager) {
angular.module('mundialitoApp').controller('DashboardCtrl', ['$scope', '$log', 'Constants', '$location', '$timeout', 'GamesManager', 'UsersManager', 'GeneralBetsManager', 'teams', 'players', 'BetsManager', 'MundialitoUtils',
function ($scope, $log, Constants, $location, $timeout, GamesManager, UsersManager, GeneralBetsManager, teams, players, BetsManager, MundialitoUtils) {
$scope.generalBetsAreOpen = false;
$scope.submittedGeneralBet = true;
$scope.pendingUpdateGames = false;
Expand Down Expand Up @@ -135,8 +135,18 @@ angular.module('mundialitoApp').controller('DashboardCtrl', ['$scope', '$log', '
});
}
});
UsersManager.getTable().then((users) => {
UsersManager.loadAllUsers().then((users) => {
$scope.users = users;
$scope.users.forEach((user) => {
if (angular.isDefined(user.GeneralBet)) {
user.GeneralBet.WinningTeam = $scope.teamsDic[user.GeneralBet.WinningTeamId].Name;
user.GeneralBet.GoldenBootPlayer = MundialitoUtils.shortName($scope.playersDic[user.GeneralBet.GoldenBootPlayerId].Name);
}
});
$scope.usersDic = users.reduce((acc, item) => {
acc[item.Id] = item;
return acc;
}, {});
});
$scope.isOpenForBetting = (item) => item.IsOpen;
$scope.isPendingUpdate = (item) => item.IsPendingUpdate;
Expand All @@ -157,6 +167,9 @@ angular.module('mundialitoApp').controller('DashboardCtrl', ['$scope', '$log', '
}
};

$scope.test = (grid,row) => {
return ""; }

function saveState() {
var state = $scope.gridApi.saveState.save();
localStorage.setItem('gridState', state);
Expand Down
20 changes: 16 additions & 4 deletions Mundialito/Client/src/Games/GameCtrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
angular.module('mundialitoApp').controller('GameCtrl', ['$scope', '$log', 'Constants', 'UsersManager', 'GamesManager', 'BetsManager', 'game', 'userBet', 'Alert', '$location', 'PluginsProvider', 'keyValueEditorUtils', function ($scope, $log, Constants, UsersManager, GamesManager, BetsManager, game, userBet, Alert, $location, PluginsProvider, keyValueEditorUtils) {
angular.module('mundialitoApp').controller('GameCtrl', ['$scope', '$log', 'Constants', 'UsersManager', 'GamesManager', 'BetsManager', 'game', 'userBet', 'Alert', '$location', 'PluginsProvider', 'keyValueEditorUtils', 'MundialitoUtils', 'teams', 'players', function ($scope, $log, Constants, UsersManager, GamesManager, BetsManager, game, userBet, Alert, $location, PluginsProvider, keyValueEditorUtils, MundialitoUtils, teams, players) {
$scope.game = game;
$scope.teamsDic = {};
$scope.playersDic = {};
$scope.simulatedGame = {};
$scope.plugins = {};
$scope.userBet = userBet;
Expand All @@ -10,7 +12,12 @@ angular.module('mundialitoApp').controller('GameCtrl', ['$scope', '$log', 'Const
return _.keys(object).map((key) => { return { 'name': key, 'value': object[key] } });
};
$scope.integrationsData = $scope.toKeyValue($scope.game.IntegrationsData);

for (var i = 0; i < teams.length; i++) {
$scope.teamsDic[teams[i].TeamId] = teams[i];
}
for (var i = 0; i < players.length; i++) {
$scope.playersDic[players[i].PlayerId] = players[i];
}
PluginsProvider.getGameDetailsFromAll($scope.game).then((results) => {
results.forEach((result) => {
$scope.plugins[result.property] = { data: result.data, template: result.template };
Expand All @@ -21,7 +28,6 @@ angular.module('mundialitoApp').controller('GameCtrl', ['$scope', '$log', 'Const
BetsManager.getGameBets($scope.game.GameId).then((data) => {
$log.debug("GameCtrl: get game bets" + angular.toJson(data));
$scope.gameBets = data;

var chart1 = {};
chart1.type = "PieChart";
chart1.options = {
Expand Down Expand Up @@ -84,6 +90,12 @@ angular.module('mundialitoApp').controller('GameCtrl', ['$scope', '$log', 'Const
$log.debug('GameCtrl: simulating game');
GamesManager.simulateGame($scope.game.GameId, $scope.simulatedGame).then((data) => {
$scope.users = data;
$scope.users.forEach((user) => {
if (angular.isDefined(user.GeneralBet)) {
user.GeneralBet.WinningTeam = $scope.teamsDic[user.GeneralBet.WinningTeamId].Name;
user.GeneralBet.GoldenBootPlayer = MundialitoUtils.shortName($scope.playersDic[user.GeneralBet.GoldenBootPlayerId].Name);
}
});
Alert.success('Table updated with simulation result');
}).catch((err) => {
Alert.error('Failed to simulate game, please try again');
Expand Down Expand Up @@ -135,7 +147,7 @@ angular.module('mundialitoApp').controller('GameCtrl', ['$scope', '$log', 'Const
return $scope.usersMap.get(user.Username).Place;
}
$scope.$watch('simulatedGame', () => { $scope.users = undefined }, true);
UsersManager.getTable().then((users) => {
UsersManager.loadAllUsers().then((users) => {
$scope.usersMap = new Map();
users.forEach((obj) => {
$scope.usersMap.set(obj.Username, obj);
Expand Down
6 changes: 3 additions & 3 deletions Mundialito/Client/src/Games/gamesTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<div class="list-group">
<a href="{{game.getUrl()}}" class="list-group-item" ng-class="{'list-group-item-warning' : !game.UserHasBet}" ng-repeat="game in games track by game.GameId" title="At {{game.Stadium.Name}} Stadium">
<div class="row">
<div class="col-md-3 col-xs-3">
<div class="col-md-2 col-xs-2">
<i ng-class="['flag','flag-fifa-{{game.HomeTeam.ShortName | lowercase}}']" tooltip="{{game.HomeTeam.Name}}"></i> <span class="hidden-xs">{{game.HomeTeam.Name}}</span>
</div>
<div class="col-md-3 col-xs-6">
<div class="col-md-5 col-xs-8">
<div ng-if="game.IsPendingUpdate" class="text-center">
<span class="label label-info"><i class="fa fa-clock"></i> Pending Update</span>
</div>
Expand All @@ -16,7 +16,7 @@
</div>
<div ng-if="game.IsOpen" class="text-center">-</div>
</div>
<div class="col-md-3 col-xs-3">
<div class="col-md-2 col-xs-2">
<i ng-class="['flag','flag-fifa-{{game.AwayTeam.ShortName | lowercase}}']" tooltip="{{::game.AwayTeam.Name}}"></i> <span class="hidden-xs">{{::game.AwayTeam.Name}}</span>
</div>
<div class="col-md-3 hidden-xs">
Expand Down
4 changes: 4 additions & 0 deletions Mundialito/Client/src/General/MundialitoUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ angular.module('mundialitoApp').factory('MundialitoUtils', [ 'Constants', functi
}
var now = new Date().getTime();
return ((now - instance.LoadTime.getTime()) > Constants.REFRESH_TIME);
},
shortName : (name) => {
let temp = name.split(' ')
return temp[0].substring(0, 1) + '.' + temp[1].substring(0, 1);
}
};

Expand Down
15 changes: 0 additions & 15 deletions Mundialito/Client/src/Users/UsersManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ angular.module('mundialitoApp').factory('UsersManager', ['$http', '$q', 'User',
return deferred.promise;
},

getTable: function () {
var scope = this;
$log.debug('UsersManager: will fetch table from server');
return $http.get('api/users/table', { tracker: 'getUsers' })
.then((usersArray) => {
var users = [];
usersArray.data.forEach((userData) => {
var user = scope._retrieveInstance(userData.Username, userData);
users.push(user);
});
return users;
});
},

getSocial: (username) => {
$log.debug('UsersManager: will fetch followers and followees of user ' + username);
return $http.get('api/users/' + username + '/followees', { tracker: 'getSocial' })
Expand Down Expand Up @@ -120,7 +106,6 @@ angular.module('mundialitoApp').factory('UsersManager', ['$http', '$q', 'User',
var user = scope._retrieveInstance(userData.Username, userData);
users.push(user);
});

deferred.resolve(users);
})
.catch((e) => {
Expand Down
2 changes: 2 additions & 0 deletions Mundialito/Client/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
templateUrl: 'App/Games/Game.html',
controller: 'GameCtrl',
resolve: {
teams: ['TeamsManager', (TeamsManager) => TeamsManager.loadAllTeams()],
players: ['PlayersManager', (PlayersManager) => PlayersManager.loadAllPlayers()],
game: ['$route', 'GamesManager', ($route, GamesManager) => {
var gameId = $route.current.params.gameId;
return GamesManager.getGame(gameId);
Expand Down
2 changes: 2 additions & 0 deletions Mundialito/Controllers/GamesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Microsoft.AspNetCore.Identity;
using Mundialito.DAL.Accounts;
using Mundialito.DAL.GeneralBets;
using Mundialito.DAL.Players;
using Mundialito.DAL.Teams;

namespace Mundialito.Controllers;

Expand Down
17 changes: 9 additions & 8 deletions Mundialito/Controllers/GeneralBetsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Mundialito.DAL.Accounts;
using Mundialito.DAL.ActionLogs;
using Mundialito.DAL.GeneralBets;
using Mundialito.DAL.Players;
using Mundialito.DAL.Teams;
using Mundialito.Logic;
using Mundialito.Models;

Expand Down Expand Up @@ -41,17 +43,18 @@ public ActionResult<IEnumerable<GeneralBetViewModel>> GetAllGeneralBets()
{
return BadRequest(new ErrorMessage { Message = "General bets are still open for betting, you can't see other users bets yet"});
}
return Ok(generalBetsRepository.GetGeneralBets().Select(bet => new GeneralBetViewModel(bet, tournamentTimesUtils.GetGeneralBetsCloseTime())).OrderBy(bet => bet.OwnerName));
return Ok(generalBetsRepository.GetGeneralBets().Select(bet =>
new GeneralBetViewModel(bet, tournamentTimesUtils.GetGeneralBetsCloseTime())).OrderBy(bet => bet.OwnerName));
}

[HttpGet("has-bet/{username}")]
public Boolean HasBet(string username)
public bool HasBet(string username)
{
return generalBetsRepository.IsGeneralBetExists(username);
}

[HttpGet("CanSubmitBets")]
public Boolean CanSubmitBets()
public bool CanSubmitBets()
{
return dateTimeProvider.UTCNow < tournamentTimesUtils.GetGeneralBetsCloseTime();
}
Expand All @@ -60,9 +63,7 @@ public Boolean CanSubmitBets()
public ActionResult<GeneralBetViewModel> GetUserGeneralBet(string username)
{
if (httpContextAccessor.HttpContext?.User.Identity.Name != username && dateTimeProvider.UTCNow < tournamentTimesUtils.GetGeneralBetsCloseTime())
{
return BadRequest(new ErrorMessage { Message = "General bets are still open for betting, you can't see other users bets yet"});
}
var item = generalBetsRepository.GetUserGeneralBet(username);
if (item == null)
return NotFound(string.Format("User '{0}' dosen't have a general bet yet", username));
Expand All @@ -83,7 +84,7 @@ public ActionResult<GeneralBetViewModel> GetGeneralBetById(int id)
public async Task<ActionResult<NewGeneralBetModel>> PostBet(NewGeneralBetModel newBet)
{
var validate = Validate();
if (!String.IsNullOrEmpty(validate))
if (!string.IsNullOrEmpty(validate))
{
AddLog(ActionType.ERROR, validate);
return BadRequest(new ErrorMessage { Message = validate});
Expand Down Expand Up @@ -165,10 +166,10 @@ private string Validate()
AddLog(ActionType.ERROR, "General bets are already closed for betting");
return "General bets are already closed for betting";
}
return String.Empty;
return string.Empty;
}

private void AddLog(ActionType actionType, String message)
private void AddLog(ActionType actionType, string message)
{
try
{
Expand Down
Loading

0 comments on commit de6e765

Please sign in to comment.