Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Dec 31, 2023
1 parent d257ddc commit 2fd7745
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 176 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
@model GeneralCommonSettingsModel
@inject Grand.Business.Core.Interfaces.Common.Security.IPermissionService permissionService
@using Grand.Business.Core.Utilities.Common.Security;
@{
var canUpload = await permissionService.Authorize(StandardPermission.ManagePlugins);
//page title
ViewBag.Title = Loc["Admin.Settings.GeneralCommon"];
}
<form asp-area="@Constants.AreaAdmin" asp-controller="Setting" asp-action="GeneralCommon" method="post">

<div asp-validation-summary="All"></div>
<div class="row">
<div class="col-md-12">
Expand Down Expand Up @@ -78,59 +74,4 @@
</div>
</div>
</div>

</form>
@if (canUpload)
{
<div class="modal-dialog" id="importfile-window" style="display:none; padding: 0 10px;">
<form asp-area="@Constants.AreaAdmin" asp-controller="Plugin" asp-action="UploadTheme" method="post" enctype="multipart/form-data">

<ul class="common-list">
<li>
<strong>NOTE: It can take up to several minutes.</strong>
</li>
<li>
<strong>NOTE: DO NOT click twice.</strong>
</li>
</ul>
<div class="form-group">
<div class="col-md-2" style="margin-top: 7px; height: 34px; padding-left: 25px;">
<label class="control-label">
Zip file
</label>
</div>
<div class="col-md-10">
<input id="importfiledialog" name="zippedFile" class="form-control" type="file">
</div>
</div>
<div class="form-group">
&nbsp;
</div>
<div class="form-group">
<div class="col-md-2">
&nbsp;
</div>
<div class="col-md-10 text-right mt-10">
<input id="importfilesubmit" class="btn btn-success" value="@Loc["Admin.Configuration.Themes.Upload"]" type="submit">
</div>
</div>
</form>
</div>

<script>
$(document).ready(function () {
$("#importfile").click(function (e) {
e.preventDefault();
var window = $("#importfile-window");
if (!window.data("kendoWindow")) {
window.kendoWindow({
modal: true,
title: "@Loc["Admin.Configuration.Themes.Upload"]",
actions: ["Close"]
});
}
window.data('kendoWindow').center().open();
});
});
</script>
}
</form>
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
@model GeneralCommonSettingsModel
@inject Grand.Business.Core.Interfaces.Common.Security.IPermissionService permissionService
@using Grand.Business.Core.Utilities.Common.Security;
@{
var canUpload = await permissionService.Authorize(StandardPermission.ManagePlugins);
}

