Skip to content

Commit 4d8a798

Browse files
LjutyjOlegoOekuvirto
authored
VCST-1917: Make module management blades similar to the Visual Studio 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 <zhukoo@gmail.com> Co-authored-by: Kutasina Elena <62027488+ekuvirto@users.noreply.github.com>
1 parent f9a5459 commit 4d8a798

13 files changed

+376
-307
lines changed

src/VirtoCommerce.Platform.Web/Controllers/Api/ModulesController.cs

+58-22
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,30 @@ namespace VirtoCommerce.Platform.Web.Controllers.Api
2929
[Authorize]
3030
public class ModulesController : Controller
3131
{
32+
private const string _managementIsDisabledMessage = "Module management is disabled.";
33+
3234
private readonly IExternalModuleCatalog _externalModuleCatalog;
3335
private readonly IModuleInstaller _moduleInstaller;
3436
private readonly IPushNotificationManager _pushNotifier;
3537
private readonly IUserNameResolver _userNameResolver;
3638
private readonly ISettingsManager _settingsManager;
3739
private readonly PlatformOptions _platformOptions;
3840
private readonly ExternalModuleCatalogOptions _externalModuleCatalogOptions;
41+
private readonly LocalStorageModuleCatalogOptions _localStorageModuleCatalogOptions;
3942
private readonly IPlatformRestarter _platformRestarter;
4043
private static readonly object _lockObject = new object();
4144
private static readonly FormOptions _defaultFormOptions = new FormOptions();
4245

43-
public ModulesController(IExternalModuleCatalog externalModuleCatalog, IModuleInstaller moduleInstaller, IPushNotificationManager pushNotifier, IUserNameResolver userNameResolver, ISettingsManager settingsManager, IOptions<PlatformOptions> platformOptions, IOptions<ExternalModuleCatalogOptions> externalModuleCatalogOptions, IPlatformRestarter platformRestarter)
46+
public ModulesController(
47+
IExternalModuleCatalog externalModuleCatalog,
48+
IModuleInstaller moduleInstaller,
49+
IPushNotificationManager pushNotifier,
50+
IUserNameResolver userNameResolver,
51+
ISettingsManager settingsManager,
52+
IOptions<PlatformOptions> platformOptions,
53+
IOptions<ExternalModuleCatalogOptions> externalModuleCatalogOptions,
54+
IOptions<LocalStorageModuleCatalogOptions> localStorageModuleCatalogOptions,
55+
IPlatformRestarter platformRestarter)
4456
{
4557
_externalModuleCatalog = externalModuleCatalog;
4658
_moduleInstaller = moduleInstaller;
@@ -49,6 +61,7 @@ public ModulesController(IExternalModuleCatalog externalModuleCatalog, IModuleIn
4961
_settingsManager = settingsManager;
5062
_platformOptions = platformOptions.Value;
5163
_externalModuleCatalogOptions = externalModuleCatalogOptions.Value;
64+
_localStorageModuleCatalogOptions = localStorageModuleCatalogOptions.Value;
5265
_platformRestarter = platformRestarter;
5366
}
5467

@@ -143,22 +156,29 @@ public ActionResult<ModuleDescriptor[]> GetMissingDependencies([FromBody] Module
143156
public async Task<ActionResult<ModuleDescriptor>> UploadModuleArchive()
144157
{
145158
EnsureModulesCatalogInitialized();
146-
ModuleDescriptor result = null;
159+
160+
if (!_localStorageModuleCatalogOptions.RefreshProbingFolderOnStart)
161+
{
162+
return BadRequest(_managementIsDisabledMessage);
163+
}
164+
147165
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
148166
{
149167
return BadRequest($"Expected a multipart request, but got {Request.ContentType}");
150168
}
169+
151170
var uploadPath = Path.GetFullPath(_platformOptions.LocalUploadFolderPath);
152171
if (!Directory.Exists(uploadPath))
153172
{
154173
Directory.CreateDirectory(uploadPath);
155174
}
156-
string targetFilePath = null;
157175

176+
ModuleDescriptor result = null;
177+
string targetFilePath = null;
158178
var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit);
159179
var reader = new MultipartReader(boundary, HttpContext.Request.Body);
160-
161180
var section = await reader.ReadNextSectionAsync();
181+
162182
if (section != null)
163183
{
164184
var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition);
@@ -205,6 +225,7 @@ public async Task<ActionResult<ModuleDescriptor>> UploadModuleArchive()
205225
}
206226
}
207227
}
228+
208229
return Ok(result);
209230
}
210231

@@ -394,27 +415,42 @@ public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNo
394415
try
395416
{
396417
notification.Started = DateTime.UtcNow;
397-
var moduleInfos = _externalModuleCatalog.Modules.OfType<ManifestModuleInfo>()
398-
.Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity)))
399-
.ToArray();
400-
var reportProgress = new Progress<ProgressMessage>(m =>
418+
419+
if (_localStorageModuleCatalogOptions.RefreshProbingFolderOnStart)
401420
{
402-
lock (_lockObject)
421+
var moduleInfos = _externalModuleCatalog.Modules.OfType<ManifestModuleInfo>()
422+
.Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity)))
423+
.ToArray();
424+
var reportProgress = new Progress<ProgressMessage>(m =>
403425
{
404-
notification.Description = m.Message;
405-
notification.ProgressLog.Add(m);
406-
_pushNotifier.Send(notification);
407-
}
408-
});
426+
lock (_lockObject)
427+
{
428+
notification.Description = m.Message;
429+
notification.ProgressLog.Add(m);
430+
_pushNotifier.Send(notification);
431+
}
432+
});
409433

410-
switch (options.Action)
434+
switch (options.Action)
435+
{
436+
case ModuleAction.Install:
437+
_moduleInstaller.Install(moduleInfos, reportProgress);
438+
break;
439+
case ModuleAction.Uninstall:
440+
_moduleInstaller.Uninstall(moduleInfos, reportProgress);
441+
break;
442+
}
443+
}
444+
else
411445
{
412-
case ModuleAction.Install:
413-
_moduleInstaller.Install(moduleInfos, reportProgress);
414-
break;
415-
case ModuleAction.Uninstall:
416-
_moduleInstaller.Uninstall(moduleInfos, reportProgress);
417-
break;
446+
notification.Finished = DateTime.UtcNow;
447+
notification.Description = _managementIsDisabledMessage;
448+
notification.ProgressLog.Add(new ProgressMessage
449+
{
450+
Level = ProgressMessageLevel.Error,
451+
Message = notification.Description,
452+
});
453+
_pushNotifier.Send(notification);
418454
}
419455
}
420456
catch (Exception ex)
@@ -430,7 +466,7 @@ public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNo
430466
_settingsManager.SetValue(PlatformConstants.Settings.Setup.ModulesAutoInstallState.Name, AutoInstallState.Completed);
431467

432468
notification.Finished = DateTime.UtcNow;
433-
notification.Description = "Installation finished.";
469+
notification.Description = options.Action == ModuleAction.Install ? "Installation finished." : "Uninstalling finished.";
434470
notification.ProgressLog.Add(new ProgressMessage
435471
{
436472
Level = ProgressMessageLevel.Info,

0 commit comments

Comments
 (0)