Add dump admin page.

This commit is contained in:
2020-08-08 03:37:41 +01:00
parent fc9cc19056
commit a1249878e8
15 changed files with 1147 additions and 1 deletions

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>4.0.0.1803</Version>
<Version>4.0.0.1808</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>
@@ -167,6 +167,12 @@
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Update="Pages\Admin\Dumps.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
<Content Update="Pages\Admin\Details\Dump.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" />
@@ -283,4 +289,12 @@
<_ContentIncludedByDefault Remove="Areas\Admin\Views\_ViewImports.cshtml" />
<_ContentIncludedByDefault Remove="Areas\Admin\Views\_ViewStart.cshtml" />
</ItemGroup>
<ItemGroup>
<Compile Update="Pages\Admin\Dumps.razor.cs">
<DependentUpon>Dumps.razor</DependentUpon>
</Compile>
<Compile Update="Pages\Admin\Details\Dump.razor.cs">
<DependentUpon>Dump.razor</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,150 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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/dumps/details/{Id:long}"
@page "/admin/dumps/edit/{Id:long}"
@page "/admin/dumps/create"
@using Marechai.Database
@using Marechai.Database.Models
@inherits OwningComponentBase<DumpsService>
@inject IStringLocalizer<DumpsService> L
@inject MediaService MediaService
@inject NavigationManager NavigationManager
@inject IWebHostEnvironment Host
@inject IJSRuntime JSRuntime
@inject Microsoft.AspNetCore.Identity.UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Dump details"]</h3>
<hr />
@if (!_loaded)
{
<p align="center">@L["Loading..."]</p>
return;
}
<div>
<Field>
<FieldLabel>@L["Dumper"]</FieldLabel>
<Validation Validator="@ValidateDumper">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Dumper">
<Feedback>
<ValidationError>@L["Please enter a valid dumper."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Field>
@if (_editing || _model.UserId != null)
{
<Field>
<FieldLabel>@L["Dumper's user"]</FieldLabel>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownUser">@L["Unknown (user)"]</Check>
}
@if (!_editing ||
!_unknownUser)
{
<Select Disabled="!_editing" TValue="string" @bind-SelectedValue="@_model.UserId">
@foreach (var user in _users)
{
<SelectItem TValue="string" Value="@user.Id">@user.UserName</SelectItem>
}
</Select>
}
</Field>
}
@if (_editing || _model.DumpingGroup != null)
{
<Field>
<FieldLabel>@L["Dumping group, or group whose guidelines where followed to make the dump"]</FieldLabel>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownDumpingGroup">@L["Unknown (dumping group)"]</Check>
}
@if (!_editing ||
!_unknownDumpingGroup)
{
<Validation Validator="@ValidateDumpingGroup">
<TextEdit Disabled="!_editing" @bind-Text="@_model.DumpingGroup">
<Feedback>
<ValidationError>@L["Please enter a valid dumping group."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editing || _model.DumpDate != null)
{
<Field>
<FieldLabel>@L["Dump date"]</FieldLabel>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownDumpDate">@L["Unknown (dump date)"]</Check>
}
@if (!_editing || !_unknownDumpDate)
{
<Validation Validator="@ValidateDumpDate">
<DateEdit TValue="DateTime?" ReadOnly="!_editing" @bind-Date="@_model.DumpDate" >
<Feedback>
<ValidationError>@L["Please enter a valid dump date."]</ValidationError>
</Feedback>
</DateEdit>
</Validation>
}
</Field>
}
<Field>
<FieldLabel>@L["Media"]</FieldLabel>
<Select Disabled="!_editing" TValue="ulong" @bind-SelectedValue="@_model.MediaId">
@foreach (var media in _medias)
{
<SelectItem TValue="ulong" Value="@media.Id">@media.Title</SelectItem>
}
</Select>
</Field>
@{
// TODO: Dump hardware
}
</div>
<div>
@if (!_editing)
{
<Button Color="Color.Primary" Clicked="@OnEditClicked">@L["Edit"]</Button>
}
else
{
<Button Color="Color.Success" Clicked="@OnSaveClicked">@L["Save"]</Button>
<Button Color="Color.Danger" Clicked="@OnCancelClicked">@L["Cancel"]</Button>
}
<a href="/admin/dumps" class="btn btn-secondary">@L["Back to list"]</a>
</div>

View File

@@ -0,0 +1,159 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Marechai.Database.Models;
using Marechai.Shared;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
namespace Marechai.Pages.Admin.Details
{
public partial class Dump
{
AuthenticationState _authState;
bool _creating;
bool _editing;
bool _loaded;
List<MediaViewModel> _medias;
DumpViewModel _model;
bool _unknownDumpDate;
bool _unknownDumpingGroup;
bool _unknownUser;
List<ApplicationUser> _users;
[Parameter]
public ulong Id { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(_loaded)
return;
_loaded = true;
_creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
StartsWith("admin/dumps/create", StringComparison.InvariantCulture);
if(Id <= 0 &&
!_creating)
return;
_medias = await MediaService.GetTitlesAsync();
_model = _creating ? new DumpViewModel() : await Service.GetAsync(Id);
_authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
_users = UserManager.Users.Select(u => new ApplicationUser
{
Id = u.Id,
UserName = u.UserName
}).ToList();
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
StartsWith("admin/dumps/edit/",
StringComparison.InvariantCulture);
if(_editing)
SetCheckboxes();
StateHasChanged();
}
void SetCheckboxes()
{
_unknownUser = string.IsNullOrWhiteSpace(_model.UserId);
_unknownDumpingGroup = string.IsNullOrWhiteSpace(_model.DumpingGroup);
_unknownDumpDate = !_model.DumpDate.HasValue;
}
void OnEditClicked()
{
_editing = true;
SetCheckboxes();
StateHasChanged();
}
async void OnCancelClicked()
{
_editing = false;
if(_creating)
{
NavigationManager.ToBaseRelativePath("admin/dumps");
return;
}
_model = await Service.GetAsync(Id);
SetCheckboxes();
StateHasChanged();
}
async void OnSaveClicked()
{
if(_unknownUser)
_model.UserId = null;
else if(string.IsNullOrWhiteSpace(_model.UserId))
return;
if(_unknownDumpingGroup)
_model.DumpingGroup = null;
else if(string.IsNullOrWhiteSpace(_model.DumpingGroup))
return;
if(_unknownDumpDate)
_model.DumpDate = null;
else if(_model.DumpDate?.Date >= DateTime.UtcNow.Date)
return;
if(string.IsNullOrWhiteSpace(_model.Dumper))
return;
if(_creating)
Id = await Service.CreateAsync(_model, (await UserManager.GetUserAsync(_authState.User)).Id);
else
await Service.UpdateAsync(_model, (await UserManager.GetUserAsync(_authState.User)).Id);
_editing = false;
_creating = false;
_model = await Service.GetAsync(Id);
SetCheckboxes();
StateHasChanged();
}
void ValidateDumper(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Dumper must be smaller than 256 characters."], 256);
void ValidateDumpingGroup(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Dumping group must be smaller than 256 characters."], 256);
void ValidateDumpDate(ValidatorEventArgs e) => Validators.ValidateDate(e);
}
}

View File

@@ -0,0 +1,110 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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/dumps"
@using Marechai.Database.Models
@inherits OwningComponentBase<DumpsService>
@inject IStringLocalizer<DumpsService> L
@inject Microsoft.AspNetCore.Identity.UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Dumps"]</h3>
@if (_dumps is null)
{
<p>@L["Loading..."]</p>
return;
}
<p>
<a class="btn btn-primary" href="/admin/dumps/create">@L["Create new"]</a>
</p>
<table class="table table-striped">
<thead>
<tr>
<th>
@L["Dumper"]
</th>
<th>
@L["Dumping group"]
</th>
<th>
@L["Dump date"]
</th>
<th>
@L["Media title"]
</th>
<th>
@L["Username"]
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in _dumps)
{
<tr>
<td>
@item.Dumper
</td>
<td>
@item.DumpingGroup
</td>
<td>
@item.DumpDate
</td>
<td>
@item.MediaTitle
</td>
<td>
@item.UserName
</td>
<td>
<a class="btn btn-primary" href="/admin/dumps/details/@item.Id">@L["Details"]</a>
<a class="btn btn-secondary" href="/admin/dumps/edit/@item.Id">@L["Edit"]</a>
<Button Color="Color.Danger" Clicked="() => {ShowModal(item.Id);}">@L["Delete"]</Button>
</td>
</tr>
}
</tbody>
</table>
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
<ModalBackdrop/>
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["Delete dump"]</ModalTitle>
<CloseButton Clicked="@HideModal"/>
</ModalHeader>
<ModalBody>
<Text>@string.Format(@L["Are you sure you want to delete the dump made by {0} on {1} for media titled {2}?"], _currentDump?.Dumper, _currentDump?.DumpDate.ToString() ?? L["Unknown (dump date)"], _currentDump?.MediaTitle)</Text>
</ModalBody>
<ModalFooter>
<Button Color="Color.Primary" Clicked="@HideModal" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
<Button Color="Color.Danger" Clicked="@ConfirmDelete" Disabled="@_deleteInProgress">@L["Delete"]</Button>
</ModalFooter>
</ModalContent>
</Modal>

View File

@@ -0,0 +1,88 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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
*******************************************************************************/
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components.Authorization;
namespace Marechai.Pages.Admin
{
public partial class Dumps
{
DumpViewModel _currentDump;
bool _deleteInProgress;
List<DumpViewModel> _dumps;
Modal _frmDelete;
bool _loaded;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(_loaded)
return;
_dumps = await Service.GetAsync();
_loaded = true;
StateHasChanged();
}
void ShowModal(ulong itemId)
{
_currentDump = _dumps.FirstOrDefault(n => n.Id == itemId);
_frmDelete.Show();
}
void HideModal() => _frmDelete.Hide();
async void ConfirmDelete()
{
if(_currentDump is null)
return;
_deleteInProgress = true;
_dumps = null;
AuthenticationState authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
// Yield thread to let UI to update
await Task.Yield();
await Service.DeleteAsync(_currentDump.Id, (await UserManager.GetUserAsync(authState.User)).Id);
_dumps = await Service.GetAsync();
_deleteInProgress = false;
_frmDelete.Hide();
// Yield thread to let UI to update
await Task.Yield();
// Tell we finished loading
StateHasChanged();
}
void ModalClosing(ModalClosingEventArgs obj) => _currentDump = null;
}
}

