Skip to content

Commit 9683cd2

Browse files
authored
Add option to not render PageViewStats in content items (#8)
- Minor change in UI
1 parent 372bc58 commit 9683cd2

8 files changed

Lines changed: 33 additions & 11 deletions

File tree

Neolution.OrchardCoreModules.PageViewStats/Controllers/DashboardController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task<ActionResult> Index(int history)
9999
{
100100
History = history,
101101
PageViewsByDay = pageViews,
102-
PageViewsBySite = pageViewsPerSite
102+
PageViewsByContentItem = pageViewsPerSite
103103
};
104104

105105
return View(viewModel);

Neolution.OrchardCoreModules.PageViewStats/Drivers/PageViewStatsContentDisplayDriver.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Microsoft.AspNetCore.Authorization;
1313
using Microsoft.AspNetCore.Http;
1414
using OrchardCore.Admin;
15+
using Neolution.OrchardCoreModules.PageViewStats.Settings;
16+
using OrchardCore.Entities;
1517

1618
public class PageViewStatsContentDisplayDriver : ContentDisplayDriver
1719
{
@@ -43,12 +45,17 @@ public override async Task<IDisplayResult> DisplayAsync(ContentItem contentItem,
4345
{
4446
return null;
4547
}
46-
4748
var settings = await this.siteService.GetSiteSettingsAsync().ConfigureAwait(false);
4849
var tz = TimeZoneInfo.FindSystemTimeZoneById(settings.TimeZoneId);
4950
var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);
5051
var today = DateOnly.FromDateTime(now);
5152

53+
var pageViewsettings = settings.As<PageViewStatsSettings>();
54+
if (!pageViewsettings.RenderInContentItem)
55+
{
56+
return null;
57+
}
58+
5259
var pageViews = await this.repository.LoadPageViewsAsync(today.AddDays(-30), today).ConfigureAwait(false);
5360
var contentPageViews = pageViews.SelectMany(x => x.PageViews).Where(x => x.ContentItemId == contentItem.ContentItemId).ToList();
5461
var totalViews = await this.repository.LoadAllPageViewsAsync().ConfigureAwait(false);

Neolution.OrchardCoreModules.PageViewStats/Drivers/PageViewStatsSettingsDisplayDriver.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public override async Task<IDisplayResult> EditAsync(PageViewStatsSettings setti
3636
m.CollectUserIp = settings.CollectUserIp;
3737
m.CollectUserAgentString = settings.CollectUserAgentString;
3838
m.CollectRequestReferer = settings.CollectRequestReferer;
39+
m.RenderInContentItem = settings.RenderInContentItem;
3940
})
4041
.Location("Content:1").OnGroup(GroupId);
4142
}
@@ -59,6 +60,7 @@ public override async Task<IDisplayResult> UpdateAsync(PageViewStatsSettings set
5960
settings.CollectUserIp = model.CollectUserIp;
6061
settings.CollectUserAgentString = model.CollectUserAgentString;
6162
settings.CollectRequestReferer = model.CollectRequestReferer;
63+
settings.RenderInContentItem = model.RenderInContentItem;
6264
}
6365

6466
return await EditAsync(settings, context);

Neolution.OrchardCoreModules.PageViewStats/Settings/PageViewStatsSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ public class PageViewStatsSettings
1515
public bool CollectUserAgentString { get; set; }
1616

1717
public bool CollectRequestReferer { get; set; }
18+
19+
public bool RenderInContentItem { get; set; }
1820
}

Neolution.OrchardCoreModules.PageViewStats/ViewModels/DashboardViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public class DashboardViewModel
77
{
88
public int History { get; set; }
99
public IList<DailyArchive> PageViewsByDay { get; set; }
10-
public List<PageViewsPerContentItem> PageViewsBySite { get; set; }
10+
public List<PageViewsPerContentItem> PageViewsByContentItem { get; set; }
1111
}

