-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented area management section of layout builder
- Loading branch information
Showing
45 changed files
with
41,700 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
# Logs | ||
**/Logs/* | ||
|
||
# Generated files | ||
*.gen.* | ||
*.gen | ||
|
||
# Common IntelliJ Platform excludes | ||
|
||
# User specific | ||
|
4 changes: 3 additions & 1 deletion
4
ReservationSystem-Server/.idea/.idea.ReservationSystem-Server/.idea/indexLayout.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
109 changes: 107 additions & 2 deletions
109
...System-Server/ReservationSystem-Server/Areas/Admin/Controllers/LayoutBuilderController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,120 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Internal; | ||
using ReservationSystem_Server.Areas.Admin.Models; | ||
using ReservationSystem_Server.Areas.Admin.Models.LayoutBuilder; | ||
using ReservationSystem_Server.Data; | ||
using ReservationSystem_Server.Data.Visual.Layout; | ||
|
||
namespace ReservationSystem_Server.Areas.Admin.Controllers; | ||
|
||
[Area("Admin")] | ||
[Authorize(Roles = "Manager")] | ||
[ApiController] | ||
[Route("[area]/[controller]")] | ||
#if DEBUG | ||
[AllowAnonymous] | ||
#endif | ||
public class LayoutBuilderController : Controller | ||
{ | ||
// GET | ||
public IActionResult Index() | ||
private readonly ApplicationDbContext _context; | ||
|
||
public LayoutBuilderController(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[HttpGet("{*path}", Order = 999)] // Catch all route, so that the underlying react app can use navigation links | ||
public IActionResult Index(string? path) | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpGet("AreaLayout")] | ||
public async Task<IActionResult> GetAreaLayout() | ||
{ | ||
return Ok( | ||
await _context.RestaurantAreas | ||
.GroupJoin(_context.RestaurantAreaVisuals.DefaultIfEmpty(), | ||
a => a.Id, | ||
v => v.AreaId, | ||
(a, v) => new { a, v }) | ||
.SelectMany(val => val.v.DefaultIfEmpty(), (val, v) => new AreaLayoutModel | ||
{ | ||
Id = val.a.Id, | ||
Name = val.a.Name, | ||
Rect = LayoutModel.Rect.FromRectangleVisual(v != null ? v.Rect : null) | ||
}).ToArrayAsync()); | ||
} | ||
|
||
[HttpPut("AreaLayout")] | ||
public async Task<IActionResult> PutAreaLayout(AreaLayoutModel[] areas) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
foreach (AreaLayoutModel model in areas) | ||
{ | ||
RestaurantArea? area = await _context.RestaurantAreas.FirstOrDefaultAsync(a => a.Id == model.Id); | ||
|
||
if (area == null) | ||
{ | ||
// New area | ||
area = new RestaurantArea | ||
{ | ||
Name = model.Name, | ||
RestaurantId = 1 | ||
}; | ||
|
||
_context.RestaurantAreas.Add(area); | ||
await _context.SaveChangesAsync(); | ||
|
||
model.Id = area.Id; | ||
} | ||
else | ||
{ | ||
// Update area | ||
area.Name = model.Name; | ||
} | ||
|
||
RestaurantAreaVisual? visual = | ||
await _context.RestaurantAreaVisuals.Include(v => v.Rect) | ||
.FirstOrDefaultAsync(v => v.AreaId == area.Id); | ||
if (visual == null) | ||
{ | ||
visual = new RestaurantAreaVisual | ||
{ | ||
AreaId = area.Id, | ||
Rect = LayoutModel.Rect.ToRectangleVisual(model.Rect), | ||
}; | ||
|
||
_context.RestaurantAreaVisuals.Add(visual); | ||
} | ||
else | ||
{ | ||
RectangleVisual changedRect = LayoutModel.Rect.ToRectangleVisual(model.Rect); | ||
|
||
visual.Rect.X = changedRect.X; | ||
visual.Rect.Y = changedRect.Y; | ||
visual.Rect.Width = changedRect.Width; | ||
visual.Rect.Height = changedRect.Height; | ||
visual.Rect.R = changedRect.R; | ||
visual.Rect.G = changedRect.G; | ||
visual.Rect.B = changedRect.B; | ||
visual.Rect.A = changedRect.A; | ||
} | ||
} | ||
|
||
// ToArray as EF couldn't translate areas.All({lambda}) | ||
foreach (RestaurantArea area in (await _context.RestaurantAreas.ToArrayAsync()).Where(a => areas.All(m => a.Id != m.Id))) | ||
{ | ||
_context.RestaurantAreas.Remove(area); | ||
} | ||
|
||
await _context.SaveChangesAsync(); | ||
return Ok(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ystem-Server/ReservationSystem-Server/Areas/Admin/Models/LayoutBuilder/AreaLayoutModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace ReservationSystem_Server.Areas.Admin.Models.LayoutBuilder; | ||
|
||
public class AreaLayoutModel | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } = null!; | ||
|
||
public LayoutModel.Rect Rect { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 8 additions & 31 deletions
39
...vationSystem-Server/ReservationSystem-Server/Areas/Admin/Views/LayoutBuilder/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,11 @@ | ||
@model ReservationSystem_Server.Areas.Admin.Models.LayoutModel | ||
|
||
@{ | ||
@{ | ||
ViewBag.Title = "Layout Builder"; | ||
} | ||
|
||
<ul class="nav nav-tabs" id="area-selector" role="tablist"> | ||
<li class="nav-item" role="presentation"> | ||
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home-tab-pane" type="button" role="tab" aria-controls="home-tab-pane" aria-selected="true">Areas Layout</button> | ||
</li> | ||
<li class="nav-item" role="presentation"> | ||
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile-tab-pane" type="button" role="tab" aria-controls="profile-tab-pane" aria-selected="false">Profile</button> | ||
</li> | ||
<li class="nav-item" role="presentation"> | ||
<button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact-tab-pane" type="button" role="tab" aria-controls="contact-tab-pane" aria-selected="false">Contact</button> | ||
</li> | ||
<li class="nav-item" role="presentation"> | ||
<button class="nav-link" id="disabled-tab" data-bs-toggle="tab" data-bs-target="#disabled-tab-pane" type="button" role="tab" aria-controls="disabled-tab-pane" aria-selected="false" disabled>Disabled</button> | ||
</li> | ||
</ul> | ||
<div class="tab-content" id="area-selector-content"> | ||
<div class="tab-pane fade show active" id="home-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0"> | ||
Tab 1 | ||
</div> | ||
<div class="tab-pane fade" id="profile-tab-pane" role="tabpanel" aria-labelledby="profile-tab" tabindex="0"> | ||
Tab 2 | ||
</div> | ||
<div class="tab-pane fade" id="contact-tab-pane" role="tabpanel" aria-labelledby="contact-tab" tabindex="0"> | ||
Tab 3 | ||
</div> | ||
<div class="tab-pane fade" id="disabled-tab-pane" role="tabpanel" aria-labelledby="disabled-tab" tabindex="0"> | ||
Tab 4 | ||
</div> | ||
</div> | ||
<config | ||
baseurl="@Url.Action("", "LayoutBuilder", new { Area = "Admin" }, Context.Request.Scheme)/" | ||
root="@Url.Action("", "LayoutBuilder", new { Area = "Admin" })"> | ||
</config> | ||
<div id="root"></div> | ||
|
||
<script defer src="~/js/layout-builder.gen.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 14 additions & 14 deletions
28
ReservationSystem-Server/ReservationSystem-Server/Areas/Admin/Views/Shared/_Nav.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
<span class="d-flex flex-nowrap"> | ||
<li class="nav-item"> | ||
<div class="d-flex flex-nowrap"> | ||
<span class="nav-item"> | ||
<a class="nav-link" style="color: #941925" asp-area="" asp-controller="Home" asp-action="Index" cth-active>Exit Admin Area</a> | ||
</li> | ||
<li class="nav-item"> | ||
</span> | ||
<span class="nav-item"> | ||
<a class="nav-link" asp-area="Admin" asp-controller="Home" asp-action="Index" cth-active>Admin Home</a> | ||
</li> | ||
<li class="nav-item"> | ||
</span> | ||
<span class="nav-item"> | ||
<a class="nav-link" asp-area="Admin" asp-controller="Sitting" asp-action="Index" cth-active>Sittings</a> | ||
</li> | ||
<li class="nav-item"> | ||
</span> | ||
<span class="nav-item"> | ||
<a class="nav-link" asp-area="Admin" asp-controller="Reservation" asp-action="Index" cth-active>Reservations</a> | ||
</li> | ||
<li class="nav-item"> | ||
</span> | ||
<span class="nav-item"> | ||
<a class="nav-link" asp-area="Admin" asp-controller="Employee" asp-action="Index" cth-active>Employees</a> | ||
</li> | ||
<li class="nav-item"> | ||
</span> | ||
<span class="nav-item"> | ||
<a class="nav-link" asp-area="Admin" asp-controller="Restaurant" asp-action="Index" cth-active>Restaurant</a> | ||
</li> | ||
</span> | ||
</span> | ||
</div> |
Oops, something went wrong.