Aggiunta metodi conteggio e lista file senza template nascosti + clone/copy template

This commit is contained in:
Samuele Locatelli
2026-04-08 17:24:24 +02:00
parent 3cfb050874
commit 5ce82b0e19
8 changed files with 119 additions and 24 deletions
+46 -4
View File
@@ -23,7 +23,8 @@ namespace Lux.Report.Data.Services
#region Public Methods
public int CountFile(string folderPath, string pattern)
/// <inheritdoc />
public int CountFile(string folderPath, string pattern, bool hideDot)
{
int answ = 0;
if (!string.IsNullOrEmpty(folderPath))
@@ -34,13 +35,44 @@ namespace Lux.Report.Data.Services
if (Directory.Exists(dirPath))
{
var fFound = Directory.GetFiles(dirPath, pattern);
answ = fFound.Count();
if (hideDot)
{
answ = fFound
.Where(path => !Path.GetFileName(path).StartsWith("."))
.Count();
}
else
{
answ = fFound.Count();
}
}
}
return answ;
}
public List<string> ListFile(string folderPath, string pattern)
public bool FileCopy(string origPath, string destPath)
{
bool done = false;
string fullPathFrom = Path.Combine(basePath, origPath);
if (File.Exists(fullPathFrom))
{
string fullPathTo = Path.Combine(basePath, destPath);
File.Copy(fullPathFrom, fullPathTo, true);
done = File.Exists(fullPathTo);
}
return done;
}
public bool FileExists(string filePath)
{
// calcolo path file...
string fullPath = Path.Combine(basePath, filePath);
return File.Exists(fullPath);
}
/// <inheritdoc />
public List<string> ListFile(string folderPath, string pattern, bool hideDot)
{
List<string> answ = new();
if (!string.IsNullOrEmpty(folderPath))
@@ -50,7 +82,17 @@ namespace Lux.Report.Data.Services
// se esiste...
if (Directory.Exists(dirPath))
{
answ = Directory.GetFiles(dirPath, pattern).ToList();
var rawList = Directory.GetFiles(dirPath, pattern).ToList();
if (hideDot)
{
answ = rawList
.Where(path => !Path.GetFileName(path).StartsWith("."))
.ToList();
}
else
{
answ = rawList;
}
}
}
return answ;
+21 -6
View File
@@ -13,23 +13,40 @@ namespace Lux.Report.Data.Services
{
#region Public Methods
/// <summary>
/// Esegue conteggio file trovati in folder richiesta dato pattern
/// </summary>
/// <param name="folderPath">Cartella di riferimento</param>
/// <param name="pattern">Pattern ricerca</param>
/// <param name="hideDot">Nasconde i "dotfile" (file nascosti che iniziano per .)</param>
/// <returns>Num file trovati</returns>
int CountFile(string folderPath, string pattern);
int CountFile(string folderPath, string pattern, bool hideDot);
/// <summary>
/// Duplica un file dato path origine + destinazione (verificando esista origine)
/// </summary>
/// <param name="origPath"></param>
/// <param name="destPath"></param>
/// <returns></returns>
bool FileCopy(string origPath, string destPath);
/// <summary>
/// Verifica esistenza file richiesto
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
bool FileExists(string filePath);
/// <summary>
/// Elenco file trovati in folder richiesta dato pattern
/// </summary>
/// <param name="folderPath">Cartella di riferimento</param>
/// <param name="pattern">Pattern ricerca</param>
/// <param name="hideDot">Nasconde i "dotfile" (file nascosti che iniziano per .)</param>
/// <returns>Elenco file trovati</returns>
List<string> ListFile(string folderPath, string pattern);
List<string> ListFile(string folderPath, string pattern, bool hideDot);
#endregion Public Methods
///// <summary>
///// Salva contenuto file (sincrono)
@@ -57,7 +74,5 @@ namespace Lux.Report.Data.Services
///// <param name="contentStream">Stream contenitore dati</param>
///// <returns>True se salvato con successo</returns>
//Task<bool> SaveFileStreamAsync(string folderPath, string pattern, Stream contentStream);
#endregion Public Methods
}
}
}
@@ -1,13 +1,17 @@
<b>@CurrReport.Name</b>
<div class="card shadow">
@* <div class="card-header">Elenco</div> *@
<div class="card-footer">
<div class="card-header">
<div class="d-flex justify-content-between">
<div class="px-0">
<b>@CurrReport.Name</b>: Modelli Disponibili
</div>
<div class="px-0">
<button class="btn btn-sm btn-success" title="Add New" @onclick="DoAddNew"><i class="fa-solid fa-file-circle-plus"></i></button>
</div>
</div>
</div>
<div class="card-body p-2">
<table class="table table-sm table-striped">
<thead>
<tr>
<th>Report</th>
</tr>
</thead>
<tbody>
@foreach (var item in ListReports)
{
@@ -15,8 +19,8 @@
<td>
<button class="btn btn-primary w-100" @onclick="() => ReqEdit(item)">
<div class="d-flex justify-content-between">
<div class="px-0"><i class="fa-solid fa-up-right-from-square"></i></div>
<div class="px-0">@FileName(item)</div>
<div class="px-0"><i class="fa-solid fa-up-right-from-square"></i></div>
</div>
</button>
@@ -1,6 +1,8 @@
using DevExpress.XtraRichEdit.Import.OpenXml;
using Lux.Report.Data.DbModel;
using Lux.Report.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Lux.Report.Manager.Components.Compo
{
@@ -13,20 +15,51 @@ namespace Lux.Report.Manager.Components.Compo
[Parameter]
public EventCallback<string> EC_ReqEdit { get; set; }
[Parameter]
public EventCallback<bool> EC_ReqUpdate { get; set; }
#endregion Public Properties
#region Protected Methods
protected override void OnParametersSet()
{
ReloadData();
}
private void ReloadData()
{
//base.OnParametersSet();
string repPath = Path.Combine("reports", CurrReport.Name);
ListReports = FService.ListFile(repPath, "*.repx");
// elenco file esclusi quelli nascosti (template)
ListReports = FService.ListFile(repPath, "*.repx", true);
}
#endregion Protected Methods
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
/// <summary>
/// Creazione nuovo report duplicando il file template
/// </summary>
private async Task DoAddNew()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler creare un nuovo modello report di tipo {CurrReport.Name} ?"))
return;
string tplPathFrom = Path.Combine("reports", CurrReport.Name, ".template.repx");
// se esiste lo duplica
if (FService.FileExists(tplPathFrom))
{
string newName = $"{CurrReport.Name}_{DateTime.Now:yyyyMMdd-HHmmss}.repx";
string tplPathTo = Path.Combine("reports", CurrReport.Name, newName);
FService.FileCopy(tplPathFrom, tplPathTo);
ReloadData();
await EC_ReqUpdate.InvokeAsync(true);
}
}
#region Private Fields
private List<string> ListReports = new List<string>();
@@ -55,7 +55,8 @@ namespace Lux.Report.Manager.Components.Pages
private int CountNumRep(string repName)
{
string repPath = Path.Combine("reports", repName);
return FService.CountFile(repPath, "*.repx");
// numero file esclusi quelli nascosti (template)
return FService.CountFile(repPath, "*.repx", true);
}
private async Task DoReset()
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>LUX - Web Windows MES</i>
<h4>Versione: 1.1.2604.0816</h4>
<h4>Versione: 1.1.2604.0817</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.1.2604.0816
1.1.2604.0817
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.1.2604.0816</version>
<version>1.1.2604.0817</version>
<url>http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html</changelog>
<mandatory>false</mandatory>