@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Organization.Designation @using Indotalent.Features.Organization.Designation.Cqrs @using Microsoft.AspNetCore.Components.Web @using Microsoft.JSInterop @using MudBlazor @using Features.Root.Shared @using ClosedXML.Excel @using System.IO @inject DesignationService DesignationService @inject IDialogService DialogService @inject ISnackbar Snackbar @inject IJSRuntime JSRuntime
Designation Management Manage job titles, hierarchies, and official designations across the organization.
/ Organization / Designation
Search
@if (_isExporting) { Processing... } else { Excel } @if (_isRefreshing) { Refreshing... } else { Refresh } @if (_selectedDesig != null) { View Edit Remove } else { Add New Designation }
Code Designation Name Level Job Description Brief @context.Code
@(!string.IsNullOrWhiteSpace(context.Name) ? context.Name.ToInitial() : "?") @context.Name
@context.Level @context.Description
Rows per page: Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
Prev @{ var totalPages = _totalPage == 0 ? 1 : _totalPage; var maxVisible = 5; var startPage = Math.Max(1, _currentPage - maxVisible / 2); var endPage = Math.Min(totalPages, startPage + maxVisible - 1); if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); } } @for (int i = startPage; i <= endPage; i++) { var pageNum = i; var isActive = pageNum == _currentPage; @pageNum } Next
@code { [Parameter] public EventCallback OnAdd { get; set; } [Parameter] public EventCallback OnEdit { get; set; } [Parameter] public EventCallback OnView { get; set; } private List _designations = new(); private GetDesignationListResponse? _selectedDesig; private string _searchString = ""; private int _skip = 0; private int _top = 5; private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top)); private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1; private bool _isRefreshing = false; private bool _isExporting = false; protected override async Task OnInitializedAsync() => await LoadData(); private async Task LoadData() { _isRefreshing = true; _selectedDesig = null; StateHasChanged(); try { var response = await DesignationService.GetDesignationListAsync(); await Task.Delay(500); if (response != null && response.IsSuccess) { _designations = response.Value ?? new(); } } finally { _isRefreshing = false; StateHasChanged(); } } private IEnumerable GetFilteredData() { if (string.IsNullOrWhiteSpace(_searchString)) return _designations; return _designations.Where(x => (x.Name?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) || (x.Code?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) || (x.Level?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) || (x.Description?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ); } private IEnumerable GetPagedData() => GetFilteredData().Skip(_skip).Take(_top); private async Task ExportToExcel() { _isExporting = true; StateHasChanged(); try { await Task.Delay(1000); using (var workbook = new XLWorkbook()) { var worksheet = workbook.Worksheets.Add("Designations"); var currentRow = 1; worksheet.Cell(currentRow, 1).Value = "Code"; worksheet.Cell(currentRow, 2).Value = "Designation Name"; worksheet.Cell(currentRow, 3).Value = "Level"; worksheet.Cell(currentRow, 4).Value = "Description"; var headerRange = worksheet.Range(1, 1, 1, 4); headerRange.Style.Font.Bold = true; headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#0D47A1"); headerRange.Style.Font.FontColor = XLColor.White; foreach (var item in GetFilteredData()) { currentRow++; worksheet.Cell(currentRow, 1).Value = item.Code; worksheet.Cell(currentRow, 2).Value = item.Name; worksheet.Cell(currentRow, 3).Value = item.Level; worksheet.Cell(currentRow, 4).Value = item.Description; } worksheet.Columns().AdjustToContents(); using (var stream = new MemoryStream()) { workbook.SaveAs(stream); var content = Convert.ToBase64String(stream.ToArray()); await JSRuntime.InvokeVoidAsync("downloadFile", "Designation_Registry.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content); Snackbar.Add("Excel exported successfully", Severity.Success); } } } catch (Exception ex) { Snackbar.Add($"Export failed: {ex.Message}", Severity.Error); } finally { _isExporting = false; StateHasChanged(); } } private void OnSearchClick() { _skip = 0; _selectedDesig = null; StateHasChanged(); } private void HandleSearchKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") OnSearchClick(); } private void OnPageChanged(int page) { if (page >= 1 && page <= _totalPage) { _skip = (page - 1) * _top; _selectedDesig = null; StateHasChanged(); } } private void OnPageSizeChanged(int size) { _top = size; _skip = 0; _selectedDesig = null; StateHasChanged(); } private async Task InvokeEdit() { if (_selectedDesig == null) return; var res = await DesignationService.GetDesignationByIdAsync(_selectedDesig.Id); if (res?.Value != null) await OnEdit.InvokeAsync(Map(res.Value)); } private async Task InvokeView() { if (_selectedDesig == null) return; var res = await DesignationService.GetDesignationByIdAsync(_selectedDesig.Id); if (res?.Value != null) await OnView.InvokeAsync(Map(res.Value)); } private UpdateDesignationRequest Map(GetDesignationByIdResponse d) => new UpdateDesignationRequest { Id = d.Id, Code = d.Code, Name = d.Name, Description = d.Description, Level = d.Level, OtherInformation1 = d.OtherInformation1 ?? string.Empty, OtherInformation2 = d.OtherInformation2 ?? string.Empty, OtherInformation3 = d.OtherInformation3 ?? string.Empty, CreatedAt = d.CreatedAt, CreatedBy = d.CreatedBy, UpdatedAt = d.UpdatedAt, UpdatedBy = d.UpdatedBy }; private async Task OnDelete() { if (_selectedDesig == null) return; var diag = await DialogService.ShowAsync<_DeleteConfirmation>("", new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedDesig.Name } }); if (!(await diag.Result).Canceled) { if (await DesignationService.DeleteDesignationByIdAsync(_selectedDesig.Id)) { await LoadData(); Snackbar.Add("Designation deleted successfully", Severity.Success); } } } }