mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add consolidation for SSCs.
This commit is contained in:
Submodule DiscImageChef.CommonTypes updated: 40ce44b1d4...73e5c50481
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DiscImageChef.CommonTypes.Metadata;
|
using DiscImageChef.CommonTypes.Metadata;
|
||||||
@@ -5,6 +6,7 @@ using DiscImageChef.Server.Models;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace DiscImageChef.Server.Areas.Admin.Controllers
|
namespace DiscImageChef.Server.Areas.Admin.Controllers
|
||||||
{
|
{
|
||||||
@@ -48,5 +50,69 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult Consolidate()
|
||||||
|
{
|
||||||
|
List<SscModel> dups = _context.Ssc.GroupBy(x => new
|
||||||
|
{
|
||||||
|
x.BlockSizeGranularity, x.MaxBlockLength, x.MinBlockLength
|
||||||
|
}).Where(x => x.Count() > 1).Select(x => new SscModel
|
||||||
|
{
|
||||||
|
BlockSizeGranularity = x.Key.BlockSizeGranularity, MaxBlockLength = x.Key.MaxBlockLength,
|
||||||
|
MinBlockLength = x.Key.MinBlockLength
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
return View(new SscModelForView
|
||||||
|
{
|
||||||
|
List = dups, Json = JsonConvert.SerializeObject(dups)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken]
|
||||||
|
public IActionResult ConsolidateConfirmed(string models)
|
||||||
|
{
|
||||||
|
SscModel[] duplicates;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
duplicates = JsonConvert.DeserializeObject<SscModel[]>(models);
|
||||||
|
}
|
||||||
|
catch(JsonSerializationException)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(duplicates is null)
|
||||||
|
return BadRequest();
|
||||||
|
|
||||||
|
foreach(SscModel duplicate in duplicates)
|
||||||
|
{
|
||||||
|
Ssc master =
|
||||||
|
_context.Ssc.FirstOrDefault(m => m.BlockSizeGranularity == duplicate.BlockSizeGranularity &&
|
||||||
|
m.MaxBlockLength == duplicate.MaxBlockLength &&
|
||||||
|
m.MinBlockLength == duplicate.MinBlockLength);
|
||||||
|
|
||||||
|
if(master is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach(Ssc ssc in _context.Ssc.Where(m => m.BlockSizeGranularity == duplicate.BlockSizeGranularity &&
|
||||||
|
m.MaxBlockLength == duplicate.MaxBlockLength &&
|
||||||
|
m.MinBlockLength == duplicate.MinBlockLength).Skip(1).
|
||||||
|
ToArray())
|
||||||
|
{
|
||||||
|
foreach(TestedSequentialMedia media in _context.TestedSequentialMedia.Where(d => d.SscId == ssc.Id))
|
||||||
|
{
|
||||||
|
media.SscId = master.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.Ssc.Update(ssc);
|
||||||
|
_context.Ssc.Remove(ssc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.SaveChanges();
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
@model SscModelForView
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Consolidate duplicate CHS";
|
||||||
|
Layout = "_Layout";
|
||||||
|
}
|
||||||
|
<h2>Consolidate duplicate SSC</h2>
|
||||||
|
<div>
|
||||||
|
The following SSC have duplicates.
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.List[0].MinBlockLength)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.List[0].MaxBlockLength)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.List[0].BlockSizeGranularity)
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model.List)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.MinBlockLength)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.MaxBlockLength)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.BlockSizeGranularity)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
Do you want to remove the duplicates?
|
||||||
|
<form asp-action="Consolidate" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" asp-for="Json" name="models" />
|
||||||
|
<a asp-action="Index" class="btn btn-primary">Back to List</a>
|
||||||
|
<input class="btn btn-danger" type="submit" value="Consolidate" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -33,6 +33,9 @@
|
|||||||
// Copyright © 2011-2019 Natalia Portillo
|
// Copyright © 2011-2019 Natalia Portillo
|
||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
}
|
}
|
||||||
|
<div>
|
||||||
|
<a asp-action="Consolidate" class="btn btn-danger">Consolidate duplicates</a>
|
||||||
|
</div>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
17
DiscImageChef.Server/Models/SscModel.cs
Normal file
17
DiscImageChef.Server/Models/SscModel.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Server.Models
|
||||||
|
{
|
||||||
|
public class SscModel
|
||||||
|
{
|
||||||
|
public byte? BlockSizeGranularity { get; set; }
|
||||||
|
public uint? MaxBlockLength { get; set; }
|
||||||
|
public uint? MinBlockLength { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SscModelForView
|
||||||
|
{
|
||||||
|
public List<SscModel> List { get; set; }
|
||||||
|
public string Json { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user