57c41c7a60
- fix naming DbModels
319 lines
8.1 KiB
C#
319 lines
8.1 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.FileData.DbModels;
|
|
using MP.Prog.Data;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Prog.Components
|
|
{
|
|
public partial class FileEditor : ComponentBase
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Item richiesto x display
|
|
/// </summary>
|
|
[Parameter]
|
|
public FileModel currItem
|
|
{
|
|
get
|
|
{
|
|
return _currItem = null;
|
|
}
|
|
set
|
|
{
|
|
_currItem = value;
|
|
CompareRev = false;
|
|
LoadRevision();
|
|
FixTitles();
|
|
}
|
|
}
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
[Parameter]
|
|
public EventCallback<int> DataReset { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataUpdated { get; set; }
|
|
|
|
[Parameter]
|
|
public List<ArchMaccModel> MacList { get; set; }
|
|
|
|
/// <summary>
|
|
/// Rev richiesta (x confronto)
|
|
/// </summary>
|
|
[Parameter]
|
|
public int ReqRev
|
|
{
|
|
get => SelRevDx;
|
|
set
|
|
{
|
|
if (value > 0)
|
|
{
|
|
CompareRev = true;
|
|
SelRevDx = value;
|
|
}
|
|
else
|
|
{
|
|
CompareRev = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public List<TagModel> TagList { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public string CurrFileContent(string fullPath)
|
|
{
|
|
string answ = "";
|
|
if (File.Exists(fullPath))
|
|
{
|
|
answ = File.ReadAllText(fullPath);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected int numDiff = 0;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected FileArchDataService FDService { get; set; }
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; }
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; }
|
|
|
|
protected int SelRevDx
|
|
{
|
|
get => _selRevDx;
|
|
set
|
|
{
|
|
if (_selRevDx != value)
|
|
{
|
|
_selRevDx = value;
|
|
LoadRevision();
|
|
FixTitles();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected int SelRevSx
|
|
{
|
|
get => _selRevSx;
|
|
set
|
|
{
|
|
if (_selRevSx != value)
|
|
{
|
|
_selRevSx = value;
|
|
// ricarico file SX
|
|
LoadRevision();
|
|
FixTitles();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
LoadRevision();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private FileModel _currItem = new FileModel();
|
|
private int _selRevDx = 0;
|
|
private int _selRevSx = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool CompareRev { get; set; } = false;
|
|
private string FileContDx { get; set; } = "";
|
|
|
|
private string FileContSx { get; set; } = "";
|
|
|
|
private List<int> ListRevDx
|
|
{
|
|
get
|
|
{
|
|
List<int> answ = new List<int>();
|
|
for (int i = 0; i <= _currItem.Rev; i++)
|
|
{
|
|
answ.Add(i);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private List<int> ListRevSx
|
|
{
|
|
get
|
|
{
|
|
List<int> answ = new List<int>() { 0 };
|
|
for (int i = 1; i < SelRevDx; i++)
|
|
{
|
|
answ.Add(i);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private string TitleDx { get; set; } = "Attuale";
|
|
|
|
private string TitleSx { get; set; } = "Archivio";
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task ApproveChange()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler accettare la modifica del file selezionato generando una nuova revisione?"))
|
|
return;
|
|
|
|
if (_currItem != null)
|
|
{
|
|
await FDService.FileModApprove(_currItem, MServ.UserName);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Log.Error("_currItem null!");
|
|
}
|
|
}
|
|
|
|
private async Task cancelUpdate()
|
|
{
|
|
await DataReset.InvokeAsync(0);
|
|
}
|
|
|
|
private async Task deleteRecord()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il file selezionato??"))
|
|
return;
|
|
|
|
if (_currItem != null)
|
|
{
|
|
await FDService.FileDelete(_currItem);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Log.Error("_currItem null!");
|
|
}
|
|
}
|
|
|
|
private void DoCompare()
|
|
{
|
|
CompareRev = !CompareRev;
|
|
if (CompareRev)
|
|
{
|
|
SelRevDx = _currItem.Rev;
|
|
}
|
|
LoadRevision();
|
|
FixTitles();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esporta da archivio a filesystem
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task ExportArchive()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler sovrascrivere il programma salvato in rete con la versione (inattiva) selezionata?"))
|
|
return;
|
|
|
|
if (_currItem != null)
|
|
{
|
|
await DataReset.InvokeAsync(0);
|
|
await FDService.FileExport(_currItem);
|
|
await DataReset.InvokeAsync(0);
|
|
await FDService.UpdateMachineArchive(_currItem.IdxMacchina, 1, false, false, MServ.UserName, true);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Log.Error("_currItem null!");
|
|
}
|
|
}
|
|
|
|
private void FixTitles()
|
|
{
|
|
// sistemo titoli
|
|
TitleSx = CompareRev ? $"Rev. {SelRevSx}" : "Archivio";
|
|
TitleDx = CompareRev ? $"Rev. {SelRevDx}" : "Attuale";
|
|
}
|
|
|
|
private void LoadRevision()
|
|
{
|
|
if (CompareRev)
|
|
{
|
|
var reqSx = FDService.FileGetByKeyRev(_currItem.FileId, SelRevSx);
|
|
var reqDx = FDService.FileGetByKeyRev(_currItem.FileId, SelRevDx);
|
|
FileContSx = reqSx.FileStringContent;
|
|
FileContDx = reqDx.FileStringContent;
|
|
}
|
|
else
|
|
{
|
|
FileContSx = _currItem.FileStringContent;
|
|
FileContDx = CurrFileContent(_currItem.Path);
|
|
}
|
|
FixTitles();
|
|
}
|
|
|
|
private async Task RejectChange()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare la modifica del file selezionato e sovrascrivere la versione in rete?"))
|
|
return;
|
|
|
|
if (_currItem != null)
|
|
{
|
|
await FDService.FileReject(_currItem);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Log.Error("_currItem null!");
|
|
}
|
|
}
|
|
|
|
private async Task saveUpdate()
|
|
{
|
|
if (_currItem != null)
|
|
{
|
|
await FDService.FileUpdate(_currItem);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Log.Error("_currItem null!");
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |