From b8a31a8be9650807d9dc841503ce5836306a2875 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Tue, 26 Jul 2022 14:44:06 -0400 Subject: [PATCH] support for module translation download/install --- .../Modules/Admin/ModuleDefinitions/Add.razor | 26 +-- .../Admin/ModuleDefinitions/Edit.razor | 166 +++++++++++++++++- .../Modules/Admin/ModuleDefinitions/Edit.resx | 15 ++ .../OqtaneServiceCollectionExtensions.cs | 2 +- 4 files changed, 188 insertions(+), 21 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor index 68af3ec7b..4428cabfa 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Add.razor @@ -91,9 +91,9 @@ - + +
+ + @SharedLocalizer["Cancel"] +
+
+
@@ -88,13 +95,88 @@
+ + @SharedLocalizer["Cancel"]
+ + @if (_packages != null) + { + if (_packages.Count > 0) + { + + + +

@context.Name

  by:  @context.Owner
+ @(context.Description.Length > 400 ? (context.Description.Substring(0, 400) + "...") : context.Description)
+ @(String.Format("{0:n0}", context.Downloads)) @SharedLocalizer["Search.Downloads"]  |   + @SharedLocalizer["Search.Released"]: @context.ReleaseDate.ToString("MMM dd, yyyy")  |   + @SharedLocalizer["Search.Version"]: @context.Version + @((MarkupString)(!string.IsNullOrEmpty(context.PackageUrl) ? "  |  " + SharedLocalizer["Search.Source"] + ": " + new Uri(context.PackageUrl).Host + "" : "")) + @((MarkupString)(context.TrialPeriod > 0 ? "  |  " + context.TrialPeriod + " " + @SharedLocalizer["Trial"] + "" : "")) + + + @if (context.Price != null && !string.IsNullOrEmpty(context.PackageUrl)) + { + + } + + + @if (context.Price != null && !string.IsNullOrEmpty(context.PaymentUrl)) + { + @context.Price.Value.ToString("$#,##0.00") + } + else + { + + } + +
+
+ + } + else + { +
+
+ @Localizer["Search.NoResults"] +
+ } + } +
- -@SharedLocalizer["Cancel"] -
-
- + +@if (_productname != "") +{ +
+ +
+} @code { private ElementReference form; @@ -121,6 +203,12 @@ private PermissionGrid _permissionGrid; #pragma warning restore 649 + private List _packages; + private string _productname = ""; + private string _packageid = ""; + private string _packagelicense = ""; + private string _packageversion = ""; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnInitializedAsync() @@ -147,7 +235,9 @@ _createdon = moduleDefinition.CreatedOn; _modifiedby = moduleDefinition.ModifiedBy; _modifiedon = moduleDefinition.ModifiedOn; - } + + _packages = await PackageService.GetPackagesAsync("translation", "", "", moduleDefinition.PackageName); + } } catch (Exception ex) { @@ -193,4 +283,66 @@ AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } + + private void HideModal() + { + _productname = ""; + _packagelicense = ""; + StateHasChanged(); + } + + private async Task GetPackage(string packageid, string version) + { + try + { + var package = await PackageService.GetPackageAsync(packageid, version); + if (package != null) + { + _productname = package.Name; + _packageid = package.PackageId; + if (!string.IsNullOrEmpty(package.License)) + { + _packagelicense = package.License.Replace("\n", "
"); + } + _packageversion = package.Version; + } + StateHasChanged(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Getting Package {PackageId} {Version}", packageid, version); + AddModuleMessage(Localizer["Error.Translation.Download"], MessageType.Error); + } + } + + private async Task DownloadTranslation() + { + try + { + await PackageService.DownloadPackageAsync(_packageid, _version, Constants.PackagesFolder); + await logger.LogInformation("Package {PackageId} {Version} Downloaded Successfully", _packageid, _version); + AddModuleMessage(Localizer["Success.Translation.Download"], MessageType.Success); + _productname = ""; + _packagelicense = ""; + StateHasChanged(); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Downloading Package {PackageId} {Version}", _packageid, _version); + AddModuleMessage(Localizer["Error.Translation.Download"], MessageType.Error); + } + } + + private async Task InstallTranslations() + { + try + { + await PackageService.InstallPackagesAsync(); + AddModuleMessage(string.Format(Localizer["Success.Translation.Install"], NavigateUrl("admin/system")), MessageType.Success); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Installing Translations"); + } + } } diff --git a/Oqtane.Client/Resources/Modules/Admin/ModuleDefinitions/Edit.resx b/Oqtane.Client/Resources/Modules/Admin/ModuleDefinitions/Edit.resx index 8150f4eb6..b7ef70df0 100644 --- a/Oqtane.Client/Resources/Modules/Admin/ModuleDefinitions/Edit.resx +++ b/Oqtane.Client/Resources/Modules/Admin/ModuleDefinitions/Edit.resx @@ -201,4 +201,19 @@ Package Name: + + Error Downloading Translation + + + No Translations Exist For This Module Or Package Service Is Disabled + + + Translation Downloaded Successfully. Click Install To Complete Installation. + + + Translation Installed Successfully. You Must <a href={0}>Restart</a> Your Application To Apply These Changes. + + + Translations + \ No newline at end of file diff --git a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs index a402d890b..72e013b12 100644 --- a/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs +++ b/Oqtane.Server/Extensions/OqtaneServiceCollectionExtensions.cs @@ -268,7 +268,7 @@ private static IServiceCollection AddOqtaneServices(this IServiceCollection serv if (implementationType.AssemblyQualifiedName != null) { var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}")); - services.AddScoped(serviceType ?? implementationType, implementationType); + services.AddTransient(serviceType ?? implementationType, implementationType); } }