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:
@@ -1,43 +0,0 @@
|
|||||||
@model Marechai.Database.Models.CompanyLogo
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Edit";
|
|
||||||
}
|
|
||||||
<h1>Edit</h1>
|
|
||||||
<h4>Company logo</h4>
|
|
||||||
<hr />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form asp-action="Edit">
|
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger">
|
|
||||||
</div>
|
|
||||||
<input type="hidden" asp-for="Id" />
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Company" class="control-label">
|
|
||||||
</label>
|
|
||||||
<select asp-for="CompanyId" class="form-control" asp-items="ViewBag.CompanyId">
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Year" class="control-label">
|
|
||||||
</label>
|
|
||||||
<input asp-for="Year" class="form-control" />
|
|
||||||
<span asp-validation-for="Year" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Guid" class="control-label">
|
|
||||||
</label>
|
|
||||||
<input asp-for="Guid" class="form-control" readonly />
|
|
||||||
<span asp-validation-for="Guid" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input class="btn btn-primary" type="submit" value="Save" />
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<Version>3.0.99.1269</Version>
|
<Version>3.0.99.1275</Version>
|
||||||
<Company>Canary Islands Computer Museum</Company>
|
<Company>Canary Islands Computer Museum</Company>
|
||||||
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
||||||
<Product>Canary Islands Computer Museum Website</Product>
|
<Product>Canary Islands Computer Museum Website</Product>
|
||||||
|
|||||||
@@ -337,9 +337,10 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var logo in _logos)
|
@foreach (var logo in _logos)
|
||||||
{
|
{
|
||||||
|
bool logoFound = File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", logo.Guid + ".svg"));
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@if (File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", logo.Guid + ".svg")))
|
@if (logoFound)
|
||||||
{
|
{
|
||||||
<picture>
|
<picture>
|
||||||
<source type="image/svg+xml" srcset="/assets/logos/@(logo.Guid).svg">
|
<source type="image/svg+xml" srcset="/assets/logos/@(logo.Guid).svg">
|
||||||
@@ -364,8 +365,11 @@
|
|||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-primary">@L["Change year"]</a>
|
@if (logoFound)
|
||||||
<Button Color="Color.Danger" Clicked="() => {ShowModal(logo.Id);}">@L["Delete"]</Button>
|
{
|
||||||
|
<Button Color="Color.Success" Clicked="() => {ShowLogoYearModal(logo.Id);}">@L["Change year"]</Button>
|
||||||
|
}
|
||||||
|
<Button Color="Color.Danger" Clicked="() => {ShowDeleteModal(logo.Id);}">@L["Delete"]</Button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
@@ -373,19 +377,62 @@
|
|||||||
</table>
|
</table>
|
||||||
}
|
}
|
||||||
|
|
||||||
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
<Modal @ref="_frmDelete" IsCentered="true" Closing="@DeleteModalClosing">
|
||||||
<ModalBackdrop/>
|
<ModalBackdrop/>
|
||||||
<ModalContent Centered="true">
|
<ModalContent Centered="true">
|
||||||
<ModalHeader>
|
<ModalHeader>
|
||||||
<ModalTitle>@L["Delete logo"]</ModalTitle>
|
<ModalTitle>@L["Delete logo"]</ModalTitle>
|
||||||
<CloseButton Clicked="@HideModal"/>
|
<CloseButton Clicked="@HideDeleteModal"/>
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<Text>@string.Format(@L["Are you sure you want to delete the company logo introduced in {0}?"], _currentLogo?.Year)</Text>
|
<Text>@string.Format(@L["Are you sure you want to delete the company logo introduced in {0}?"], _currentLogo?.Year)</Text>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<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>
|
<Button Color="Color.Danger" Clicked="@ConfirmDelete" Disabled="@_deleteInProgress">@L["Delete"]</Button>
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</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;
|
List<Iso31661Numeric> _countries;
|
||||||
bool _creating;
|
bool _creating;
|
||||||
CompanyLogo _currentLogo;
|
CompanyLogo _currentLogo;
|
||||||
|
int? _currentLogoYear;
|
||||||
bool _deleteInProgress;
|
bool _deleteInProgress;
|
||||||
bool _editing;
|
bool _editing;
|
||||||
Modal _frmDelete;
|
Modal _frmDelete;
|
||||||
|
Modal _frmLogoYear;
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
List<CompanyLogo> _logos;
|
List<CompanyLogo> _logos;
|
||||||
CompanyViewModel _model;
|
CompanyViewModel _model;
|
||||||
@@ -28,12 +30,15 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
bool _unknownCountry;
|
bool _unknownCountry;
|
||||||
bool _unknownFacebook;
|
bool _unknownFacebook;
|
||||||
bool _unknownFounded;
|
bool _unknownFounded;
|
||||||
|
bool _unknownLogoYear;
|
||||||
bool _unknownPostalCode;
|
bool _unknownPostalCode;
|
||||||
bool _unknownProvince;
|
bool _unknownProvince;
|
||||||
bool _unknownSold;
|
bool _unknownSold;
|
||||||
bool _unknownSoldTo;
|
bool _unknownSoldTo;
|
||||||
bool _unknownTwitter;
|
bool _unknownTwitter;
|
||||||
bool _unknownWebsite;
|
bool _unknownWebsite;
|
||||||
|
|
||||||
|
bool _yearChangeInProgress;
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
@@ -237,13 +242,13 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
void ValidateFacebook(ValidatorEventArgs e) =>
|
void ValidateFacebook(ValidatorEventArgs e) =>
|
||||||
Validators.ValidateString(e, L["Facebook username must be smaller than 256 characters."], 256);
|
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);
|
_currentLogo = _logos.FirstOrDefault(n => n.Id == itemId);
|
||||||
_frmDelete.Show();
|
_frmDelete.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HideModal() => _frmDelete.Hide();
|
void HideDeleteModal() => _frmDelete.Hide();
|
||||||
|
|
||||||
async void ConfirmDelete()
|
async void ConfirmDelete()
|
||||||
{
|
{
|
||||||
@@ -268,6 +273,55 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
StateHasChanged();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,4 +162,8 @@
|
|||||||
<value>Unknown</value>
|
<value>Unknown</value>
|
||||||
<comment>Unknown, referring to another company name</comment>
|
<comment>Unknown, referring to another company name</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Unknown (logo year)" xml:space="preserve">
|
||||||
|
<value>Unknown</value>
|
||||||
|
<comment>Unknown, referring to a company logo year</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -402,4 +402,48 @@
|
|||||||
<value>Por favor introduce una fecha de venta, fusión, bancarrota o renombre válida.</value>
|
<value>Por favor introduce una fecha de venta, fusión, bancarrota o renombre válida.</value>
|
||||||
<comment>Please enter a valid sold/merge/bankruptcy date.</comment>
|
<comment>Please enter a valid sold/merge/bankruptcy date.</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Unknown (logo year)" xml:space="preserve">
|
||||||
|
<value>Desconocido</value>
|
||||||
|
<comment>Unknown, referring to a company logo year</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Upload new logo" xml:space="preserve">
|
||||||
|
<value>Subir nuevo logo</value>
|
||||||
|
<comment>Upload new logo</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Logos" xml:space="preserve">
|
||||||
|
<value>Logos</value>
|
||||||
|
<comment>Logos</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Logo" xml:space="preserve">
|
||||||
|
<value>Logo</value>
|
||||||
|
<comment>Logo</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Year logo came in use" xml:space="preserve">
|
||||||
|
<value>Año el logo empezó a usarse</value>
|
||||||
|
<comment>Year logo came in use</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Cannot find logo file" xml:space="preserve">
|
||||||
|
<value>No se pudo encontrar el archivo del logo</value>
|
||||||
|
<comment>Cannot find logo file</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Change year" xml:space="preserve">
|
||||||
|
<value>Cambiar año</value>
|
||||||
|
<comment>Change year</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Delete logo" xml:space="preserve">
|
||||||
|
<value>Borrar logo</value>
|
||||||
|
<comment>Delete logo</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Are you sure you want to delete the company logo introduced in {0}?" xml:space="preserve">
|
||||||
|
<value>¿Estás seguro de que quieres borrar el logo que la compañía empezó a utilizar en {0}?</value>
|
||||||
|
<comment>Are you sure you want to delete the company logo introduced in {0}?</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Change logo year" xml:space="preserve">
|
||||||
|
<value>Cambiar año del logo</value>
|
||||||
|
<comment>Change logo year</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Please enter a valid year." xml:space="preserve">
|
||||||
|
<value>Por favor introduce un año válido.</value>
|
||||||
|
<comment>Please enter a valid year.</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -73,5 +73,16 @@ namespace Marechai.Services
|
|||||||
if(File.Exists(Path.Combine(_webRootPath, "assets/logos/thumbs/png/3x", logo.Guid + ".png")))
|
if(File.Exists(Path.Combine(_webRootPath, "assets/logos/thumbs/png/3x", logo.Guid + ".png")))
|
||||||
File.Delete(Path.Combine(_webRootPath, "assets/logos/thumbs/png/3x", logo.Guid + ".png"));
|
File.Delete(Path.Combine(_webRootPath, "assets/logos/thumbs/png/3x", logo.Guid + ".png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task ChangeYearAsync(int id, int? year)
|
||||||
|
{
|
||||||
|
CompanyLogo logo = await _context.CompanyLogos.Where(l => l.Id == id).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if(logo is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
logo.Year = year;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user