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

Add Userfiles List Page #1779

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 42 additions & 44 deletions TASVideos/Pages/Games/List.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,56 @@
(!string.IsNullOrWhiteSpace(Model.Games.SearchTerms) ? " - " + $@"""{Model.Games.SearchTerms}""" : string.Empty));
}

<div class="container">
<div class="row">
<div class="col-lg-6 mb-1">
<form>
<div class="row mb-1">
<div class="col-10">
<div class="input-group">
<label asp-for="SearchTerms" class="input-group-text"></label>
<input type="text" asp-for="SearchTerms" class="form-control" />
</div>
<span asp-validation-for="SearchTerms" class="text-danger"></span>
</div>
<div class="col-1 mb-1">
<button type="Submit" class="btn btn-secondary float-center">Go</button>
<div class="row">
<div class="col-lg-6 mb-1">
<form>
<div class="row mb-1">
<div class="col-10">
<div class="input-group">
<label asp-for="SearchTerms" class="input-group-text"></label>
<input type="text" asp-for="SearchTerms" class="form-control" />
</div>
<span asp-validation-for="SearchTerms" class="text-danger"></span>
</div>
<div class="col-1 mb-1">
<button type="Submit" class="btn btn-secondary float-center">Go</button>
</div>
<div class="row mb-1">
<div class="col-5 mb-1">
<div class="input-group">
<label asp-for="@Model.Games.SystemCode" class="input-group-text"></label>
<select asp-items="@Model.SystemList" asp-for="@Model.Games.SystemCode" name="SystemCode" class="form-control"></select>
</div>
</div>
<div class="row mb-1">
<div class="col-5 mb-1">
<div class="input-group">
<label asp-for="@Model.Games.SystemCode" class="input-group-text"></label>
<select asp-items="@Model.SystemList" asp-for="@Model.Games.SystemCode" name="SystemCode" class="form-control"></select>
</div>
<div class="col-5 mb-1">
<div class="input-group">
<label asp-for="@Model.Games.Letter" class="input-group-text"></label>
<select asp-items="@Model.LetterList" asp-for="@Model.Games.Letter" name="Letter" class="form-control"></select>
</div>
</div>
<div class="col-5 mb-1">
<div class="input-group">
<label asp-for="@Model.Games.Letter" class="input-group-text"></label>
<select asp-items="@Model.LetterList" asp-for="@Model.Games.Letter" name="Letter" class="form-control"></select>
</div>
</div>
<div class="row mb-1">
<div class="col-5 mb-1">
<div class="input-group">
<label asp-for="@Model.Games.Genre" class="input-group-text"></label>
<select asp-for="@Model.Games.Genre" asp-items="@Model.GenreList" name="Genre" class="form-control"></select>
</div>
</div>
<div class="row mb-1">
<div class="col-5 mb-1">
<div class="input-group">
<label asp-for="@Model.Games.Genre" class="input-group-text"></label>
<select asp-for="@Model.Games.Genre" asp-items="@Model.GenreList" name="Genre" class="form-control"></select>
</div>
<div class="col-5 mb-1">
<div class="input-group">
<label asp-for="@Model.Games.Group" class="input-group-text"></label>
<select asp-for="@Model.Games.Group" asp-items="@Model.GroupList" name="Group" class="form-control"></select>
</div>
</div>
<div class="col-5 mb-1">
<div class="input-group">
<label asp-for="@Model.Games.Group" class="input-group-text"></label>
<select asp-for="@Model.Games.Group" asp-items="@Model.GroupList" name="Group" class="form-control"></select>
</div>
</div>
</form>
</div>
<div class="col">
<a href="/GamesHowTo" class="btn btn-secondary mb-1 float-end ms-1">Games How To</a>
<a asp-page="/GameGroups/List" class="btn btn-secondary mb-1 float-end">Game Groups</a>
<a asp-page="Edit" permission="CatalogMovies" class="btn btn-primary mb-1 float-end me-1"><i class="fa fa-plus"></i> Create</a>
<a asp-page="Rewire" permission="RewireGames" class="btn btn-primary mb-1 float-end me-1"><i class="fa fa-wrench"></i> Rewire</a>
</div>
</div>
</form>
</div>
<div class="col">
<a href="/GamesHowTo" class="btn btn-secondary mb-1 float-end ms-1">Games How To</a>
<a asp-page="/GameGroups/List" class="btn btn-secondary mb-1 float-end">Game Groups</a>
<a asp-page="Edit" permission="CatalogMovies" class="btn btn-primary mb-1 float-end me-1"><i class="fa fa-plus"></i> Create</a>
<a asp-page="Rewire" permission="RewireGames" class="btn btn-primary mb-1 float-end me-1"><i class="fa fa-wrench"></i> Rewire</a>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions TASVideos/Pages/UserFiles/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
</small>
</div>
}
<a asp-page="List">More...</a>
</cardbody>
</card>
<card>
Expand Down
32 changes: 32 additions & 0 deletions TASVideos/Pages/UserFiles/List.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@page
@model TASVideos.Pages.UserFiles.ListModel
@{
ViewData.SetTitle("User File List");
}

