Skip to content

Commit 61f0421

Browse files
committed
First steps on new widgets framework (3.2.0.4)
1 parent f63d9c8 commit 61f0421

14 files changed

Lines changed: 428 additions & 36 deletions

File tree

BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,16 @@
115115
<Reference Include="System.Xml" />
116116
</ItemGroup>
117117
<ItemGroup>
118+
<Compile Include="Data\Contracts\IWidgetsRepository.cs" />
118119
<Compile Include="Data\Contracts\IDashboardRepository.cs" />
120+
<Compile Include="Data\WidgetsRepository.cs" />
119121
<Compile Include="Data\DashboardRepository.cs" />
120122
<Compile Include="Data\Models\EditorOptions.cs" />
121123
<Compile Include="Data\Services\Json.cs" />
122124
<Compile Include="Data\ViewModels\CommentsVM.cs" />
123125
<Compile Include="Data\ViewModels\DashboardVM.cs" />
124126
<Compile Include="Data\ViewModels\SettingsVM.cs" />
127+
<Compile Include="Data\ViewModels\WidgetsVM.cs" />
125128
<Compile Include="Services\Syndication\BlogML\BaseReader.cs" />
126129
<Compile Include="Services\Syndication\BlogML\BlogImporter.cs" />
127130
<Compile Include="Services\Syndication\BlogML\BlogMLExtendedPost.cs" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using BlogEngine.Core.Data.ViewModels;
2+
3+
namespace BlogEngine.Core.Data.Contracts
4+
{
5+
/// <summary>
6+
/// Widgets repository
7+
/// </summary>
8+
public interface IWidgetsRepository
9+
{
10+
/// <summary>
11+
/// Get all widgets items
12+
/// </summary>
13+
/// <returns>Widgets view model</returns>
14+
WidgetsVM Get();
15+
}
16+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using BlogEngine.Core.Data.Models;
2+
using BlogEngine.Core.DataStore;
3+
using BlogEngine.Core.Providers;
4+
using BlogEngine.Core.Providers.CacheProvider;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Collections.Specialized;
8+
using System.Linq;
9+
using System.Net;
10+
using System.Text;
11+
using System.Threading;
12+
using System.Threading.Tasks;
13+
using System.Xml;
14+
15+
namespace BlogEngine.Core.Data.ViewModels
16+
{
17+
/// <summary>
18+
/// List of zones and widgets
19+
/// for a current theme
20+
/// </summary>
21+
public class WidgetsVM
22+
{
23+
/// <summary>
24+
/// Theme widtegs
25+
/// </summary>
26+
public WidgetsVM()
27+
{
28+
try
29+
{
30+
WidgetZones = new List<WidgetZone>();
31+
WebClient client = new WebClient();
32+
var html = client.DownloadString(Utils.AbsoluteWebRoot);
33+
var cnt = 0;
34+
var tag = "widgetzone_";
35+
36+
for (int i = 0; i < 10; i++)
37+
{
38+
int from = html.IndexOf(tag, cnt);
39+
if (from > 0)
40+
{
41+
from = from + 11;
42+
int to = html.IndexOf("\"", from);
43+
var zoneId = html.Substring(from, to - from);
44+
var zone = new WidgetZone();
45+
zone.Id = zoneId;
46+
47+
//var ws = new WidgetSettings(zoneId);
48+
49+
//var abc = ws.GetSettings();
50+
51+
// var x = (StringDictionary)ws.GetSettings();
52+
53+
54+
var xml = RetrieveXml(zoneId);
55+
var wd = new WidgetData { Settings = xml.InnerXml };
56+
57+
//------------------------------
58+
var widgets = xml.SelectSingleNode("widgets");
59+
if (widgets != null)
60+
{
61+
zone.Widgets = new List<WidgetItem>();
62+
foreach (XmlNode node in widgets.ChildNodes)
63+
{
64+
if (node != null && node.Attributes != null)
65+
{
66+
var item = new WidgetItem();
67+
item.Id = new Guid(node.Attributes["id"].InnerText);
68+
item.Title = node.Attributes["title"].InnerText;
69+
item.ShowTitle = bool.Parse(node.Attributes["showTitle"].InnerText);
70+
zone.Widgets.Add(item);
71+
}
72+
}
73+
}
74+
//------------------------------
75+
76+
WidgetZones.Add(zone);
77+
cnt = to;
78+
}
79+
else { break; }
80+
}
81+
}
82+
catch (Exception) { }
83+
}
84+
/// <summary>
85+
/// Widget zones
86+
/// </summary>
87+
public List<WidgetZone> WidgetZones { get; set; }
88+
89+
private static XmlDocument RetrieveXml(string zoneName)
90+
{
91+
var ws = new WidgetSettings(zoneName) { SettingsBehavior = new XmlDocumentBehavior() };
92+
var doc = (XmlDocument)ws.GetSettings();
93+
return doc;
94+
}
95+
}
96+
97+
/// <summary>
98+
/// Widget zone
99+
/// </summary>
100+
public class WidgetZone
101+
{
102+
/// <summary>
103+
/// Zone ID
104+
/// </summary>
105+
public string Id { get; set; }
106+
/// <summary>
107+
/// List of widgets
108+
/// </summary>
109+
public List<WidgetItem> Widgets { get; set; }
110+
}
111+
112+
public class WidgetItem
113+
{
114+
public Guid Id { get; set; }
115+
public string Title { get; set; }
116+
public bool ShowTitle { get; set; }
117+
}
118+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using BlogEngine.Core.Data.ViewModels;
2+
using BlogEngine.Core.Data.Contracts;
3+
4+
namespace BlogEngine.Core.Data
5+
{
6+
/// <summary>
7+
/// Widgets repository
8+
/// </summary>
9+
public class WidgetsRepository : IWidgetsRepository
10+
{
11+
/// <summary>
12+
/// Get theme widgets
13+
/// </summary>
14+
/// <returns>Widgets view model</returns>
15+
public WidgetsVM Get()
16+
{
17+
if (!Security.IsAuthorizedTo(Rights.ManageWidgets))
18+
throw new System.UnauthorizedAccessException();
19+
20+
return new WidgetsVM();
21+
}
22+
}
23+
}

BlogEngine/BlogEngine.Core/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
[assembly: CLSCompliant(false)]
2020
[assembly: ComVisible(false)]
2121
[assembly: AllowPartiallyTrustedCallers]
22-
[assembly: AssemblyVersion("3.2.0.3")]
22+
[assembly: AssemblyVersion("3.2.0.4")]
2323
[assembly: SecurityRules(SecurityRuleSet.Level1)]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using BlogEngine.Core.Data.Contracts;
2+
using BlogEngine.Core.Data.Models;
3+
using BlogEngine.Core.Data.ViewModels;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Net;
7+
using System.Net.Http;
8+
using System.Web.Http;
9+
10+
public class WidgetsController : ApiController
11+
{
12+
readonly IWidgetsRepository repository;
13+
14+
public WidgetsController(IWidgetsRepository repository)
15+
{
16+
this.repository = repository;
17+
}
18+
19+
public IEnumerable<WidgetZone> Get()
20+
{
21+
var widgetsVM = new WidgetsVM();
22+
return widgetsVM.WidgetZones;
23+
}
24+
25+
}

BlogEngine/BlogEngine.NET/AppCode/App_Start/BlogEngineConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static void RegisterBundles(BundleCollection bundles)
138138

139139
.Include("~/admin/app/custom/plugins/pluginController.js")
140140
.Include("~/admin/app/custom/themes/themeController.js")
141+
.Include("~/admin/app/custom/widgets/widgetController.js")
141142

142143
.Include("~/admin/app/security/users/userController.js")
143144
.Include("~/admin/app/security/roles/roleController.js")
@@ -231,6 +232,7 @@ static void RegisterDiCintainer()
231232
container.Register<IFileManagerRepository, FileManagerRepository>(Lifestyle.Transient);
232233
container.Register<ICommentFilterRepository, CommentFilterRepository>(Lifestyle.Transient);
233234
container.Register<IDashboardRepository, DashboardRepository>(Lifestyle.Transient);
235+
container.Register<IWidgetsRepository, WidgetsRepository>(Lifestyle.Transient);
234236

235237
container.Verify();
236238

BlogEngine/BlogEngine.NET/BlogEngine.NET.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
<Content Include="admin\app\custom\themes\themeController.js" />
137137
<Content Include="admin\app\custom\themes\themeGallery.html" />
138138
<Content Include="admin\app\custom\themes\themeView.html" />
139+
<Content Include="admin\app\custom\widgets\widgetController.js" />
139140
<Content Include="admin\app\custom\widgets\widgetView.html" />
140141
<Content Include="admin\themes\standard\css\styles.css" />
141142
<Content Include="admin\themes\standard\img\logo-sidebar.png" />
@@ -1925,6 +1926,7 @@
19251926
<Compile Include="AppCode\Api\SettingsController.cs" />
19261927
<Compile Include="AppCode\Api\NewsFeedController.cs" />
19271928
<Compile Include="AppCode\Api\StatsController.cs" />
1929+
<Compile Include="AppCode\Api\WidgetsController.cs" />
19281930
<Compile Include="AppCode\Api\TagsController.cs" />
19291931
<Compile Include="AppCode\Api\TrashController.cs" />
19301932
<Compile Include="AppCode\Api\ToolsController.cs" />

BlogEngine/BlogEngine.NET/admin/app/app.js

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
var config = ["$routeProvider", function ($routeProvider) {
55
$routeProvider
66
.when("/", { templateUrl: "app/dashboard/dashboardView.html" })
7-
7+
88
.when("/content/posts", { templateUrl: "app/content/posts/postView.html" })
99
.when("/content/blogs", { templateUrl: "app/content/blogs/blogView.html" })
1010
.when("/content/comments", { templateUrl: "app/content/comments/commentView.html" })
@@ -81,6 +81,98 @@
8181
};
8282
});
8383

84+
// dragable
85+
app.factory('DragDropHandler', [function () {
86+
return {
87+
dragObject: undefined,
88+
addObject: function (object, objects, to) {
89+
objects.splice(to, 0, object);
90+
},
91+
moveObject: function (objects, from, to) {
92+
objects.splice(to, 0, objects.splice(from, 1)[0]);
93+
}
94+
};
95+
}]);
96+
97+
app.directive('draggable', ['DragDropHandler', function (DragDropHandler) {
98+
return {
99+
scope: {
100+
draggable: '='
101+
},
102+
link: function (scope, element, attrs) {
103+
element.draggable({
104+
connectToSortable: attrs.draggableTarget,
105+
helper: "clone",
106+
start: function () {
107+
DragDropHandler.dragObject = scope.draggable;
108+
},
109+
stop: function () {
110+
DragDropHandler.dragObject = undefined;
111+
}
112+
});
113+
114+
element.disableSelection();
115+
}
116+
};
117+
}]);
118+
119+
app.directive('droppable', ['DragDropHandler', function (DragDropHandler) {
120+
return {
121+
scope: {
122+
droppable: '=',
123+
ngMove: '&',
124+
ngCreate: '&'
125+
},
126+
link: function (scope, element, attrs) {
127+
element.sortable({
128+
connectWith: ['.draggable', '.sortable'],
129+
});
130+
element.disableSelection();
131+
var list = element.attr('id');
132+
element.on("sortupdate", function (event, ui) {
133+
134+
var from = angular.element(ui.item).scope().$index;
135+
var to = element.children().index(ui.item);
136+
137+
if (to >= 0) {
138+
//item is moved to this list
139+
scope.$apply(function () {
140+
if (from >= 0) {
141+
//item is coming from a sortable
142+
143+
if (!ui.sender) {
144+
//item is coming from this sortable
145+
DragDropHandler.moveObject(scope.droppable, from, to);
146+
147+
} else {
148+
//item is coming from another sortable
149+
scope.ngMove({
150+
from: from,
151+
to: to,
152+
fromList: ui.sender.attr('id'),
153+
toList: list
154+
});
155+
ui.item.remove();
156+
}
157+
} else {
158+
//item is coming from a draggable
159+
scope.ngCreate({
160+
object: DragDropHandler.dragObject,
161+
to: to,
162+
list: list
163+
});
164+
165+
ui.item.remove();
166+
}
167+
});
168+
}
169+
});
170+
171+
}
172+
};
173+
}]);
174+
// end dragable
175+
84176
var run = ["$rootScope", "$log", function ($rootScope, $log) {
85177

86178
$rootScope.lbl = BlogAdmin.i18n;

0 commit comments

Comments
 (0)