View File

@@ -111,3 +111,11 @@
</li>
</ul>
</div>
<div class="content">
<h3>@L["Administrative pages for media dumps"]</h3>
<ul>
<li>
<a href="/admin/dumps">@L["Dumps"]</a>
</li>
</ul>
</div>

View File

@@ -23,4 +23,10 @@
<data name="Currency pegging" xml:space="preserve">
<value>Currency pegging</value>
</data>
<data name="Dumps" xml:space="preserve">
<value>Dumps</value>
</data>
<data name="Administrative pages for media dumps" xml:space="preserve">
<value>Administrative pages for media dumps</value>
</data>
</root>

View File

@@ -222,4 +222,10 @@
<data name="Currency pegging" xml:space="preserve">
<value>Vinculación de divisa</value>
</data>
<data name="Dumps" xml:space="preserve">
<value>Volcados</value>
</data>
<data name="Administrative pages for media dumps" xml:space="preserve">
<value>Páginas de administración de volcados</value>
</data>
</root>

View File

@@ -0,0 +1,92 @@
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Dumps" xml:space="preserve">
<value>Dumps</value>
</data>
<data name="Loading..." xml:space="preserve">
<value>Loading...</value>
</data>
<data name="Create new" xml:space="preserve">
<value>Create new</value>
</data>
<data name="Dumper" xml:space="preserve">
<value>Dumper</value>
</data>
<data name="Dumping group" xml:space="preserve">
<value>Dumping group</value>
</data>
<data name="Dump date" xml:space="preserve">
<value>Dump date</value>
</data>
<data name="Media title" xml:space="preserve">
<value>Media title</value>
</data>
<data name="Username" xml:space="preserve">
<value>Username</value>
</data>
<data name="Details" xml:space="preserve">
<value>Details</value>
</data>
<data name="Edit" xml:space="preserve">
<value>Edit</value>
</data>
<data name="Delete" xml:space="preserve">
<value>Delete</value>
</data>
<data name="Delete dump" xml:space="preserve">
<value>Delete dump</value>
</data>
<data name="Are you sure you want to delete the dump made by {0} on {1} for media titled {2}?" xml:space="preserve">
<value>Are you sure you want to delete the dump made by {0} on {1} for media titled {2}?</value>
</data>
<data name="Unknown (dump date)" xml:space="preserve">
<value>Unknown</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="Dump details" xml:space="preserve">
<value>Dump details</value>
</data>
<data name="Please enter a valid dumper." xml:space="preserve">
<value>Please enter a valid dumper.</value>
</data>
<data name="Dumper's user" xml:space="preserve">
<value>Dumper's user</value>
</data>
<data name="Unknown (user)" xml:space="preserve">
<value>Unknown</value>
</data>
<data name="Dumping group, or group whose guidelines where followed to make the dump" xml:space="preserve">
<value>Dumping group, or group whose guidelines where followed to make the dump</value>
</data>
<data name="Unknown (dumping group)" xml:space="preserve">
<value>Unknown</value>
</data>
<data name="Please enter a valid dumping group." xml:space="preserve">
<value>Please enter a valid dumping group.</value>
</data>
<data name="Please enter a valid dump date." xml:space="preserve">
<value>Please enter a valid dump date.</value>
</data>
<data name="Media" xml:space="preserve">
<value>Media</value>
</data>
<data name="Save" xml:space="preserve">
<value>Save</value>
</data>
<data name="Back to list" xml:space="preserve">
<value>Back to list</value>
</data>
</root>

