SPEC:
- OK salvataggio ricetta in MongoDB
This commit is contained in:
@@ -13,13 +13,14 @@ namespace MP.Data.Conf
|
||||
{
|
||||
/// <summary>
|
||||
/// Dizionario delle chiavi, differenziate dai primi caratteri:
|
||||
/// [C] --> Calcolato
|
||||
/// [F] --> Fixed (NON modificabile)
|
||||
/// [E] --> Enum: modificabile ma da dizionario valori seguente
|
||||
/// C: --> Calcolato
|
||||
/// E: --> Enum: modificabile ma da dizionario valori seguente
|
||||
/// F: --> Fixed (NON modificabile)
|
||||
/// "" --> editabile
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ListKeys { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario degli enum permessi
|
||||
/// </summary>
|
||||
@@ -31,9 +32,9 @@ namespace MP.Data.Conf
|
||||
|
||||
public class CalcDetail
|
||||
{
|
||||
public string Description { get; set; } = null!;
|
||||
public string Type { get; set; } = null!;
|
||||
public string Format { get; set; } = null!;
|
||||
public string Description { get; set; } = "";
|
||||
public string Type { get; set; } = "";
|
||||
public string Format { get; set; } = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using MP.Data.MgModels;
|
||||
using System.IO;
|
||||
using MP.Data.Conf;
|
||||
using Newtonsoft.Json;
|
||||
using static MP.Data.MgModels.RecipeModel;
|
||||
|
||||
namespace MP.Data.Controllers
|
||||
{
|
||||
@@ -23,8 +24,13 @@ namespace MP.Data.Controllers
|
||||
_configuration = configuration;
|
||||
string mongoConf = _configuration.GetConnectionString("MongoConnect");
|
||||
client = new MongoClient(mongoConf);
|
||||
mongoDb = client.GetDatabase("MAPO");
|
||||
Log.Info("Avviata classe MpMongoController");
|
||||
}
|
||||
/// <summary>
|
||||
/// Database corrente MongoDB
|
||||
/// </summary>
|
||||
private IMongoDatabase mongoDb;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -41,12 +47,45 @@ namespace MP.Data.Controllers
|
||||
{
|
||||
await Task.Delay(1);
|
||||
RecipeModel answ = new RecipeModel();
|
||||
try
|
||||
{
|
||||
// definisco filtro
|
||||
var filtBuilder = Builders<RecipeModel>.Filter;
|
||||
var filter = filtBuilder.Eq<int>("IdxPODL", idxPODL);
|
||||
var collectionData = mongoDb.GetCollection<RecipeModel>("RecipeArchive");
|
||||
// recupero
|
||||
answ = collectionData.Find(filter).Project<RecipeModel>("{_id: 0}").FirstOrDefault<RecipeModel>();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Salva ricetta su MongoDB
|
||||
/// </summary>
|
||||
/// <param name="currRecord"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RecipeSetByPODL(RecipeModel currRecord)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
// definisco filtro
|
||||
var filtBuilder = Builders<RecipeModel>.Filter;
|
||||
var filter = filtBuilder.Eq<int>("IdxPODL", currRecord.IdxPODL);
|
||||
var collectionData = mongoDb.GetCollection<RecipeModel>("RecipeArchive");
|
||||
// elimino old
|
||||
collectionData.DeleteMany(filter);
|
||||
// aggiungo
|
||||
collectionData.InsertOne(currRecord);
|
||||
answ = true;
|
||||
}
|
||||
catch(Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in RecipeSetByPODL{Environment.NewLine}{exc}");
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -65,6 +104,8 @@ namespace MP.Data.Controllers
|
||||
{
|
||||
string rawData = File.ReadAllText(fullPath);
|
||||
var currRecipe = JsonConvert.DeserializeObject<RecipeConfig>(rawData);
|
||||
//// calcolo obj riga base (ne aggiungo1...)
|
||||
//var rigaBase = RecipeModel.ConvertToObj(currRecipe.RowsConf.ListKeys);
|
||||
// copio la mia ricetta come conf...
|
||||
answ = new RecipeModel()
|
||||
{
|
||||
@@ -72,14 +113,16 @@ namespace MP.Data.Controllers
|
||||
TemplateFile = currRecipe.TemplateFile,
|
||||
HeadConf = currRecipe.HeadConf,
|
||||
RowsConf = currRecipe.RowsConf,
|
||||
HeadVal = currRecipe.HeadConf.ListKeys,
|
||||
//HeadVal = currRecipe.HeadConf.ListKeys,
|
||||
HeadVal = RecipeModel.ConvertToObj(currRecipe.HeadConf.ListKeys),
|
||||
// aggiungo 1 riga...
|
||||
RowsVal = new Dictionary<int, Dictionary<string, string>>()
|
||||
RowsVal = new Dictionary<string, Dictionary<string, KeyConfig>>()
|
||||
{
|
||||
{ 1, currRecipe.RowsConf.ListKeys}
|
||||
//{ "1", rigaBase }
|
||||
{ "1", RecipeModel.ConvertToObj(currRecipe.RowsConf.ListKeys)}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
return answ;
|
||||
|
||||
@@ -6,9 +6,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MP.Data.Conf;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace MP.Data.MgModels
|
||||
{
|
||||
[BsonIgnoreExtraElements]
|
||||
public class RecipeModel : RecipeConfig
|
||||
{
|
||||
[BsonId]
|
||||
@@ -19,15 +21,93 @@ namespace MP.Data.MgModels
|
||||
public int IdxODL { get; set; } = 0;
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// Dizionario chiavi/valori campi header
|
||||
///// </summary>
|
||||
//public Dictionary<string, string> HeadVal { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
///// <summary>
|
||||
///// Elenco righe ricetta (ogni riga dizionario chiavi/valori)
|
||||
///// </summary>
|
||||
//public Dictionary<int, Dictionary<string, string>> RowsVal { get; set; } = new Dictionary<int, Dictionary<string, string>>();
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario chiavi/valori campi header
|
||||
/// Dizionario chiavi/valori estesi campi header
|
||||
/// </summary>
|
||||
public Dictionary<string, string> HeadVal { get; set; } = new Dictionary<string, string>();
|
||||
public Dictionary<string, KeyConfig> HeadVal { get; set; } = new Dictionary<string, KeyConfig>();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco righe ricetta (ogni riga dizionario chiavi/valori)
|
||||
/// </summary>
|
||||
public Dictionary<int, Dictionary<string, string>> RowsVal { get; set; } = new Dictionary<int, Dictionary<string, string>>();
|
||||
public Dictionary<string, Dictionary<string, KeyConfig>> RowsVal { get; set; } = new Dictionary<string, Dictionary<string, KeyConfig>>();
|
||||
|
||||
/// <summary>
|
||||
/// Inizializza la ListObj da ListKeys
|
||||
/// </summary>
|
||||
public static Dictionary<string, KeyConfig> ConvertToObj(Dictionary<string,string> ListKeys)
|
||||
{
|
||||
Dictionary<string, KeyConfig> ListObj = ListKeys.ToDictionary(x => x.Key, x => new KeyConfig(x.Value));
|
||||
return ListObj;
|
||||
}
|
||||
|
||||
public class KeyConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Init classe da valore raw
|
||||
/// </summary>
|
||||
/// <param name="rawValue"></param>
|
||||
public KeyConfig(string rawValue)
|
||||
{
|
||||
this.OrigVal = rawValue;
|
||||
this.Value = rawValue;
|
||||
// cerco se ho uno dei 3 caratteri (C/E/F):
|
||||
if (rawValue.Length >= 2 && rawValue.Substring(1, 1) == ":")
|
||||
{
|
||||
string selTipo = rawValue.Substring(0, 2);
|
||||
switch (selTipo)
|
||||
{
|
||||
case "C:":
|
||||
this.Type = KeyType.Calc;
|
||||
this.Value = rawValue.Substring(2);
|
||||
break;
|
||||
case "E:":
|
||||
this.Type = KeyType.Enum;
|
||||
this.Value = "";
|
||||
this.EnumType = rawValue.Substring(2);
|
||||
break;
|
||||
case "F:":
|
||||
this.Type = KeyType.Fixed;
|
||||
this.Value = rawValue.Substring(2);
|
||||
break;
|
||||
default:
|
||||
this.Type = KeyType.None;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Type = KeyType.Free;
|
||||
}
|
||||
}
|
||||
[NotMapped]
|
||||
public KeyType Type { get; set; } = KeyType.None;
|
||||
[NotMapped]
|
||||
public string Value { get; set; } = "";
|
||||
[NotMapped]
|
||||
public string EnumType { get; set; } = "";
|
||||
public string OrigVal { get; set; } = "";
|
||||
}
|
||||
|
||||
public enum KeyType
|
||||
{
|
||||
None = 0,
|
||||
Calc,
|
||||
Enum,
|
||||
Fixed,
|
||||
Free
|
||||
}
|
||||
|
||||
public string RawRecipe { get; set; } = "";
|
||||
|
||||
|
||||
@@ -4,25 +4,54 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card">
|
||||
<div class="card shadow p-3 mb-5 bg-body rounded">
|
||||
<div class="card-header">
|
||||
<h5>Dati Ricetta</h5>
|
||||
<h5>Testata Ricetta</h5>
|
||||
@if (CurrRecipe?.HeadVal != null)
|
||||
{
|
||||
<div class="row g-1">
|
||||
@foreach (var item in CurrRecipe.HeadVal)
|
||||
{
|
||||
<div class="col-3">
|
||||
<div class="form-floating">
|
||||
<input type="text" class="form-control" placeholder="@item.Key" @bind-value="@CurrRecipe.HeadVal[item.Key]">
|
||||
<label>@item.Key</label>
|
||||
<div class="form-floating2">
|
||||
<small class="form-label small">@item.Key</small>
|
||||
@if (item.Value.Type == MP.Data.MgModels.RecipeModel.KeyType.Fixed)
|
||||
{
|
||||
<input type="text" class="form-control" placeholder="@item.Key" @bind-value="@item.Value.Value" disabled>
|
||||
}
|
||||
else if (item.Value.Type == MP.Data.MgModels.RecipeModel.KeyType.Enum)
|
||||
{
|
||||
<select class="form-select" @bind="@item.Value.Value">
|
||||
@foreach (var enumItem in GetListByType(item.Value.EnumType))
|
||||
{
|
||||
<option value="@enumItem.Key">@enumItem.Value</option>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="text" class="form-control" placeholder="@item.Key" @bind-value="@item.Value.Value">
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="row g-1">
|
||||
<div class="col-6">
|
||||
<div class="d-grid">
|
||||
<button class="btn btn-sm btn-success" @onclick="() => SaveHeadData()">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="d-grid">
|
||||
<button class="btn btn-sm btn-warning" @onclick="() => CancelHeadData()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5>Righe Ricetta</h5>
|
||||
@if (CurrRecipe?.RowsVal != null)
|
||||
{
|
||||
@foreach (var riga in CurrRecipe.RowsVal)
|
||||
@@ -32,7 +61,7 @@ else
|
||||
{
|
||||
<div class="col-3">
|
||||
<div class="form-floating">
|
||||
<input type="text" class="form-control" placeholder="@item.Key" @bind-value="@CurrRecipe.RowsVal[riga.Key][item.Key]">
|
||||
<input type="text" class="form-control" placeholder="@item.Key" @bind-value="@item.Value.Value">
|
||||
<label>@item.Key</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,20 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.AspNetCore.Components.Routing;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Components.Web.Virtualization;
|
||||
using Microsoft.JSInterop;
|
||||
using MP.SPEC;
|
||||
using MP.SPEC.Shared;
|
||||
using MP.SPEC.Components;
|
||||
using EgwCoreLib.Razor;
|
||||
using MP.Data.MgModels;
|
||||
using MP.SPEC.Data;
|
||||
|
||||
@@ -22,20 +6,72 @@ namespace MP.SPEC.Components
|
||||
{
|
||||
public partial class RecipeMan
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
[Parameter]
|
||||
public int IdxPODL { get; set; } = 0;
|
||||
|
||||
[Parameter]
|
||||
public string RecipePath { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected bool isLoading = false;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected RecipeModel? CurrRecipe { get; set; } = null;
|
||||
|
||||
[Inject]
|
||||
protected MpDataService MDService { get; set; } = null!;
|
||||
|
||||
protected RecipeModel? CurrRecipe { get; set; } = null;
|
||||
#endregion Protected Properties
|
||||
|
||||
protected bool isLoading = false;
|
||||
#region Protected Methods
|
||||
|
||||
protected async Task CancelHeadData()
|
||||
{
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected Dictionary<string, string> GetListByType(string DictType)
|
||||
{
|
||||
Dictionary<string, string> answ = new Dictionary<string, string>();
|
||||
// inn primis il "selezionare"
|
||||
answ.Add("", "--- Selezionare ---");
|
||||
// cerco tipo in enums...
|
||||
if (CurrRecipe != null && CurrRecipe.HeadConf.EnumVal.ContainsKey(DictType))
|
||||
{
|
||||
foreach (var item in CurrRecipe.HeadConf.EnumVal[DictType])
|
||||
{
|
||||
answ.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
protected async Task SaveHeadData()
|
||||
{
|
||||
if (CurrRecipe != null)
|
||||
{
|
||||
await MDService.RecipeSetByPODL(CurrRecipe);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private async Task ReloadData()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
isLoading = true;
|
||||
@@ -52,7 +88,8 @@ namespace MP.SPEC.Components
|
||||
}
|
||||
await Task.Delay(1);
|
||||
isLoading = false;
|
||||
//await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,17 @@ namespace MP.SPEC.Data
|
||||
return mongoController.InitRecipe(idxPODL, confPath);
|
||||
}
|
||||
/// <summary>
|
||||
/// Salva ricetta su MongoDB
|
||||
/// </summary>
|
||||
/// <param name="currRecord"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RecipeSetByPODL(RecipeModel currRecord)
|
||||
{
|
||||
bool answ = false;
|
||||
answ = await mongoController.RecipeSetByPODL(currRecord);
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ricerca ricetta su MongoDB dato PODL
|
||||
/// </summary>
|
||||
/// <param name="idxPODL"></param>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP.SPEC</RootNamespace>
|
||||
<Version>6.16.2302.815</Version>
|
||||
<Version>6.16.2302.818</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MAPOSPEC </i>
|
||||
<h4>Versione: 6.16.2302.815</h4>
|
||||
<h4>Versione: 6.16.2302.818</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2302.815
|
||||
6.16.2302.818
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2302.815</version>
|
||||
<version>6.16.2302.818</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user