Files
marechai/Marechai/Pages/Admin/Details/Company.razor

535 lines
23 KiB
Plaintext
Raw Normal View History

2020-05-25 02:44:52 +01:00
@{
2020-12-20 21:34:13 +00:00
/******************************************************************************
2020-05-25 02:44:52 +01:00
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
}
@page "/admin/companies/details/{Id:int}"
2020-05-27 21:24:53 +01:00
@page "/admin/companies/edit/{Id:int}"
2020-05-27 22:30:06 +01:00
@page "/admin/companies/create"
@using Marechai.Database.Models
2020-12-20 21:34:13 +00:00
@using Marechai.Database
2020-05-25 02:44:52 +01:00
@inherits OwningComponentBase<CompaniesService>
@inject IStringLocalizer<CompaniesService> L
@inject Iso31661NumericService CountriesService
2020-05-27 21:24:53 +01:00
@inject NavigationManager NavigationManager
@inject CompanyLogosService CompanyLogosService
@inject IWebHostEnvironment Host
@inject IFileReaderService FileReaderService;
@inject IJSRuntime JSRuntime
2020-12-20 21:34:13 +00:00
@inject UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
2020-05-25 02:44:52 +01:00
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Company details"]</h3>
<hr />
2020-12-20 21:34:13 +00:00
@if(!_loaded)
2020-05-25 02:44:52 +01:00
{
<p align="center">@L["Loading..."]</p>
return;
}
<div>
2020-12-20 21:34:13 +00:00
<Field>
<FieldLabel>@L["Common name (as usually displayed publicly)"]</FieldLabel>
<Validation Validator="@ValidateName">
<TextEdit @bind-Text="@_model.Name" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid name."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Field>
@if(_editing || _model.LegalName != null)
{
2020-05-25 02:44:52 +01:00
<Field>
2020-12-20 21:34:13 +00:00
<FieldLabel>@L["Legal name (as shown in governmental registries including \"Inc.\", \"Corp.\", \"gmbH\", etc...)"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownLegalName" @TValue="bool">@L["Unknown (legal name)"]</Check> }
@if(!_editing ||
!_unknownLegalName)
{
<Validation Validator="@ValidateLegalName">
<TextEdit @bind-Text="@_model.LegalName" Disabled="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid legal name."]</ValidationError>
</Feedback>
</TextEdit>
</Validation> }
</Field>}
<Field>
<FieldLabel>@L["Status"]</FieldLabel>
<Select @bind-SelectedValue="@Status" Disabled="!_editing" @TValue="int">
@foreach(int status in Enum.GetValues(typeof(CompanyStatus)))
{
<SelectItem @TValue="int" Value="@status">@(((CompanyStatus)status).ToString())</SelectItem> }
</Select>
</Field>
@if(_editing || _model.Founded != null)
{
2020-05-25 02:44:52 +01:00
<Field>
2020-12-20 21:34:13 +00:00
<FieldLabel>@L["Founded"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownFounded" @TValue="bool">@L["Unknown (foundation date)"]</Check> }
@if(!_editing ||
!_unknownFounded)
{
<Check @bind-Checked="@_model.FoundedMonthIsUnknown" Disabled="!_editing" @TValue="bool">@L["Unknown foundation month"]</Check>
<Check @bind-Checked="@_model.FoundedDayIsUnknown" Disabled="_model.FoundedMonthIsUnknown || !_editing" @TValue="bool">@L["Unknown foundation day"]</Check>
@L["If the foundation day or month are selected as unknown, pick anyone in the field below, it will be ignored."]
<Validation Validator="@ValidateFounded">
<DateEdit @bind-Date="@_model.Founded" ReadOnly="!_editing" @TValue="DateTime?">
<Feedback>
<ValidationError>@L["Please enter a valid foundation date."]</ValidationError>
</Feedback>
</DateEdit>
</Validation> }
</Field>}
@if(_editing || _model.Website != null)
{
<Field>
<FieldLabel>@L["Website"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownWebsite" @TValue="bool">@L["Unknown (website)"]</Check> }
@if(!_editing ||
!_unknownWebsite)
{
<Validation Validator="@ValidateWebsite">
<TextEdit @bind-Text="@_model.Website" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid website."]</ValidationError>
</Feedback>
</TextEdit>
</Validation> }
</Field>}
@if(_editing || _model.Twitter != null)
{
<Field>
<FieldLabel>@L["Twitter"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownTwitter" @TValue="bool">@L["Unknown (twitter)"]</Check> }
@if(!_editing ||
!_unknownTwitter)
{
<Validation Validator="@ValidateTwitter">
<TextEdit @bind-Text="@_model.Twitter" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid Twitter handle."]</ValidationError>
</Feedback>
</TextEdit>
</Validation> }
</Field>}
@if(_editing || _model.Facebook != null)
{
<Field>
<FieldLabel>@L["Facebook"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownFacebook" @TValue="bool">@L["Unknown (facebook)"]</Check> }
@if(!_editing ||
!_unknownFacebook)
{
<Validation Validator="@ValidateFacebook">
<TextEdit @bind-Text="@_model.Facebook" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid Facebook user name."]</ValidationError>
</Feedback>
</TextEdit>
</Validation> }
</Field>}
@if(_editing || _model.Address != null)
{
<Field>
<FieldLabel>@L["Address"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownAddress" @TValue="bool">@L["Unknown (address)"]</Check> }
@if(!_editing ||
!_unknownAddress)
{
<Validation Validator="@ValidateAddress">
<TextEdit @bind-Text="@_model.Address" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid address."]</ValidationError>
</Feedback>
</TextEdit>
</Validation> }
</Field>}
@if(_editing || _model.City != null)
{
<Field>
<FieldLabel>@L["City"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownCity" @TValue="bool">@L["Unknown (city)"]</Check> }
@if(!_editing ||
!_unknownCity)
{
<Validation Validator="@ValidateCity">
<TextEdit @bind-Text="@_model.City" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid city."]</ValidationError>
</Feedback>
</TextEdit>
</Validation> }
</Field>}
@if(_editing || _model.Province != null)
{
<Field>
<FieldLabel>@L["Province"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownProvince" @TValue="bool">@L["Unknown (province)"]</Check> }
@if(!_editing ||
!_unknownProvince)
{
<Validation Validator="@ValidateProvince">
<TextEdit @bind-Text="@_model.Province" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid province."]</ValidationError>
</Feedback>
</TextEdit>
</Validation> }
</Field>}
@if(_editing || _model.PostalCode != null)
{
<Field>
<FieldLabel>@L["Postal code"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownPostalCode" @TValue="bool">@L["Unknown (postal code)"]</Check> }
@if(!_editing ||
!_unknownPostalCode)
{
<Validation Validator="@ValidatePostalCode">
<TextEdit @bind-Text="@_model.PostalCode" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid postal code."]</ValidationError>
</Feedback>
</TextEdit>
</Validation> }
</Field>}
@if(_editing || _model.CountryId != null)
{
<Field>
<FieldLabel>@L["Country"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownCountry" @TValue="bool">@L["Unknown (country)"]</Check> }
@if(!_editing ||
!_unknownCountry)
{
<Select @bind-SelectedValue="@_model.CountryId" Disabled="!_editing" @TValue="short?">
@foreach(var country in _countries)
{
<SelectItem @TValue="short?" Value="@country.Id">@country.Name</SelectItem> }
</Select> }
</Field>}
@if((int)_model.Status > 1)
{
@if(_editing || _model.Sold != null)
2020-05-25 02:44:52 +01:00
{
<Field>
2020-12-20 21:34:13 +00:00
<FieldLabel>@L["Sold"]</FieldLabel>
@if(_editing)
2020-05-27 21:24:53 +01:00
{
2020-12-20 21:34:13 +00:00
<Check @bind-Checked="@_unknownSold" @TValue="bool">@L["Unknown (sold/merged/bankrupt date)"]</Check> }
@if(!_editing ||
!_unknownSold)
2020-05-27 21:24:53 +01:00
{
2020-12-20 21:34:13 +00:00
<Check @bind-Checked="@_model.SoldMonthIsUnknown" Disabled="!_editing" @TValue="bool">@L["Unknown sold/merge/bankruptcy month"]</Check>
<Check @bind-Checked="@_model.SoldDayIsUnknown" Disabled="_model.SoldMonthIsUnknown || !_editing" @TValue="bool">@L["Unknown sold/merge/bankruptcy day"]</Check>
@L["If the sold, merge or bankruptcy day or month are selected as unknown, pick anyone in the field below, it will be ignored."]
<Validation Validator="@ValidateSold">
<DateEdit @bind-Date="@_model.Sold" ReadOnly="!_editing" @TValue="DateTime?">
2020-05-27 21:24:53 +01:00
<Feedback>
2020-12-20 21:34:13 +00:00
<ValidationError>@L["Please enter a valid sold/merge/bankruptcy date."]</ValidationError>
2020-05-27 21:24:53 +01:00
</Feedback>
</DateEdit>
2020-12-20 21:34:13 +00:00
</Validation> }
</Field> }
@if(_editing || _model.SoldToId != null)
2020-05-25 02:44:52 +01:00
{
<Field>
2020-12-20 21:34:13 +00:00
<FieldLabel>@L["Sold to"]</FieldLabel>
@if(_editing)
2020-05-27 21:24:53 +01:00
{
2020-12-20 21:34:13 +00:00
<Check @bind-Checked="@_unknownSoldTo" @TValue="bool">@L["Unknown (sold to)"]</Check> }
@if(!_editing ||
!_unknownSoldTo)
2020-05-27 21:24:53 +01:00
{
2020-12-20 21:34:13 +00:00
<Select @bind-SelectedValue="@_model.SoldToId" Disabled="!_editing" @TValue="int?">
@foreach(var company in _companies)
2020-05-27 21:24:53 +01:00
{
2020-12-20 21:34:13 +00:00
<SelectItem @TValue="int?" Value="@company.Id">@company.Name</SelectItem> }
</Select> }
</Field> }
}
2020-05-25 02:44:52 +01:00
</div>
<div>
2020-12-20 21:34:13 +00:00
@if(!_editing)
2020-05-27 21:24:53 +01:00
{
2020-12-20 21:34:13 +00:00
<Button Clicked="@OnEditClicked" Color="Color.Primary">@L["Edit"]</Button> }
2020-05-27 21:24:53 +01:00
else
{
2020-12-20 21:34:13 +00:00
<Button Clicked="@OnSaveClicked" Color="Color.Success">@L["Save"]</Button>
<Button Clicked="@OnCancelClicked" Color="Color.Danger">@L["Cancel"]</Button> }
<a class="btn btn-secondary" href="/admin/companies">@L["Back to list"]</a>
@if(!_editing)
{
<Button Clicked="@ShowUploadModal" Color="Color.Success">@L["Upload new logo"]</Button> }
</div>
2020-12-20 21:34:13 +00:00
@if(_logos.Count > 0)
{
<h4>@L["Logos"]</h4>
<table class="table table-striped">
<thead>
2020-12-20 21:34:13 +00:00
<tr>
<th>
@L["Logo"]
</th>
<th>
@L["Year logo came in use"]
</th>
<th></th>
</tr>
</thead>
<tbody>
2020-12-20 21:34:13 +00:00
@foreach(var logo in _logos)
{
2020-12-20 21:34:13 +00:00
var logoFound = File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", logo.Guid + ".svg"));
<tr>
<td>
2020-12-20 21:34:13 +00:00
@if(logoFound)
{
<picture>
2020-12-20 21:34:13 +00:00
<source srcset="/assets/logos/@(logo.Guid).svg" type="image/svg+xml">
<source srcset="/assets/logos/webp/1x/@(logo.Guid).webp, /assets/logos/webp/2x/@(logo.Guid).webp 2x, /assets/logos/webp/3x/@(logo.Guid).webp 3x" type="image/webp">
<img alt="" height="auto" src="/assets/logos/png/1x/@(logo.Guid).png" srcset="/assets/logos/png/1x/@(logo.Guid).png, /assets/logos/png/2x/@(logo.Guid).png 2x, /assets/logos/png/3x/@(logo.Guid).png 3x" style="max-height: 256px; max-width: 256px" width="auto" />
</picture>
}
else
{
<strong>@L["Cannot find logo file"]</strong>
}
</td>
<td>
2020-12-20 21:34:13 +00:00
@if(logo.Year.HasValue)
{
@logo.Year
}
else
{
@L["Unknown (logo year)"]
}
</td>
<td>
2020-12-20 21:34:13 +00:00
@if(logoFound)
{
2020-12-20 21:34:13 +00:00
<Button Clicked="() => {ShowLogoYearModal(logo.Id);}" Color="Color.Success">@L["Change year"]</Button> }
<Button Clicked="() => {ShowDeleteModal(logo.Id);}" Color="Color.Danger">@L["Delete"]</Button>
</td>
</tr>
}
</tbody>
2020-12-20 21:34:13 +00:00
</table>}
<Modal Closing="@DeleteModalClosing" IsCentered="true" ref="_frmDelete">
<ModalBackdrop />
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["Delete logo"]</ModalTitle>
2020-12-20 21:34:13 +00:00
<CloseButton Clicked="@HideDeleteModal" />
</ModalHeader>
<ModalBody>
2020-12-20 21:34:13 +00:00
@if(_currentLogo?.Year != null)
{
2020-12-20 21:34:13 +00:00
<Text>@string.Format(L["Are you sure you want to delete the company logo introduced in {0}?"], _currentLogo?.Year)</Text> }
else
{
2020-12-20 21:34:13 +00:00
<Text>@L["Are you sure you want to delete the company logo you selected?"]</Text> }
</ModalBody>
<ModalFooter>
2020-12-20 21:34:13 +00:00
<Button Clicked="@HideDeleteModal" Color="Color.Primary" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
<Button Clicked="@ConfirmDelete" Color="Color.Danger" Disabled="@_deleteInProgress">@L["Delete"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
2020-12-20 21:34:13 +00:00
<Modal Closing="@LogoYearModalClosing" IsCentered="true" ref="_frmLogoYear">
<ModalBackdrop />
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["Change logo year"]</ModalTitle>
2020-12-20 21:34:13 +00:00
<CloseButton Clicked="@HideLogoYearModal" />
</ModalHeader>
<ModalBody>
2020-12-20 21:34:13 +00:00
@if(_currentLogo != null)
{
<div class="text-center">
<picture>
2020-12-20 21:34:13 +00:00
<source srcset="/assets/logos/@(_currentLogo.Guid).svg" type="image/svg+xml">
<source srcset="/assets/logos/webp/1x/@(_currentLogo.Guid).webp, /assets/logos/webp/2x/@(_currentLogo.Guid).webp 2x, /assets/logos/webp/3x/@(_currentLogo.Guid).webp 3x" type="image/webp">
<img alt="" height="auto" src="/assets/logos/png/1x/@(_currentLogo.Guid).png" srcset="/assets/logos/png/1x/@(_currentLogo.Guid).png, /assets/logos/png/2x/@(_currentLogo.Guid).png 2x, /assets/logos/png/3x/@(_currentLogo.Guid).png 3x" style="max-height: 256px; max-width: 256px" width="auto" />
</picture>
</div>
<Field>
<FieldLabel>@L["Year logo came in use"]</FieldLabel>
2020-12-20 21:34:13 +00:00
<Check @bind-Checked="@_unknownLogoYear" @TValue="bool">@L["Unknown (logo year)"]</Check>
@if(!_unknownLogoYear)
{
<Validation Validator="@ValidateLogoYear">
2020-12-20 21:34:13 +00:00
<NumericEdit @bind-Value="@_currentLogoYear" Decimals="0" @TValue="int?">
<Feedback>
<ValidationError>@L["Please enter a valid year."]</ValidationError>
</Feedback>
</NumericEdit>
2020-12-20 21:34:13 +00:00
</Validation> }
</Field> }
</ModalBody>
<ModalFooter>
2020-12-20 21:34:13 +00:00
<Button Clicked="@HideLogoYearModal" Color="Color.Primary" Disabled="@_yearChangeInProgress">@L["Cancel"]</Button>
@if(_currentLogo != null)
{
2020-12-20 21:34:13 +00:00
<Button Clicked="@ConfirmLogoYear" Color="Color.Success" Disabled="@_yearChangeInProgress">@L["Save"]</Button> }
</ModalFooter>
</ModalContent>
</Modal>
2020-12-20 21:34:13 +00:00
<Modal Closing="@UploadModalClosing" IsCentered="true" ref="_frmUpload">
<ModalBackdrop />
<ModalContent Centered="true" Size="ModalSize.ExtraLarge">
<ModalHeader>
<ModalTitle>@L["Upload new logo"]</ModalTitle>
2020-12-20 21:34:13 +00:00
<CloseButton Clicked="@HideUploadModal" />
</ModalHeader>
<ModalBody>
<Field>
2020-12-20 21:34:13 +00:00
@if(!_uploaded)
{
2020-12-20 21:34:13 +00:00
@if(!_uploading)
{
<FieldLabel>@L["Choose SVG (version 1.1 or lower) logo file"]</FieldLabel>
2020-12-20 21:34:13 +00:00
<input Accept=".svg" @ref=_inputUpload type="file" />
<br />
<Button Clicked="@UploadFile" Color="Color.Success" Disabled="@_uploading">@L["Upload"]</Button> <br />
}
else
{
@L["Uploading..."]
<div class="progress">
2020-12-20 21:34:13 +00:00
<div aria-valuemax="100" aria-valuemin="0" aria-valuenow="@_progressValue" class="progress-bar" role="progressbar" style="width: @(_progressValue)%;">@($"{_progressValue:F2}")%</div>
</div>
}
2020-12-20 21:34:13 +00:00
@if(_uploadError)
{
<span class="text-danger">@_uploadErrorMessage</span>
}
}
else
{
<table class="table table-dark">
<thead>
<tr>
<th>@L["SVG"]</th>
<th>@L["PNG"]</th>
<th>@L["WebP"]</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class="text-warning">@L["May not show properly"]</span>
2020-12-20 21:34:13 +00:00
</td>
<td></td>
<td>
<span class="text-warning">@L["May not show properly"]</span>
2020-12-20 21:34:13 +00:00
</td>
</tr>
<tr>
<td>
2020-12-20 21:34:13 +00:00
<img alt="" height="auto" src="@_uploadedSvgData" style="max-height: 256px; max-width: 256px" width="auto" />
</td>
<td>
2020-12-20 21:34:13 +00:00
<img alt="" height="auto" src="@_uploadedPngData" style="max-height: 256px; max-width: 256px" width="auto" />
</td>
<td>
2020-12-20 21:34:13 +00:00
<img alt="" height="auto" src="@_uploadedWebpData" style="max-height: 256px; max-width: 256px" width="auto" />
</td>
</tr>
</tbody>
</table>
<Field>
<FieldLabel>@L["Year logo came in use"]</FieldLabel>
2020-12-20 21:34:13 +00:00
<Check @bind-Checked="@_unknownLogoYear" @TValue="bool">@L["Unknown (logo year)"]</Check>
@if(!_unknownLogoYear)
{
<Validation Validator="@ValidateLogoYear">
2020-12-20 21:34:13 +00:00
<NumericEdit @bind-Value="@_currentLogoYear" Decimals="0" @TValue="int?">
<Feedback>
<ValidationError>@L["Please enter a valid year."]</ValidationError>
</Feedback>
</NumericEdit>
2020-12-20 21:34:13 +00:00
</Validation> }
</Field> }
</Field>
</ModalBody>
<ModalFooter>
2020-12-20 21:34:13 +00:00
<Button Clicked="@HideUploadModal" Color="Color.Primary" Disabled="_uploading || _savingLogo">@L["Cancel"]</Button>
<Button Clicked="@ConfirmUpload" Color="Color.Success" Disabled="!_uploaded || _savingLogo">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
2020-12-20 21:34:13 +00:00
<hr />
<div class="container">
<h4>@L["Company description"]</h4>
2020-12-20 21:34:13 +00:00
<hr />
@if(_readonlyDescription && _description is null)
{
2020-12-20 21:34:13 +00:00
<Button Clicked="@AddNewDescription" Color="Color.Success">@L["Add new description"]</Button> }
@if(!_readonlyDescription ||
_description != null)
{
2020-12-20 21:34:13 +00:00
if(_readonlyDescription)
{
2020-12-20 21:34:13 +00:00
<Button Clicked="@EditDescription" Color="Color.Success">@L["Edit"]</Button> }
else
{
2020-12-20 21:34:13 +00:00
<Button Clicked="@CancelDescription" Color="Color.Primary">@L["Cancel"]</Button>
<Button Clicked="@SaveDescription" Color="Color.Success">@L["Save"]</Button> }
<Tabs SelectedTab="@_selectedDescriptionTab" SelectedTabChanged="@OnSelectedDescriptionTabChanged">
<Items>
<Tab Name="markdown">Markdown</Tab>
<Tab Name="preview">Preview</Tab>
</Items>
<Content>
<TabPanel Name="markdown">
2020-12-20 21:34:13 +00:00
<textarea class="form-control" id="txtCompanyDescriptionMarkdown" onchange="OnCompanyMarkdownChanged()" readonly="@_readonlyDescription" rows="200">@_description.Markdown</textarea>
</TabPanel>
<TabPanel Name="preview">
@((MarkupString)_description.Html)
</TabPanel>
</Content>
2020-12-20 21:34:13 +00:00
</Tabs> }
</div>