View File

@@ -0,0 +1,92 @@
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Dumps" xml:space="preserve">
<value>Volcados</value>
</data>
<data name="Loading..." xml:space="preserve">
<value>Cargando...</value>
</data>
<data name="Create new" xml:space="preserve">
<value>Crear nuevo</value>
</data>
<data name="Dumper" xml:space="preserve">
<value>Volcador(a)</value>
</data>
<data name="Dumping group" xml:space="preserve">
<value>Grupo de volcado</value>
</data>
<data name="Dump date" xml:space="preserve">
<value>Fecha de volcado</value>
</data>
<data name="Media title" xml:space="preserve">
<value>Título del medio</value>
</data>
<data name="Username" xml:space="preserve">
<value>Nombre de usuario/a</value>
</data>
<data name="Details" xml:space="preserve">
<value>Detalles</value>
</data>
<data name="Edit" xml:space="preserve">
<value>Editar</value>
</data>
<data name="Delete" xml:space="preserve">
<value>Eliminar</value>
</data>
<data name="Delete dump" xml:space="preserve">
<value>Eliminar volcado</value>
</data>
<data name="Are you sure you want to delete the dump made by {0} on {1} for media titled {2}?" xml:space="preserve">
<value>¿Estás seguro de eliminar el volcado realizado por {0} el {1} para el medio titulado {2}?</value>
</data>
<data name="Unknown (dump date)" xml:space="preserve">
<value>Desconocida</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancelar</value>
</data>
<data name="Dump details" xml:space="preserve">
<value>Detalles del volcado</value>
</data>
<data name="Please enter a valid dumper." xml:space="preserve">
<value>Por favor introduce un(a) volcador(a) válido/a.</value>
</data>
<data name="Dumper's user" xml:space="preserve">
<value>Usuario/a del volcador(a)</value>
</data>
<data name="Unknown (user)" xml:space="preserve">
<value>Desconocido</value>
</data>
<data name="Dumping group, or group whose guidelines where followed to make the dump" xml:space="preserve">
<value>Grupo de volcado, o grupo cuyas instrucciones se siguieron para realizar el volcado</value>
</data>
<data name="Unknown (dumping group)" xml:space="preserve">
<value>Desconocido</value>
</data>
<data name="Please enter a valid dumping group." xml:space="preserve">
<value>Por favor introduce un grupo de volcado válido.</value>
</data>
<data name="Please enter a valid dump date." xml:space="preserve">
<value>Por favor introduce una fecha de volcado válida.</value>
</data>
<data name="Media" xml:space="preserve">
<value>Medio</value>
</data>
<data name="Save" xml:space="preserve">
<value>Guardar</value>
</data>
<data name="Back to list" xml:space="preserve">
<value>Volver a la lista</value>
</data>
</root>

