Skip to content

Commit

Permalink
Merge pull request #75 from ezraroi/69-add-stats-view
Browse files Browse the repository at this point in the history
added
  • Loading branch information
ezraroi authored Jul 8, 2024
2 parents 6d8402a + 3820136 commit 9ec6eaa
Show file tree
Hide file tree
Showing 11 changed files with 548 additions and 114 deletions.
162 changes: 113 additions & 49 deletions Mundialito/Client/src/Users/UserProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,60 +60,124 @@ <h4><i class="fa fa-user"></i> {{profileUser.Name}} Profile</h4>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading"><i class="fa fa-info-circle"></i> User Statistics</div>
<div class="panel panel-info" cg-busy="{tracker:'getStats'}">
<div class="panel-heading"><i class="fa-solid fa-chart-pie"></i> Statistics</div>
<div class="panel-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Points</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.Points}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Total Points</small></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Results</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.Results}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Number of games that the user guessed the game result - 5
Points(3 for the Mark + 2)</small></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Game Marks</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.Marks}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Number of games that the user guessed the game mark (1,X,2)
- 3 Points</small></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Yellow Cards</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.YellowCards}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Number of games that the user guessed the game yellow cards
mark (1,X,2) - 1 Point</small></span>
<div class="row">
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading"><i class="fa-solid fa-person-running"></i> Performance (Without General Bets)</div>
<div class="panel-body">
<div class="table-responsive hidden-xs">
<table class="table table-striped">
<thead>
<th><i class="fa-solid fa-list"></i> Category</th>
<th class="text-center"><i class="fa-solid fa-people-group"></i> Overall</th>
<th class="text-center"><i class="fa-solid fa-trophy"></i> Leader</th>
<th class="text-center" ng-if="!isLoggedUserProfile()"><i class="fa-solid fa-user"></i> {{::profileUser.Name}}</th>
<th class="text-center" ng-if="isLoggedUserProfile()"><i class="fa-solid fa-users"></i> Followees</th>
<th class="text-center"><i class="fa-solid fa-user"></i> You</th>
</thead>
<tbody>
<tr ng-repeat="(key,value) in performance">
<td>{{::value.Category}}</td>
<td class="text-center"><span class="label label-default">{{::value.Overall}}</span></td>
<td class="text-center"><span class="label label-default">{{::value.Leader}}</span></td>
<td class="text-center" ng-if="!isLoggedUserProfile()"><span ng-class="{'label-danger': value.User < value.Overall, 'label-warning': value.User >= value.Overall && value.User < value.Leader, 'label-success': value.User >= value.Leader}" class="label">{{::value.User}}</span></td>
<td class="text-center" ng-if="isLoggedUserProfile()"><span ng-class="{'label-danger': value.Followees < value.Overall, 'label-warning': value.Followees >= value.Overall && value.Followees < value.Leader, 'label-success': value.Followees >= value.Leader}" class="label">{{::value.Followees}}</span></td>
<td class="text-center"><span ng-class="{'label-danger': value.You < value.Overall, 'label-warning': value.You >= value.Overall && value.You < value.Leader, 'label-success': value.You >= value.Leader}" class="label">{{::value.You}}</span></td>
</tr>
</tbody>
</table>
</div>
<div class="table-responsive visible-xs">
<div class="panel panel-info" ng-repeat="(key,value) in performance">
<div class="panel-heading"><i class="fa-solid fa-list"></i> {{::value.Category}}</div>
<div class="panel-body">
<div class="list-group">
<span class="list-group-item">
<i class="fa-solid fa-people-group"></i> Overall<span class="label label-default pull-right">{{::value.Overall}}</span>
</span>
<span class="list-group-item">
<i class="fa-solid fa-trophy"></i> Leader<span class="label label-default pull-right">{{::value.Leader}}</span>
</span>
<span class="list-group-item" ng-if="!isLoggedUserProfile()">
<i class="fa-solid fa-user"></i> {{::profileUser.Name}}<span ng-class="{'label-danger': value.User < value.Overall, 'label-warning': value.User >= value.Overall && value.User < value.Leader, 'label-success': value.User >= value.Leader}" class="label pull-right">{{::value.User}}</span>
</span>
<span class="list-group-item" ng-if="isLoggedUserProfile()">
<i class="fa-solid fa-users"></i> Followees<span ng-class="{'label-danger': value.Followees < value.Overall, 'label-warning': value.Followees >= value.Overall && value.Followees < value.Leader, 'label-success': value.Followees >= value.Leader}" class="label pull-right">{{::value.Followees}}</span>
</span>
<span class="list-group-item">
<i class="fa-solid fa-user"></i> You<span ng-class="{'label-danger': value.You < value.Overall, 'label-warning': value.You >= value.Overall && value.You < value.Leader, 'label-success': value.You >= value.Leader}" class="label pull-right">{{::value.You}}</span>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Corners</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.Corners}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Number of games that the user guessed the game corners mark
(1,X,2) - 1 Point</small></span>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading"><i class="fa-solid fa-clipboard-list"></i> User Summary</div>
<div class="panel-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Points</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.Points}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Total Points</small></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Results</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.Results}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Number of games that the user guessed the game result - 5
Points(3 for the Mark + 2)</small></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Game Marks</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.Marks}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Number of games that the user guessed the game mark (1,X,2)
- 3 Points</small></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Yellow Cards</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.YellowCards}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Number of games that the user guessed the game yellow cards
mark (1,X,2) - 1 Point</small></span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-9 control-label">Corners</label>
<div class="col-md-1 col-xs-3">
<p class="form-control-static">{{profileUser.Corners}}</p>
</div>
<div class="col-md-8 hidden-xs">
<span class="help-block"><small>Number of games that the user guessed the game corners mark
(1,X,2) - 1 Point</small></span>
</div>
</div>
</form>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
Expand Down
21 changes: 19 additions & 2 deletions Mundialito/Client/src/Users/UserProfileCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ angular.module('mundialitoApp').controller('UserProfileCtrl', ['$scope', '$log',
$scope.security.user.Followees.splice(index, 1);
Alert.success('You no longer following ' + $scope.profileUser.Username);
}).catch((err) => {
Alert.error('Failed to unfollow ' + $scope.profileUser.Username + ': ' + e);
Alert.error('Failed to unfollow ' + $scope.profileUser.Username + ': ' + err);
});
} else {
UsersManager.follow($scope.profileUser.Username).then(() => {
$scope.alreadyFollow = true;
$scope.security.user.Followees.push($scope.profileUser.Username);
Alert.success('You are now following ' + $scope.profileUser.Username);
}).catch((err) => {
Alert.error('Failed to follow ' + $scope.profileUser.Username + ': ' + e);
Alert.error('Failed to follow ' + $scope.profileUser.Username + ': ' + err);
});
}
};
Expand All @@ -102,4 +102,21 @@ angular.module('mundialitoApp').controller('UserProfileCtrl', ['$scope', '$log',
$scope.followers = data['followers'];
$scope.followees = data['followees'];
});

