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-1634: add white labeling for store #4

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = true
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_namespace_declarations = file_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_lambdas = true:silent
Expand Down
1 change: 1 addition & 0 deletions VirtoCommerce.WhiteLabeling.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=15b5b1f1_002D457c_002D4ca6_002Db278_002D5615aedc07d3/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=virto/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
3 changes: 3 additions & 0 deletions module.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ System.Reactive.dll
System.Reactive.Linq.dll
System.Reactive.xml
TimeZoneConverter.dll
VirtoCommerce.Platform.Data.MySql.dll
VirtoCommerce.Platform.Data.PostgreSql.dll
VirtoCommerce.Platform.Data.SqlServer.dll
VirtoCommerce.Tools.dll
VirtoCommerce.Xapi.Core.dll
VirtoCommerce.XCMS.Core.dll
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class WhiteLabelingSettingSearchCriteria : SearchCriteriaBase
{
public bool? IsEnabled { get; set; }
public string OrganizationId { get; set; }
public string StoreId { get; set; }
}
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ protected override IQueryable<WhiteLabelingSettingEntity> BuildQuery(IRepository
query = query.Where(x => x.OrganizationId == criteria.OrganizationId);
}

if (!string.IsNullOrEmpty(criteria.StoreId))
{
query = query.Where(x => x.StoreId == criteria.StoreId);
}

return query;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using GraphQL;
using GraphQL.Types;
using VirtoCommerce.Xapi.Core.BaseQueries;
using VirtoCommerce.WhiteLabeling.ExperienceApi.Models;
using VirtoCommerce.Xapi.Core.BaseQueries;

namespace VirtoCommerce.WhiteLabeling.ExperienceApi.Queries
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using VirtoCommerce.Xapi.Core.BaseQueries;
using VirtoCommerce.WhiteLabeling.ExperienceApi.Models;
using VirtoCommerce.WhiteLabeling.ExperienceApi.Schemas;
using VirtoCommerce.Xapi.Core.BaseQueries;