View File

@@ -0,0 +1,118 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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
*******************************************************************************/
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
namespace Marechai.Services
{
public class DumpsService
{
readonly MarechaiContext _context;
public DumpsService(MarechaiContext context) => _context = context;
public async Task<List<DumpViewModel>> GetAsync() => await _context.
Dumps.OrderBy(d => d.Dumper).
ThenBy(d => d.DumpingGroup).
ThenBy(b => b.Media.Title).ThenBy(d => d.DumpDate).
Select(d => new DumpViewModel
{
Id = d.Id,
Dumper = d.Dumper,
UserId = d.UserId,
DumpingGroup = d.DumpingGroup,
DumpDate = d.DumpDate,
UserName = d.User.UserName,
MediaId = d.MediaId,
MediaTitle = d.Media.Title,
MediaDumpId = d.MediaDumpId
}).ToListAsync();
public async Task<DumpViewModel> GetAsync(ulong id) => await _context.Dumps.Where(d => d.Id == id).
Select(d => new DumpViewModel
{
Id = d.Id,
Dumper = d.Dumper,
UserId = d.User.Id,
DumpingGroup = d.DumpingGroup,
DumpDate = d.DumpDate,
UserName = d.User.UserName,
MediaId = d.MediaId,
MediaTitle = d.Media.Title,
MediaDumpId = d.MediaDumpId
}).FirstOrDefaultAsync();
public async Task UpdateAsync(DumpViewModel viewModel, string userId)
{
Dump model = await _context.Dumps.FindAsync(viewModel.Id);
if(model is null)
return;
model.Dumper = viewModel.Dumper;
model.UserId = viewModel.UserId;
model.DumpingGroup = viewModel.DumpingGroup;
model.DumpDate = viewModel.DumpDate;
model.MediaId = viewModel.MediaId;
model.MediaDumpId = viewModel.MediaDumpId;
await _context.SaveChangesWithUserAsync(userId);
}
public async Task<ulong> CreateAsync(DumpViewModel viewModel, string userId)
{
var model = new Dump
{
Dumper = viewModel.Dumper,
UserId = viewModel.UserId,
DumpingGroup = viewModel.DumpingGroup,
DumpDate = viewModel.DumpDate,
MediaId = viewModel.MediaId,
MediaDumpId = viewModel.MediaDumpId
};
await _context.Dumps.AddAsync(model);
await _context.SaveChangesWithUserAsync(userId);
return model.Id;
}
public async Task DeleteAsync(ulong id, string userId)
{
Dump item = await _context.Dumps.FindAsync(id);
if(item is null)
return;
_context.Dumps.Remove(item);
await _context.SaveChangesWithUserAsync(userId);
}
}
}

View File

