sozsoft-platform/api/src/Sozsoft.Platform.Domain.Shared/WizardConsts.cs
2026-06-07 14:07:48 +03:00

230 lines
8.9 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.Data;
using System.Text.Json;
using Sozsoft.Platform.Enums;
using static Sozsoft.Platform.PlatformConsts;
using System.Linq;
using System.Reflection;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using System.Globalization;
public static class WizardConsts
{
public static string WizardKey(string code) => $"{Prefix.App}.Wizard.{code}";
public static string WizardKeyTitle(string code) => $"{WizardKey(code)}.Title";
public static string WizardKeyDesc(string code) => $"{WizardKey(code)}.Desc";
public static string WizardKeyParent(string code) => $"{WizardKey(code)}.Parent";
public static string PermCreate(string code) => $"{WizardKey(code)}.Create";
public static string PermUpdate(string code) => $"{WizardKey(code)}.Update";
public static string PermDelete(string code) => $"{WizardKey(code)}.Delete";
public static string PermExport(string code) => $"{WizardKey(code)}.Export";
public static string PermImport(string code) => $"{WizardKey(code)}.Import";
public static string PermNote(string code) => $"{WizardKey(code)}.Note";
public static string LangKeyCreate => "Create";
public static string LangKeyUpdate => "Update";
public static string LangKeyDelete => "Delete";
public static string LangKeyExport => "Export";
public static string LangKeyImport => "Import";
public static string LangKeyNote => "Note";
public static string MenuUrl(string code) => $"/admin/list/{code}";
public static string MenuIcon => "FcList";
public static class LabelHelper
{
public static string GetCamelCaseLabel<T>(string propertyName)
{
var prop = typeof(T).GetProperty(propertyName);
if (prop == null)
return propertyName;
// 1. Display varsa direkt onu kullan
var displayAttr = prop.GetCustomAttribute<DisplayAttribute>();
if (displayAttr != null && !string.IsNullOrWhiteSpace(displayAttr.Name))
return displayAttr.Name;
// 2. CamelCase → kelimelere ayır
var words = Regex
.Split(propertyName, "(?=[A-Z])")
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToList();
// 3. Türkçe karakter dönüşümü + düzgün büyük harf
var culture = new CultureInfo("tr-TR");
words = words.Select(w =>
{
w = w.ToLower(culture);
// Türkçe karakter normalize (genel yaklaşım)
w = w
.Replace("i", "i") // bilinçli bırakıyoruz
.Replace("ı", "ı"); // zaten doğru
return culture.TextInfo.ToTitleCase(w);
}).ToList();
return string.Join(" ", words);
}
}
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 Pivot = true, bool Chart = true, bool Tree = true, bool Gantt = true, bool Scheduler = true) => JsonSerializer.Serialize(new
{
Grid = Grid,
Pivot = Pivot,
Chart = Chart,
Tree = Tree,
Gantt = Gantt,
Scheduler = Scheduler,
DefaultLayout = DefaultLayout,
});
public static readonly string DefaultFilterJson = "\"IsDeleted\" = 'false'";
public static readonly string DefaultFilterRowJson = JsonSerializer.Serialize(new { Visible = true });
public static readonly string DefaultHeaderFilterJson = JsonSerializer.Serialize(new { Visible = true });
public static readonly string DefaultSearchPanelJson = JsonSerializer.Serialize(new { Visible = true });
public static readonly string DefaultGroupPanelJson = JsonSerializer.Serialize(new { Visible = true });
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 string DefaultLookupJson(UiLookupDataSourceTypeEnum dataSourceType, string displayExpr = "name", string valueExpr = "key", string lookupQuery = "") => JsonSerializer.Serialize(new
{
DataSourceType = dataSourceType,
DisplayExpr = displayExpr,
ValueExpr = valueExpr,
LookupQuery = lookupQuery,
});
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 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 DefaultFieldsJsonOnlyId(DbType dbType = DbType.Guid)
{
return JsonSerializer.Serialize(new[]
{
new { FieldName = "Id", FieldDbType = dbType, Value = "@NEWID", 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
});
}