Skip to content

Commit

Permalink
Add game archive button (joinrpg#1335)
Browse files Browse the repository at this point in the history
* Add game archive button

* Apply dotnet format

* Add text for empty Archive

* Make archive separated button

* Add new project view model with IsActive field

* Add new repo method for getting all user's projects

* Update view model receiving

* Apply new render rules for Archived Games button

* Apply dotnet format rules
  • Loading branch information
Jeidoz committed Apr 27, 2021
1 parent b2fc705 commit 730b77f
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/JoinRpg.Dal.Impl/Repositories/ProjectRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public IEnumerable<Project> GetMyActiveProjects(int? userInfoId)
public async Task<IEnumerable<Project>> GetMyActiveProjectsAsync(int userInfoId) => await
ActiveProjects.Where(MyProjectPredicate(userInfoId)).ToListAsync();

public async Task<IEnumerable<Project>> GetAllMyProjectsAsync(int userInfoId)
=> await AllProjects.Where(MyProjectPredicate(userInfoId)).ToListAsync();

public async Task<IEnumerable<Project>> GetActiveProjectsWithSchedule()
=> await ActiveProjects.Where(project => project.Details.ScheduleEnabled)
.ToListAsync();
Expand Down
1 change: 1 addition & 0 deletions src/JoinRpg.Data.Interfaces/IProjectRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Task<IReadOnlyCollection<ProjectWithClaimCount>> GetArchivedProjectsWithClaimCou
IEnumerable<Project> GetMyActiveProjects(int? userInfoId);

Task<IEnumerable<Project>> GetMyActiveProjectsAsync(int userInfoId);
Task<IEnumerable<Project>> GetAllMyProjectsAsync(int user);

Task<IEnumerable<Project>> GetActiveProjectsWithSchedule();
Task<Project> GetProjectAsync(int project);
Expand Down
8 changes: 4 additions & 4 deletions src/JoinRpg.Portal/Menu/MainMenuViewComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public async Task<IViewComponentResult> InvokeAsync()
return View("MainMenu", viewModel);
}

private async Task<List<ProjectLinkViewModel>> GetProjectLinks()
private async Task<List<MainMenuProjectLinkViewModel>> GetProjectLinks()
{
var user = CurrentUserAccessor.UserIdOrDefault;
if (user == null)
{
return new List<ProjectLinkViewModel>();
return new List<MainMenuProjectLinkViewModel>();
}
var projects = await ProjectRepository.GetMyActiveProjectsAsync(user.Value);
return projects.ToLinkViewModels().ToList();
var projects = await ProjectRepository.GetAllMyProjectsAsync(user.Value);
return projects.ToMainMenuLinkViewModels().ToList();
}
}
}
2 changes: 1 addition & 1 deletion src/JoinRpg.Portal/Models/MainMenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace JoinRpg.Portal.Models
{
public class MainMenuViewModel
{
public List<ProjectLinkViewModel> ProjectLinks { get; set; }
public List<MainMenuProjectLinkViewModel> ProjectLinks { get; set; }
}
}
15 changes: 11 additions & 4 deletions src/JoinRpg.Portal/Views/Home/BrowseGames.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
@{
ViewBag.Title = "Все игры";
}
<h3>Игры</h3>
@if (Model.ActiveProjects.Any())
{
<h3>Игры</h3>

<div class="row">
<div class="row">
@foreach (var project in Model.ActiveProjects)
{
@await Html.PartialAsync("ProjectCard", project)
@await Html.PartialAsync("ProjectCard", project)
}
</div>
</div>
}
else
{
<h3>Архив игр пуст</h3>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@model MainMenuViewModel
@{
var activeProjects = Model.ProjectLinks.Where(p => p.IsActive).ToArray();
var archivedProjects = Model.ProjectLinks.Where(p => !p.IsActive).ToArray();
}

<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
Expand All @@ -17,25 +21,40 @@
<li>@Html.ActionLink("Мои заявки", "My", "ClaimList", new { area = "" }, null)</li>
}

@if (Model.ProjectLinks.Count > 1)
@if (activeProjects.Length > 1)
{
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Мои проекты <span class="caret"></span></a>

<ul class="dropdown-menu">
@foreach (var project in Model.ProjectLinks)
@foreach (var project in activeProjects)
{
<li>@Html.ActionLink(@project.ProjectName, "Details", "Game", new { project.ProjectId, area = "" }, null)</li>
}

@if (archivedProjects.Any())
{
<li><hr class="list-divider"/></li>
<li>
<a asp-action="GameArchive" asp-controller="Home">Архив игр</a>
</li>
}
</ul>
</li>
}
else if (Model.ProjectLinks.Count == 1)
else if (activeProjects.Length == 1)
{
var project = Model.ProjectLinks.Single();
var project = activeProjects.Single();
<li>@Html.ActionLink(@project.ProjectName, "Details", "Game", new { project.ProjectId, area = "" }, null)</li>
}

@if (archivedProjects.Any() && activeProjects.Length <= 1)
{
<li>
<a asp-action="GameArchive" asp-controller="Home">Архив игр</a>
</li>
}

@if (ViewBag.IsProduction != true)
{
<li class="alert-danger hidden-sm">@Html.ActionLink("Тестовая версия", "About", "Home", new { area = "" }, null)</li>
Expand Down
15 changes: 11 additions & 4 deletions src/JoinRpg.Portal/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ body {
padding-right: 15px;
}

/* Override the default bootstrap behavior where horizontal description lists
will truncate terms that are too long to fit in the left column
/* Override the default bootstrap behavior where horizontal description lists
will truncate terms that are too long to fit in the left column
*/
.dl-horizontal dt {
white-space: normal;
Expand All @@ -45,7 +45,7 @@ textarea {
}

input[type=number] {
max-width: 150px;
max-width: 150px;
text-align: right;
}

Expand Down Expand Up @@ -310,7 +310,7 @@ tr.unapprovedPayment td:last-child {
}

.join-users-h {
list-style-type: none;
list-style-type: none;
display: block;
column-count: 3;
}
Expand Down Expand Up @@ -429,3 +429,10 @@ tr.unapprovedPayment td:last-child {
width: 90%;
vertical-align: middle;
}

hr.list-divider {
margin-top: 0;
margin-bottom: 0;
border: 0;
border-top: 3px solid #b37400;
}
13 changes: 13 additions & 0 deletions src/JoinRpg.WebPortal.Models/ProjectViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class ProjectLinkViewModel
public string ProjectName { get; set; }
}

public sealed class MainMenuProjectLinkViewModel : ProjectLinkViewModel
{
public bool IsActive { get; set; }
}

public static class ProjectLinkViewModelBuilder
{
public static IEnumerable<ProjectLinkViewModel> ToLinkViewModels(
Expand All @@ -25,6 +30,14 @@ public static IEnumerable<ProjectLinkViewModel> ToLinkViewModels(
ProjectId = p.ProjectId,
ProjectName = p.ProjectName,
});

public static IEnumerable<MainMenuProjectLinkViewModel> ToMainMenuLinkViewModels(this IEnumerable<Project> projects) =>
projects.Select(p => new MainMenuProjectLinkViewModel
{
ProjectId = p.ProjectId,
ProjectName = p.ProjectName,
IsActive = p.Active
});
}

public abstract class ProjectViewModelBase
Expand Down

0 comments on commit 730b77f

Please sign in to comment.