@@ -0,0 +1,200 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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
*******************************************************************************/
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
namespace Marechai.Services
{
public class MediaService
{
readonly MarechaiContext _context;
public MediaService(MarechaiContext context) => _context = context;
public async Task<List<MediaViewModel>> GetAsync() => await _context.
Media.OrderBy(d => d.Title).
Select(d => new MediaViewModel
{
Id = d.Id,
Title = d.Title,
Sequence = d.Sequence,
LastSequence = d.LastSequence,
Type = d.Type,
WriteOffset = d.WriteOffset,
Sides = d.Sides,
Layers = d.Layers,
Sessions = d.Sessions,
Tracks = d.Tracks,
Sectors = d.Sectors,
Size = d.Size,
CopyProtection = d.CopyProtection,
PartNumber = d.PartNumber,
SerialNumber = d.SerialNumber,
Barcode = d.Barcode,
CatalogueNumber = d.CatalogueNumber,
Manufacturer = d.Manufacturer,
Model = d.Model,
Revision = d.Revision,
Firmware = d.Firmware,
PhysicalBlockSize = d.PhysicalBlockSize,
LogicalBlockSize = d.LogicalBlockSize,
BlockSizes = d.BlockSizes.Object,
StorageInterface = d.StorageInterface,
TableOfContents = d.TableOfContents.Object
}).ToListAsync();
public async Task<List<MediaViewModel>> GetTitlesAsync() => await _context.
Media.OrderBy(d => d.Title).
Select(d => new MediaViewModel
{
Id = d.Id,
Title = d.Title
}).ToListAsync();
public async Task<MediaViewModel> GetAsync(ulong id) => await _context.Media.Where(d => d.Id == id).
Select(d => new MediaViewModel
{
Id = d.Id,
Title = d.Title,
Sequence = d.Sequence,
LastSequence = d.LastSequence,
Type = d.Type,
WriteOffset = d.WriteOffset,
Sides = d.Sides,
Layers = d.Layers,
Sessions = d.Sessions,
Tracks = d.Tracks,
Sectors = d.Sectors,
Size = d.Size,
CopyProtection = d.CopyProtection,
PartNumber = d.PartNumber,
SerialNumber = d.SerialNumber,
Barcode = d.Barcode,
CatalogueNumber = d.CatalogueNumber,
Manufacturer = d.Manufacturer,
Model = d.Model,
Revision = d.Revision,
Firmware = d.Firmware,
PhysicalBlockSize =
d.PhysicalBlockSize,
LogicalBlockSize =
d.LogicalBlockSize,
BlockSizes = d.BlockSizes.Object,
StorageInterface =
d.StorageInterface,
TableOfContents =
d.TableOfContents.Object
}).FirstOrDefaultAsync();
public async Task UpdateAsync(MediaViewModel viewModel, string userId)
{
Media model = await _context.Media.FindAsync(viewModel.Id);
if(model is null)
return;
model.Title = viewModel.Title;
model.Sequence = viewModel.Sequence;
model.LastSequence = viewModel.LastSequence;
model.Type = viewModel.Type;
model.WriteOffset = viewModel.WriteOffset;
model.Sides = viewModel.Sides;
model.Layers = viewModel.Layers;
model.Sessions = viewModel.Sessions;
model.Tracks = viewModel.Tracks;
model.Sectors = viewModel.Sectors;
model.Size = viewModel.Size;
model.CopyProtection = viewModel.CopyProtection;
model.PartNumber = viewModel.PartNumber;
model.SerialNumber = viewModel.SerialNumber;
model.Barcode = viewModel.Barcode;
model.CatalogueNumber = viewModel.CatalogueNumber;
model.Manufacturer = viewModel.Manufacturer;
model.Model = viewModel.Model;
model.Revision = viewModel.Revision;
model.Firmware = viewModel.Firmware;
model.PhysicalBlockSize = viewModel.PhysicalBlockSize;
model.LogicalBlockSize = viewModel.LogicalBlockSize;
model.BlockSizes = viewModel.BlockSizes;
model.StorageInterface = viewModel.StorageInterface;
model.TableOfContents = viewModel.TableOfContents;
await _context.SaveChangesWithUserAsync(userId);
}
public async Task<ulong> CreateAsync(MediaViewModel viewModel, string userId)
{
var model = new Media
{
Title = viewModel.Title,
Sequence = viewModel.Sequence,
LastSequence = viewModel.LastSequence,
Type = viewModel.Type,
WriteOffset = viewModel.WriteOffset,
Sides = viewModel.Sides,
Layers = viewModel.Layers,
Sessions = viewModel.Sessions,
Tracks = viewModel.Tracks,
Sectors = viewModel.Sectors,
Size = viewModel.Size,
CopyProtection = viewModel.CopyProtection,
PartNumber = viewModel.PartNumber,
SerialNumber = viewModel.SerialNumber,
Barcode = viewModel.Barcode,
CatalogueNumber = viewModel.CatalogueNumber,
Manufacturer = viewModel.Manufacturer,
Model = viewModel.Model,
Revision = viewModel.Revision,
Firmware = viewModel.Firmware,
PhysicalBlockSize = viewModel.PhysicalBlockSize,
LogicalBlockSize = viewModel.LogicalBlockSize,
BlockSizes = viewModel.BlockSizes,
StorageInterface = viewModel.StorageInterface,
TableOfContents = viewModel.TableOfContents
};
await _context.Media.AddAsync(model);
await _context.SaveChangesWithUserAsync(userId);
return model.Id;
}
public async Task DeleteAsync(ulong id, string userId)
{
Media item = await _context.Media.FindAsync(id);
if(item is null)
return;
_context.Media.Remove(item);
await _context.SaveChangesWithUserAsync(userId);
}
}
}

