Refactor quick action output handling and extend case note support
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
using C4IT.F4SD.DisplayFormatting;
|
||||
using C4IT.FASD.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static C4IT.Logging.cLogManager;
|
||||
|
||||
namespace FasdDesktopUi.Basics.Models.QuickActionOutput
|
||||
{
|
||||
public class cQuickActionOutputList : cQuickActionOutput
|
||||
{
|
||||
public cQuickActionOutputList(cF4sdQuickActionRevision.cOutput scriptOutput) : base(scriptOutput)
|
||||
{
|
||||
InstantiateDisplayTypes(scriptOutput);
|
||||
}
|
||||
|
||||
public Dictionary<string, RawValueType> DisplayTypes { get; set; } = new Dictionary<string, RawValueType>();
|
||||
public List<List<KeyValuePair<string, object>>> Values { get; set; } = new List<List<KeyValuePair<string, object>>>();
|
||||
|
||||
private void InstantiateDisplayTypes(cF4sdQuickActionRevision.cOutput scriptOutput)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (scriptOutput.ColumnTypes is Newtonsoft.Json.Linq.JArray columnTypeJArray)
|
||||
{
|
||||
var columnTypes = columnTypeJArray.ToObject<List<dynamic>>();
|
||||
if (columnTypes != null && columnTypes.Count > 0)
|
||||
{
|
||||
foreach (var columnTypeObject in columnTypes)
|
||||
{
|
||||
var displayType = GetDisplayType(columnTypeObject);
|
||||
DisplayTypes[displayType.Key] = displayType.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (scriptOutput.ColumnTypes is Newtonsoft.Json.Linq.JObject columnTypeJObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
var displayType = GetDisplayType(columnTypeJObject);
|
||||
|
||||
DisplayTypes[displayType.Key] = displayType.Value;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetDisplayValue(int row, int column, Dictionary<string, cColumnOutputFormatting> columnOutputFormattings, bool getSecretValue = false)
|
||||
{
|
||||
string output = null;
|
||||
|
||||
try
|
||||
{
|
||||
RawValueType displayType = RawValueType.STRING;
|
||||
DisplayTypes.TryGetValue(Values[row][column].Key, out displayType);
|
||||
output = _rawValueFormatter.GetDisplayValue(Values[row][column].Value, displayType);
|
||||
|
||||
if (columnOutputFormattings != null && columnOutputFormattings.TryGetValue(Values[row][column].Key, out var outputFormatting))
|
||||
{
|
||||
if (outputFormatting.Hidden)
|
||||
return string.Empty;
|
||||
|
||||
if (outputFormatting.IsSecret && !getSecretValue)
|
||||
return veiledText;
|
||||
|
||||
if (outputFormatting.DisplayType != null)
|
||||
output = _rawValueFormatter.GetDisplayValue(Values[row][column].Value, outputFormatting.DisplayType.Value);
|
||||
|
||||
if (outputFormatting.Translation != null)
|
||||
{
|
||||
var abstractTranslation = cF4SDHealthCardConfig.GetTranslationsWithName(DataProvider?.HealthCardDataHelper?.SelectedHealthCard, outputFormatting.Translation);
|
||||
if (abstractTranslation != null && abstractTranslation is cHealthCardTranslator translator)
|
||||
{
|
||||
output = translator.DefaultTranslation?.Translation.GetValue() ?? Values[row].ToList()[column].Value.ToString();
|
||||
|
||||
foreach (var translation in translator.Translations)
|
||||
{
|
||||
if (translation.Values.Any(value => value.Equals(Values[row].ToList()[column].Value.ToString(), StringComparison.InvariantCultureIgnoreCase)))
|
||||
output = translation.Translation.GetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user