Skip to content

Commit

Permalink
Rework: Account pages navigation #1451
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Chmir committed Jun 8, 2016
1 parent 5763dd0 commit 4a7f29d
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 86 deletions.
98 changes: 91 additions & 7 deletions src/Presentation/Nop.Web/Controllers/CustomerController.cs
Expand Up @@ -1232,13 +1232,97 @@ public ActionResult AccountActivation(string token, string email)
public ActionResult CustomerNavigation(int selectedTabId = 0)
{
var model = new CustomerNavigationModel();
model.HideAvatar = !_customerSettings.AllowCustomersToUploadAvatars;
model.HideRewardPoints = !_rewardPointsSettings.Enabled;
model.HideForumSubscriptions = !_forumSettings.ForumsEnabled || !_forumSettings.AllowCustomersToManageSubscriptions;
model.HideReturnRequests = !_orderSettings.ReturnRequestsEnabled ||
_returnRequestService.SearchReturnRequests(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id, 0, null, 0, 1).Count == 0;
model.HideDownloadableProducts = _customerSettings.HideDownloadableProductsTab;
model.HideBackInStockSubscriptions = _customerSettings.HideBackInStockSubscriptionsTab;
var languageId = _workContext.WorkingLanguage.Id;

This comment has been minimized.

Copy link
@AndreiMaz

AndreiMaz Jun 8, 2016

Member

зачем languageId передавать? он и так там определеться в GetResource


model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerInfo",
Title = _localizationService.GetResource("Account.CustomerInfo", languageId),
Tab = CustomerNavigationEnum.Info
});

model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerAddresses",
Title = _localizationService.GetResource("Account.CustomerAddresses", languageId),
Tab = CustomerNavigationEnum.Addresses
});

model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerOrders",
Title = _localizationService.GetResource("Account.CustomerOrders", languageId),
Tab = CustomerNavigationEnum.Orders
});

if (_orderSettings.ReturnRequestsEnabled &&
_returnRequestService.SearchReturnRequests(_storeContext.CurrentStore.Id,
_workContext.CurrentCustomer.Id, 0, null, 0, 1).Any())
{
model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerReturnRequests",
Title = _localizationService.GetResource("Account.CustomerReturnRequests", languageId),
Tab = CustomerNavigationEnum.ReturnRequests
});
}

if (!_customerSettings.HideDownloadableProductsTab)
{
model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerDownloadableProducts",
Title = _localizationService.GetResource("Account.DownloadableProducts", languageId),
Tab = CustomerNavigationEnum.DownloadableProducts
});
}

if (!_customerSettings.HideBackInStockSubscriptionsTab)
{
model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerBackInStockSubscriptions",
Title = _localizationService.GetResource("Account.BackInStockSubscriptions", languageId),
Tab = CustomerNavigationEnum.BackInStockSubscriptions
});
}

if (_rewardPointsSettings.Enabled)
{
model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerRewardPoints",
Title = _localizationService.GetResource("Account.RewardPoints", languageId),
Tab = CustomerNavigationEnum.RewardPoints
});
}

model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerChangePassword",
Title = _localizationService.GetResource("Account.ChangePassword", languageId),
Tab = CustomerNavigationEnum.ChangePassword
});

if (_customerSettings.AllowCustomersToUploadAvatars)
{
model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerAvatar",
Title = _localizationService.GetResource("Account.Avatar", languageId),
Tab = CustomerNavigationEnum.Avatar
});
}

if (_forumSettings.ForumsEnabled && _forumSettings.AllowCustomersToManageSubscriptions)
{
model.CustomerNavigationItems.Add(new CustomerNavigationItemModel
{
RouteName = "CustomerForumSubscriptions",
Title = _localizationService.GetResource("Account.ForumSubscriptions", languageId),
Tab = CustomerNavigationEnum.ForumSubscriptions
});
}

model.SelectedTab = (CustomerNavigationEnum)selectedTabId;

Expand Down
27 changes: 16 additions & 11 deletions src/Presentation/Nop.Web/Models/Customer/CustomerNavigationModel.cs
@@ -1,23 +1,28 @@
using Nop.Web.Framework.Mvc;
using System.Collections;
using System.Collections.Generic;
using Nop.Web.Framework.Mvc;

