feat(user-page): enhance user main page with additional address and postal code fields in export
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 6m4s

- Added new columns for default address and postal code in the user export functionality.
- Updated the export logic to handle the new fields and changed the file format from CSV to Excel (.xls) for better compatibility.
- Bumped Foursat.CMSMicroservice.Protobuf version to 0.0.209 to align with recent changes.
- Made minor adjustments to the .gitignore for clarity.
This commit is contained in:
masoodafar-web
2026-08-14 03:19:10 +03:30
parent aa97d25302
commit fe79089770
4 changed files with 62 additions and 36 deletions
+1 -1
View File
@@ -143,7 +143,7 @@
<ProjectReference Include="../../../CMS/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj" /> <ProjectReference Include="../../../CMS/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="!Exists('../../../CMS/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj')"> <ItemGroup Condition="!Exists('../../../CMS/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj')">
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.208" /> <PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.209" />
</ItemGroup> </ItemGroup>
<!-- ============================================================ --> <!-- ============================================================ -->
+17 -2
View File
@@ -28,6 +28,8 @@
<col /> <col />
<col /> <col />
<col /> <col />
<col style="min-width: 180px;" />
<col />
<col style="width: 58px;" /> <col style="width: 58px;" />
</ColGroup> </ColGroup>
<ToolBarContent> <ToolBarContent>
@@ -46,8 +48,21 @@
</CellTemplate> </CellTemplate>
</PropertyColumn> </PropertyColumn>
<PropertyColumn Property="x => x.NationalCode" Title="کدملی" /> <PropertyColumn Property="x => x.NationalCode" Title="کدملی" />
<TemplateColumn Title="آدرس پیش‌فرض">
<CellTemplate>
<MudText Typo="Typo.caption" Style="max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
Title="@(context.Item.DefaultAddress ?? "")">
@(string.IsNullOrWhiteSpace(context.Item.DefaultAddress) ? "-" : context.Item.DefaultAddress)
</MudText>
</CellTemplate>
</TemplateColumn>
<TemplateColumn Title="کدپستی پیش‌فرض">
<CellTemplate>
<MudText Typo="Typo.caption">
@(string.IsNullOrWhiteSpace(context.Item.DefaultPostalCode) ? "-" : context.Item.DefaultPostalCode)
</MudText>
</CellTemplate>
</TemplateColumn>
<TemplateColumn StickyLeft="true" Title="عملیات" CellStyle="text-wrap: nowrap;" HeaderStyle="text-wrap: nowrap;"> <TemplateColumn StickyLeft="true" Title="عملیات" CellStyle="text-wrap: nowrap;" HeaderStyle="text-wrap: nowrap;">
<CellTemplate> <CellTemplate>
+43 -32
View File
@@ -1,11 +1,10 @@
using CMSMicroservice.Protobuf.Protos.User; using CMSMicroservice.Protobuf.Protos.User;
using BackOffice.Common.BaseComponents; using BackOffice.Common.BaseComponents;
using BackOffice.Common.Utilities;
using BackOffice.Pages.User.Components; using BackOffice.Pages.User.Components;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using MudBlazor; using MudBlazor;
using System.Text;
using DateTimeConverterCL;
using DataModel = CMSMicroservice.Protobuf.Protos.User.GetAllUserByFilterResponseModel; using DataModel = CMSMicroservice.Protobuf.Protos.User.GetAllUserByFilterResponseModel;
namespace BackOffice.Pages.User; namespace BackOffice.Pages.User;
@@ -84,51 +83,63 @@ public partial class UserMainPage
{ {
try try
{ {
var exportRequest = new GetAllUserByFilterRequest var filter = _request.Filter?.Clone() ?? new();
var all = new List<DataModel>();
const int pageSize = 200;
var page = 1;
while (page <= 500)
{ {
Filter = _request.Filter?.Clone() ?? new(), var result = await UserContract.GetAllUserByFilterAsync(new GetAllUserByFilterRequest
PaginationState = new() { PageNumber = 1, PageSize = 1000 } {
}; Filter = filter,
PaginationState = new() { PageNumber = page, PageSize = pageSize }
});
var result = await UserContract.GetAllUserByFilterAsync(exportRequest); var batch = result?.Models?.ToList() ?? new();
if (batch.Count == 0)
break;
if (result?.Models == null || !result.Models.Any()) all.AddRange(batch);
var hasNext = result?.MetaData?.HasNext == true;
if (!hasNext || batch.Count < pageSize)
break;
page++;
}
if (all.Count == 0)
{ {
Snackbar.Add("داده‌ای برای خروجی وجود ندارد.", Severity.Info); Snackbar.Add("داده‌ای برای خروجی وجود ندارد.", Severity.Info);
return; return;
} }
var sb = new StringBuilder(); var headers = new[]
sb.AppendLine("شناسه,موبایل,نام,نام خانوادگی,کدملی");
foreach (var u in result.Models)
{ {
sb.AppendLine(string.Join(",", "شناسه", "موبایل", "نام", "نام خانوادگی", "کدملی",
u.Id, "آدرس پیش‌فرض", "کدپستی پیش‌فرض"
EscapeCsv(u.Mobile), };
EscapeCsv(u.FirstName),
EscapeCsv(u.LastName),
EscapeCsv(u.NationalCode)));
}
var bytes = Encoding.UTF8.GetPreamble().Concat(Encoding.UTF8.GetBytes(sb.ToString())).ToArray(); var rows = all.Select(u => new object?[]
var base64 = Convert.ToBase64String(bytes); {
var filename = $"users-{DateTime.Now:yyyyMMddHHmmss}.csv"; u.Id,
u.Mobile,
u.FirstName,
u.LastName,
u.NationalCode,
u.DefaultAddress,
u.DefaultPostalCode
});
await JsRuntime.InvokeVoidAsync("jsSaveAsFile", filename, base64); var filename = $"users-{DateTime.Now:yyyyMMddHHmmss}.xls";
Snackbar.Add("خروجی Excel (CSV) آماده شد.", Severity.Success); await JsRuntime.InvokeVoidAsync("jsSaveAsFile", filename,
CsvExportHelper.ToExcelXmlBase64("کاربران", headers, rows));
Snackbar.Add($"خروجی Excel آماده شد ({all.Count} کاربر).", Severity.Success);
} }
catch (Exception ex) catch (Exception ex)
{ {
Snackbar.Add($"خطا در خروجی Excel: {ex.Message}", Severity.Error); Snackbar.Add($"خطا در خروجی Excel: {ex.Message}", Severity.Error);
} }
} }
private static string EscapeCsv(string value)
{
if (string.IsNullOrEmpty(value)) return "";
if (value.Contains(',') || value.Contains('"') || value.Contains('\n'))
return $"\"{value.Replace("\"", "\"\"")}\"";
return value;
}
} }