mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Allow to change company logo year in admin view.
This commit is contained in:
@@ -337,9 +337,10 @@
|
||||
<tbody>
|
||||
@foreach (var logo in _logos)
|
||||
{
|
||||
bool logoFound = File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", logo.Guid + ".svg"));
|
||||
<tr>
|
||||
<td>
|
||||
@if (File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", logo.Guid + ".svg")))
|
||||
@if (logoFound)
|
||||
{
|
||||
<picture>
|
||||
<source type="image/svg+xml" srcset="/assets/logos/@(logo.Guid).svg">
|
||||
@@ -364,8 +365,11 @@
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-primary">@L["Change year"]</a>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowModal(logo.Id);}">@L["Delete"]</Button>
|
||||
@if (logoFound)
|
||||
{
|
||||
<Button Color="Color.Success" Clicked="() => {ShowLogoYearModal(logo.Id);}">@L["Change year"]</Button>
|
||||
}
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowDeleteModal(logo.Id);}">@L["Delete"]</Button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@@ -373,19 +377,62 @@
|
||||
</table>
|
||||
}
|
||||
|
||||
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
||||
<Modal @ref="_frmDelete" IsCentered="true" Closing="@DeleteModalClosing">
|
||||
<ModalBackdrop/>
|
||||
<ModalContent Centered="true">
|
||||
<ModalHeader>
|
||||
<ModalTitle>@L["Delete logo"]</ModalTitle>
|
||||
<CloseButton Clicked="@HideModal"/>
|
||||
<CloseButton Clicked="@HideDeleteModal"/>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<Text>@string.Format(@L["Are you sure you want to delete the company logo introduced in {0}?"], _currentLogo?.Year)</Text>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button Color="Color.Primary" Clicked="@HideModal" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
|
||||
<Button Color="Color.Primary" Clicked="@HideDeleteModal" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
|
||||
<Button Color="Color.Danger" Clicked="@ConfirmDelete" Disabled="@_deleteInProgress">@L["Delete"]</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
<Modal @ref="_frmLogoYear" IsCentered="true" Closing="@LogoYearModalClosing">
|
||||
<ModalBackdrop/>
|
||||
<ModalContent Centered="true">
|
||||
<ModalHeader>
|
||||
<ModalTitle>@L["Change logo year"]</ModalTitle>
|
||||
<CloseButton Clicked="@HideLogoYearModal"/>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
@if (_currentLogo != null)
|
||||
{
|
||||
<div class="text-center">
|
||||
<picture>
|
||||
<source type="image/svg+xml" srcset="/assets/logos/@(_currentLogo.Guid).svg">
|
||||
<source type="image/webp" srcset="/assets/logos/webp/1x/@(_currentLogo.Guid).webp, /assets/logos/webp/2x/@(_currentLogo.Guid).webp 2x, /assets/logos/webp/3x/@(_currentLogo.Guid).webp 3x">
|
||||
<img srcset="/assets/logos/png/1x/@(_currentLogo.Guid).png, /assets/logos/png/2x/@(_currentLogo.Guid).png 2x, /assets/logos/png/3x/@(_currentLogo.Guid).png 3x" src="/assets/logos/png/1x@(_currentLogo.Guid).png" alt="" height="auto" width="auto" style="max-height: 256px; max-width: 256px" />
|
||||
</picture>
|
||||
</div>
|
||||
<Field>
|
||||
<FieldLabel>@L["Year logo came in use"]</FieldLabel>
|
||||
<Check TValue="bool" @bind-Checked="@_unknownLogoYear">@L["Unknown (logo year)"]</Check>
|
||||
@if (!_unknownLogoYear)
|
||||
{
|
||||
<Validation Validator="@ValidateLogoYear">
|
||||
<NumericEdit TValue="int?" Decimals="0" @bind-Value="@_currentLogoYear">
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid year."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button Color="Color.Primary" Clicked="@HideLogoYearModal" Disabled="@_yearChangeInProgress">@L["Cancel"]</Button>
|
||||
@if (_currentLogo != null)
|
||||
{
|
||||
<Button Color="Color.Success" Clicked="@ConfirmLogoYear" Disabled="@_yearChangeInProgress">@L["Save"]</Button>
|
||||
}
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
@@ -17,9 +17,11 @@ namespace Marechai.Pages.Admin.Details
|
||||
List<Iso31661Numeric> _countries;
|
||||
bool _creating;
|
||||
CompanyLogo _currentLogo;
|
||||
int? _currentLogoYear;
|
||||
bool _deleteInProgress;
|
||||
bool _editing;
|
||||
Modal _frmDelete;
|
||||
Modal _frmLogoYear;
|
||||
bool _loaded;
|
||||
List<CompanyLogo> _logos;
|
||||
CompanyViewModel _model;
|
||||
@@ -28,12 +30,15 @@ namespace Marechai.Pages.Admin.Details
|
||||
bool _unknownCountry;
|
||||
bool _unknownFacebook;
|
||||
bool _unknownFounded;
|
||||
bool _unknownLogoYear;
|
||||
bool _unknownPostalCode;
|
||||
bool _unknownProvince;
|
||||
bool _unknownSold;
|
||||
bool _unknownSoldTo;
|
||||
bool _unknownTwitter;
|
||||
bool _unknownWebsite;
|
||||
|
||||
bool _yearChangeInProgress;
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -237,13 +242,13 @@ namespace Marechai.Pages.Admin.Details
|
||||
void ValidateFacebook(ValidatorEventArgs e) =>
|
||||
Validators.ValidateString(e, L["Facebook username must be smaller than 256 characters."], 256);
|
||||
|
||||
void ShowModal(int itemId)
|
||||
void ShowDeleteModal(int itemId)
|
||||
{
|
||||
_currentLogo = _logos.FirstOrDefault(n => n.Id == itemId);
|
||||
_frmDelete.Show();
|
||||
}
|
||||
|
||||
void HideModal() => _frmDelete.Hide();
|
||||
void HideDeleteModal() => _frmDelete.Hide();
|
||||
|
||||
async void ConfirmDelete()
|
||||
{
|
||||
@@ -268,6 +273,55 @@ namespace Marechai.Pages.Admin.Details
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ModalClosing(ModalClosingEventArgs obj) => _currentLogo = null;
|
||||
void DeleteModalClosing(ModalClosingEventArgs e) => _currentLogo = null;
|
||||
|
||||
void ShowLogoYearModal(int itemId)
|
||||
{
|
||||
_currentLogo = _logos.FirstOrDefault(n => n.Id == itemId);
|
||||
_currentLogoYear = _currentLogo?.Year;
|
||||
_unknownLogoYear = _currentLogoYear is null;
|
||||
_frmLogoYear.Show();
|
||||
}
|
||||
|
||||
void HideLogoYearModal() => _frmLogoYear.Hide();
|
||||
|
||||
async void ConfirmLogoYear()
|
||||
{
|
||||
if(_currentLogo is null)
|
||||
return;
|
||||
|
||||
_yearChangeInProgress = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await CompanyLogosService.ChangeYearAsync(_currentLogo.Id, _unknownLogoYear ? null : _currentLogoYear);
|
||||
_logos = await CompanyLogosService.GetByCompany(Id);
|
||||
|
||||
_yearChangeInProgress = false;
|
||||
_frmLogoYear.Hide();
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void LogoYearModalClosing(ModalClosingEventArgs e)
|
||||
{
|
||||
_currentLogo = null;
|
||||
_currentLogoYear = null;
|
||||
}
|
||||
|
||||
void ValidateLogoYear(ValidatorEventArgs e)
|
||||
{
|
||||
if(!(e.Value is int item) ||
|
||||
item <= 1000 ||
|
||||
item > DateTime.UtcNow.Year)
|
||||
e.Status = ValidationStatus.Error;
|
||||
else
|
||||
e.Status = ValidationStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user