Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCST-509: optional modules #207

Merged
merged 6 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions module.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VirtoCommerce.ExportModule.Core.dll
VirtoCommerce.ExportModule.Data.dll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.CatalogModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.CoreModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.823.0-alpha.12900-vcst-509-optional-modules" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.ExportModule.Data" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Data" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Security" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Data" Version="3.823.0-alpha.12900-vcst-509-optional-modules" />
<PackageReference Include="VirtoCommerce.Platform.Security" Version="3.823.0-alpha.12900-vcst-509-optional-modules" />
<PackageReference Include="VirtoCommerce.SearchModule.Data" Version="3.800.0" />
</ItemGroup>
<ItemGroup>
Expand Down
58 changes: 32 additions & 26 deletions src/VirtoCommerce.PricingModule.Web/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
using VirtoCommerce.ExportModule.Core.Services;
using VirtoCommerce.ExportModule.Data.Extensions;
using VirtoCommerce.ExportModule.Data.Services;
using VirtoCommerce.Platform.Core.Bus;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Events;
using VirtoCommerce.Platform.Core.ExportImport;
using VirtoCommerce.Platform.Core.Extensions;
using VirtoCommerce.Platform.Core.Modularity;
using VirtoCommerce.Platform.Core.Security;
using VirtoCommerce.Platform.Core.Settings;
Expand All @@ -40,12 +41,15 @@

namespace VirtoCommerce.PricingModule.Web
{
public class Module : IModule, IExportSupport, IImportSupport, IHasConfiguration
public class Module : IModule, IExportSupport, IImportSupport, IHasConfiguration, IHasModuleCatalog
{
private IApplicationBuilder _applicationBuilder;

public ManifestModuleInfo ModuleInfo { get; set; }
public IConfiguration Configuration { get; set; }
public IModuleCatalog ModuleCatalog { get; set; }

private const string GenericExportModuleId = "VirtoCommerce.Export";

public void Initialize(IServiceCollection serviceCollection)
{
Expand Down Expand Up @@ -131,41 +135,43 @@ public void PostInitialize(IApplicationBuilder appBuilder)
}

//Subscribe for Search configuration changes
var handlerRegistrar = appBuilder.ApplicationServices.GetService<IHandlerRegistrar>();
handlerRegistrar.RegisterHandler<ObjectSettingChangedEvent>(async (message, _) => await appBuilder.ApplicationServices.GetService<ObjectSettingEntryChangedEventHandler>().Handle(message));
appBuilder.RegisterEventHandler<ObjectSettingChangedEvent, ObjectSettingEntryChangedEventHandler>();

//Configure Search
var moduleConfigurator = appBuilder.ApplicationServices.GetService<ModuleConfigurator>();
moduleConfigurator.ConfigureSearchAsync().GetAwaiter().GetResult();

handlerRegistrar.RegisterHandler<PriceChangedEvent>(async (message, _) => await appBuilder.ApplicationServices.GetService<LogChangesChangedEventHandler>().Handle(message));
handlerRegistrar.RegisterHandler<ProductChangedEvent>(async (message, _) => await appBuilder.ApplicationServices.GetService<DeletePricesProductChangedEventHandler>().Handle(message));
handlerRegistrar.RegisterHandler<PriceChangedEvent>(async (message, _) => await appBuilder.ApplicationServices.GetService<IndexPricesProductChangedEventHandler>().Handle(message));
appBuilder.RegisterEventHandler<PriceChangedEvent, LogChangesChangedEventHandler>();
appBuilder.RegisterEventHandler<ProductChangedEvent, DeletePricesProductChangedEventHandler>();
appBuilder.RegisterEventHandler<PriceChangedEvent, IndexPricesProductChangedEventHandler>();

foreach (var conditionTree in AbstractTypeFactory<PriceConditionTreePrototype>.TryCreateInstance().Traverse<IConditionTree>(x => x.AvailableChildren))
{
AbstractTypeFactory<IConditionTree>.RegisterType(conditionTree.GetType());
}

var exportTypesRegistrar = appBuilder.ApplicationServices.GetService<IKnownExportTypesRegistrar>();

exportTypesRegistrar.RegisterType(
ExportedTypeDefinitionBuilder.Build<ExportablePrice, PriceExportDataQuery>()
.WithDataSourceFactory(appBuilder.ApplicationServices.GetService<IPricingExportPagedDataSourceFactory>())
.WithMetadata(typeof(ExportablePrice).GetPropertyNames())
.WithTabularMetadata(typeof(TabularPrice).GetPropertyNames()));

exportTypesRegistrar.RegisterType(
ExportedTypeDefinitionBuilder.Build<ExportablePricelist, PricelistExportDataQuery>()
.WithDataSourceFactory(appBuilder.ApplicationServices.GetService<IPricingExportPagedDataSourceFactory>())
.WithMetadata(typeof(ExportablePricelist).GetPropertyNames())
.WithTabularMetadata(typeof(TabularPricelist).GetPropertyNames()));

exportTypesRegistrar.RegisterType(
ExportedTypeDefinitionBuilder.Build<ExportablePricelistAssignment, PricelistAssignmentExportDataQuery>()
.WithDataSourceFactory(appBuilder.ApplicationServices.GetService<IPricingExportPagedDataSourceFactory>())
.WithMetadata(typeof(ExportablePricelistAssignment).GetPropertyNames())
.WithTabularMetadata(typeof(TabularPricelistAssignment).GetPropertyNames()));
if (ModuleCatalog.IsModuleInstalled(GenericExportModuleId))
{
var exportTypesRegistrar = appBuilder.ApplicationServices.GetService<IKnownExportTypesRegistrar>();

exportTypesRegistrar.RegisterType(
ExportedTypeDefinitionBuilder.Build<ExportablePrice, PriceExportDataQuery>()
.WithDataSourceFactory(appBuilder.ApplicationServices.GetService<IPricingExportPagedDataSourceFactory>())
.WithMetadata(typeof(ExportablePrice).GetPropertyNames())
.WithTabularMetadata(typeof(TabularPrice).GetPropertyNames()));

exportTypesRegistrar.RegisterType(
ExportedTypeDefinitionBuilder.Build<ExportablePricelist, PricelistExportDataQuery>()
.WithDataSourceFactory(appBuilder.ApplicationServices.GetService<IPricingExportPagedDataSourceFactory>())
.WithMetadata(typeof(ExportablePricelist).GetPropertyNames())
.WithTabularMetadata(typeof(TabularPricelist).GetPropertyNames()));

exportTypesRegistrar.RegisterType(
ExportedTypeDefinitionBuilder.Build<ExportablePricelistAssignment, PricelistAssignmentExportDataQuery>()
.WithDataSourceFactory(appBuilder.ApplicationServices.GetService<IPricingExportPagedDataSourceFactory>())
.WithMetadata(typeof(ExportablePricelistAssignment).GetPropertyNames())
.WithTabularMetadata(typeof(TabularPricelistAssignment).GetPropertyNames()));
}
}

public void Uninstall()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('virtoCommerce.pricingModule')
.controller('virtoCommerce.pricingModule.assignmentListController', ['$scope', 'virtoCommerce.pricingModule.pricelistAssignments', 'platformWebApp.dialogService', 'platformWebApp.uiGridHelper', 'platformWebApp.bladeUtils', 'virtoCommerce.catalogModule.catalogs', '$localStorage',
function ($scope, assignments, dialogService, uiGridHelper, bladeUtils, catalogs, $localStorage) {
.controller('virtoCommerce.pricingModule.assignmentListController', ['$scope', '$injector', 'virtoCommerce.pricingModule.pricelistAssignments', 'platformWebApp.dialogService', 'platformWebApp.uiGridHelper', 'platformWebApp.bladeUtils', 'virtoCommerce.catalogModule.catalogs', '$localStorage',
function ($scope, $injector, assignments, dialogService, uiGridHelper, bladeUtils, catalogs, $localStorage) {
$scope.uiGridConstants = uiGridHelper.uiGridConstants;
var blade = $scope.blade;
var bladeNavigationService = bladeUtils.bladeNavigationService;
Expand All @@ -12,6 +12,7 @@ angular.module('virtoCommerce.pricingModule')
};
var exportDataRequest = angular.copy(defaultDataRequest);
var filter = blade.filter = $scope.filter = {};
blade.exportFeaturesEnabled = $injector.modules['virtoCommerce.exportModule'];

blade.refresh = function () {

Expand Down Expand Up @@ -159,8 +160,11 @@ angular.module('virtoCommerce.pricingModule')
return blade.currentEntities && blade.currentEntities.length > 0;
},
permission: 'pricing:delete'
},
{
}
];

if (blade.exportFeaturesEnabled) {
blade.toolbarCommands.push({
name: "platform.commands.export",
icon: 'fa fa-upload',
canExecuteMethod: function () {
Expand Down Expand Up @@ -193,18 +197,18 @@ angular.module('virtoCommerce.pricingModule')
};
bladeNavigationService.showBlade(newBlade, blade);
}
}
];
});
}

filter.criteriaChanged = function () {

if ($scope.pageSettings.currentPage > 1) {
blade.refresh();
$scope.pageSettings.currentPage = 1;
} else {
blade.refresh();
}
};

// ui-grid
$scope.setGridOptions = function (gridOptions) {
$scope.gridOptions = gridOptions;
Expand Down Expand Up @@ -250,7 +254,7 @@ angular.module('virtoCommerce.pricingModule')

$scope.exportSearchFilterId = $localStorage.exportSearchFilterIds[exportDataRequest.exportTypeName];

if ($scope.exportSearchFilterId) {
if ($scope.exportSearchFilterId && blade.exportFeaturesEnabled) {
filter.current = _.findWhere($scope.exportSearchFilters, { id: $scope.exportSearchFilterId });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div class="blade-static">
<div class="form-group searchrow">
<div class="form-input column-half">
<div class="form-input" ng-class="{'column-half': blade.exportFeaturesEnabled, 'column': !blade.exportFeaturesEnabled}">
<input placeholder="{{ 'platform.placeholders.search-keyword' | translate }}" ng-model="filter.keyword" ng-keyup="$event.which === 13 && filter.criteriaChanged()">
<button class="btn" title="Clear" ng-click="filter.keyword=null;filter.criteriaChanged()"></button>
</div>
<ui-select ng-model="filter.current" ng-change="filter.change()" class="column-half">
<ui-select ng-model="filter.current" ng-change="filter.change()" class="column-half" ng-if="blade.exportFeaturesEnabled">
<ui-select-match allow-clear="true" placeholder="{{'export.blades.export-generic-viewer.placeholders.select-filter' | translate}}">{{$select.selected.name | translate}}</ui-select-match>
<ui-select-choices repeat="x in exportSearchFilters | filter: $select.search">
<span ng-bind-html="x.name | translate | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
<a href="" ng-click="filter.edit()" class="filter-edit"><i class="fa fa-pencil"></i></a>
<a href="" ng-click="filter.edit()" class="filter-edit" ng-if="blade.exportFeaturesEnabled"><i class="fa fa-pencil"></i></a>
</div>
</div>
<div class="blade-static __bottom" ng-if="pageSettings.itemsPerPageCount < pageSettings.totalItems" ng-include="'pagerTemplate.html'"></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('virtoCommerce.pricingModule')
.controller('virtoCommerce.pricingModule.pricelistItemListController', ['$scope', 'virtoCommerce.pricingModule.prices', '$filter', 'platformWebApp.bladeNavigationService', 'uiGridConstants', 'platformWebApp.uiGridHelper', 'platformWebApp.bladeUtils', 'platformWebApp.dialogService', '$translate', function ($scope, prices, $filter, bladeNavigationService, uiGridConstants, uiGridHelper, bladeUtils, dialogService, $translate) {
.controller('virtoCommerce.pricingModule.pricelistItemListController', ['$scope', '$injector', 'virtoCommerce.pricingModule.prices', '$filter', 'platformWebApp.bladeNavigationService', 'uiGridConstants', 'platformWebApp.uiGridHelper', 'platformWebApp.bladeUtils', 'platformWebApp.dialogService', '$translate', function ($scope, $injector, prices, $filter, bladeNavigationService, uiGridConstants, uiGridHelper, bladeUtils, dialogService, $translate) {
$scope.uiGridConstants = uiGridConstants;
$scope.noProductRowName = $translate.instant('pricing.blades.pricelist-item-list.labels.no-product-row-name');
var blade = $scope.blade;
Expand All @@ -9,6 +9,7 @@ angular.module('virtoCommerce.pricingModule')
exportTypeName: 'PriceExportDataQuery'
}
};
blade.exportFeaturesEnabled = $injector.modules['virtoCommerce.exportModule'];

blade.getSearchCriteria = function() {
var result = {
Expand Down Expand Up @@ -217,8 +218,11 @@ angular.module('virtoCommerce.pricingModule')
return $scope.gridApi && _.any($scope.gridApi.selection.getSelectedRows());
},
permission: blade.updatePermission
},
{
}
];

if (blade.exportFeaturesEnabled) {
blade.toolbarCommands.push({
name: "platform.commands.export",
icon: 'fa fa-upload',
canExecuteMethod: function () {
Expand All @@ -227,8 +231,8 @@ angular.module('virtoCommerce.pricingModule')
executeMethod: function () {
blade.exportPrices();
}
}
];
});
}

$scope.getPriceRange = function (priceGroup) {
var retVal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('virtoCommerce.pricingModule')
.controller('virtoCommerce.pricingModule.pricelistListController', ['$scope', 'virtoCommerce.pricingModule.pricelists', 'platformWebApp.dialogService', 'platformWebApp.uiGridHelper', 'platformWebApp.bladeUtils', '$localStorage',
function ($scope, pricelists, dialogService, uiGridHelper, bladeUtils, $localStorage) {
.controller('virtoCommerce.pricingModule.pricelistListController', ['$scope', '$injector', 'virtoCommerce.pricingModule.pricelists', 'platformWebApp.dialogService', 'platformWebApp.uiGridHelper', 'platformWebApp.bladeUtils', '$localStorage',
function ($scope, $injector, pricelists, dialogService, uiGridHelper, bladeUtils, $localStorage) {
var blade = $scope.blade;
var bladeNavigationService = bladeUtils.bladeNavigationService;

Expand All @@ -12,6 +12,7 @@ angular.module('virtoCommerce.pricingModule')
};
var exportDataRequest = angular.copy(defaultDataRequest);
var filter = blade.filter = $scope.filter = {};
blade.exportFeaturesEnabled = $injector.modules['virtoCommerce.exportModule'];

blade.refresh = function (parentRefresh) {
blade.isLoading = true;
Expand Down Expand Up @@ -110,8 +111,11 @@ angular.module('virtoCommerce.pricingModule')
},
canExecuteMethod: isItemsChecked,
permission: 'pricing:delete'
},
{
}
];

if ($injector.modules['virtoCommerce.exportModule']) {
blade.toolbarCommands.push({
name: "platform.commands.export",
icon: 'fa fa-upload',
canExecuteMethod: function () {
Expand Down Expand Up @@ -145,8 +149,8 @@ angular.module('virtoCommerce.pricingModule')
};
bladeNavigationService.showBlade(newBlade, blade);
}
}
];
});
}

filter.criteriaChanged = function () {
if ($scope.pageSettings.currentPage > 1) {
Expand All @@ -169,8 +173,6 @@ angular.module('virtoCommerce.pricingModule')
bladeUtils.initializePagination($scope);
};



if (!$localStorage.exportSearchFilters) {
$localStorage.exportSearchFilters = {};
}
Expand All @@ -187,7 +189,7 @@ angular.module('virtoCommerce.pricingModule')

$scope.exportSearchFilterId = $localStorage.exportSearchFilterIds[exportDataRequest.exportTypeName];

if ($scope.exportSearchFilterId) {
if ($scope.exportSearchFilterId && blade.exportFeaturesEnabled) {
filter.current = _.findWhere($scope.exportSearchFilters, { id: $scope.exportSearchFilterId });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div class="blade-static">
<div class="form-group searchrow">
<div class="form-input column-half">
<div class="form-input" ng-class="{'column-half': blade.exportFeaturesEnabled, 'column': !blade.exportFeaturesEnabled}">
<input placeholder="{{ 'platform.placeholders.search-keyword' | translate }}" ng-model="filter.keyword" ng-keyup="$event.which === 13 && filter.criteriaChanged()">
<button class="btn" title="Clear" ng-click="filter.keyword=null;filter.criteriaChanged()"></button>
</div>
<ui-select ng-model="filter.current" ng-change="filter.change()" class="column-half">
<ui-select ng-model="filter.current" ng-change="filter.change()" class="column-half" ng-if="blade.exportFeaturesEnabled">
<ui-select-match allow-clear="true" placeholder="{{'export.blades.export-generic-viewer.placeholders.select-filter' | translate}}">{{$select.selected.name | translate}}</ui-select-match>
<ui-select-choices repeat="x in exportSearchFilters | filter: $select.search">
<span ng-bind-html="x.name | translate | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
<a href="" ng-click="filter.edit()" class="filter-edit"><i class="fa fa-pencil"></i></a>
<a href="" ng-click="filter.edit()" class="filter-edit" ng-if="blade.exportFeaturesEnabled"><i class="fa fa-pencil"></i></a>
</div>
</div>
<div class="blade-static __bottom" ng-if="pageSettings.itemsPerPageCount < pageSettings.totalItems" ng-include="'pagerTemplate.html'"></div>
Expand Down
Loading
Loading