sozsoft-platform/api/src/Sozsoft.Platform.HttpApi.Host/PredefinedReports/DynamicReportColumn.cs
2026-10-06 15:36:01 +03:00

111 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using Microsoft.Extensions.Localization;
using Sozsoft.Platform;
using Sozsoft.Platform.Entities;
using Sozsoft.Platform.Enums;
using Sozsoft.Platform.ListForms;
using Sozsoft.Platform.Localization;
using Sozsoft.Platform.Queries;
namespace Sozsoft.Reports.PredefinedReports;
/// <summary>
/// Grid ve Tree raporlarının ortak kolon tanımı.
/// </summary>
internal sealed record DynamicReportColumn(
ListFormField Field,
string BindingName,
LookupDto Lookup,
Dictionary<string, string> StaticLookupValues,
bool IsMultiValue,
bool IsImage,
bool IsHtml,
string EditorType,
int ImageCount = 1) : DynamicReportSqlBuilder.IReportLookupColumn, DynamicReportGridStateHelper.IReportColumnWidth
{
public float ImageWidth => DynamicReportImageHelper.GetGridImageColumnWidth(ImageCount);
/// <summary><c>phoneCountry</c> biçimli telefon kolonunda satırın ülke değerini taşıyan kolon.</summary>
public string PhoneCountryBindingName { get; init; }
/// <summary>Biçim ifadesine verilecek ülke operandı; telefon kolonu değilse <c>null</c>.</summary>
public string PhoneCountryExpression =>
string.IsNullOrWhiteSpace(PhoneCountryBindingName) ? null : $"[{PhoneCountryBindingName}]";
public bool HasBindingName =>
!string.IsNullOrWhiteSpace(BindingName) && BindingName != "undefined";
}
internal static class DynamicReportColumnFactory
{
public static DynamicReportColumn Create(
ListFormField field,
IReadOnlyDictionary<string, SelectField> selectFieldsByName,
DefaultValueHelper defaultValueHelper,
string editorType,
IStringLocalizer<PlatformResource> localizer)
{
var column = CreateColumn(field, selectFieldsByName[field.FieldName], defaultValueHelper, editorType, localizer);
var phoneCountryField = DynamicReportImageHelper.GetPhoneCountryFieldName(field);
return phoneCountryField != null && selectFieldsByName.TryGetValue(phoneCountryField, out var countrySelectField)
? column with { PhoneCountryBindingName = DynamicReportImageHelper.GetReportFieldName(countrySelectField) }
: column;
}
private static DynamicReportColumn CreateColumn(
ListFormField field,
SelectField selectField,
DefaultValueHelper defaultValueHelper,
string editorType,
IStringLocalizer<PlatformResource> localizer)
{
var bindingName = DynamicReportImageHelper.GetReportFieldName(selectField);
var lookup = DynamicReportImageHelper.GetLookup(field);
var isMultiValue = IsMultiValueLookupEditor(editorType);
var isImage = DynamicReportImageHelper.IsImageEditor(editorType);
var isHtml = editorType == PlatformConsts.EditorTypes.dxHtmlEditor;
if (lookup == null || selectField?.IsJoined == true)
{
return new DynamicReportColumn(field, bindingName, null, null, isMultiValue, isImage, isHtml, editorType);
}
if (DynamicReportSqlBuilder.IsReportQueryableLookup(lookup))
{
return new DynamicReportColumn(
field,
DynamicReportSqlBuilder.GetLookupBindingName(field),
lookup,
null,
isMultiValue,
isImage,
isHtml,
editorType);
}
if (lookup.DataSourceType == UiLookupDataSourceTypeEnum.StaticData)
{
var staticLookupValues = DynamicReportImageHelper.GetStaticLookupValues(
lookup,
defaultValueHelper,
localizer);
return new DynamicReportColumn(
field,
staticLookupValues?.Count > 0 ? DynamicReportSqlBuilder.GetLookupBindingName(field) : bindingName,
lookup,
staticLookupValues,
isMultiValue,
isImage,
isHtml,
editorType);
}
return new DynamicReportColumn(field, bindingName, null, null, isMultiValue, isImage, isHtml, editorType);
}
public static bool IsMultiValueLookupEditor(string editorType)
{
return editorType is PlatformConsts.EditorTypes.dxTagBox or "dxGridBox";
}
}