Optimize view of GPUs by machine admin page.

This commit is contained in:
2019-05-20 01:11:45 +01:00
parent f54a8599ea
commit 43e472732f
4 changed files with 86 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
using System.Linq;
using System.Threading.Tasks;
using Cicm.Database.Models;
using cicm_web.Areas.Admin.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
@@ -25,7 +26,11 @@ namespace cicm_web.Areas.Admin.Controllers
{
IIncludableQueryable<GpusByMachine, Machine> cicmContext =
_context.GpusByMachine.Include(g => g.Gpu).Include(g => g.Machine);
return View(await cicmContext.OrderBy(g => g.Machine.Name).ThenBy(g => g.Gpu.Name).ToListAsync());
return View(await cicmContext.OrderBy(g => g.Machine.Name).ThenBy(g => g.Gpu.Name)
.Select(g => new GpusByMachineViewModel
{
Id = g.Id, Gpu = g.Gpu.Name, Machine = g.Machine.Name
}).ToListAsync());
}
// GET: GpusByMachine/Details/5

View File

@@ -0,0 +1,43 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : GpusByMachine.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Junction betweeen GPU and machine.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
using System.ComponentModel;
using Cicm.Database.Models;
namespace cicm_web.Areas.Admin.Models
{
public class GpusByMachineViewModel : BaseModel<long>
{
[DisplayName("GPU")]
public string Gpu;
public long Id;
public string Machine;
}
}

View File

@@ -1,4 +1,5 @@
@model IEnumerable<Cicm.Database.Models.GpusByMachine>
@using cicm_web.Areas.Admin.Models
@model IEnumerable<cicm_web.Areas.Admin.Models.GpusByMachineViewModel>
@{
ViewData["Title"] = "Index";
@@ -7,7 +8,10 @@
<h1>GPUs by machine</h1>
<p>
<a asp-action="Create" class="btn btn-primary">Create New</a>
<a asp-action="Create"
class="btn btn-primary">
Create New
</a>
</p>
<table class="table">
<thead>
@@ -22,18 +26,31 @@
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
@foreach(GpusByMachineViewModel item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Machine.Name)
@Html.DisplayFor(modelItem => item.Machine)
</td>
<td>
@Html.DisplayFor(modelItem => item.Gpu.Name)
@Html.DisplayFor(modelItem => item.Gpu)
</td>
<td>
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-primary">Details</a>
<a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-secondary">Edit</a>
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Delete</a>
<a asp-action="Details"
asp-route-id="@item.Id"
class="btn btn-primary">
Details
</a>
<a asp-action="Edit"
asp-route-id="@item.Id"
class="btn btn-secondary">
Edit
</a>
<a asp-action="Delete"
asp-route-id="@item.Id"
class="btn btn-danger">
Delete
</a>
</td>
</tr>
}

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>3.0.99.549</Version>
<Version>3.0.99.550</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>