154 lines
4.0 KiB
Plaintext
154 lines
4.0 KiB
Plaintext
@using MP.Land.Data
|
|
@using System.Text
|
|
@using DiffMatchPatch
|
|
|
|
<div class="row">
|
|
<div class="col-6 table-success">
|
|
<div class="row">
|
|
<div class="col-4 text-success">
|
|
<h4>Archivio</h4>
|
|
</div>
|
|
<div class="col-4">
|
|
</div>
|
|
<div class="col-4 text-end">
|
|
<input @bind="@pHeight" class="text-end" width="20" inputmode="numeric" /> <i class="fas fa-arrows-alt-v"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@if (numChanges > 0)
|
|
{
|
|
<div class="col-6 table-danger">
|
|
<div class="row">
|
|
<div class="col-4 text-danger">
|
|
<h4>Attuale</h4>
|
|
</div>
|
|
<div class="col-4">
|
|
</div>
|
|
<div class="col-4 text-end p-2">
|
|
<span class="border border-danger table-danger py-1 px-2"><b>@numChanges</b> modifiche</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
<div class="row" style="height: @(pHeight)em; overflow-y: scroll;">
|
|
<div class="col-6 table-success">
|
|
<div class="border border-success p-2 bg-light">
|
|
<p>@((MarkupString)oldResult)</p>
|
|
</div>
|
|
</div>
|
|
@if (numChanges > 0)
|
|
{
|
|
<div class="col-6 table-danger">
|
|
<div class="border border-danger p-2 bg-light">
|
|
<p>@((MarkupString)newResult)</p>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
@code {
|
|
|
|
string sepDest = "<br />";
|
|
|
|
protected int pHeight = 25;
|
|
|
|
protected string oldResult = "";
|
|
protected string newResult = "";
|
|
|
|
protected string _oldText = "";
|
|
protected string _newText = "";
|
|
|
|
[Parameter]
|
|
public EventCallback<int> diffDone { get; set; }
|
|
|
|
protected int numChanges { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public string oldText
|
|
{
|
|
get
|
|
{
|
|
return _oldText;
|
|
}
|
|
set
|
|
{
|
|
_oldText = value;
|
|
}
|
|
}
|
|
|
|
protected string oldTextFix
|
|
{
|
|
get
|
|
{
|
|
return _oldText.Replace(Environment.NewLine, sepDest).Replace("\n", sepDest).Replace("\r", sepDest);
|
|
}
|
|
}
|
|
|
|
protected string newTextFix
|
|
{
|
|
get
|
|
{
|
|
return _newText.Replace(Environment.NewLine, sepDest).Replace("\n", sepDest).Replace("\r", sepDest);
|
|
}
|
|
}
|
|
[Parameter]
|
|
public string newText
|
|
{
|
|
get
|
|
{
|
|
return _newText;
|
|
}
|
|
set
|
|
{
|
|
_newText = value;
|
|
ReloadData();
|
|
}
|
|
}
|
|
protected void ReloadData()
|
|
{
|
|
numChanges = 0;
|
|
// calcolo diff
|
|
diff_match_patch dmp = new diff_match_patch();
|
|
List<Diff> diff = dmp.diff_main(oldTextFix, newTextFix);
|
|
dmp.diff_cleanupSemantic(diff);
|
|
|
|
// predispongo la stringa secondo l'elenco dei diff....
|
|
StringBuilder sbNew = new StringBuilder();
|
|
StringBuilder sbOld = new StringBuilder();
|
|
foreach (var item in diff)
|
|
{
|
|
switch (item.operation)
|
|
{
|
|
case Operation.DELETE:
|
|
sbOld.Append($"<span class=\"border border-success table-success\">{item.text}</span>");
|
|
break;
|
|
case Operation.INSERT:
|
|
sbNew.Append($"<span class=\"border border-danger table-danger\">{item.text}</span>");
|
|
numChanges++;
|
|
break;
|
|
case Operation.EQUAL:
|
|
sbNew.Append($"<span class=\"text-dark\">{item.text}</span>");
|
|
sbOld.Append($"<span class=\"text-dark\">{item.text}</span>");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
newResult = sbNew.ToString().Trim();
|
|
oldResult = sbOld.ToString().Trim();
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await diffDone.InvokeAsync(numChanges);
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
|
|
protected override Task OnInitializedAsync()
|
|
{
|
|
ReloadData();
|
|
return base.OnInitializedAsync();
|
|
}
|
|
|
|
} |