sozsoft-platform/api/src/Sozsoft.Platform.Domain.Shared/WizardConsts.cs
2026-10-01 16:42:56 +03:00

248 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Text.Json;
using Sozsoft.Platform.Enums;
using static Sozsoft.Platform.PlatformConsts;
public static class WizardConsts
{
public static int EditFormMaxWidth => 1200;
public static int EditFormMaxColumnCount = 3;
public static int EditFormHeightDefault => 125;
public static int EditFormHeightByRow => 75;
public static string WizardKey(string code) => $"{Prefix.App}.Wizard.{code}";
public static string LangKeyCreate => "App.Platform.Create";
public static string LangKeyUpdate => "App.Platform.Update";
public static string LangKeyDelete => "App.Platform.Delete";
public static string LangKeyExport => "App.Platform.Export";
public static string LangKeyImport => "App.Platform.Import";
public static string LangKeyNote => "App.Platform.Note";
/// <summary>Liste verisinin aynalandigi seed klasoru; SeedPathResolver ile ayni deger.</summary>
public const string SeedDataFolder = "data";
/// <summary>Ekranin varsayilan veri seed dosyasi, kapsam klasorune gore goreli.</summary>
public static string SeedDataFilePath(string listFormCode) => $"{SeedDataFolder}/{listFormCode}.json";
public static string MenuUrl(string code) => $"/admin/list/{code}";
public static string MenuIcon => "FcList";
public static readonly string DefaultExportJson = JsonSerializer.Serialize(new
{
Enabled = true,
AllowExportSelectedData = false,
PrintingEnabled = true,
BackgroundColor = "#FFFFFF",
Margin = 10
});
public static string DefaultLayoutJson(string DefaultLayout = "grid", bool Grid = true, bool Card = true, bool Pivot = true, bool Chart = true, bool Tree = false, bool Gantt = false, bool Scheduler = false, bool Todo = false) => JsonSerializer.Serialize(new
{
Grid = Grid,
Card = Card,
Pivot = Pivot,
Chart = Chart,
Tree = Tree,
Gantt = Gantt,
Scheduler = Scheduler,
Todo = Todo,
DefaultLayout = DefaultLayout,
});
public static readonly string DefaultFilterJson = "\"IsDeleted\" = 'false'";
public static string DefaultFilterRowJson(bool visible = true) => JsonSerializer.Serialize(new { Visible = visible });
public static string DefaultHeaderFilterJson(bool visible = true) => JsonSerializer.Serialize(new { Visible = visible });
public static string DefaultSearchPanelJson(bool visible = true) => JsonSerializer.Serialize(new { Visible = visible });
public static string DefaultGroupPanelJson(bool visible = true) => JsonSerializer.Serialize(new { Visible = visible });
public static string DefaultSelectionSingleJson(string Mode = "none") => JsonSerializer.Serialize(new
{
Mode = Mode,
AllowSelectAll = false
});
public static string DefaultColumnOptionJson(bool FocusedRowEnabled = true) => JsonSerializer.Serialize(new
{
ColumnFixingEnabled = true,
ColumnAutoWidth = true,
ColumnChooserEnabled = true,
AllowColumnResizing = true,
AllowColumnReordering = true,
ColumnResizingMode = "widget",
FocusedRowEnabled = FocusedRowEnabled,
});
public static string DefaultPermissionJson(string permissionName)
{
return JsonSerializer.Serialize(new
{
C = permissionName + ".Create",
R = permissionName,
U = permissionName + ".Update",
D = permissionName + ".Delete",
E = permissionName + ".Export",
I = permissionName + ".Import",
N = permissionName + ".Note",
});
}
public static string DefaultFieldPermissionJson(string permissionName)
{
return JsonSerializer.Serialize(new
{
C = permissionName + ".Create",
R = permissionName,
U = permissionName + ".Update",
E = true,
I = true,
Deny = false
});
}
public static readonly string DefaultColumnCustomizationJson = JsonSerializer.Serialize(new
{
AllowReordering = true,
});
public static readonly string DefaultColumnFilteringJson = JsonSerializer.Serialize(new
{
AllowFiltering = true,
});
public static readonly string DefaultPivotSettingsJson = JsonSerializer.Serialize(new
{
IsPivot = true
});
public static readonly string DefaultValidationRuleRequiredJson = JsonSerializer.Serialize(new[]
{
new { Type = Enum.GetName(UiColumnValidationRuleTypeEnum.required) }
});
public static readonly string DefaultValidationRuleEmailJson = JsonSerializer.Serialize(new[]
{
new { Type = Enum.GetName(UiColumnValidationRuleTypeEnum.email), Reevaluate = true, IgnoreEmptyValue = true }
});
public static readonly string DefaultValidationRuleEmailRequiredJson = JsonSerializer.Serialize(new[]
{
new { Type = Enum.GetName(UiColumnValidationRuleTypeEnum.email) },
new { Type = Enum.GetName(UiColumnValidationRuleTypeEnum.required) }
});
/// <summary>
/// Cascade alanlari yalnizca doluysa yazilir; cascade'siz lookup'in JSON'u onceki bicimiyle
/// ayni kalir, boylece yeniden deploy edilen ekranlarin seed dosyalari sahte fark uretmez.
/// </summary>
public static string DefaultLookupJson(
UiLookupDataSourceTypeEnum dataSourceType,
string displayExpr = "name",
string valueExpr = "key",
string lookupQuery = "",
WizardLookupCascade cascade = null)
{
var lookup = new Dictionary<string, object>
{
["DataSourceType"] = dataSourceType,
["DisplayExpr"] = displayExpr,
["ValueExpr"] = valueExpr,
["LookupQuery"] = lookupQuery,
};
if (!string.IsNullOrWhiteSpace(cascade?.ParentFields))
{
lookup["CascadeParentFields"] = cascade.ParentFields.Trim();
lookup["CascadeFilterOperator"] = string.IsNullOrWhiteSpace(cascade.FilterOperator) ? "=" : cascade.FilterOperator.Trim();
if (!string.IsNullOrWhiteSpace(cascade.RelationField))
lookup["CascadeRelationField"] = cascade.RelationField.Trim();
}
if (!string.IsNullOrWhiteSpace(cascade?.EmptyFields))
lookup["CascadeEmptyFields"] = cascade.EmptyFields.Trim();
return JsonSerializer.Serialize(lookup);
}
/// <summary>
/// Query kaynagi turetilmis tablo olarak sarilir ve kolonlar bu takma adla nitelenir;
/// TableName bos kalirsa takma ad olarak sorgu metninin kendisi kullanilir.
/// </summary>
public const string QuerySourceAlias = "Q";
public static string DefaultDeleteCommand(string tableName)
{
return $"UPDATE \"{tableName}\" SET \"DeleterId\"=@DeleterId, \"DeletionTime\"=CURRENT_TIMESTAMP, \"IsDeleted\"='true' WHERE \"Id\" IN @Id";
}
public static string DefaultInsertFieldsDefaultValueJson(DbType dbType = DbType.Guid)
{
return JsonSerializer.Serialize(new[]
{
new { FieldName = "CreationTime", FieldDbType = DbType.DateTime, Value = "@NOW", CustomValueType = FieldCustomValueTypeEnum.CustomKey },
new { FieldName = "CreatorId", FieldDbType = DbType.Guid, Value = "@USERID", CustomValueType = FieldCustomValueTypeEnum.CustomKey },
new { FieldName = "IsDeleted", FieldDbType = DbType.Boolean, Value = "false", CustomValueType = FieldCustomValueTypeEnum.Value },
new { FieldName = "Id", FieldDbType = dbType, Value = "@NEWID", CustomValueType = FieldCustomValueTypeEnum.CustomKey }
});
}
public static string DefaultInsertFieldsJsonOnlyId(DbType dbType = DbType.Guid)
{
return JsonSerializer.Serialize(new[]
{
new { FieldName = "Id", FieldDbType = dbType, Value = "@NEWID", CustomValueType = FieldCustomValueTypeEnum.CustomKey }
});
}
public static string DefaultDeleteFieldsDefaultValueJson(DbType dbType = DbType.Guid)
{
return JsonSerializer.Serialize(new[]
{
new { FieldName = "DeleterId", FieldDbType = DbType.Guid, Value = "@USERID", CustomValueType = FieldCustomValueTypeEnum.CustomKey },
new { FieldName = "Id", FieldDbType = dbType, Value = "@ID", CustomValueType = FieldCustomValueTypeEnum.CustomKey }
});
}
public static string DefaultDeleteFieldsJsonOnlyId(DbType dbType = DbType.Guid)
{
return JsonSerializer.Serialize(new[]
{
new { FieldName = "Id", FieldDbType = dbType, Value = "@ID", CustomValueType = FieldCustomValueTypeEnum.CustomKey }
});
}
public static readonly string DefaultPagerOptionJson = JsonSerializer.Serialize(new
{
Visible = true,
AllowedPageSizes = "10,20,50,100",
ShowPageSizeSelector = true,
ShowNavigationButtons = true,
ShowInfo = false,
InfoText = "Page {0} of {1} ({2} items)",
DisplayMode = GridColumnOptions.PagerDisplayModeAdaptive,
ScrollingMode = GridColumnOptions.ScrollingModeStandard,
LoadPanelEnabled = "auto",
LoadPanelText = "Loading..."
});
public static string DefaultEditingOptionJson(
string Title,
int Width,
int Height,
bool AllowDeleting,
bool AllowAdding,
bool AllowUpdating,
bool ConfirmDelete,
bool SendOnlyChangedFormValuesUpdate,
bool AllowDetail = false) => JsonSerializer.Serialize(new
{
Popup = new { Title = Title, Width = Width, Height = Height },
AllowDeleting = AllowDeleting,
AllowAdding = AllowAdding,
AllowUpdating = AllowUpdating,
ConfirmDelete = ConfirmDelete,
SendOnlyChangedFormValuesUpdate = SendOnlyChangedFormValuesUpdate,
AllowDetail = AllowDetail
});
}
/// <summary>Wizard alanindan lookup'a yazilan cascade ayarlari (<c>LookupDto.Cascade*</c>).</summary>
public sealed record WizardLookupCascade(string ParentFields, string RelationField, string FilterOperator, string EmptyFields);