184 lines
4.6 KiB
C#
184 lines
4.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.FileData.DatabaseModels;
|
|
using MP.Prog.Data;
|
|
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 Protected Fields
|
|
|
|
protected int numDiff = 0;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Public Fields
|
|
|
|
public FileModel _currItem = new FileModel();
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected FileArchDataService DataService { get; set; }
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public FileModel currItem
|
|
{
|
|
get
|
|
{
|
|
return _currItem = null;
|
|
}
|
|
set
|
|
{
|
|
_currItem = value;
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataReset { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataUpdated { get; set; }
|
|
|
|
[Parameter]
|
|
public List<MacchinaModel> MacList { get; set; }
|
|
|
|
[Parameter]
|
|
public List<TagModel> TagList { get; set; }
|
|
|
|
#endregion Public 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 DataService.FileApprove(_currItem);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("File 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 DataService.FileDelete(_currItem);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("File null!");
|
|
}
|
|
}
|
|
|
|
/// <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 DataService.FileExport(_currItem);
|
|
await DataReset.InvokeAsync(0);
|
|
await DataService.updateMachineArchive(_currItem.IdxMacchina, 1, false, false);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("File null!");
|
|
}
|
|
}
|
|
|
|
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 DataService.FileReject(_currItem);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("File null!");
|
|
}
|
|
}
|
|
|
|
private async Task saveUpdate()
|
|
{
|
|
if (_currItem != null)
|
|
{
|
|
await DataService.FileUpdate(_currItem);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("File null!");
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected void diffDoneHandler(int numChanges)
|
|
{
|
|
#if false
|
|
numDiff = numChanges;
|
|
#endif
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
public string CurrFileContent(string fullPath)
|
|
{
|
|
string answ = "";
|
|
if (File.Exists(fullPath))
|
|
{
|
|
answ = File.ReadAllText(fullPath);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |