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
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:
+1
-1
@@ -11,7 +11,7 @@
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
<ProjectReference Include="../../../CMS/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj" />
|
||||
</ItemGroup>
|
||||
<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>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
<col />
|
||||
<col />
|
||||
<col />
|
||||
<col style="min-width: 180px;" />
|
||||
<col />
|
||||
<col style="width: 58px;" />
|
||||
</ColGroup>
|
||||
<ToolBarContent>
|
||||
@@ -46,8 +48,21 @@
|
||||
</CellTemplate>
|
||||
</PropertyColumn>
|
||||
<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;">
|
||||
<CellTemplate>
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using CMSMicroservice.Protobuf.Protos.User;
|
||||
using BackOffice.Common.BaseComponents;
|
||||
using BackOffice.Common.Utilities;
|
||||
using BackOffice.Pages.User.Components;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MudBlazor;
|
||||
using System.Text;
|
||||
using DateTimeConverterCL;
|
||||
using DataModel = CMSMicroservice.Protobuf.Protos.User.GetAllUserByFilterResponseModel;
|
||||
|
||||
namespace BackOffice.Pages.User;
|
||||
@@ -84,51 +83,63 @@ public partial class UserMainPage
|
||||
{
|
||||
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(),
|
||||
PaginationState = new() { PageNumber = 1, PageSize = 1000 }
|
||||
};
|
||||
var result = await UserContract.GetAllUserByFilterAsync(new GetAllUserByFilterRequest
|
||||
{
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("شناسه,موبایل,نام,نام خانوادگی,کدملی");
|
||||
|
||||
foreach (var u in result.Models)
|
||||
var headers = new[]
|
||||
{
|
||||
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 base64 = Convert.ToBase64String(bytes);
|
||||
var filename = $"users-{DateTime.Now:yyyyMMddHHmmss}.csv";
|
||||
var rows = all.Select(u => new object?[]
|
||||
{
|
||||
u.Id,
|
||||
u.Mobile,
|
||||
u.FirstName,
|
||||
u.LastName,
|
||||
u.NationalCode,
|
||||
u.DefaultAddress,
|
||||
u.DefaultPostalCode
|
||||
});
|
||||
|
||||
await JsRuntime.InvokeVoidAsync("jsSaveAsFile", filename, base64);
|
||||
Snackbar.Add("خروجی Excel (CSV) آماده شد.", Severity.Success);
|
||||
var filename = $"users-{DateTime.Now:yyyyMMddHHmmss}.xls";
|
||||
await JsRuntime.InvokeVoidAsync("jsSaveAsFile", filename,
|
||||
CsvExportHelper.ToExcelXmlBase64("کاربران", headers, rows));
|
||||
Snackbar.Add($"خروجی Excel آماده شد ({all.Count} کاربر).", Severity.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user