if ($scope.isLoggedUserProfile()) {
UsersManager.getMyStats().then((data) => {
$scope.performance = data;
}).catch((err) => {
$log.error('Failed to get user slef statistics', err);
Alert.error('Failed to fetch user statistics: ' + err);
});
} else {
UsersManager.getStats($scope.profileUser.Username).then((data) => {
$scope.performance = data;
}).catch((err) => {
$log.error('Failed to get user statistics', err);
Alert.error('Failed to fetch user statistics: ' + err);
});
}

}]);
16 changes: 16 additions & 0 deletions Mundialito/Client/src/Users/UsersManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ angular.module('mundialitoApp').factory('UsersManager', ['$http', '$q', 'User',
});
},

getMyStats: () => {
$log.debug('UsersManager: will the stats of logged user');
return $http.get('api/stats/me', { tracker: 'getStats' })
.then((res) => {
return res.data;
});
},

getStats: (username) => {
$log.debug('UsersManager: will the stats of ' + username);
return $http.get('api/stats/' + username, { tracker: 'getStats' })
.then((res) => {
return res.data;
});
},

follow: (username) => {
$log.debug('UsersManager: will follow ' + username);
return $http.post('api/users/follow/' + username, undefined, { tracker: 'follow' });
Expand Down
2 changes: 0 additions & 2 deletions Mundialito/Controllers/GeneralBetsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
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
Loading

0 comments on commit 9ec6eaa

Please sign in to comment.