diff --git a/MP.Data/Conf/RecipeBlockConfig.cs b/MP.Data/Conf/RecipeBlockConfig.cs index 3cc966dc..8c400c81 100644 --- a/MP.Data/Conf/RecipeBlockConfig.cs +++ b/MP.Data/Conf/RecipeBlockConfig.cs @@ -13,13 +13,14 @@ namespace MP.Data.Conf { /// /// 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 /// public Dictionary ListKeys { get; set; } = new Dictionary(); + /// /// Dizionario degli enum permessi /// @@ -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; } = ""; } } } diff --git a/MP.Data/Controllers/MpMongoController.cs b/MP.Data/Controllers/MpMongoController.cs index b148332a..7d371c81 100644 --- a/MP.Data/Controllers/MpMongoController.cs +++ b/MP.Data/Controllers/MpMongoController.cs @@ -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"); } + /// + /// Database corrente MongoDB + /// + 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.Filter; + var filter = filtBuilder.Eq("IdxPODL", idxPODL); + var collectionData = mongoDb.GetCollection("RecipeArchive"); + // recupero + answ = collectionData.Find(filter).Project("{_id: 0}").FirstOrDefault(); + } + catch + { } return answ; } + /// + /// Salva ricetta su MongoDB + /// + /// + /// public async Task RecipeSetByPODL(RecipeModel currRecord) { await Task.Delay(1); bool answ = false; + try + { + // definisco filtro + var filtBuilder = Builders.Filter; + var filter = filtBuilder.Eq("IdxPODL", currRecord.IdxPODL); + var collectionData = mongoDb.GetCollection("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(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>() + RowsVal = new Dictionary>() { - { 1, currRecipe.RowsConf.ListKeys} + //{ "1", rigaBase } + { "1", RecipeModel.ConvertToObj(currRecipe.RowsConf.ListKeys)} } }; - + } return answ; diff --git a/MP.Data/MgModels/RecipeModel.cs b/MP.Data/MgModels/RecipeModel.cs index 13e3de31..a81a8cd8 100644 --- a/MP.Data/MgModels/RecipeModel.cs +++ b/MP.Data/MgModels/RecipeModel.cs @@ -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; + ///// + ///// Dizionario chiavi/valori campi header + ///// + //public Dictionary HeadVal { get; set; } = new Dictionary(); + + ///// + ///// Elenco righe ricetta (ogni riga dizionario chiavi/valori) + ///// + //public Dictionary> RowsVal { get; set; } = new Dictionary>(); + + + /// - /// Dizionario chiavi/valori campi header + /// Dizionario chiavi/valori estesi campi header /// - public Dictionary HeadVal { get; set; } = new Dictionary(); + public Dictionary HeadVal { get; set; } = new Dictionary(); + /// /// Elenco righe ricetta (ogni riga dizionario chiavi/valori) /// - public Dictionary> RowsVal { get; set; } = new Dictionary>(); + public Dictionary> RowsVal { get; set; } = new Dictionary>(); + /// + /// Inizializza la ListObj da ListKeys + /// + public static Dictionary ConvertToObj(Dictionary ListKeys) + { + Dictionary ListObj = ListKeys.ToDictionary(x => x.Key, x => new KeyConfig(x.Value)); + return ListObj; + } + + public class KeyConfig + { + /// + /// Init classe da valore raw + /// + /// + 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; } = ""; diff --git a/MP.SPEC/Components/RecipeMan.razor b/MP.SPEC/Components/RecipeMan.razor index 86e9e2ff..e0aaedc2 100644 --- a/MP.SPEC/Components/RecipeMan.razor +++ b/MP.SPEC/Components/RecipeMan.razor @@ -4,25 +4,54 @@ } else { -
+
-
Dati Ricetta
+
Testata Ricetta
@if (CurrRecipe?.HeadVal != null) {
@foreach (var item in CurrRecipe.HeadVal) {
-
- - +
+ @item.Key + @if (item.Value.Type == MP.Data.MgModels.RecipeModel.KeyType.Fixed) + { + + } + else if (item.Value.Type == MP.Data.MgModels.RecipeModel.KeyType.Enum) + { + + } + else + { + + }
}
+
+
+
+ +
+
+
+
+ +
+
+
}
+
Righe Ricetta
@if (CurrRecipe?.RowsVal != null) { @foreach (var riga in CurrRecipe.RowsVal) @@ -32,7 +61,7 @@ else {
- +
diff --git a/MP.SPEC/Components/RecipeMan.razor.cs b/MP.SPEC/Components/RecipeMan.razor.cs index 386d034a..0bfb29f4 100644 --- a/MP.SPEC/Components/RecipeMan.razor.cs +++ b/MP.SPEC/Components/RecipeMan.razor.cs @@ -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 GetListByType(string DictType) + { + Dictionary answ = new Dictionary(); + // 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 } } \ No newline at end of file diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index f52df1b3..237c2f2b 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -82,6 +82,17 @@ namespace MP.SPEC.Data return mongoController.InitRecipe(idxPODL, confPath); } /// + /// Salva ricetta su MongoDB + /// + /// + /// + public async Task RecipeSetByPODL(RecipeModel currRecord) + { + bool answ = false; + answ = await mongoController.RecipeSetByPODL(currRecord); + return answ; + } + /// /// Ricerca ricetta su MongoDB dato PODL /// /// diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 4a372ee7..51fb6385 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2302.815 + 6.16.2302.818 diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 500c0062..c1c0ae3f 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2302.815

+

Versione: 6.16.2302.818


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 654e02ac..8933711c 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2302.815 +6.16.2302.818 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index ce9cbcf3..2c233e02 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2302.815 + 6.16.2302.818 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false