Skip to content

Commit 2765312

Browse files
committed
Added Month list widget
1 parent 82c90ed commit 2765312

File tree

7 files changed

+98
-5
lines changed

7 files changed

+98
-5
lines changed

BlogEngine/BlogEngine.NET/App_Data/datastore/widgets/be_WIDGET_ZONE.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
<widget id="abde36cb-9ba6-4645-afc3-c0e4292ce72e" title="Newsletter" showTitle="True">Newsletter</widget>
99
<widget id="4b7cb5e1-b090-4779-b7bc-24898a269477" title="Comment List" showTitle="True">CommentList</widget>
1010
<widget id="fb6b97ea-7d73-4821-a2a3-3aaf13e233d3" title="Link List" showTitle="True">LinkList</widget>
11+
<widget id="4cb23700-ca29-4c88-a46c-9a262a9f4240" title="Month List" showTitle="True">MonthList</widget>
1112
</widgets>

BlogEngine/BlogEngine.NET/BlogEngine.NET.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@
724724
<Content Include="Custom\Widgets\CommentList\widget.cshtml" />
725725
<Content Include="Custom\Widgets\LinkList\edit.cshtml" />
726726
<Content Include="Custom\Widgets\LinkList\widget.cshtml" />
727+
<Content Include="Custom\Widgets\MonthList\widget.cshtml" />
727728
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
728729
<Content Include="Scripts\i18n\angular-locale_aa-dj.js" />
729730
<Content Include="Scripts\i18n\angular-locale_aa-er.js" />
@@ -2120,6 +2121,7 @@
21202121
<Compile Include="Custom\Widgets\CategoryList\CategoryList.cs" />
21212122
<Compile Include="Custom\Widgets\Common.cs" />
21222123
<Compile Include="Custom\Widgets\LinkList\LinkList.cs" />
2124+
<Compile Include="Custom\Widgets\MonthList\MonthList.cs" />
21232125
<Compile Include="Custom\Widgets\Newsletter\Newsletter.cs" />
21242126
<Compile Include="default.aspx.cs">
21252127
<DependentUpon>default.aspx</DependentUpon>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using BlogEngine.Core;
5+
6+
namespace BlogEngine.NET.Custom.Widgets
7+
{
8+
public class MonthList
9+
{
10+
class DateComparer_Desc : IComparer<DateTime>
11+
{
12+
int IComparer<DateTime>.Compare(DateTime x, DateTime y) { return -x.CompareTo(y); }
13+
}
14+
class IntComparer_Desc : IComparer<int>
15+
{
16+
int IComparer<int>.Compare(int x, int y) { return -x.CompareTo(y); }
17+
}
18+
19+
private static readonly IComparer<DateTime> date_Desc = new DateComparer_Desc();
20+
private static readonly IComparer<int> int_Desc = new IntComparer_Desc();
21+
22+
public MonthList() { }
23+
24+
public SortedDictionary<int, List<MonthItem>> GetList()
25+
{
26+
var months = new SortedDictionary<DateTime, int>(date_Desc);
27+
var years = new SortedDictionary<int, List<MonthItem>>(int_Desc);
28+
29+
foreach (var month in Post.ApplicablePosts.Where(post => post.IsVisibleToPublic).
30+
Select(post => new DateTime(post.DateCreated.Year, post.DateCreated.Month, 1)))
31+
{
32+
int count;
33+
months.TryGetValue(month, out count);
34+
++count;
35+
months[month] = count;
36+
}
37+
foreach (KeyValuePair<DateTime, int> aIt in months)
38+
{
39+
if (!years.Keys.Contains(aIt.Key.Year))
40+
{
41+
years.Add(aIt.Key.Year, new List<MonthItem>());
42+
}
43+
var item = new MonthItem();
44+
item.Title = aIt.Key.ToString("MMMM");
45+
item.Url = string.Format("{0}{1}/{2}", Utils.RelativeOrAbsoluteWebRoot, aIt.Key.Year, aIt.Key.Month.ToString("00"));
46+
item.Count = aIt.Value;
47+
years[aIt.Key.Year].Add(item);
48+
}
49+
return years;
50+
}
51+
}
52+
53+
public class MonthItem
54+
{
55+
public string Title { get; set; }
56+
public string Url { get; set; }
57+
public int Count { get; set; }
58+
}
59+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@using BlogEngine.NET.Custom.Widgets
2+
@{
3+
var title = Model.Title;
4+
var mList = new MonthList();
5+
var years = mList.GetList();
6+
var cnt = 0;
7+
var cls = "open";
8+
}
9+
<div class="widget monthlist">
10+
<h4 class="widget-header">@title</h4>
11+
<div class="widget-content">
12+
<ul id="monthList">
13+
@foreach (KeyValuePair<int, List<MonthItem>> y in years)
14+
{
15+
var yId = "year" + @y.Key;
16+
var tgl = "BlogEngine.toggleMonth('" + yId + "')";
17+
cnt = cnt + 1;
18+
cls = cnt > 1 ? "close" : "open";
19+
<li onclick="@tgl" class="year">@y.Key
20+
<ul id="@yId" class="@cls">
21+
@foreach (var item in y.Value)
22+
{
23+
<li><a href="@item.Url/default">@item.Title</a> (@item.Count)</li>
24+
}
25+
</ul>
26+
</li>
27+
}
28+
</ul>
29+
</div>
30+
</div>

BlogEngine/BlogEngine.NET/Custom/Widgets/TagCloud/edit.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
@Html.DropDownList("ddCloudSize", cloudSizeOptions, new { @class = "form-control" })
6161
</div>
6262
<div>
63-
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
63+
<button type="submit" class="btn btn-success btn-sm pull-left">
6464
@Resources.labels.save
6565
</button>
6666
</div>

BlogEngine/BlogEngine.NET/Custom/Widgets/TextBox/edit.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<form method="post">
4545
<textarea style="opacity:0; height:300px; width:100%;" id="txtContent" name="txtContent" class="post">@txt</textarea>
4646
<div style="margin-top: 15px">
47-
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
47+
<button type="submit" class="btn btn-success btn-sm pull-left">
4848
Save
4949
</button>
5050
</div>

BlogEngine/BlogEngine.NET/admin/app/custom/widgets/widgetView.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div data-ng-controller="CustomWidgetsController">
22
<style>
33
.red-border { border: 1px solid red !important; }
4+
#w-zones .panel-body { padding: 10px 15px; line-height: 30px; }
5+
.panel-primary { margin-bottom: 5px; }
46
.modal .modal-body { padding: 10px 40px !important; height: 320px; }
57
#settingsFrame { height: 300px; }
68
.header-txt { border: 1px solid #e5e5e5; line-height: 32px; margin-top: 10px 10px 0 0; width: 400px; padding: 0 10px; }
@@ -45,7 +47,7 @@ <h3>Available Widgets</h3>
4547
</div>
4648
</div>
4749
</div>
48-
<div class="col-lg-6">
50+
<div class="col-lg-6" id="w-zones">
4951
<div ng-if="widgetZones.titles && widgetZones.titles.length > 0">
5052
<h3>{{widgetZones.titles[0]}}</h3>
5153
<div droppable='widgetZones.list1' ng-move='moveObject(from, to, fromList, toList)'
@@ -135,8 +137,7 @@ <h3>{{widgetZones.titles[4]}}</h3>
135137
</div>
136138
</div>
137139
</div>
138-
</div>
139-
140+
</div>
140141
</div>
141142
</div>
142143

0 commit comments

Comments
 (0)