Skip to content

Commit

Permalink
VCST-1917: Make module management blades similar to the Visual Studio…
Browse files Browse the repository at this point in the history
… NuGet package manager (#2844)

fix: the display of the module icon on the details page, size of search field, displaying number of module version, translation
feat: Rename the module menu item Available to Browse and show all modules in this list. Context menu items for all allowed actions. Toolbar commands for all allowed actions. Uniform behavior and display of modules in all sections.

Co-authored-by: Oleg Zhuk <[email protected]>
Co-authored-by: Kutasina Elena <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent f9a5459 commit 4d8a798
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 307 deletions.
80 changes: 58 additions & 22 deletions src/VirtoCommerce.Platform.Web/Controllers/Api/ModulesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,30 @@ namespace VirtoCommerce.Platform.Web.Controllers.Api
[Authorize]
public class ModulesController : Controller
{
private const string _managementIsDisabledMessage = "Module management is disabled.";

private readonly IExternalModuleCatalog _externalModuleCatalog;
private readonly IModuleInstaller _moduleInstaller;
private readonly IPushNotificationManager _pushNotifier;
private readonly IUserNameResolver _userNameResolver;
private readonly ISettingsManager _settingsManager;
private readonly PlatformOptions _platformOptions;
private readonly ExternalModuleCatalogOptions _externalModuleCatalogOptions;
private readonly LocalStorageModuleCatalogOptions _localStorageModuleCatalogOptions;
private readonly IPlatformRestarter _platformRestarter;
private static readonly object _lockObject = new object();
private static readonly FormOptions _defaultFormOptions = new FormOptions();

public ModulesController(IExternalModuleCatalog externalModuleCatalog, IModuleInstaller moduleInstaller, IPushNotificationManager pushNotifier, IUserNameResolver userNameResolver, ISettingsManager settingsManager, IOptions<PlatformOptions> platformOptions, IOptions<ExternalModuleCatalogOptions> externalModuleCatalogOptions, IPlatformRestarter platformRestarter)
public ModulesController(
IExternalModuleCatalog externalModuleCatalog,
IModuleInstaller moduleInstaller,
IPushNotificationManager pushNotifier,
IUserNameResolver userNameResolver,
ISettingsManager settingsManager,
IOptions<PlatformOptions> platformOptions,
IOptions<ExternalModuleCatalogOptions> externalModuleCatalogOptions,
IOptions<LocalStorageModuleCatalogOptions> localStorageModuleCatalogOptions,
IPlatformRestarter platformRestarter)
{
_externalModuleCatalog = externalModuleCatalog;
_moduleInstaller = moduleInstaller;
Expand All @@ -49,6 +61,7 @@ public ModulesController(IExternalModuleCatalog externalModuleCatalog, IModuleIn
_settingsManager = settingsManager;
_platformOptions = platformOptions.Value;
_externalModuleCatalogOptions = externalModuleCatalogOptions.Value;
_localStorageModuleCatalogOptions = localStorageModuleCatalogOptions.Value;
_platformRestarter = platformRestarter;
}

Expand Down Expand Up @@ -143,22 +156,29 @@ public ActionResult<ModuleDescriptor[]> GetMissingDependencies([FromBody] Module
public async Task<ActionResult<ModuleDescriptor>> UploadModuleArchive()
{
EnsureModulesCatalogInitialized();
ModuleDescriptor result = null;

if (!_localStorageModuleCatalogOptions.RefreshProbingFolderOnStart)
{
return BadRequest(_managementIsDisabledMessage);
}

if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
{
return BadRequest($"Expected a multipart request, but got {Request.ContentType}");
}

var uploadPath = Path.GetFullPath(_platformOptions.LocalUploadFolderPath);
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string targetFilePath = null;

ModuleDescriptor result = null;
string targetFilePath = null;
var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit);
var reader = new MultipartReader(boundary, HttpContext.Request.Body);

var section = await reader.ReadNextSectionAsync();

if (section != null)
{
var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition);
Expand Down Expand Up @@ -205,6 +225,7 @@ public async Task<ActionResult<ModuleDescriptor>> UploadModuleArchive()
}
}
}

return Ok(result);
}

Expand Down Expand Up @@ -394,27 +415,42 @@ public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNo
try
{
notification.Started = DateTime.UtcNow;
var moduleInfos = _externalModuleCatalog.Modules.OfType<ManifestModuleInfo>()
.Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity)))
.ToArray();
var reportProgress = new Progress<ProgressMessage>(m =>

if (_localStorageModuleCatalogOptions.RefreshProbingFolderOnStart)
{
lock (_lockObject)
var moduleInfos = _externalModuleCatalog.Modules.OfType<ManifestModuleInfo>()
.Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity)))
.ToArray();
var reportProgress = new Progress<ProgressMessage>(m =>
{
notification.Description = m.Message;
notification.ProgressLog.Add(m);
_pushNotifier.Send(notification);
}
});
lock (_lockObject)
{
notification.Description = m.Message;
notification.ProgressLog.Add(m);
_pushNotifier.Send(notification);
}
});

switch (options.Action)
switch (options.Action)
{
case ModuleAction.Install:
_moduleInstaller.Install(moduleInfos, reportProgress);
break;
case ModuleAction.Uninstall:
_moduleInstaller.Uninstall(moduleInfos, reportProgress);
break;
}
}
else
{
case ModuleAction.Install:
_moduleInstaller.Install(moduleInfos, reportProgress);
break;
case ModuleAction.Uninstall:
_moduleInstaller.Uninstall(moduleInfos, reportProgress);
break;
notification.Finished = DateTime.UtcNow;
notification.Description = _managementIsDisabledMessage;
notification.ProgressLog.Add(new ProgressMessage
{
Level = ProgressMessageLevel.Error,
Message = notification.Description,
});
_pushNotifier.Send(notification);
}
}
catch (Exception ex)
Expand All @@ -430,7 +466,7 @@ public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNo
_settingsManager.SetValue(PlatformConstants.Settings.Setup.ModulesAutoInstallState.Name, AutoInstallState.Completed);

notification.Finished = DateTime.UtcNow;
notification.Description = "Installation finished.";
notification.Description = options.Action == ModuleAction.Install ? "Installation finished." : "Uninstalling finished.";
notification.ProgressLog.Add(new ProgressMessage
{
Level = ProgressMessageLevel.Info,
Expand Down
Loading

0 comments on commit 4d8a798

Please sign in to comment.