namespace VirtoCommerce.WhiteLabeling.ExperienceApi.Queries
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ public GetWhiteLabelingSettingsQueryHandler(IWhiteLabelingSettingSearchService w

public async Task<ExpWhiteLabelingSetting> Handle(GetWhiteLabelingSettingsQuery request, CancellationToken cancellationToken)
{
var searchCriteria = AbstractTypeFactory<WhiteLabelingSettingSearchCriteria>.TryCreateInstance();
searchCriteria.IsEnabled = true;
searchCriteria.OrganizationId = request.OrganizationId;
searchCriteria.Take = 1;

var searchResult = await _whiteLabelingSettingSearchService.SearchAsync(searchCriteria);
var whiteLabelingSetting = searchResult.Results?.FirstOrDefault();

var whiteLabelingSetting = await GetWhiteLabelingSettingAsync(request);
if (whiteLabelingSetting == null)
{
return null;
Expand All @@ -58,7 +51,7 @@ public async Task<ExpWhiteLabelingSetting> Handle(GetWhiteLabelingSettingsQuery
var newFavicon = new ExpFavicon()
{
Rel = "icon",
Type = $"image/{Path.GetExtension(whiteLabelingSetting.FaviconUrl)?[1..]}",
Type = $"image/{Path.GetExtension(whiteLabelingSetting.FaviconUrl)[1..]}",
Sizes = faviconSize,
Href = GenerateFaviconName(whiteLabelingSetting.FaviconUrl, faviconSize),
};
Expand Down Expand Up @@ -87,7 +80,38 @@ public async Task<ExpWhiteLabelingSetting> Handle(GetWhiteLabelingSettingsQuery
return result;
}

// copypasted from VirtoCommerce.ImageToolsModule.Data.ThumbnailGeneration.FileNameHelper, didn't want to add a dependency just for one method
protected virtual async Task<WhiteLabelingSetting> GetWhiteLabelingSettingAsync(GetWhiteLabelingSettingsQuery request)
{
WhiteLabelingSetting whiteLabelingSetting = null;

if (!string.IsNullOrEmpty(request.OrganizationId))
{
whiteLabelingSetting = await GetWhiteLabelingSettingAsync(organizationId: request.OrganizationId);
}

if (whiteLabelingSetting == null && !string.IsNullOrEmpty(request.StoreId))
{
whiteLabelingSetting = await GetWhiteLabelingSettingAsync(storeId: request.StoreId);
}

return whiteLabelingSetting;
}

private async Task<WhiteLabelingSetting> GetWhiteLabelingSettingAsync(string organizationId = null, string storeId = null)
{
var searchCriteria = AbstractTypeFactory<WhiteLabelingSettingSearchCriteria>.TryCreateInstance();

searchCriteria.OrganizationId = organizationId;
searchCriteria.StoreId = storeId;
searchCriteria.IsEnabled = true;
searchCriteria.Take = 1;

var searchResult = await _whiteLabelingSettingSearchService.SearchAsync(searchCriteria);

return searchResult.Results?.FirstOrDefault();
}

// copy-pasted from VirtoCommerce.ImageToolsModule.Data.ThumbnailGeneration.FileNameHelper, didn't want to add a dependency just for one method
private static string GenerateFaviconName(string fileName, string aliasName)
{
var name = Path.GetFileNameWithoutExtension(fileName);
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public WhiteLabelingSettingsType()
{
Field(x => x.LabelingSetting.UserId, nullable: true).Description("User ID");
Field(x => x.LabelingSetting.OrganizationId, nullable: true).Description("Organization ID");
Field(x => x.LabelingSetting.StoreId, nullable: true).Description("Store ID");
Field(x => x.LabelingSetting.LogoUrl, nullable: true).Description("Logo URL");
Field(x => x.LabelingSetting.SecondaryLogoUrl, nullable: true).Description("Logo URL for footer");
Field(x => x.LabelingSetting.FaviconUrl, nullable: true).Description("Master favicon URL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public async Task<ActionResult<WhiteLabelingSetting>> GetByOrganizationId([FromR
return Ok(result);
}

[HttpGet("store/{storeId}")]
[Authorize(ModuleConstants.Security.Permissions.Read)]
public async Task<ActionResult<WhiteLabelingSetting>> GetByStoreId([FromRoute] string storeId)
{
var searchCriteria = AbstractTypeFactory<WhiteLabelingSettingSearchCriteria>.TryCreateInstance();

searchCriteria.StoreId = storeId;
searchCriteria.Take = 1;

var searchResult = await _whiteLabelingSettingSearchService.SearchAsync(searchCriteria);
var result = searchResult.Results?.FirstOrDefault();

return Ok(result);
}

[HttpPost]
[Authorize(ModuleConstants.Security.Permissions.Create)]
public async Task<ActionResult<WhiteLabelingSetting>> Create([FromBody] WhiteLabelingSetting model)
Expand Down
4 changes: 2 additions & 2 deletions src/VirtoCommerce.WhiteLabeling.Web/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using VirtoCommerce.Xapi.Core.Extensions;
using VirtoCommerce.Xapi.Core.Infrastructure;
using VirtoCommerce.Platform.Core.Modularity;
using VirtoCommerce.Platform.Core.Security;
using VirtoCommerce.Platform.Core.Settings;
Expand All @@ -19,6 +17,8 @@
using VirtoCommerce.WhiteLabeling.Data.Services;
using VirtoCommerce.WhiteLabeling.Data.SqlServer;
using VirtoCommerce.WhiteLabeling.ExperienceApi;
using VirtoCommerce.Xapi.Core.Extensions;
using VirtoCommerce.Xapi.Core.Infrastructure;

namespace VirtoCommerce.WhiteLabeling.Web;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
<div class="note">
To enable personalized footer content for your organization through white labeling in Virto Commerce, follow these steps:
<div style="margin-top:20px;margin-bottom:20px">
<p>1. Navigate to the <a href style="font-size:14px" ng-click="blade.openContent()">Content</a> section.</p>
<p>2. Choose the specific Store you want to customize the footer for.</p>
<p>3. Select <b>'Linked lists'</b> from the widgets.</p>
<p>4. Create a new linked list by clicking <b>'Add'</b></p>
<p>5. Name this new list <b>'footer-{{ blade.organization.name }}'</b> to identify it easily.</p>
<p>1. Navigate to the <a href style="font-size:14px" ng-click="blade.openContent()">Content</a> section.</p>
<p>2. Choose the specific Store you want to customize the footer for.</p>
<p>3. Select <b>'Linked lists'</b> from the widgets.</p>
<p>4. Create a new linked list by clicking <b>'Add'</b></p>
<p>5. Name this new list <b>'footer-{{ blade.organization.name }}'</b> to identify it easily.</p>
</div>
After completing these steps, your organization will start displaying the personalized footer content as intended.
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('WhiteLabeling')
.controller('WhiteLabeling.organizationLabelingController', ['$scope', 'WhiteLabeling.webApi', 'platformWebApp.bladeNavigationService',
.controller('WhiteLabeling.whiteLabelingDetailsController', ['$scope', 'WhiteLabeling.webApi', 'platformWebApp.bladeNavigationService',
function ($scope, api, bladeNavigationService) {
const blade = $scope.blade;
blade.title = 'white-labeling.blades.white-labeling-detail.title';
Expand All @@ -8,7 +8,16 @@ angular.module('WhiteLabeling')
blade.refresh = function () {
blade.isLoading = true;

api.getByOrganization({ organizationId: blade.organization.id }, function (data) {
if (blade.organization) {
getByOrganization(blade.organization.id);
}
else if (blade.store) {
getByStore(blade.store.id);
}
};

function getByOrganization(id) {
api.getByOrganization({ organizationId: id }, function (data) {

if (data && data.id) {
blade.currentEntity = angular.copy(data);
Expand All @@ -18,14 +27,34 @@ angular.module('WhiteLabeling')
blade.isNew = true;
blade.originalEntity = {
isEnabled: false,
organizationId: blade.organization.id
organizationId: id
};
blade.currentEntity = angular.copy(blade.originalEntity);
}

blade.isLoading = false;
});
};
}

function getByStore(id) {
api.getByStore({ storeId: id }, function (data) {

if (data && data.id) {
blade.currentEntity = angular.copy(data);
blade.originalEntity = data;
}
else {
blade.isNew = true;
blade.originalEntity = {
isEnabled: false,
storeId: id
};
blade.currentEntity = angular.copy(blade.originalEntity);
}

blade.isLoading = false;
});
}

blade.saveChanges = function () {
blade.isLoading = true;
Expand All @@ -45,7 +74,7 @@ angular.module('WhiteLabeling')

$scope.setForm = function (form) {
$scope.formScope = form;
}
};

function canSave() {
return isDirty() && $scope.formScope && $scope.formScope.$valid;
Expand All @@ -65,7 +94,7 @@ angular.module('WhiteLabeling')
isClosingDisabled: false
};
bladeNavigationService.showBlade(newBlade, blade);
}
};

blade.toolbarCommands = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('WhiteLabeling')
.controller('WhiteLabeling.whiteLabelingFaviconController', ['$scope', 'FileUploader', 'platformWebApp.bladeNavigationService', 'platformWebApp.dialogService',
function ($scope, FileUploader, bladeNavigationService, dialogService) {
.controller('WhiteLabeling.whiteLabelingFaviconController', ['$scope', 'FileUploader', 'platformWebApp.bladeNavigationService', 'platformWebApp.dialogService', 'WhiteLabeling.service',
function ($scope, FileUploader, bladeNavigationService, dialogService, whiteLabelingService) {
const blade = $scope.blade;
blade.title = 'white-labeling.blades.white-labeling-favicon.title';
blade.updatePermission = 'WhiteLabeling:update';
Expand All @@ -19,7 +19,7 @@ angular.module('WhiteLabeling')
const dialog = {
title: 'white-labeling.dialogs.white-labeling-favicon-upload-filter.title',
message: 'white-labeling.dialogs.white-labeling-favicon-upload-filter.message',
}
};
dialogService.showErrorDialog(dialog);
}
return approval;
Expand All @@ -31,7 +31,8 @@ angular.module('WhiteLabeling')

faviconUploader.onAfterAddingFile = function (item) {
const fileExtension = '.' + item.file.name.split('.').pop();
item.file.name = `favicon_${blade.currentEntity.organizationId}_${Date.now().toString()}${fileExtension}`;
const entityId = whiteLabelingService.getEntityId(blade.currentEntity);
item.file.name = `favicon_${entityId}_${Date.now().toString()}${fileExtension}`;
};

faviconUploader.onSuccessItem = function (_, uploadedImages) {
Expand All @@ -46,11 +47,11 @@ angular.module('WhiteLabeling')
let formScope;
$scope.setForm = function (form) {
formScope = form;
}
};

$scope.browseFiles = function (id) {
window.document.querySelector(`#${id}`).click()
}
window.document.querySelector(`#${id}`).click();
};

function isDirty() {
return !angular.equals(blade.currentEntity, blade.origEntity) && blade.hasUpdatePermission();
Expand All @@ -73,7 +74,7 @@ angular.module('WhiteLabeling')
blade.currentEntity = angular.copy(blade.currentEntity);

blade.isLoading = false;
}
};

blade.toolbarCommands = [
{
Expand Down
Loading