Neolution.OrchardCoreModules.PageViewStats/ViewModels/PageViewStatsSettingsViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
public class PageViewStatsSettingsViewModel
44
{
55
public bool IsEnabled { get; set; }
6+
67
public bool CollectUserIp { get; set; }
78

89
public bool CollectUserAgentString { get; set; }
910

1011
public bool CollectRequestReferer { get; set; }
12+
13+
public bool RenderInContentItem { get; set; }
1114
}

Neolution.OrchardCoreModules.PageViewStats/Views/Dashboard/Index.cshtml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<a class="nav-link active" id="byday-tab" data-bs-toggle="tab" href="#byday" role="tab" aria-controls="byday" aria-selected="true">@T["By day"]</a>
2020
</li>
2121
<li class="nav-item pr-md-2">
22-
<a class="nav-link" id="bysite-tab" data-bs-toggle="tab" href="#bysite" role="tab" aria-controls="bysite">@T["By site"]</a>
22+
<a class="nav-link" id="bycontentitem-tab" data-bs-toggle="tab" href="#bycontentitem" role="tab" aria-controls="bycontentitem">@T["By content item"]</a>
2323
</li>
2424
</ul>
2525

@@ -65,19 +65,19 @@
6565
</tbody>
6666
</table>
6767
</div>
68-
<div class="tab-pane fade" id="bysite" role="tabpanel" aria-labelledby="bysite-tab">
68+
<div class="tab-pane fade" id="bycontentitem" role="tabpanel" aria-labelledby="bycontentitem-tab">
6969
<div class="form-group d-inline-flex float-end mb-1">
7070
<div class="btn-group">
7171
<div class="dropdown order-md-1">
7272
<button type="button" class="btn btn-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
7373
@GetDropDownButtonText()
7474
</button>
7575
<ul class="dropdown-menu">
76-
<li><a class="dropdown-item" href="?history=7#bysite">Last week</a></li>
77-
<li><a class="dropdown-item" href="?history=14#bysite">Last two weeks</a></li>
78-
<li><a class="dropdown-item" href="?history=21#bysite">Last three weeks</a></li>
79-
<li><a class="dropdown-item" href="?history=30#bysite">Last month</a></li>
80-
<li><a class="dropdown-item" href="?history=0#bysite">Since ever</a></li>
76+
<li><a class="dropdown-item" href="?history=7#bycontentitem">Last week</a></li>
77+
<li><a class="dropdown-item" href="?history=14#bycontentitem">Last two weeks</a></li>
78+
<li><a class="dropdown-item" href="?history=21#bycontentitem">Last three weeks</a></li>
79+
<li><a class="dropdown-item" href="?history=30#bycontentitem">Last month</a></li>
80+
<li><a class="dropdown-item" href="?history=0#bycontentitem">Since ever</a></li>
8181
</ul>
8282
</div>
8383
</div>
@@ -94,7 +94,7 @@
9494
</tr>
9595
</thead>
9696
<tbody>
97-
@foreach (var item in Model.PageViewsBySite)
97+
@foreach (var item in Model.PageViewsByContentItem)
9898
{
9999
<tr>
100100
<td>@item.ContentItemId</td>

Neolution.OrchardCoreModules.PageViewStats/Views/PageViewStatsSettings.Edit.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@
3030
<label asp-for="CollectRequestReferer" class="custom-control-label">@T["Collect request referer of visitors"]</label>
3131
</div>
3232
<span class="hint">@T["Collecting the request referer may allow you to track which from which website the visitors where linked to your site."]</span>
33+
</fieldset>
34+
35+
<fieldset class="form-group" asp-validation-class-for="RenderInContentItem">
36+
<div class="custom-control custom-checkbox">
37+
<input asp-for="RenderInContentItem" class="custom-control-input" type="checkbox" />
38+
<label asp-for="RenderInContentItem" class="custom-control-label">@T["Render stats summary in content items"]</label>
39+
</div>
40+
<span class="hint">@T["Renders an overview of the page view statistics for each content item next to it in the content items section."]</span>
3341
</fieldset>

0 commit comments

Comments
 (0)