View File

@@ -72,6 +72,8 @@ namespace Marechai.Services
services.AddScoped<Iso4217Service>();
services.AddScoped<CurrencyPeggingService>();
services.AddScoped<DocumentsService>();
services.AddScoped<DumpsService>();
services.AddScoped<MediaService>();
}
}
}

View File

@@ -0,0 +1,41 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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
*******************************************************************************/
using System;
namespace Marechai.ViewModels
{
public class DumpViewModel : BaseViewModel<ulong>
{
public string Dumper { get; set; }
public string UserId { get; set; }
public string DumpingGroup { get; set; }
public DateTime? DumpDate { get; set; }
public string UserName { get; set; }
public ulong MediaId { get; set; }
public string MediaTitle { get; set; }
public ulong MediaDumpId { get; set; }
}
}

View File

@@ -0,0 +1,60 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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
*******************************************************************************/
using Aaru.CommonTypes;
using Marechai.Database;
using Marechai.Database.Models;
namespace Marechai.ViewModels
{
public class MediaViewModel : BaseViewModel<ulong>
{
public string Title { get; set; }
public ushort? Sequence { get; set; }
public ushort? LastSequence { get; set; }
public MediaType Type { get; set; }
public int? WriteOffset { get; set; }
public ushort? Sides { get; set; }
public ushort? Layers { get; set; }
public ushort? Sessions { get; set; }
public ushort? Tracks { get; set; }
public ulong Sectors { get; set; }
public ulong Size { get; set; }
public string CopyProtection { get; set; }
public string PartNumber { get; set; }
public string SerialNumber { get; set; }
public string Barcode { get; set; }
public string CatalogueNumber { get; set; }
public string Manufacturer { get; set; }
public string Model { get; set; }
public string Revision { get; set; }
public string Firmware { get; set; }
public int? PhysicalBlockSize { get; set; }
public int? LogicalBlockSize { get; set; }
public VariableBlockSize[] BlockSizes { get; set; }
public StorageInterface? StorageInterface { get; set; }
public OpticalDiscTrack[] TableOfContents { get; set; }
}
}