Refactor quick action output handling and extend case note support
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using C4IT.F4SD.DisplayFormatting;
|
||||
using C4IT.FASD.Base;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static C4IT.Logging.cLogManager;
|
||||
|
||||
namespace FasdDesktopUi.Basics.Models.QuickActionOutput
|
||||
{
|
||||
public class cQuickActionOutputObject : cQuickActionOutput
|
||||
{
|
||||
public Dictionary<string, RawValueType> DisplayTypes { get; set; } = new Dictionary<string, RawValueType>();
|
||||
public List<KeyValuePair<string, object>> Values { get; set; } = new List<KeyValuePair<string, object>>();
|
||||
|
||||
public cQuickActionOutputObject(cF4sdQuickActionRevision.cOutput scriptOutput) : base(scriptOutput)
|
||||
{
|
||||
try
|
||||
{
|
||||
InstantiateDisplayTypes(scriptOutput);
|
||||
InstantiateValues(scriptOutput);
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void InstantiateValues(cF4sdQuickActionRevision.cOutput scriptOutput)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(scriptOutput.Values is JObject valuesJObject))
|
||||
return;
|
||||
|
||||
if (valuesJObject.Properties() == null)
|
||||
return;
|
||||
|
||||
foreach (var property in valuesJObject.Properties())
|
||||
{
|
||||
Values.Add(new KeyValuePair<string, object>(property.Name, property.Value));
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetDisplayValue(int index, Dictionary<string, cColumnOutputFormatting> columnOutputFormattings, bool getSecretValue = false)
|
||||
{
|
||||
string output = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (Values.Count <= index)
|
||||
return null;
|
||||
|
||||
var selectedItem = Values[index];
|
||||
|
||||
RawValueType displayType = RawValueType.STRING;
|
||||
DisplayTypes.TryGetValue(selectedItem.Key, out displayType);
|
||||
output = _rawValueFormatter.GetDisplayValue(selectedItem.Value, displayType);
|
||||
|
||||
if (columnOutputFormattings != null && columnOutputFormattings.TryGetValue(selectedItem.Key, out var outputFormatting))
|
||||
{
|
||||
if (outputFormatting.Hidden)
|
||||
return string.Empty;
|
||||
|
||||
if (outputFormatting.IsSecret && !getSecretValue)
|
||||
return veiledText;
|
||||
|
||||
if (outputFormatting.DisplayType != null)
|
||||
output = _rawValueFormatter.GetDisplayValue(selectedItem.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() ?? selectedItem.Value.ToString();
|
||||
|
||||
foreach (var translation in translator.Translations)
|
||||
{
|
||||
if (translation.Values.Any(value => value.Equals(selectedItem.Value.ToString(), StringComparison.InvariantCultureIgnoreCase)))
|
||||
output = translation.Translation.GetValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user