Skip to content

Commit

Permalink
Merge pull request #113 from ezraroi/110-in-admin-view-add-indication…
Browse files Browse the repository at this point in the history
…-if-the-user-is-active-or-not

110 in admin view add indication if the user is active or not
  • Loading branch information
ezraroi authored Sep 12, 2024
2 parents 701a546 + be15636 commit 1089b58
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 31 deletions.
4 changes: 4 additions & 0 deletions Mundialito/Client/css/Site.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ input.ng-invalid.ng-dirty, textarea.ng-invalid.ng-dirty, select.ng-invalid.ng-di
.big-logo {
width: 40px;
height: 40px;
}

.label-as-badge {
border-radius: 1em;
}
4 changes: 2 additions & 2 deletions Mundialito/Client/src/General/teamFlagTemplate.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<img ng-if="useFlagsCss !== 'true'" ng-src="{{::team.Flag}}" style="width: 28px; height: 28px; padding-left: 3px; padding-right: 3px;" class="img-reponsive img-rounded" />
<i ng-if="useFlagsCss === 'true'" ng-class="['flag','flag-fifa-{{team.ShortName | lowercase}}']" tooltip="{{team.Name}}"></i>&nbsp;&nbsp;
<img ng-if="useFlagsCss !== 'true'" ng-src="{{::team.Flag}}" style="width: 28px; height: 28px; margin-left: 3px; margin-right: 3px;" class="img-reponsive img-rounded" />
<i ng-if="useFlagsCss === 'true'" ng-class="['flag','flag-fifa-{{team.ShortName | lowercase}}']" tooltip="{{team.Name}}" style="margin-left: 3px; margin-right: 3px;"></i>
8 changes: 4 additions & 4 deletions Mundialito/Client/src/Users/ManageApp.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
</thead>
<tbody>
<tr ng-repeat="user in users">
<td><a href="{{user.getUrl()}}">{{user.Name}}</a></td>
<td><a href="{{user.getUrl()}}">{{::user.Name}}</a><span style="margin-left: 5px;" class="label label-as-badge" ng-class="{'label-success': user.Roles === 'Admin', 'label-default': user.Roles === 'Active', 'label-danger':user.Roles === 'Disabled'}">{{::user.Roles}}</span> </td>
<td>{{user.Email}}</td>
<td>
<button title="delete" type="button" class="btn btn-danger btn-sm" ng-click="deleteUser(user)" tooltip="Delete User"><i class="fa fa-times-circle"></i> <span class="hidden-xs">Delete</span></button>
<button title="makeadmin" ng-show="!user.IsAdmin" type="button" class="btn btn-primary btn-sm" ng-click="makeAdmin(user)" tooltip="Make Admin"><i class="fa fa-gear"></i> <span class="hidden-xs">Admin</span></button>
<button title="activate" ng-show="user.Roles === Disabled && !user.IsAdmin" type="button" class="btn btn-success btn-sm" ng-click="activate(user)" tooltip="Activate"><i class="fa-solid fa-user-check"></i> <span class="hidden-xs">Activate</span></button>
<button title="deactivate" ng-show="user.Roles === Active && !user.IsAdmin" type="button" class="btn btn-warning btn-sm" ng-click="deactivate(user)" tooltip="Deactivate"><i class="fa-solid fa-user-minus"></i> <span class="hidden-xs">Deactivate</span></button>
<button title="makeadmin" ng-show="user.Roles !== 'Admin'" type="button" class="btn btn-primary btn-sm" ng-click="makeAdmin(user)" tooltip="Make Admin"><i class="fa fa-gear"></i> <span class="hidden-xs">Admin</span></button>
<button title="activate" ng-show="user.Roles === 'Disabled'" type="button" class="btn btn-success btn-sm" ng-click="activate(user)" tooltip="Activate"><i class="fa-solid fa-user-check"></i> <span class="hidden-xs">Activate</span></button>
<button title="deactivate" ng-show="user.Roles === 'Active'" type="button" class="btn btn-warning btn-sm" ng-click="deactivate(user)" tooltip="Deactivate"><i class="fa-solid fa-user-minus"></i> <span class="hidden-xs">Deactivate</span></button>
</td>
</tr>
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions Mundialito/Client/src/Users/ManageAppCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ angular.module('mundialitoApp').controller('ManageAppCtrl', ['$scope', '$log', '

$scope.makeAdmin = (user) => {
user.makeAdmin().then(() => {
Alert.success('User was is now admin');
user.IsAdmin = true;
Alert.success('User is now admin');
user.Roles = "Admin";
});
};

Expand Down
12 changes: 1 addition & 11 deletions Mundialito/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public UsersController(ILogger<UsersController> logger, IActionLogsRepository ac
public ActionResult<IEnumerable<UserWithPointsModel>> GetAllUsers()
{
var res = GetTableDetails(userManager.Users.ToList()).ToList();
res.ForEach(user => IsAdmin(user));
return Ok(res);
}

Expand Down Expand Up @@ -143,7 +142,7 @@ public async Task<ActionResult<UserModel>> GetUserByUsername(string username)
var generalBet = generalBetsRepository.GetUserGeneralBet(username);
if (generalBet != null)
userModel.SetGeneralBet(new GeneralBetViewModel(generalBet, tournamentTimesUtils.GetGeneralBetsCloseTime()));
return await IsAdmin(userModel);
return userModel;
}

[HttpGet("me")]
Expand Down Expand Up @@ -308,15 +307,6 @@ private IEnumerable<UserCompareModel> CompareUsers(List<MundialitoUser> users)
return resEntries;
}

private async Task<ActionResult<UserModel>> IsAdmin(UserModel param)
{
var user = await userManager.FindByIdAsync(param.Id);
if (user == null)
return NotFound();
param.IsAdmin = user.Role == Role.Admin;
return Ok(param);
}

private void AddLog(ActionType actionType, string message)
{
try
Expand Down
10 changes: 9 additions & 1 deletion Mundialito/Models/GeneralBetsModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ public GeneralBetViewModel(GeneralBet bet, DateTime closeTime)
{
OwnerId = bet.User.Id;
GeneralBetId = bet.GeneralBetId;
WinningTeam = bet.WinningTeam;
WinningTeam = new Team {
TeamId = bet.WinningTeam.TeamId,
Name = bet.WinningTeam.Name,
Flag = bet.WinningTeam.Flag,
Logo = bet.WinningTeam.Logo,
ShortName = bet.WinningTeam.ShortName,
TeamPage = bet.WinningTeam.TeamPage,
IntegrationsData = bet.WinningTeam.IntegrationsData
};
GoldenBootPlayer = bet.GoldBootPlayer;
IsResolved = bet.IsResolved;
if (IsResolved)
Expand Down
3 changes: 3 additions & 0 deletions Mundialito/Models/UserModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public UserModel(MundialitoUser user)
[JsonPropertyName("Id")]
public string Id { get; private set; }

[JsonPropertyName("Roles")]
public string Roles { get; set; }

[JsonPropertyName("ProfilePicture")]
public string? ProfilePicture { get; private set; }
Expand Down Expand Up @@ -91,6 +93,7 @@ public UserWithPointsModel(MundialitoUser user) : base(user)
{
Points = 0;
Place = string.Empty;
Roles = user.Role.ToString();
}

[JsonPropertyName("Place")]
Expand Down
4 changes: 2 additions & 2 deletions Mundialito/wwwroot/App/General/teamFlagTemplate.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<img ng-if="useFlagsCss !== 'true'" ng-src="{{::team.Flag}}" style="width: 28px; height: 28px; padding-left: 3px; padding-right: 3px;" class="img-reponsive img-rounded" />
<i ng-if="useFlagsCss === 'true'" ng-class="['flag','flag-fifa-{{team.ShortName | lowercase}}']" tooltip="{{team.Name}}"></i>&nbsp;&nbsp;
<img ng-if="useFlagsCss !== 'true'" ng-src="{{::team.Flag}}" style="width: 28px; height: 28px; margin-left: 3px; margin-right: 3px;" class="img-reponsive img-rounded" />
<i ng-if="useFlagsCss === 'true'" ng-class="['flag','flag-fifa-{{team.ShortName | lowercase}}']" tooltip="{{team.Name}}" style="margin-left: 3px; margin-right: 3px;"></i>
8 changes: 4 additions & 4 deletions Mundialito/wwwroot/App/Users/ManageApp.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
</thead>
<tbody>
<tr ng-repeat="user in users">
<td><a href="{{user.getUrl()}}">{{user.Name}}</a></td>
<td><a href="{{user.getUrl()}}">{{::user.Name}}</a><span style="margin-left: 5px;" class="label label-as-badge" ng-class="{'label-success': user.Roles === 'Admin', 'label-default': user.Roles === 'Active', 'label-danger':user.Roles === 'Disabled'}">{{::user.Roles}}</span> </td>
<td>{{user.Email}}</td>
<td>
<button title="delete" type="button" class="btn btn-danger btn-sm" ng-click="deleteUser(user)" tooltip="Delete User"><i class="fa fa-times-circle"></i> <span class="hidden-xs">Delete</span></button>
<button title="makeadmin" ng-show="!user.IsAdmin" type="button" class="btn btn-primary btn-sm" ng-click="makeAdmin(user)" tooltip="Make Admin"><i class="fa fa-gear"></i> <span class="hidden-xs">Admin</span></button>
<button title="activate" ng-show="user.Roles === Disabled && !user.IsAdmin" type="button" class="btn btn-success btn-sm" ng-click="activate(user)" tooltip="Activate"><i class="fa-solid fa-user-check"></i> <span class="hidden-xs">Activate</span></button>
<button title="deactivate" ng-show="user.Roles === Active && !user.IsAdmin" type="button" class="btn btn-warning btn-sm" ng-click="deactivate(user)" tooltip="Deactivate"><i class="fa-solid fa-user-minus"></i> <span class="hidden-xs">Deactivate</span></button>
<button title="makeadmin" ng-show="user.Roles !== 'Admin'" type="button" class="btn btn-primary btn-sm" ng-click="makeAdmin(user)" tooltip="Make Admin"><i class="fa fa-gear"></i> <span class="hidden-xs">Admin</span></button>
<button title="activate" ng-show="user.Roles === 'Disabled'" type="button" class="btn btn-success btn-sm" ng-click="activate(user)" tooltip="Activate"><i class="fa-solid fa-user-check"></i> <span class="hidden-xs">Activate</span></button>
<button title="deactivate" ng-show="user.Roles === 'Active'" type="button" class="btn btn-warning btn-sm" ng-click="deactivate(user)" tooltip="Deactivate"><i class="fa-solid fa-user-minus"></i> <span class="hidden-xs">Deactivate</span></button>
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion Mundialito/wwwroot/css/app-cerulean.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Mundialito/wwwroot/css/app-space-lab.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Mundialito/wwwroot/js/app-min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Mundialito/wwwroot/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2306,8 +2306,8 @@ angular.module('mundialitoApp').controller('ManageAppCtrl', ['$scope', '$log', '

$scope.makeAdmin = (user) => {
user.makeAdmin().then(() => {
Alert.success('User was is now admin');
user.IsAdmin = true;
Alert.success('User is now admin');
user.Roles = "Admin";
});
};

Expand Down

0 comments on commit 1089b58

Please sign in to comment.