From 61f90f434ca27d3bf374ca7fb198c1bca0ab3bd1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 26 May 2020 02:41:55 +0100 Subject: [PATCH] Add machine details in admin view. --- .../Areas/Admin/Views/Machines/Details.cshtml | 87 -------------- Marechai/Marechai.csproj | 5 +- Marechai/Pages/Admin/Details/Machine.razor | 110 ++++++++++++++++++ Marechai/Pages/Admin/Details/Machine.razor.cs | 42 +++++++ Marechai/Pages/Admin/Machines.razor | 4 +- .../Services/MachinesService.es.resx | 32 +++++ Marechai/Services/MachinesService.cs | 2 + 7 files changed, 191 insertions(+), 91 deletions(-) delete mode 100644 Marechai/Areas/Admin/Views/Machines/Details.cshtml create mode 100644 Marechai/Pages/Admin/Details/Machine.razor create mode 100644 Marechai/Pages/Admin/Details/Machine.razor.cs diff --git a/Marechai/Areas/Admin/Views/Machines/Details.cshtml b/Marechai/Areas/Admin/Views/Machines/Details.cshtml deleted file mode 100644 index 22f879c9..00000000 --- a/Marechai/Areas/Admin/Views/Machines/Details.cshtml +++ /dev/null @@ -1,87 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : Details.cshtml -// Author(s) : Natalia Portillo -// -// --[ 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 . -// -// ---------------------------------------------------------------------------- -// Copyright © 2003-2020 Natalia Portillo -*******************************************************************************/ -} -@model Marechai.Database.Models.Machine - -@{ - ViewData["Title"] = "Details"; -} -

Details

-
-

Machine

-
-
-
- @Html.DisplayNameFor(model => model.Company) -
-
- @Html.DisplayFor(model => model.Company.Name) -
-
- @Html.DisplayNameFor(model => model.Family) -
-
- @Html.DisplayFor(model => model.Family.Name) -
-
- @Html.DisplayNameFor(model => model.Name) -
-
- @Html.DisplayFor(model => model.Name) -
-
- @Html.DisplayNameFor(model => model.Model) -
-
- @Html.DisplayFor(model => model.Model) -
-
- @Html.DisplayNameFor(model => model.Introduced) -
-
- @Html.DisplayFor(model => model.Introduced) -
-
- @Html.DisplayNameFor(model => model.Type) -
-
- @Html.DisplayFor(model => model.Type) -
-
-
-
- - Edit - - - Back to List - -
\ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 51b777ad..7fbccde4 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.1185 + 3.0.99.1188 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website @@ -106,6 +106,9 @@ true + + true + <_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" /> diff --git a/Marechai/Pages/Admin/Details/Machine.razor b/Marechai/Pages/Admin/Details/Machine.razor new file mode 100644 index 00000000..8f99adab --- /dev/null +++ b/Marechai/Pages/Admin/Details/Machine.razor @@ -0,0 +1,110 @@ +@{ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Filename : Details.cshtml +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ +} + +@page "/admin/machines/details/{Id:int}" +@using Marechai.Database +@inherits OwningComponentBase +@inject IStringLocalizer L +@inject CompaniesService CompaniesService +@inject MachineFamiliesService MachineFamiliesService +@attribute [Authorize(Roles = "UberAdmin, Admin")] +

@L["Machine details"]

+
+ +@if (!_loaded) +{ +

@L["Loading..."]

+ + return; +} + +
+ + @L["Company"] + + + + @L["Name"] + + + + @L["Type"] + + + @if (_editable || _model.Model != null) + { + + @L["Model"] + + + } + @if(_editable || _model.Introduced.HasValue) + { + + @L["Introduced"] + @if(_model.Introduced?.Year == 1000) + { + @L["PROTOTYPE"] + } + else + { + + } + + } + @if (_editable || _model.FamilyId.HasValue) + { + + @L["Family"] + + + } +
+
+ @L["Edit"] + @L["Back to list"] +
\ No newline at end of file diff --git a/Marechai/Pages/Admin/Details/Machine.razor.cs b/Marechai/Pages/Admin/Details/Machine.razor.cs new file mode 100644 index 00000000..e9e39788 --- /dev/null +++ b/Marechai/Pages/Admin/Details/Machine.razor.cs @@ -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 _companies; + bool _editable; + List _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(); + } + } +} \ No newline at end of file diff --git a/Marechai/Pages/Admin/Machines.razor b/Marechai/Pages/Admin/Machines.razor index d579fb0b..ae86fa3b 100644 --- a/Marechai/Pages/Admin/Machines.razor +++ b/Marechai/Pages/Admin/Machines.razor @@ -93,9 +93,7 @@ @item.Type - - @L["Details"] - + @L["Details"] @L["Edit"] diff --git a/Marechai/Resources/Services/MachinesService.es.resx b/Marechai/Resources/Services/MachinesService.es.resx index 4a055204..b6cc37ec 100644 --- a/Marechai/Resources/Services/MachinesService.es.resx +++ b/Marechai/Resources/Services/MachinesService.es.resx @@ -446,6 +446,22 @@ Compañía Company + + Máquinas + Machines + + + Detalles + Detailes + + + Editar + Edit + + + Eliminar + Delete + Eliminar máquina Delete machine @@ -458,4 +474,20 @@ Cancelar Cancel + + Detalles de máquina + Machine details + + + Volver a la lista + Back to list + + + Modelo + Model + + + Familia + Family + \ No newline at end of file diff --git a/Marechai/Services/MachinesService.cs b/Marechai/Services/MachinesService.cs index 52942f5f..6f22a870 100644 --- a/Marechai/Services/MachinesService.cs +++ b/Marechai/Services/MachinesService.cs @@ -35,6 +35,8 @@ namespace Marechai.Services Introduced = m.Introduced, Type = m.Type, Family = m.Family.Name }).ToListAsync(); + public async Task GetAsync(int id) => await _context.Machines.FindAsync(id); + public async Task GetMachine(int id) { Machine machine = await _context.Machines.FindAsync(id);