parent
4f68a139de
commit
d41e03850b
|
@ -41,6 +41,7 @@
|
||||||
Icon="@Icons.Material.Outlined.Pages">
|
Icon="@Icons.Material.Outlined.Pages">
|
||||||
<MudNavLink Href="management/pages" Icon="@Icons.Material.Filled.Pageview">برگه ها</MudNavLink>
|
<MudNavLink Href="management/pages" Icon="@Icons.Material.Filled.Pageview">برگه ها</MudNavLink>
|
||||||
<MudNavLink Href="setting/faq" Icon="@Icons.Material.Filled.ManageAccounts">سوالات متداول</MudNavLink>
|
<MudNavLink Href="setting/faq" Icon="@Icons.Material.Filled.ManageAccounts">سوالات متداول</MudNavLink>
|
||||||
|
<MudNavLink Href="setting/pages" Icon="@Icons.Material.Outlined.Folder">تنظیماتــ برگه ها</MudNavLink>
|
||||||
</MudNavGroup>
|
</MudNavGroup>
|
||||||
|
|
||||||
<MudNavGroup Title="شخصی سازی" Expanded="false" Icon="@Icons.Material.Filled.SettingsSystemDaydream">
|
<MudNavGroup Title="شخصی سازی" Expanded="false" Icon="@Icons.Material.Filled.SettingsSystemDaydream">
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
@page "/setting/pages"
|
||||||
|
@attribute [Microsoft.AspNetCore.Authorization.Authorize]
|
||||||
|
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject IUserUtility UserUtility
|
||||||
|
@inject IRestWrapper RestWrapper
|
||||||
|
|
||||||
|
<MudStack class="h-full w-full p-8">
|
||||||
|
<MudStack class="mx-2 mb-5">
|
||||||
|
<MudText Typo="Typo.h4">تنظیمات برگه ها</MudText>
|
||||||
|
<MudText Typo="Typo.caption">برگه های وب سایت خود را ویرایش نمایید</MudText>
|
||||||
|
</MudStack>
|
||||||
|
|
||||||
|
<MudPaper class="px-5 py-5">
|
||||||
|
<MudStack>
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12">
|
||||||
|
<MudText class="mb-5 mt-4" Typo="Typo.h6">افزودن لینک حذف شده</MudText>
|
||||||
|
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="10">
|
||||||
|
<MudTextField @bind-Value="@ViewModel.NewDeletedPage.Url" T="string" Label="لینک" Variant="Variant.Outlined" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="2">
|
||||||
|
<MudButton class="mt-1 w-full py-3" Variant="Variant.Outlined" Color="Color.Secondary" OnClick="ViewModel.AddDeletedPage">افزودن +</MudButton>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12">
|
||||||
|
|
||||||
|
|
||||||
|
<MudDataGrid FixedFooter="true" FixedHeader="true" Striped="true"
|
||||||
|
T="DeletedPageItem" Items="@ViewModel.DeletedPages" CurrentPage="@ViewModel.DeletedPagesCurrentPage"
|
||||||
|
RowsPerPage="20" Filterable="false" Loading="@ViewModel.IsProcessing"
|
||||||
|
SortMode="@SortMode.None" Groupable="false">
|
||||||
|
<Columns>
|
||||||
|
<PropertyColumn Title="لینک حذف شده" Property="arg => arg.Url" />
|
||||||
|
<TemplateColumn CellClass="d-flex justify-end">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudStack Row="true">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||||
|
Size="@Size.Small"
|
||||||
|
Variant="@Variant.Outlined"
|
||||||
|
OnClick="async () => await ViewModel.RemoveDeletedPageAsync(context.Item)"
|
||||||
|
Color="@Color.Error" />
|
||||||
|
</MudStack>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
</Columns>
|
||||||
|
<PagerContent>
|
||||||
|
<MudStack Row="true" class="w-full">
|
||||||
|
|
||||||
|
<MudPagination Rectangular="true" Variant="Variant.Filled" Count="@ViewModel.DeletedPagesCount"
|
||||||
|
SelectedChanged="@ViewModel.DeletedPagesChangePageAsync" class="mx-auto my-4" />
|
||||||
|
</MudStack>
|
||||||
|
|
||||||
|
</PagerContent>
|
||||||
|
</MudDataGrid>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
<MudPaper class="px-5 py-5">
|
||||||
|
<MudStack>
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12">
|
||||||
|
<MudText class="mb-5 mt-4" Typo="Typo.h6">افزودن ریدایرکت جدید</MudText>
|
||||||
|
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="5">
|
||||||
|
<MudTextField @bind-Value="@ViewModel.NewRedirectItem.OldUrl" T="string" Label="لینک قدیمی" Variant="Variant.Outlined" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="5">
|
||||||
|
<MudTextField @bind-Value="@ViewModel.NewRedirectItem.NewUrl" T="string" Label="لینک جدید" Variant="Variant.Outlined" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="2">
|
||||||
|
<MudButton class="mt-1 w-full py-3" Variant="Variant.Outlined" Color="Color.Secondary" OnClick="ViewModel.AddPageAsync">افزودن +</MudButton>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12">
|
||||||
|
|
||||||
|
|
||||||
|
<MudDataGrid FixedFooter="true" FixedHeader="true" Striped="true"
|
||||||
|
T="RedirectItem" Items="@ViewModel.RedirectItems" CurrentPage="@ViewModel.RedirectItemsCurrentPage"
|
||||||
|
RowsPerPage="20" Filterable="false" Loading="@ViewModel.IsProcessing"
|
||||||
|
SortMode="@SortMode.None" Groupable="false">
|
||||||
|
<Columns>
|
||||||
|
<PropertyColumn Title="لینک قدیمی" Property="arg => arg.OldUrl" />
|
||||||
|
<PropertyColumn Title="لینک جدید" Property="arg => arg.NewUrl" />
|
||||||
|
<TemplateColumn CellClass="d-flex justify-end">
|
||||||
|
<CellTemplate>
|
||||||
|
<MudStack Row="true">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||||
|
Size="@Size.Small"
|
||||||
|
Variant="@Variant.Outlined"
|
||||||
|
OnClick="async () => await ViewModel.RemovePageAsync(context.Item)"
|
||||||
|
Color="@Color.Error" />
|
||||||
|
</MudStack>
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
|
</Columns>
|
||||||
|
<PagerContent>
|
||||||
|
<MudStack Row="true" class="w-full">
|
||||||
|
|
||||||
|
<MudPagination Rectangular="true" Variant="Variant.Filled" Count="@ViewModel.RedirectItemPageCount"
|
||||||
|
SelectedChanged="@ViewModel.RedirectItemChangePageAsync" class="mx-auto my-4" />
|
||||||
|
</MudStack>
|
||||||
|
|
||||||
|
</PagerContent>
|
||||||
|
</MudDataGrid>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudStack>
|
||||||
|
</MudPaper>
|
||||||
|
</MudStack>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
public PagesSettingPageViewModel ViewModel { get; set; }
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
ViewModel = new PagesSettingPageViewModel(NavigationManager, Snackbar, UserUtility, RestWrapper, DialogService);
|
||||||
|
await ViewModel.InitializeAsync();
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,244 @@
|
||||||
|
namespace Netina.AdminPanel.PWA.Pages;
|
||||||
|
|
||||||
|
public class PagesSettingPageViewModel(NavigationManager navigationManager,
|
||||||
|
ISnackbar snackbar,
|
||||||
|
IUserUtility userUtility,
|
||||||
|
IRestWrapper restWrapper,
|
||||||
|
IDialogService dialogService) : BaseViewModel<PageSetting> (userUtility)
|
||||||
|
{
|
||||||
|
public ObservableCollection<RedirectItem> RedirectItems { get; set; } = new ObservableCollection<RedirectItem> ();
|
||||||
|
public ObservableCollection<DeletedPageItem> DeletedPages { get; set; } = new ObservableCollection<DeletedPageItem> ();
|
||||||
|
|
||||||
|
public override async Task InitializeAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsProcessing = true;
|
||||||
|
var token = await _userUtility.GetBearerTokenAsync();
|
||||||
|
if (token == null)
|
||||||
|
throw new Exception("Token is null");
|
||||||
|
var pages = await restWrapper.SettingRestApi.GetSettingAsync<PageSetting>(nameof(PageSetting), token);
|
||||||
|
PageDto = pages;
|
||||||
|
RedirectItems.Clear();
|
||||||
|
if (PageDto.RedirectItems.Count > 20)
|
||||||
|
RedirectItemPageCount = RedirectItemsCurrentPage + 2;
|
||||||
|
PageDto.RedirectItems.Skip(RedirectItemsCurrentPage * 20).Take(20).ToList().ForEach(a=>RedirectItems.Add(a));
|
||||||
|
|
||||||
|
DeletedPages.Clear();
|
||||||
|
if (PageDto.DeletedPages.Count > 20)
|
||||||
|
DeletedPagesCount = DeletedPagesCurrentPage + 2;
|
||||||
|
PageDto.DeletedPages.Skip(DeletedPagesCurrentPage * 20).Take(20).ToList().ForEach(a => DeletedPages.Add(a));
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
var exe = await e.GetContentAsAsync<ApiResult>();
|
||||||
|
if (e.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
await _userUtility.LogoutAsync();
|
||||||
|
navigationManager.NavigateTo("login", true, true);
|
||||||
|
}
|
||||||
|
snackbar.Add(exe != null ? exe.Message : e.Content, Severity.Error);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
snackbar.Add(ex.Message, Severity.Error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsProcessing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await base.InitializeAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int RedirectItemsCurrentPage { get; set; } = 0;
|
||||||
|
public int RedirectItemPageCount { get; set; } = 0;
|
||||||
|
public void RedirectItemChangePageAsync(int page)
|
||||||
|
{
|
||||||
|
RedirectItemsCurrentPage = page - 1;
|
||||||
|
|
||||||
|
if (PageDto.RedirectItems.Count > (RedirectItemsCurrentPage * 20))
|
||||||
|
RedirectItemPageCount = RedirectItemsCurrentPage + 2;
|
||||||
|
|
||||||
|
PageDto.RedirectItems.Skip(RedirectItemsCurrentPage * 20).Take(20).ToList().ForEach(a => RedirectItems.Add(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedirectItem NewRedirectItem { get; set; } = new();
|
||||||
|
public async Task AddPageAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsProcessing = true;
|
||||||
|
var token = await _userUtility.GetBearerTokenAsync();
|
||||||
|
if (token == null)
|
||||||
|
throw new Exception("Token is null");
|
||||||
|
|
||||||
|
if (NewRedirectItem.OldUrl.IsNullOrEmpty())
|
||||||
|
throw new AppException("لینک قدیمی را وارد کنید");
|
||||||
|
if (NewRedirectItem.NewUrl.IsNullOrEmpty())
|
||||||
|
throw new AppException("لینک جدید را وارد کنید");
|
||||||
|
var newUrl = StringExtensions.GetSlug(NewRedirectItem.NewUrl);
|
||||||
|
var oldUrl = StringExtensions.GetSlug(NewRedirectItem.OldUrl);
|
||||||
|
var item = new RedirectItem
|
||||||
|
{
|
||||||
|
NewUrl = newUrl,
|
||||||
|
OldUrl = oldUrl
|
||||||
|
};
|
||||||
|
if (PageDto.RedirectItems.Any(c => c.OldUrl == item.OldUrl))
|
||||||
|
throw new AppException("لینک مورد نظر قبلا اضافه شده است");
|
||||||
|
PageDto.RedirectItems.Add(item);
|
||||||
|
await restWrapper.SettingRestApi.PostSettingAsync(nameof(PageSetting), PageDto, token);
|
||||||
|
NewRedirectItem = new RedirectItem();
|
||||||
|
snackbar.Add("لینک ریدایرکت با موفقیت افزوده شد", Severity.Success);
|
||||||
|
await InitializeAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
var exe = await e.GetContentAsAsync<ApiResult>();
|
||||||
|
if (e.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
await _userUtility.LogoutAsync();
|
||||||
|
navigationManager.NavigateTo("login", true, true);
|
||||||
|
}
|
||||||
|
snackbar.Add(exe != null ? exe.Message : e.Content, Severity.Error);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
snackbar.Add(ex.Message, Severity.Error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsProcessing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task RemovePageAsync(RedirectItem item)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsProcessing = true;
|
||||||
|
var token = await _userUtility.GetBearerTokenAsync();
|
||||||
|
if (token == null)
|
||||||
|
throw new Exception("Token is null");
|
||||||
|
PageDto.RedirectItems.Remove(item);
|
||||||
|
await restWrapper.SettingRestApi.PostSettingAsync(nameof(PageSetting), PageDto, token);
|
||||||
|
snackbar.Add("لینک ریدایرکت مورد نظر با موفقیت حذف شد", Severity.Success);
|
||||||
|
await InitializeAsync();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
var exe = await e.GetContentAsAsync<ApiResult>();
|
||||||
|
if (e.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
await _userUtility.LogoutAsync();
|
||||||
|
navigationManager.NavigateTo("login", true, true);
|
||||||
|
}
|
||||||
|
snackbar.Add(exe != null ? exe.Message : e.Content, Severity.Error);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
snackbar.Add(ex.Message, Severity.Error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsProcessing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeletedPageItem NewDeletedPage { get; set; } = new();
|
||||||
|
public async Task AddDeletedPage()
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsProcessing = true;
|
||||||
|
var token = await _userUtility.GetBearerTokenAsync();
|
||||||
|
if (token == null)
|
||||||
|
throw new Exception("Token is null");
|
||||||
|
|
||||||
|
if (NewDeletedPage.Url.IsNullOrEmpty())
|
||||||
|
throw new AppException("لینک حذف شده را وارد کنید");
|
||||||
|
var item = new DeletedPageItem()
|
||||||
|
{
|
||||||
|
Url = NewDeletedPage.Url
|
||||||
|
};
|
||||||
|
if (PageDto.DeletedPages.Any(c => c.Url == item.Url))
|
||||||
|
throw new AppException("لینک مورد نظر قبلا اضافه شده است");
|
||||||
|
|
||||||
|
PageDto.DeletedPages.Add(NewDeletedPage);
|
||||||
|
DeletedPages.Add(NewDeletedPage);
|
||||||
|
await restWrapper.SettingRestApi.PostSettingAsync(nameof(PageSetting), PageDto, token);
|
||||||
|
NewRedirectItem = new RedirectItem();
|
||||||
|
snackbar.Add("لینک حذف با موفقیت افزوده شد", Severity.Success);
|
||||||
|
await InitializeAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
var exe = await e.GetContentAsAsync<ApiResult>();
|
||||||
|
if (e.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
await _userUtility.LogoutAsync();
|
||||||
|
navigationManager.NavigateTo("login", true, true);
|
||||||
|
}
|
||||||
|
snackbar.Add(exe != null ? exe.Message : e.Content, Severity.Error);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
snackbar.Add(ex.Message, Severity.Error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsProcessing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RemoveDeletedPageAsync(DeletedPageItem item)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsProcessing = true;
|
||||||
|
var token = await _userUtility.GetBearerTokenAsync();
|
||||||
|
if (token == null)
|
||||||
|
throw new Exception("Token is null");
|
||||||
|
PageDto.DeletedPages.Remove(item);
|
||||||
|
await restWrapper.SettingRestApi.PostSettingAsync(nameof(PageSetting), PageDto, token);
|
||||||
|
snackbar.Add("لینک مورد نظر با موفقیت حذف شد", Severity.Success);
|
||||||
|
await InitializeAsync();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
var exe = await e.GetContentAsAsync<ApiResult>();
|
||||||
|
if (e.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
await _userUtility.LogoutAsync();
|
||||||
|
navigationManager.NavigateTo("login", true, true);
|
||||||
|
}
|
||||||
|
snackbar.Add(exe != null ? exe.Message : e.Content, Severity.Error);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
snackbar.Add(ex.Message, Severity.Error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsProcessing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int DeletedPagesCurrentPage { get; set; } = 0;
|
||||||
|
public int DeletedPagesCount { get; set; } = 0;
|
||||||
|
public void DeletedPagesChangePageAsync(int page)
|
||||||
|
{
|
||||||
|
DeletedPagesCurrentPage = page - 1;
|
||||||
|
|
||||||
|
if (PageDto.RedirectItems.Count > (DeletedPagesCurrentPage * 20))
|
||||||
|
DeletedPagesCount = DeletedPagesCurrentPage + 2;
|
||||||
|
|
||||||
|
PageDto.DeletedPages.Skip(DeletedPagesCurrentPage * 20).Take(20).ToList().ForEach(a => DeletedPages.Add(a));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue