Skip to content
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
8 changes: 4 additions & 4 deletions JustBigO(Fun).Tests/Controllers/HomeControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public HomeControllerTests()
}

[Fact]
public async Task Index_ReturnsViewWithProblems()
public async Task Problems_ReturnsViewWithProblems()
{
// Arrange
using var db = new ApplicationDbContext(_options);
Expand All @@ -44,7 +44,7 @@ public async Task Index_ReturnsViewWithProblems()
};

// Act
var result = await controller.Index(null, null);
var result = await controller.Problems(null, null);

// Assert
var viewResult = Assert.IsType<ViewResult>(result);
Expand All @@ -53,7 +53,7 @@ public async Task Index_ReturnsViewWithProblems()
}

[Fact]
public async Task Index_FiltersByDifficulty()
public async Task Problems_FiltersByDifficulty()
{
// Arrange
using var db = new ApplicationDbContext(_options);
Expand All @@ -72,7 +72,7 @@ public async Task Index_FiltersByDifficulty()
};

// Act
var result = await controller.Index(null, "Easy");
var result = await controller.Problems(null, "Easy");

// Assert
var viewResult = Assert.IsType<ViewResult>(result);
Expand Down
19 changes: 13 additions & 6 deletions JustBigO(Fun)/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ public HomeController(ILogger<HomeController> logger, ApplicationDbContext db, I
_markdown = markdown;
}

// --- INCEPUT MODIFICARE ---
// Am adăugat parametrul `difficultyFilter` și am implementat logica de filtrare `.Where(...)`
public async Task<IActionResult> Index(string sortOrder, string difficultyFilter)
public IActionResult Index()
{
return View();
}

public async Task<IActionResult> Problems(string sortOrder, string difficultyFilter)
{
var problemItems = await BuildProblemListAsync(sortOrder, difficultyFilter);
return View(problemItems);
}

private async Task<List<ProblemListItem>> BuildProblemListAsync(string sortOrder, string difficultyFilter)
{
// Salvăm parametrii în ViewData pentru a menține starea în butoanele de pe UI
ViewData["DifficultySortParm"] = sortOrder == "diff_asc" ? "diff_desc" : "diff_asc";
Expand Down Expand Up @@ -76,7 +85,7 @@ public async Task<IActionResult> Index(string sortOrder, string difficultyFilter
_ => problemItems.OrderBy(p => problems.First(x => x.Id == p.Id).OrderIndex)
};

return View(problemItems.ToList());
return problemItems.ToList();
}

private static int GetDifficultyWeight(string difficulty)
Expand All @@ -89,8 +98,6 @@ private static int GetDifficultyWeight(string difficulty)
_ => 0
};
}
// --- SFARSIT MODIFICARE ---