<script>
$(document).ready(function () {
Expand Down Expand Up @@ -71,11 +66,6 @@
</ul>
</div>
<span asp-validation-for="StoreInformationSettings.DefaultStoreTheme"></span>
@if (canUpload)
{
<div class="note note-info">@Loc["Admin.Settings.GeneralCommon.DefaultStoreTheme.GetMore"] <a href="http://www.grandnode.com/extensions?category=4&utm_source=admin-panel&utm_medium=theme-settings&utm_campaign=admin-panel" target="_blank">http://www.grandnode.com/extensions</a></div>
<input type="button" id="importfile" class="btn yellow" value="@Loc["Admin.Configuration.Themes.Upload"]" />
}
</div>
</div>
<div class="form-group">
Expand Down
52 changes: 0 additions & 52 deletions src/Web/Grand.Web.Admin/Controllers/PluginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,58 +340,6 @@ public IActionResult UploadPlugin(IFormFile zippedFile)
return RedirectToAction("List");
}

[HttpPost]
public IActionResult UploadTheme(IFormFile zippedFile)
{
if (_extConfig.DisableUploadExtensions)
{
Error("Upload plugins/themes is disable");
return RedirectToAction("GeneralCommon", "Setting");
}

if (zippedFile == null || zippedFile.Length == 0)
{
Error(_translationService.GetResource("Admin.Common.UploadFile"));
return RedirectToAction("GeneralCommon", "Setting");
}

var zipFilePath = "";

try
{
if (!Path.GetExtension(zippedFile.FileName)
?.Equals(".zip", StringComparison.InvariantCultureIgnoreCase) ?? true)
throw new Exception("Only zip archives are supported");

//ensure that temp directory is created
var tempDirectory = CommonPath.TmpUploadPath;
Directory.CreateDirectory(new DirectoryInfo(tempDirectory).FullName);

//copy original archive to the temp directory
zipFilePath = Path.Combine(tempDirectory, zippedFile.FileName);
using (var fileStream = new FileStream(zipFilePath, FileMode.Create))
zippedFile.CopyTo(fileStream);

Upload(zipFilePath);

var message = _translationService.GetResource("Admin.Configuration.Themes.Uploaded");
Success(message);
}
catch (Exception ex)
{
var message = _translationService.GetResource("Admin.Configuration.Themes.Failed");
Error(message + "\r\n" + ex.Message);
}
finally
{
//delete temporary file
if (!string.IsNullOrEmpty(zipFilePath))
System.IO.File.Delete(zipFilePath);
}

return RedirectToAction("GeneralCommon", "Setting");
}

private void Upload(string archivePath)
{
var pluginsDirectory = CommonPath.PluginsPath;
Expand Down
19 changes: 13 additions & 6 deletions src/Web/Grand.Web.Admin/Controllers/SettingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ public async Task<IActionResult> Customer(CustomerSettingsModel model)
return RedirectToAction("Customer");
}

public async Task<IActionResult> GeneralCommon()
public async Task<IActionResult> GeneralCommon([FromServices] IEnumerable<IThemeView> themes)
{
var model = new GeneralCommonSettingsModel();
var storeScope = await GetActiveStore();
Expand All @@ -614,11 +614,18 @@ public async Task<IActionResult> GeneralCommon()
var storeInformationSettings = _settingService.LoadSetting<StoreInformationSettings>(storeScope);
model.StoreInformationSettings = storeInformationSettings.ToModel();

//TODO
/*model.StoreInformationSettings.AvailableStoreThemes = _themeProvider
.GetConfigurations()
.Select(x => x.ToModel(storeInformationSettings.DefaultStoreTheme)).ToList();*/

model.StoreInformationSettings.AvailableStoreThemes =
themes.Where(x => x.AreaName == "").Select(x =>
new GeneralCommonSettingsModel.StoreInformationSettingsModel.ThemeConfigurationModel {
ThemeName = x.ThemeName,
ThemeTitle = x.ThemeInfo.Title,
PreviewImageUrl = x.ThemeInfo.PreviewImageUrl,
PreviewText = x.ThemeInfo.PreviewText,
SupportRtl = x.ThemeInfo.SupportRtl,
ThemeVersion = x.ThemeInfo.Version,
Selected = x.ThemeName == storeInformationSettings.DefaultStoreTheme
}).ToList();

//common
var commonSettings = _settingService.LoadSetting<CommonSettings>(storeScope);
model.CommonSettings = commonSettings.ToModel();
Expand Down

This file was deleted.

20 changes: 0 additions & 20 deletions src/Web/Grand.Web.Admin/Mapper/ThemeConfigurationProfile.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Web/Grand.Web.Common/Startup/StartupApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ private void RegisterContextService(IServiceCollection serviceCollection)

//Default theme context
serviceCollection.AddScoped<IThemeContext, ThemeContext>();


//Default theme view
serviceCollection.AddScoped<IThemeView, DefaultThemeView>();
}


Expand Down
17 changes: 17 additions & 0 deletions src/Web/Grand.Web.Common/Themes/DefaultThemeView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Grand.Web.Common.Themes;

public class DefaultThemeView : IThemeView
{
public string AreaName => "";
public string ThemeName => "Default";

public ThemeInfo ThemeInfo => new ("Default theme", "~/assets/samples/default-theme.jpg", "Default GrandNode theme", true, "1.0");

public IEnumerable<string> GetViewLocations()
{
return new List<string> {
"/Views/{1}/{0}.cshtml",
"/Views/Shared/{0}.cshtml"
};
}
}
5 changes: 4 additions & 1 deletion src/Web/Grand.Web.Common/Themes/IThemeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ public interface IThemeView
{
string AreaName { get; }
string ThemeName { get; }
public ThemeInfo ThemeInfo { get; }
IEnumerable<string> GetViewLocations();
}
}

public record ThemeInfo(string Title, string PreviewImageUrl, string PreviewText, bool SupportRtl, string Version);
6 changes: 0 additions & 6 deletions src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5010,12 +5010,6 @@
<Resource Name="Admin.Configuration.Themes.Failed" Area="Admin">
<Value>Failed to upload theme. Make sure you are not uploading already existing one. If so, try deleting it manually before resubmitting.</Value>
</Resource>
<Resource Name="Admin.Configuration.Themes.Upload" Area="Admin">
<Value>Upload theme</Value>
</Resource>
<Resource Name="Admin.Configuration.Themes.Uploaded" Area="Admin">
<Value>Theme uploaded</Value>
</Resource>
<Resource Name="Admin.Configuration.Updated" Area="Admin">
<Value>The settings have been updated successfully.</Value>
</Resource>
Expand Down
3 changes: 0 additions & 3 deletions src/Web/Grand.Web/Grand.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,5 @@
<Content Update="Plugins\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Infrastructure\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@inject StoreInformationSettings storeInformationSettings
@inject IThemeProvider themeProvider
@inject IThemeContext themeContext
@{
if (storeInformationSettings.AllowCustomerToSelectTheme)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2fd7745

Please sign in to comment.