namespace Nop.Web.Models.Customer
{
public partial class CustomerNavigationModel : BaseNopModel
{
public bool HideInfo { get; set; }
public bool HideAddresses { get; set; }
public bool HideOrders { get; set; }
public bool HideBackInStockSubscriptions { get; set; }
public bool HideReturnRequests { get; set; }
public bool HideDownloadableProducts { get; set; }
public bool HideRewardPoints { get; set; }
public bool HideChangePassword { get; set; }
public bool HideAvatar { get; set; }
public bool HideForumSubscriptions { get; set; }
public CustomerNavigationModel()
{
CustomerNavigationItems = new List<CustomerNavigationItemModel>();
}

public IList<CustomerNavigationItemModel> CustomerNavigationItems { get; set; }

public CustomerNavigationEnum SelectedTab { get; set; }
}

public class CustomerNavigationItemModel
{
public string RouteName { get; set; }
public string Title { get; set; }
public CustomerNavigationEnum Tab { get; set; }
}

public enum CustomerNavigationEnum
{
Info = 0,
Expand Down
72 changes: 4 additions & 68 deletions src/Presentation/Nop.Web/Views/Customer/CustomerNavigation.cshtml
Expand Up @@ -7,75 +7,11 @@
<div class="listbox">
<ul class="list">
@Html.Widget("account_navigation_before")
@if (!Model.HideInfo)
@foreach (var item in Model.CustomerNavigationItems)
{
<li><a href="@Url.RouteUrl("CustomerInfo")" class="@if (Model.SelectedTab == CustomerNavigationEnum.Info)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.CustomerInfo")</a></li>
}
@if (!Model.HideAddresses)
{
<li><a href="@Url.RouteUrl("CustomerAddresses")" class="@if (Model.SelectedTab == CustomerNavigationEnum.Addresses)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.CustomerAddresses")</a></li>
}
@if (!Model.HideOrders)
{
<li><a href="@Url.RouteUrl("CustomerOrders")" class="@if (Model.SelectedTab == CustomerNavigationEnum.Orders)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.CustomerOrders")</a></li>
}
@if (!Model.HideReturnRequests)
{
<li><a href="@Url.RouteUrl("CustomerReturnRequests")" class="@if (Model.SelectedTab == CustomerNavigationEnum.ReturnRequests)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.CustomerReturnRequests")</a></li>
}
@if (!Model.HideDownloadableProducts)
{
<li><a href="@Url.RouteUrl("CustomerDownloadableProducts")" class="@if (Model.SelectedTab == CustomerNavigationEnum.DownloadableProducts)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.DownloadableProducts")</a></li>
}
@if (!Model.HideBackInStockSubscriptions)
{
<li><a href="@Url.RouteUrl("CustomerBackInStockSubscriptions")" class="@if (Model.SelectedTab == CustomerNavigationEnum.BackInStockSubscriptions)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.BackInStockSubscriptions")</a></li>
}
@if (!Model.HideRewardPoints)
{
<li><a href="@Url.RouteUrl("CustomerRewardPoints")" class="@if (Model.SelectedTab == CustomerNavigationEnum.RewardPoints)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.RewardPoints")</a></li>
}
@if (!Model.HideChangePassword)
{
<li><a href="@Url.RouteUrl("CustomerChangePassword")" class="@if (Model.SelectedTab == CustomerNavigationEnum.ChangePassword)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.ChangePassword")</a></li>
}
@if (!Model.HideAvatar)
{
<li><a href="@Url.RouteUrl("CustomerAvatar")" class="@if (Model.SelectedTab == CustomerNavigationEnum.Avatar)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.Avatar")</a></li>
}
@if (!Model.HideForumSubscriptions)
{
<li><a href="@Url.RouteUrl("CustomerForumSubscriptions")" class="@if (Model.SelectedTab == CustomerNavigationEnum.ForumSubscriptions)
{<text>active</text>}
else
{<text>inactive</text>}">@T("Account.ForumSubscriptions")</a></li>
<li>
<a href="@Url.RouteUrl(item.RouteName)" class="@(Model.SelectedTab == item.Tab ? "active" : "inactive")">@(item.Title)</a>

This comment has been minimized.

Copy link
@AndreiMaz

AndreiMaz Jun 8, 2016

Member

@(item.Title) можно просто писать @item.Title

</li>
}
@Html.Widget("account_navigation_after")
</ul>
Expand Down

0 comments on commit 4a7f29d

Please sign in to comment.