mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add machine details in admin view.
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
@{
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Details.cshtml
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Admin view details
|
||||
//
|
||||
// --[ 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-2020 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
}
|
||||
@model Marechai.Database.Models.Machine
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Details";
|
||||
}
|
||||
<h2>Details</h2>
|
||||
<div>
|
||||
<h4>Machine</h4>
|
||||
<hr />
|
||||
<dl class="dl-horizontal">
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Company)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Company.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Family)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Family.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Name)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Model)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Model)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Introduced)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Introduced)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Type)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Type)
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-primary">
|
||||
Edit
|
||||
</a>
|
||||
<a asp-action="Index" class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Version>3.0.99.1185</Version>
|
||||
<Version>3.0.99.1188</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
@@ -106,6 +106,9 @@
|
||||
<Content Update="Pages\Admin\Details\MachineFamily.razor">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
</Content>
|
||||
<Content Update="Pages\Admin\Details\Machine.razor">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" />
|
||||
|
||||
110
Marechai/Pages/Admin/Details/Machine.razor
Normal file
110
Marechai/Pages/Admin/Details/Machine.razor
Normal file
@@ -0,0 +1,110 @@
|
||||
@{
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Details.cshtml
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Admin view details
|
||||
//
|
||||
// --[ 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-2020 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
}
|
||||
|
||||
@page "/admin/machines/details/{Id:int}"
|
||||
@using Marechai.Database
|
||||
@inherits OwningComponentBase<MachinesService>
|
||||
@inject IStringLocalizer<MachinesService> L
|
||||
@inject CompaniesService CompaniesService
|
||||
@inject MachineFamiliesService MachineFamiliesService
|
||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||
<h3>@L["Machine details"]</h3>
|
||||
<hr />
|
||||
|
||||
@if (!_loaded)
|
||||
{
|
||||
<p align="center">@L["Loading..."]</p>
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
<div>
|
||||
<Field>
|
||||
<FieldLabel>@L["Company"]</FieldLabel>
|
||||
<Select Disabled="!_editable" TValue="int" @bind-SelectedValue="@_model.CompanyId">
|
||||
@foreach (var company in _companies)
|
||||
{
|
||||
<SelectItem TValue="int" Value="@company.Id">@company.Name</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel>@L["Name"]</FieldLabel>
|
||||
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Name"/>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel>@L["Type"]</FieldLabel>
|
||||
<Select Disabled="!_editable" TValue="int" @bind-SelectedValue="@Type">
|
||||
@foreach (int type in Enum.GetValues(typeof(MachineType)))
|
||||
{
|
||||
<SelectItem TValue="int" Value="@type">@(((MachineType)type).ToString())</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
@if (_editable || _model.Model != null)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Model"]</FieldLabel>
|
||||
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Model"/>
|
||||
</Field>
|
||||
}
|
||||
@if(_editable || _model.Introduced.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Introduced"]</FieldLabel>
|
||||
@if(_model.Introduced?.Year == 1000)
|
||||
{
|
||||
<TextEdit ReadOnly="true">@L["PROTOTYPE"]</TextEdit>
|
||||
}
|
||||
else
|
||||
{
|
||||
<DateEdit ReadOnly="!_editable" TValue="DateTime?" @bind-Date="@_model.Introduced"/>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.FamilyId.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Family"]</FieldLabel>
|
||||
<Select Disabled="!_editable" TValue="int?" @bind-SelectedValue="@_model.FamilyId">
|
||||
@foreach (MachineFamilyViewModel family in _families)
|
||||
{
|
||||
<SelectItem TValue="int?" Value="@family.Id">@family.Name</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
}
|
||||
</div>
|
||||
<div>
|
||||
<span class="btn btn-primary">@L["Edit"]</span>
|
||||
<a href="/admin/machines" class="btn btn-secondary">@L["Back to list"]</a>
|
||||
</div>
|
||||
42
Marechai/Pages/Admin/Details/Machine.razor.cs
Normal file
42
Marechai/Pages/Admin/Details/Machine.razor.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Database;
|
||||
using Marechai.ViewModels;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Marechai.Pages.Admin.Details
|
||||
{
|
||||
public partial class Machine
|
||||
{
|
||||
List<CompanyViewModel> _companies;
|
||||
bool _editable;
|
||||
List<MachineFamilyViewModel> _families;
|
||||
bool _loaded;
|
||||
Database.Models.Machine _model;
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
int Type
|
||||
{
|
||||
get => (int)_model.Type;
|
||||
set => _model.Type = (MachineType)value;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_loaded)
|
||||
return;
|
||||
|
||||
_loaded = true;
|
||||
|
||||
if(Id <= 0)
|
||||
return;
|
||||
|
||||
_companies = await CompaniesService.GetAsync();
|
||||
_families = await MachineFamiliesService.GetAsync();
|
||||
_model = await Service.GetAsync(Id);
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,9 +93,7 @@
|
||||
@item.Type
|
||||
</td>
|
||||
<td>
|
||||
<span class="btn btn-primary">
|
||||
@L["Details"]
|
||||
</span>
|
||||
<a class="btn btn-primary" href="/admin/machines/details/@item.Id">@L["Details"]</a>
|
||||
<span class="btn btn-secondary">
|
||||
@L["Edit"]
|
||||
</span>
|
||||
|
||||
@@ -446,6 +446,22 @@
|
||||
<value>Compañía</value>
|
||||
<comment>Company</comment>
|
||||
</data>
|
||||
<data name="Machines" xml:space="preserve">
|
||||
<value>Máquinas</value>
|
||||
<comment>Machines</comment>
|
||||
</data>
|
||||
<data name="Details" xml:space="preserve">
|
||||
<value>Detalles</value>
|
||||
<comment>Detailes</comment>
|
||||
</data>
|
||||
<data name="Edit" xml:space="preserve">
|
||||
<value>Editar</value>
|
||||
<comment>Edit</comment>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Eliminar</value>
|
||||
<comment>Delete</comment>
|
||||
</data>
|
||||
<data name="Delete machine" xml:space="preserve">
|
||||
<value>Eliminar máquina</value>
|
||||
<comment>Delete machine</comment>
|
||||
@@ -458,4 +474,20 @@
|
||||
<value>Cancelar</value>
|
||||
<comment>Cancel</comment>
|
||||
</data>
|
||||
<data name="Machine details" xml:space="preserve">
|
||||
<value>Detalles de máquina</value>
|
||||
<comment>Machine details</comment>
|
||||
</data>
|
||||
<data name="Back to list" xml:space="preserve">
|
||||
<value>Volver a la lista</value>
|
||||
<comment>Back to list</comment>
|
||||
</data>
|
||||
<data name="Model" xml:space="preserve">
|
||||
<value>Modelo</value>
|
||||
<comment>Model</comment>
|
||||
</data>
|
||||
<data name="Family" xml:space="preserve">
|
||||
<value>Familia</value>
|
||||
<comment>Family</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -35,6 +35,8 @@ namespace Marechai.Services
|
||||
Introduced = m.Introduced, Type = m.Type, Family = m.Family.Name
|
||||
}).ToListAsync();
|
||||
|
||||
public async Task<Machine> GetAsync(int id) => await _context.Machines.FindAsync(id);
|
||||
|
||||
public async Task<MachineViewModel> GetMachine(int id)
|
||||
{
|
||||
Machine machine = await _context.Machines.FindAsync(id);
|
||||
|
||||
Reference in New Issue
Block a user