2015-05-06 12:35:26 +02:00
|
|
|
|
using Orchard.ContentManagement;
|
2015-05-20 01:27:53 +02:00
|
|
|
|
using Orchard.Core.Title.Models;
|
2015-05-04 19:40:11 +02:00
|
|
|
|
using Orchard.Dashboards.Models;
|
2015-05-20 01:27:53 +02:00
|
|
|
|
using Orchard.Layouts.Models;
|
2015-05-04 19:40:11 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Orchard.Dashboards.Services {
|
|
|
|
|
|
public class DefaultDashboardSelector : IDashboardSelector {
|
|
|
|
|
|
private readonly IOrchardServices _services;
|
2015-05-20 19:12:38 +02:00
|
|
|
|
public const string DefaultLayout = "{\"elements\":[{\"typeName\":\"Orchard.Layouts.Elements.Canvas\",\"data\":\"\",\"exportableData\":\"\",\"index\":0,\"elements\":[{\"typeName\":\"Orchard.Layouts.Elements.Grid\",\"data\":\"\",\"exportableData\":\"\",\"index\":0,\"elements\":[{\"typeName\":\"Orchard.Layouts.Elements.Row\",\"data\":\"\",\"exportableData\":\"\",\"index\":0,\"elements\":[{\"typeName\":\"Orchard.Layouts.Elements.Column\",\"data\":\"Width=2&Offset=0&Collapsible=null\",\"exportableData\":\"\",\"index\":0,\"elements\":[{\"typeName\":\"Orchard.Layouts.Elements.Html\",\"data\":\"TypeName=Orchard.Layouts.Elements.Html&Text=%3ch2%3e%3ci+class%3d%22fa+fa-cog%22%3e%3c%2fi%3e+Get+up+and+running%3c%2fh2%3e%0d%0a%3cp%3eStart+by+exploring+the+menu+on+the+left+and+familiarize+yourself+with+Orchard.+As+for+the+basics%2c+we+suggest+%3ca+href%3d%22%23%7bUrl.Action%3aIndex%2cAdmin%2carea%3dOrchard.Themes%7d%22%3echanging+the+theme%3c%2fa%3e%2c+%3ca+href%3d%22%23%7bUrl.Action%3aCreate%2cAdmin%2carea%3dContents%7d%22%3eadding+some+pages%3c%2fa%3e%2c+%3ca+href%3d%22%23%7bUrl.Action%3aCreate%2cBlogAdmin%2carea%3dOrchard.Blogs%7d%22%3esetup+up+a+blog%3c%2fa%3e%2c+and+%3ca+href%3d%22%23%7bUrl.Action%3aIndex%2cAdmin%2carea%3dSettings%2cgroupInfoId%3dIndex%7d%22%3econfiguring+basic+settings%3c%2fa%3e.%3c%2fp%3e&Content=%3ch2%3e%3ci+class%3d%22fa+fa-cog%22%3e%3c%2fi%3e+Get+up+and+running%3c%2fh2%3e%0d%0a%3cp%3eStart+by+exploring+the+menu+on+the+left+and+familiarize+yourself+with+Orchard.+As+for+the+basics%2c+we+suggest+%3ca+href%3d%22%23%7bUrl.Action%3aIndex%2cAdmin%2carea%3dOrchard.Themes%7d%22%3echanging+the+theme%3c%2fa%3e%2c+%3ca+href%3d%22%23%7bUrl.Action%3aCreate%2cAdmin%2carea%3dContents%7d%22%3eadding+some+pages%3c%2fa%3e%2c+%3ca+href%3d%22%23%7bUrl.Action%3aCreate%2cBlogAdmin%2carea%3dOrchard.Blogs%7d%22%3esetup+up+a+blog%3c%2fa%3e%2c+and+%3ca+href%3d%22%23%7bUrl.Action%3aIndex%2cAdmin%2carea%3dSettings%2cgroupInfoId%3dIndex%7d%22%3econfiguring+basic+settings%3c%2fa%3e.%3c%2fp%3e\",\"exportableData\":\"\",\"index\":0,\"elements\":[],\"isTemplated\":false,\"htmlId\":\"\",\"htmlClass\":\"\",\"htmlStyle\":\"\",\"rule\":\"\"}],\"isTemplated\":false,\"htmlId\":\"\",\"htmlClass\":\"\",\"htmlStyle\":\"\",\"rule\":\"\"},{\"typeName\":\"Orchard.Layouts.Elements.Column\",\"data\":\"Width=2&Offset=0&Collapsible=null\",\"exportableData\":\"\",\"index\":1,\"elements\":[{\"typeName\":\"Orchard.Layouts.Elements.Html\",\"data\":\"TypeName=Orchard.Layouts.Elements.Html&Text=%3ch2%3e%3ci+class%3d%22fa+fa-th-large%22%3e%3c%2fi%3eGet+more+goodies%3c%2fh2%3e%0d%0a%3cp%3eChange+the+way+your+site+works+and+looks+with+%3ca+href%3d%22%23%7bUrl.Action%3aThemes%2cGallery%2carea%3dOrchard.Packaging%7d%22%3ethemes%3c%2fa%3e+and+%3ca+href%3d%22%23%7bUrl.Action%3aModules%2cGallery%2carea%3dOrchard.Packaging%7d%22%3emodules%3c%2fa%3e.+There%26rsquo%3bs+plenty+to+choose+from+in+the+%3ca+href%3d%22http%3a%2f%2fgallery.orchardproject.net%22%3eOrchard+Gallery%3c%2fa%3e.+We%26rsquo%3bre+always+adding+things%2c+so+be+sure+to+check+back+often+to+see+what%26rsquo%3bs+new.%3c%2fp%3e&Content=%3ch2%3e%3ci+class%3d%22fa+fa-th-large%22%3e%3c%2fi%3eGet+more+goodies%3c%2fh2%3e%0d%0a%3cp%3eChange+the+way+your+site+works+and+looks+with+%3ca+href%3d%22%23%7bUrl.Action%3aThemes%2cGallery%2carea%3dOrchard.Packaging%7d%22%3ethemes%3c%2fa%3e+and+%3ca+href%3d%22%23%7bUrl.Action%3aModules%2cGallery%2carea%3dOrchard.Packaging%7d%22%3emodules%3c%2fa%3e.+There%26rsquo%3bs+plenty+to+choose+from+in+the+%3ca+href%3d%22http%3a%2f%2fgallery.orchardproject.net%22%3eOrchard+Gallery%3c%2fa%3e.+We%26rsquo%3bre+always+adding+things%2c+so+be+sure+to+check+back+often+to+see+what%26rsquo%3bs+new.%3c%2fp%3e\",\"exportableData\":\"\",\"index\":0,\"elements\":[],\"isTemplated\":false,\"htmlId\":\"\",\"htmlClass\":\"\",\"htmlStyle\":\"\",\"rule\":\"\"}],\"isTemplated\":false,\"htmlId\":\"\",\"htmlClass\":\"\",\"htmlStyle\":\"\",\"rule\":\"\"},{\"typeName\":\"Orchard.Layouts.Elements.Column\",\"data\":\"Width=2&Offset=0&Collapsible=null\",\"exportableData\":\"\",\"index\":2,\"elements\":[{\"
|
2015-05-20 01:27:53 +02:00
|
|
|
|
|
2015-05-04 19:40:11 +02:00
|
|
|
|
public DefaultDashboardSelector(IOrchardServices services) {
|
|
|
|
|
|
_services = services;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-05-06 12:35:26 +02:00
|
|
|
|
public DashboardDescriptor GetDashboardDescriptor() {
|
2015-05-04 19:40:11 +02:00
|
|
|
|
var settings = _services.WorkContext.CurrentSite.As<DashboardSiteSettingsPart>();
|
|
|
|
|
|
var dashboardId = settings.DefaultDashboardId;
|
|
|
|
|
|
var dashboard = dashboardId != null ? _services.ContentManager.Get(dashboardId.Value) : default(ContentItem);
|
2015-05-06 12:35:26 +02:00
|
|
|
|
var descriptor = new DashboardDescriptor { Priority = -10 };
|
|
|
|
|
|
|
|
|
|
|
|
if (dashboard == null)
|
2015-05-20 01:27:53 +02:00
|
|
|
|
dashboard = CreateDefaultDashboard();
|
|
|
|
|
|
|
|
|
|
|
|
descriptor.Display = shapeFactory => _services.ContentManager.BuildDisplay(dashboard, displayType: "Dashboard");
|
|
|
|
|
|
descriptor.Editor = shapeFactory => _services.ContentManager.BuildEditor(dashboard);
|
|
|
|
|
|
descriptor.UpdateEditor = (shapeFactory, updater) => _services.ContentManager.UpdateEditor(dashboard, updater);
|
2015-05-06 12:35:26 +02:00
|
|
|
|
|
|
|
|
|
|
return descriptor;
|
2015-05-04 19:40:11 +02:00
|
|
|
|
}
|
2015-05-20 01:27:53 +02:00
|
|
|
|
|
|
|
|
|
|
private ContentItem CreateDefaultDashboard() {
|
|
|
|
|
|
var dashboard = _services.ContentManager.Create("Dashboard");
|
|
|
|
|
|
var settings = _services.WorkContext.CurrentSite.As<DashboardSiteSettingsPart>();
|
|
|
|
|
|
var titlePart = dashboard.As<TitlePart>();
|
|
|
|
|
|
var layoutPart = dashboard.As<LayoutPart>();
|
|
|
|
|
|
|
|
|
|
|
|
titlePart.Title = "Welcome to Orchard";
|
|
|
|
|
|
layoutPart.LayoutData = DefaultLayout;
|
|
|
|
|
|
settings.DefaultDashboardId = dashboard.Id;
|
|
|
|
|
|
|
|
|
|
|
|
return dashboard;
|
|
|
|
|
|
}
|
2015-05-04 19:40:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|