public async Task<IActionResult> Solve(int? id)
{
Problem? problem;
Expand Down
1 change: 1 addition & 0 deletions JustBigO(Fun)/JustBigO(Fun).csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<ItemGroup>
<PackageReference Include="HtmlSanitizer" Version="9.0.892" />
<PackageReference Include="HtmlSanitizer.NetCore3.1" Version="1.0.0" />
<PackageReference Include="Markdig" Version="1.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.11" />
Expand Down
5 changes: 5 additions & 0 deletions JustBigO(Fun)/Services/HtmlSanitizerService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// To fix CS0246, you must add a reference to the Ganss.Xss NuGet package.
// In Visual Studio, right-click your project > Manage NuGet Packages > Browse > search for "Ganss.Xss" > Install.
// Or, run the following command in the Package Manager Console:
// Install-Package Ganss.Xss

using Ganss.Xss;

namespace JustBigO_Fun_.Services;
Expand Down
96 changes: 3 additions & 93 deletions JustBigO(Fun)/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@model IEnumerable<JustBigO_Fun_.Models.ProblemListItem>
@{
ViewData["Title"] = "Dashboard";
string GetDifficultyClass(string d) => d?.ToLowerInvariant() switch { "medium" => "medium", "hard" => "hard", _ => "easy" };
ViewData["Title"] = "Home";
}

<section class="jbo-hero">
Expand All @@ -25,7 +23,7 @@
and get instant feedback from smart agents on complexity, transpilations, and hints.
</p>
<div class="jbo-hero-cta">
<a asp-area="" asp-controller="Home" asp-action="Index" asp-fragment="problemset" class="btn jbo-btn-primary">
<a asp-area="" asp-controller="Home" asp-action="Problems" class="btn jbo-btn-primary">
Start solving problems
</a>
<a asp-area="Identity" asp-page="/Account/Login" class="btn jbo-btn-ghost">
Expand Down Expand Up @@ -104,96 +102,8 @@
</div>
</section>

<div class="jbo-grid-row" id="problemset">
<div class="jbo-grid-row" id="agents">
<section class="jbo-section-card">
<header class="jbo-section-header">
<div>
<h2 class="jbo-section-title">
Problemset &amp;
progress
</h2>
<p class="jbo-section-subtitle">
Browse problems by difficulty and track the status of your submissions.
</p>
</div>
<div class="jbo-chip-row">
<a asp-action="Index"
asp-route-sortOrder="@Context.Request.Query["sortOrder"]"
asp-route-difficultyFilter=""
asp-fragment="problemset"
class="jbo-chip"
style="text-decoration: none; color: inherit; @(string.IsNullOrEmpty(ViewData["CurrentFilter"]?.ToString()) ? "outline: 2px solid currentColor; outline-offset: 2px;" : "opacity: 0.6;")">
All
</a>
<a asp-action="Index"
asp-route-sortOrder="@Context.Request.Query["sortOrder"]"
asp-route-difficultyFilter="Easy"
asp-fragment="problemset"
class="jbo-chip jbo-chip--easy"
style="text-decoration: none; @(ViewData["CurrentFilter"]?.ToString() == "Easy" ? "outline: 2px solid currentColor; outline-offset: 2px;" : "opacity: 0.6;")">
Easy
</a>
<a asp-action="Index"
asp-route-sortOrder="@Context.Request.Query["sortOrder"]"
asp-route-difficultyFilter="Medium"
asp-fragment="problemset"
class="jbo-chip jbo-chip--medium"
style="text-decoration: none; @(ViewData["CurrentFilter"]?.ToString() == "Medium" ? "outline: 2px solid currentColor; outline-offset: 2px;" : "opacity: 0.6;")">
Medium
</a>
<a asp-action="Index"
asp-route-sortOrder="@Context.Request.Query["sortOrder"]"
asp-route-difficultyFilter="Hard"
asp-fragment="problemset"
class="jbo-chip jbo-chip--hard"
style="text-decoration: none; @(ViewData["CurrentFilter"]?.ToString() == "Hard" ? "outline: 2px solid currentColor; outline-offset: 2px;" : "opacity: 0.6;")">
Hard
</a>
</div>
</header>

<table class="jbo-mini-table">
<thead>
<tr>
<th>Problem</th>
<th>Tags</th>
<th>
<a asp-action="Index"
asp-route-sortOrder="@ViewData["DifficultySortParm"]"
asp-route-difficultyFilter="@ViewData["CurrentFilter"]"
asp-fragment="problemset"
style="color: inherit; text-decoration: underline; cursor: pointer;">
Difficulty ↕
</a>
</th>
<th>Best status</th>
</tr>
</thead>
<tbody>
@foreach (var p in Model ?? Enumerable.Empty<JustBigO_Fun_.Models.ProblemListItem>())
{

<tr>
<td><a asp-action="Solve" asp-route-id="@p.Id" class="jbo-problem-link">@p.Title</a></td>
<td>@p.Tags</td>
<td><span class="jbo-chip jbo-chip--@GetDifficultyClass(p.Difficulty)">@p.Difficulty</span></td>

<td>
@{
string statusClass = "";
if (p.BestStatus == "Accepted") statusClass = "jbo-status-chip--accepted";
else if (p.BestStatus == "TimeLimitExceeded") statusClass = "jbo-status-chip--tle";
else if (p.BestStatus != "—") statusClass = "jbo-status-chip--wa";
}
<span class="jbo-status-chip @statusClass">@p.BestStatus</span>
</td>
</tr>
}
</tbody>
</table>
</section>

<section class="jbo-section-card" id="agents">
<header class="jbo-section-header">

<div>
Expand Down
83 changes: 83 additions & 0 deletions JustBigO(Fun)/Views/Home/Problems.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
@model IEnumerable<JustBigO_Fun_.Models.ProblemListItem>
@{
ViewData["Title"] = "Problem Set";
string GetDifficultyClass(string d) => d?.ToLowerInvariant() switch { "medium" => "medium", "hard" => "hard", _ => "easy" };
}

<section class="jbo-section-card" id="problemset">
<header class="jbo-section-header">
<div>
<h1 class="jbo-section-title">Problem set</h1>
<p class="jbo-section-subtitle">
Browse problems by difficulty and track the status of your submissions.
</p>
</div>
<div class="jbo-chip-row">
<a asp-action="Problems"
asp-route-sortOrder="@Context.Request.Query["sortOrder"]"
asp-route-difficultyFilter=""
class="jbo-chip"
style="text-decoration: none; color: inherit; @(string.IsNullOrEmpty(ViewData["CurrentFilter"]?.ToString()) ? "outline: 2px solid currentColor; outline-offset: 2px;" : "opacity: 0.6;")">
All
</a>
<a asp-action="Problems"
asp-route-sortOrder="@Context.Request.Query["sortOrder"]"
asp-route-difficultyFilter="Easy"
class="jbo-chip jbo-chip--easy"
style="text-decoration: none; @(ViewData["CurrentFilter"]?.ToString() == "Easy" ? "outline: 2px solid currentColor; outline-offset: 2px;" : "opacity: 0.6;")">
Easy
</a>
<a asp-action="Problems"
asp-route-sortOrder="@Context.Request.Query["sortOrder"]"
asp-route-difficultyFilter="Medium"
class="jbo-chip jbo-chip--medium"
style="text-decoration: none; @(ViewData["CurrentFilter"]?.ToString() == "Medium" ? "outline: 2px solid currentColor; outline-offset: 2px;" : "opacity: 0.6;")">
Medium
</a>
<a asp-action="Problems"
asp-route-sortOrder="@Context.Request.Query["sortOrder"]"
asp-route-difficultyFilter="Hard"
class="jbo-chip jbo-chip--hard"
style="text-decoration: none; @(ViewData["CurrentFilter"]?.ToString() == "Hard" ? "outline: 2px solid currentColor; outline-offset: 2px;" : "opacity: 0.6;")">
Hard
</a>
</div>
</header>

<table class="jbo-mini-table">
<thead>
<tr>
<th>Problem</th>
<th>Tags</th>
<th>
<a asp-action="Problems"
asp-route-sortOrder="@ViewData["DifficultySortParm"]"
asp-route-difficultyFilter="@ViewData["CurrentFilter"]"
style="color: inherit; text-decoration: underline; cursor: pointer;">
Difficulty ↕
</a>
</th>
<th>Best status</th>
</tr>
</thead>
<tbody>
@foreach (var p in Model ?? Enumerable.Empty<JustBigO_Fun_.Models.ProblemListItem>())
{
<tr>
<td><a asp-action="Solve" asp-route-id="@p.Id" class="jbo-problem-link">@p.Title</a></td>
<td>@p.Tags</td>
<td><span class="jbo-chip jbo-chip--@GetDifficultyClass(p.Difficulty)">@p.Difficulty</span></td>
<td>
@{
string statusClass = "";
if (p.BestStatus == "Accepted") statusClass = "jbo-status-chip--accepted";
else if (p.BestStatus == "TimeLimitExceeded") statusClass = "jbo-status-chip--tle";
else if (p.BestStatus != "—") statusClass = "jbo-status-chip--wa";
}
<span class="jbo-status-chip @statusClass">@p.BestStatus</span>
</td>
</tr>
}
</tbody>
</table>
</section>
4 changes: 2 additions & 2 deletions JustBigO(Fun)/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1 jbo-nav-links">
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">Dashboard</a>
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index" asp-fragment="problemset">Problemset</a>
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Problems">Problems</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index" asp-fragment="agents">AI Agents</a>
Expand Down
Loading