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

PT-2966: Create company's Default address #194

Merged
merged 2 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/VirtoCommerce.CoreModule.Core/Common/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class Address : ValueObject, IHasOuterId
public string Phone { get; set; }
public string Email { get; set; }
public string OuterId { get; set; }

public bool DefaultAddress { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename it to IsDefault?


protected override IEnumerable<object> GetEqualityComponents()
{
var result = base.GetEqualityComponents();
Expand Down
39 changes: 38 additions & 1 deletion src/VirtoCommerce.CoreModule.Web/Content/css/common.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* widget for statistics */
/* widget for statistics */
.list.__stats {
height: 100%;
line-height: 1.2;
Expand Down Expand Up @@ -28,3 +28,40 @@
font-weight: 500;
margin: 0 0 0 10px;
}

.table-statusDefault {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 4px 4px;
width: 50px;
height: 17px;
top: calc(50% - 17px/2);
background: #FBFDFE;
border: 1px solid #BDD1DF;
border-radius: 2px;
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 11px;
line-height: 20px;
text-align: center;
color: #465769;
flex: none;
order: 0;
flex-grow: 0;
margin-left: 25px;
}

.list-head {
font-size: 22px;
line-height: 2;
background: none;
color: #333;
padding: 4px 0;
position: inherit;
text-align: left;
-webkit-box-shadow: inherit;
box-shadow: inherit;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"core": {
"commands": {
"rebuild-index": "Suchindex erstellen"
},
"commands": {
"rebuild-index": "Suchindex erstellen",
"default": "Standardmäßig verwenden"
},
"blades": {
"index-progress": {
"labels": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"core": {
"commands": {
"apply-filter": "Save & apply",
"rebuild-index": "Build Index"
"rebuild-index": "Build Index",
"default": "Make default"
},
"main-menu-title": {
"search-index": "Search index"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"core": {
"commands": {
"apply-filter": "Сохранить & применить",
"rebuild-index": "Построение Индексов"
},
"commands": {
"apply-filter": "Сохранить & применить",
"rebuild-index": "Построение Индексов",
"default": "Использовать по умолчанию"
},
"main-menu-title": {
"search-index": "Поисковый индекс"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,48 @@ angular.module('virtoCommerce.coreModule.common')
blade.currentEntity.regionId = newId;
});

blade.toolbarCommands = [{
name: "platform.commands.reset", icon: 'fa fa-undo',
executeMethod: function () {
angular.copy(blade.origEntity, blade.currentEntity);
blade.toolbarCommands = [
{
name: "platform.commands.save", icon: 'fas fa-save',
executeMethod: function () {
if (blade.confirmChangesFn) {
blade.confirmChangesFn(blade.currentEntity);
}
angular.copy(blade.currentEntity, blade.origEntity);
$scope.bladeClose();
},
canExecuteMethod: canSave,
permission: blade.updatePermission
},
{
name: "platform.commands.reset", icon: 'fa fa-undo',
executeMethod: function () {
angular.copy(blade.origEntity, blade.currentEntity);
},
canExecuteMethod: isDirty
},
canExecuteMethod: isDirty
}, {
name: "platform.commands.delete", icon: 'fas fa-trash-alt',
executeMethod: deleteEntry,
canExecuteMethod: function () {
return !blade.currentEntity.isNew;
{
name: "platform.commands.delete", icon: 'fas fa-trash-alt',
executeMethod: deleteEntry,
canExecuteMethod: function () {
return !blade.currentEntity.isNew;
}
},
{
name: "core.commands.default", icon: 'fas fa-flag',
executeMethod: function () {
blade.searchDefaultAddress(blade.currentEntity.addressType);
blade.currentEntity.defaultAddress = true;
},
canExecuteMethod: function () {
if (blade.currentEntity.addressType === 'BillingAndShipping' || blade.numberOfAddresses())
return false;
else
return !blade.currentEntity.defaultAddress;
},
meta: "default"
}
}];
];

blade.isLoading = false;

Expand All @@ -105,18 +134,6 @@ angular.module('virtoCommerce.coreModule.common')
return $scope.formScope && $scope.formScope.$valid;
};

$scope.cancelChanges = function () {
$scope.bladeClose();
};

$scope.saveChanges = function () {
if (blade.confirmChangesFn) {
blade.confirmChangesFn(blade.currentEntity);
}
angular.copy(blade.currentEntity, blade.origEntity);
$scope.bladeClose();
};

function isDirty() {
return !angular.equals(blade.currentEntity, blade.origEntity);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<div class="blade-static __bottom" ng-include="'$(Platform)/Scripts/common/templates/ok-cancel.tpl.html'"></div>
<div class="blade-content">
<div class="blade-inner">
<div class="inner-block">
Expand Down
120 changes: 65 additions & 55 deletions src/VirtoCommerce.CoreModule.Web/Scripts/common/blades/address-list.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,78 @@
angular.module('virtoCommerce.coreModule.common')
.controller('virtoCommerce.coreModule.common.coreAddressListController', ['$timeout', '$scope', 'platformWebApp.bladeNavigationService', function ($timeout, $scope, bladeNavigationService) {
var blade = $scope.blade;
$scope.selectedItem = null;
var blade = $scope.blade;
$scope.selectedItem = null;

$scope.openDetailBlade = function (address) {
if (!address) {
address = { isNew: true };
}
$scope.selectedItem = address;
$scope.openDetailBlade = function (address) {
if (!address) {
address = { isNew: true };
}
$scope.selectedItem = address;

var newBlade = {
id: 'coreAddressDetail',
currentEntity: address,
title: blade.title,
subtitle: 'core.blades.address-detail.subtitle',
controller: 'virtoCommerce.coreModule.common.coreAddressDetailController',
confirmChangesFn: function (address) {
address.name = $scope.getAddressName(address);
if (address.isNew) {
address.isNew = undefined;
blade.currentEntities.push(address);
if (blade.confirmChangesFn) {
blade.confirmChangesFn(address);
var newBlade = {
id: 'coreAddressDetail',
currentEntity: address,
title: blade.title,
subtitle: 'core.blades.address-detail.subtitle',
controller: 'virtoCommerce.coreModule.common.coreAddressDetailController',
confirmChangesFn: function (address) {
address.name = $scope.getAddressName(address);
if (address.isNew) {
address.isNew = undefined;
blade.currentEntities.push(address);
if (blade.confirmChangesFn) {
blade.confirmChangesFn(address);
}
}
}
},
deleteFn: function (address) {
var toRemove = _.find(blade.currentEntities, function (x) { return angular.equals(x, address) });
if (toRemove) {
var idx = blade.currentEntities.indexOf(toRemove);
blade.currentEntities.splice(idx, 1);
if (blade.deleteFn) {
blade.deleteFn(address);
},
deleteFn: function (address) {
var toRemove = _.find(blade.currentEntities, function (x) { return angular.equals(x, address) });
if (toRemove) {
var idx = blade.currentEntities.indexOf(toRemove);
blade.currentEntities.splice(idx, 1);
if (blade.deleteFn) {
blade.deleteFn(address);
}
}
}
},
},
searchDefaultAddress: function (addressType) {
blade.currentEntities.find((defAddress, i) => {
if (defAddress.addressType === addressType && defAddress.defaultAddress) {
blade.currentEntities[i].defaultAddress = false;
return true;
}
});
},
numberOfAddresses: function () {
return blade.currentEntities.length <= 1;
},
template: 'Modules/$(VirtoCommerce.Core)/Scripts/common/blades/address-detail.tpl.html'
};
bladeNavigationService.showBlade(newBlade, $scope.blade);
}

template: 'Modules/$(VirtoCommerce.Core)/Scripts/common/blades/address-detail.tpl.html'
$scope.getAddressName = function (address) {
return [address.countryCode, address.regionName, address.city, address.line1].join(", ");
};
bladeNavigationService.showBlade(newBlade, $scope.blade);
}

$scope.getAddressName = function (address) {
return [address.countryCode, address.regionName, address.city, address.line1].join(", ");
};
blade.headIcon = blade.parentBlade.headIcon;

blade.headIcon = blade.parentBlade.headIcon;

blade.toolbarCommands = [
{
name: "platform.commands.add", icon: 'fas fa-plus',
executeMethod: function () {
$scope.openDetailBlade();
},
canExecuteMethod: function () {
return true;
blade.toolbarCommands = [
{
name: "platform.commands.add", icon: 'fas fa-plus',
executeMethod: function () {
$scope.openDetailBlade();
},
canExecuteMethod: function () {
return true;
}
}
}
];
];

blade.isLoading = false;
blade.isLoading = false;

// open blade for new setting
if (!_.some(blade.currentEntities)) {
$timeout($scope.openDetailBlade, 60, false);
}
}]);
// open blade for new setting
if (!_.some(blade.currentEntities)) {
$timeout($scope.openDetailBlade, 60, false);
}
}]);
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<div class="blade-content">
<div class="blade-content">
<div class="blade-inner">
<div class="inner-block">
<ul class="list __items" ng-if="blade.currentEntities.length">
<li class="list-item" ng-click="openDetailBlade(address)" ng-repeat="address in blade.currentEntities" ng-class="{'__selected': address == selectedItem}">
<!--<i class="list-ico fa fa-wrench"></i>-->
<span class="list-t">
{{getAddressName(address) | limitTo:50}}
</span>
<span class="list-descr">{{address.addressType}}</span>
<ul class="list __items" style="list-style-type: none" ng-if="blade.currentEntities.length">
<li class="list-head" ng-repeat="(addressType, listType) in blade.currentEntities | groupBy:'addressType'">
{{addressType}}
<table>
<tr class="list-item" ng-click="openDetailBlade(address)" ng-repeat="address in listType" ng-class="{'__selected': address == selectedItem}">
<td>
<span class="list-t">{{getAddressName(address) | limitTo:50}}</span>
<span class="list-descr">{{address.addressType}}</span>
<td ng-if="address.defaultAddress">
<span class="table-statusDefault">Default</span>
</td>
</tr>
</table>
</li>
</ul>
<p class="note" ng-if="!blade.currentEntities.length">{{ 'core.blades.address-list.labels.no-addresses' | translate }}</p>
Expand Down