<partial name="_Pager" model="Model.UserFiles" />
<div class="table-container">
<table class="table table-bordered table-striped table-sm">
<sortable-table-head sorting="@Model.Search" model-type="typeof(Models.UserFileListModel)" />
@foreach (var userFile in Model.UserFiles)
{
<tr>
<td>
<a asp-page="Info" asp-route-id="@userFile.Id">@(string.IsNullOrWhiteSpace(userFile.Title) ? userFile.FileName : userFile.Title)</a>
</td>
<td><a asp-page="ForUser" asp-route-username="@userFile.Author">@userFile.Author</a></td>
<td>
@if (userFile.GameId != null)
{
<a asp-page="Game" asp-route-id="@userFile.GameId">@userFile.GameName</a>
}
</td>
<td>@userFile.Frames</td>
<td>@userFile.Rerecords</td>
<td>@userFile.CommentCount</td>
<td class="text-nowrap"><timezone-convert asp-for="@userFile.UploadTimestamp" /></td>
</tr>
}
</table>
</div>
<partial name="_Pager" model="Model.UserFiles" />
42 changes: 42 additions & 0 deletions TASVideos/Pages/UserFiles/List.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TASVideos.Core;
using TASVideos.Data;
using TASVideos.Data.Entity;
using TASVideos.Pages.UserFiles.Models;

namespace TASVideos.Pages.UserFiles;

public class ListModel : PageModel
{
private readonly ApplicationDbContext _db;
public ListModel(ApplicationDbContext db)
{
_db = db;
}

[FromQuery]
public UserFileListRequest Search { get; set; } = new();

public PageOf<UserFileListModel> UserFiles { get; set; } = PageOf<UserFileListModel>.Empty();
public async Task OnGet()
{
UserFiles = await _db.UserFiles
.ThatArePublic()
.ByRecentlyUploaded()
.Select(uf => new UserFileListModel
{
Id = uf.Id,
Title = uf.Title,
FileName = uf.FileName,
Author = uf.Author!.UserName,
GameId = uf.GameId,
GameName = uf.Game != null ? uf.Game.DisplayName : "",
Frames = uf.Frames,
Rerecords = uf.Rerecords,
CommentCount = uf.Comments.Count,
UploadTimestamp = uf.UploadTimestamp,
})
.SortedPageOf(Search);
}
}
39 changes: 39 additions & 0 deletions TASVideos/Pages/UserFiles/Models/UserFileListModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.ComponentModel.DataAnnotations;
using TASVideos.Core;

namespace TASVideos.Pages.UserFiles.Models;

public class UserFileListModel
{
[TableIgnore]
public long Id { get; set; }

public string Title { get; set; } = "";

[TableIgnore]
public string FileName { get; set; } = "";

[Sortable]
public string Author { get; set; } = "";

[TableIgnore]
public int? GameId { get; set; }

[Sortable]
[Display(Name = "Game")]
public string GameName { get; set; } = "";

[Sortable]
public int Frames { get; set; }

[Sortable]
public int Rerecords { get; set; }

[Sortable]
[Display(Name = "Comments")]
public int CommentCount { get; set; }

[Sortable]
[Display(Name = "Uploaded")]
public DateTime UploadTimestamp { get; set; }
}
13 changes: 13 additions & 0 deletions TASVideos/Pages/UserFiles/Models/UserFileListRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using TASVideos.Core;
using TASVideos.Data.Entity;

namespace TASVideos.Pages.UserFiles.Models;

public class UserFileListRequest : PagingModel
{
public UserFileListRequest()
{
PageSize = 50;
Sort = $"-{nameof(UserFileListModel.UploadTimestamp)}";
}
}
Loading