Skip to content

Commit a0a4d1a

Browse files
Implemented function to show widget zone with a filter instead of widget
1 parent e283be2 commit a0a4d1a

File tree

5 files changed

+127
-223
lines changed

5 files changed

+127
-223
lines changed

src/Plugins/SmartStore.DevTools/DependencyRegistrar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, b
2626
{
2727
// intercept ALL public store controller actions
2828
builder.RegisterType<ProfilerFilter>().AsActionFilterFor<SmartController>();
29-
29+
builder.RegisterType<WidgetZoneFilter>().AsActionFilterFor<SmartController>();
30+
3031
//// intercept CatalogController's Product action
3132
//builder.RegisterType<SampleResultFilter>().AsResultFilterFor<CatalogController>(x => x.Product(default(int), default(string))).InstancePerRequest();
3233
//builder.RegisterType<SampleActionFilter>().AsActionFilterFor<PublicControllerBase>().InstancePerRequest();
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Web;
8+
using System.Web.Mvc;
9+
using SmartStore.Core.Logging;
10+
using SmartStore.Core.Localization;
11+
using SmartStore.DevTools.Services;
12+
using SmartStore.Core;
13+
using SmartStore.Services;
14+
using SmartStore.Services.Customers;
15+
using SmartStore.Web.Framework.UI;
16+
using SmartStore.Utilities;
17+
using System.IO;
18+
19+
namespace SmartStore.DevTools.Filters
20+
{
21+
public class WidgetZoneFilter : IActionFilter, IResultFilter
22+
{
23+
private readonly ICommonServices _services;
24+
private readonly Lazy<IWidgetProvider> _widgetProvider;
25+
private readonly ProfilerSettings _profilerSettings;
26+
27+
public WidgetZoneFilter(
28+
ICommonServices services,
29+
Lazy<IWidgetProvider> widgetProvider,
30+
ProfilerSettings profilerSettings)
31+
{
32+
this._services = services;
33+
this._widgetProvider = widgetProvider;
34+
this._profilerSettings = profilerSettings;
35+
}
36+
37+
public void OnActionExecuting(ActionExecutingContext filterContext)
38+
{
39+
if (!_profilerSettings.DisplayWidgetZones)
40+
return;
41+
}
42+
43+
public void OnActionExecuted(ActionExecutedContext filterContext)
44+
{
45+
if (!_profilerSettings.DisplayWidgetZones)
46+
return;
47+
}
48+
49+
public void OnResultExecuting(ResultExecutingContext filterContext)
50+
{
51+
if (!_profilerSettings.DisplayWidgetZones)
52+
return;
53+
54+
// should only run on a full view rendering result
55+
var result = filterContext.Result as ViewResultBase;
56+
if (result == null)
57+
{
58+
return;
59+
}
60+
61+
if (!this.ShouldRender(filterContext.HttpContext))
62+
{
63+
return;
64+
}
65+
66+
if (!filterContext.IsChildAction)
67+
{
68+
_widgetProvider.Value.RegisterAction(
69+
new Wildcard("*"),
70+
"WidgetZone",
71+
"DevTools",
72+
new { area = "SmartStore.DevTools" });
73+
}
74+
75+
var viewName = result.ViewName;
76+
77+
if (viewName.IsEmpty())
78+
{
79+
string action = (filterContext.RouteData.Values["action"] as string).EmptyNull();
80+
viewName = action;
81+
82+
if (action == "WidgetsByZone")
83+
{
84+
var model = result.Model as WidgetZoneModel;
85+
86+
filterContext.Result = new ViewResult
87+
{
88+
ViewName = "~/Plugins/SmartStore.DevTools/Views/DevTools/WidgetZone.cshtml",
89+
};
90+
filterContext.RouteData.Values.Add("widgetZone", model.WidgetZone);
91+
}
92+
}
93+
}
94+
95+
public void OnResultExecuted(ResultExecutedContext filterContext)
96+
{
97+
if (!_profilerSettings.DisplayWidgetZones)
98+
return;
99+
100+
// should only run on a full view rendering result
101+
if (!(filterContext.Result is ViewResultBase))
102+
{
103+
return;
104+
}
105+
106+
if (!this.ShouldRender(filterContext.HttpContext))
107+
{
108+
return;
109+
}
110+
}
111+
112+
private bool ShouldRender(HttpContextBase ctx)
113+
{
114+
if (!_services.WorkContext.CurrentCustomer.IsAdmin())
115+
{
116+
return ctx.Request.IsLocal;
117+
}
118+
119+
return true;
120+
}
121+
122+
}
123+
}

src/Plugins/SmartStore.DevTools/SmartStore.DevTools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<Compile Include="Controllers\DevToolsController.cs" />
145145
<Compile Include="Controllers\MyCheckoutController.cs" />
146146
<Compile Include="DependencyRegistrar.cs" />
147+
<Compile Include="Filters\WidgetZoneFilter.cs" />
147148
<Compile Include="Filters\Samples\SampleCheckoutFilter.cs" />
148149
<Compile Include="Filters\ProfilerFilter.cs" />
149150
<Compile Include="Filters\Samples\SampleResultFilter.cs" />
@@ -155,7 +156,6 @@
155156
<Compile Include="Services\IProfilerService.cs" />
156157
<Compile Include="Services\ProfilerService.cs" />
157158
<Compile Include="Settings\ProfilerSettings.cs" />
158-
<Compile Include="Widgets\ShowZonesWidget.cs" />
159159
</ItemGroup>
160160
<ItemGroup>
161161
<ProjectReference Include="..\..\Libraries\SmartStore.Core\SmartStore.Core.csproj">
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<span class="label tooltip-toggle" title="@ViewData["widgetZone"]">
1+
<span class="label tooltip-toggle widget-zone-info" title="@ViewData["widgetZone"]">
22
Widget Zone
33
</span>

src/Plugins/SmartStore.DevTools/Widgets/ShowZonesWidget.cs

Lines changed: 0 additions & 220 deletions
This file was deleted.

0 commit comments

Comments
 (0)