129 lines
4.9 KiB
C#
129 lines
4.9 KiB
C#
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 cQuickActionOutputSingle : cQuickActionOutput
|
|
{
|
|
public cQuickActionOutputSingle(cF4sdQuickActionRevision.cOutput scriptOutput) : base(scriptOutput)
|
|
{
|
|
Instantiate(scriptOutput);
|
|
}
|
|
|
|
|
|
public RawValueType DisplayType { get; set; }
|
|
public string Key { get; set; }
|
|
public object Value { get; set; }
|
|
|
|
private void Instantiate(cF4sdQuickActionRevision.cOutput scriptOutput)
|
|
{
|
|
try
|
|
{
|
|
Value = scriptOutput.Values;
|
|
|
|
if (scriptOutput.Values is JObject scriptValueJObject)
|
|
{
|
|
string scriptValueKey = null;
|
|
|
|
try
|
|
{
|
|
var scriptValueHelperDictionary = scriptValueJObject.ToObject<Dictionary<string, object>>();
|
|
scriptValueKey = scriptValueHelperDictionary.Keys.ToList()[0];
|
|
|
|
Key = scriptValueKey;
|
|
Value = scriptValueHelperDictionary[scriptValueKey];
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
LogException(E);
|
|
}
|
|
|
|
if (scriptOutput.ColumnTypes is JArray columnTypeJArray)
|
|
{
|
|
var columnTypes = columnTypeJArray.ToObject<List<dynamic>>();
|
|
if (columnTypes != null && columnTypes.Count > 0)
|
|
{
|
|
foreach (var columnTypeObject in columnTypes)
|
|
{
|
|
var displayType = cQuickActionOutput.GetDisplayType(columnTypeObject);
|
|
|
|
if (displayType.Key == scriptValueKey)
|
|
DisplayType = displayType.Value;
|
|
}
|
|
}
|
|
|
|
}
|
|
else if (scriptOutput.ColumnTypes is JObject columnTypeJObject)
|
|
{
|
|
try
|
|
{
|
|
var dispayType = cQuickActionOutput.GetDisplayType(columnTypeJObject);
|
|
DisplayType = dispayType.Value;
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
LogException(E);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
LogException(E);
|
|
}
|
|
}
|
|
|
|
public string GetDisplayValue(Dictionary<string, cColumnOutputFormatting> columnOutputFormattings, bool getSecretValue = false)
|
|
{
|
|
string output = null;
|
|
|
|
try
|
|
{
|
|
output = _rawValueFormatter.GetDisplayValue(Value, DisplayType);
|
|
|
|
cColumnOutputFormatting outputFormatting = null;
|
|
|
|
if (string.IsNullOrEmpty(Key))
|
|
outputFormatting = columnOutputFormattings?.Values.FirstOrDefault();
|
|
else
|
|
columnOutputFormattings?.TryGetValue(Key, out outputFormatting);
|
|
|
|
if (outputFormatting != null)
|
|
{
|
|
if (outputFormatting.IsSecret && !getSecretValue)
|
|
return veiledText;
|
|
|
|
if (outputFormatting.DisplayType != null)
|
|
output = _rawValueFormatter.GetDisplayValue(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() ?? Value.ToString();
|
|
|
|
foreach (var translation in translator.Translations)
|
|
{
|
|
if (translation.Values.Any(value => value.Equals(Value.ToString(), StringComparison.InvariantCultureIgnoreCase)))
|
|
output = translation.Translation.GetValue();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
LogException(E);
|
|
}
|
|
|
|
return output;
|
|
}
|
|
}
|
|
}
|