mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 03:40:56 +08:00
Incremental work on Dashboards.
This commit is contained in:
@@ -1,10 +1,17 @@
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Orchard.Dashboards.Services;
|
||||||
|
using Orchard.Mvc;
|
||||||
|
|
||||||
namespace Orchard.Dashboards.Controllers {
|
namespace Orchard.Dashboards.Controllers {
|
||||||
public class AdminController : Controller {
|
public class AdminController : Controller {
|
||||||
|
private readonly IDashboardService _dashboardService;
|
||||||
|
public AdminController(IDashboardService dashboardService) {
|
||||||
|
_dashboardService = dashboardService;
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult Index() {
|
public ActionResult Index() {
|
||||||
return View();
|
var shape = _dashboardService.GetDashboardShape();
|
||||||
|
return new ShapeResult(this, shape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ using Orchard.ContentManagement.Drivers;
|
|||||||
using Orchard.Dashboards.Models;
|
using Orchard.Dashboards.Models;
|
||||||
using Orchard.Dashboards.ViewModels;
|
using Orchard.Dashboards.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Dashboards.Elements {
|
namespace Orchard.Dashboards.Drivers {
|
||||||
public class DashboardSiteSettingsPartDriver : ContentPartDriver<DashboardSiteSettingsPart> {
|
public class DashboardSiteSettingsPartDriver : ContentPartDriver<DashboardSiteSettingsPart> {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ namespace Orchard.Dashboards.Elements {
|
|||||||
protected override DriverResult Editor(DashboardSiteSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
protected override DriverResult Editor(DashboardSiteSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
return ContentShape("Parts_DashboardSettings", () => {
|
return ContentShape("Parts_DashboardSettings", () => {
|
||||||
var viewModel = new DashboardSiteSettingsViewModel {
|
var viewModel = new DashboardSiteSettingsViewModel {
|
||||||
SelectedDashboardId = part.DefaultDashboardId.ToString(),
|
SelectedDashboardId = part.DefaultDashboardId.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (updater != null) {
|
if (updater != null) {
|
||||||
File diff suppressed because one or more lines are too long
@@ -68,12 +68,15 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Placement.info" />
|
<None Include="Placement.info" />
|
||||||
|
<Content Include="Styles\Dashboard.css" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Content Include="Scripts\Web.config" />
|
<Content Include="Scripts\Web.config" />
|
||||||
<Content Include="Styles\Web.config" />
|
<Content Include="Styles\Web.config" />
|
||||||
<Content Include="Properties\AssemblyInfo.cs" />
|
<Content Include="Properties\AssemblyInfo.cs" />
|
||||||
<Content Include="Module.txt" />
|
<Content Include="Module.txt" />
|
||||||
<Content Include="Views\EditorTemplates\Parts.DashboardSettings.cshtml" />
|
<Content Include="Views\EditorTemplates\Parts.DashboardSettings.cshtml" />
|
||||||
|
<Content Include="Views\StaticDashboard.cshtml" />
|
||||||
|
<Content Include="Views\Content.Dashboard.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
|
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
|
||||||
@@ -89,21 +92,19 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
<Compile Include="Elements\DashboardSiteSettingsPartDriver.cs" />
|
<Compile Include="Drivers\DashboardSiteSettingsPartDriver.cs" />
|
||||||
<Compile Include="Handlers\DashboardSiteSettingsPartHandler.cs" />
|
<Compile Include="Handlers\DashboardSiteSettingsPartHandler.cs" />
|
||||||
<Compile Include="Migrations.cs" />
|
<Compile Include="Migrations.cs" />
|
||||||
|
<Compile Include="Services\IDashboardService.cs" />
|
||||||
<Compile Include="ViewModels\DashboardSiteSettingsViewModel.cs" />
|
<Compile Include="ViewModels\DashboardSiteSettingsViewModel.cs" />
|
||||||
<Compile Include="Models\DashboardSiteSettingsPart.cs" />
|
<Compile Include="Models\DashboardSiteSettingsPart.cs" />
|
||||||
<Compile Include="Routes.cs" />
|
<Compile Include="Routes.cs" />
|
||||||
<Compile Include="Services\DashboardSelectorResult.cs" />
|
<Compile Include="Services\DashboardDescriptor.cs" />
|
||||||
<Compile Include="Services\DefaultDashboardSelector.cs" />
|
<Compile Include="Services\DefaultDashboardSelector.cs" />
|
||||||
<Compile Include="Services\IDashboardSelector.cs" />
|
<Compile Include="Services\IDashboardSelector.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Drivers\" />
|
<Folder Include="Elements\" />
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="Views\Admin\Index.cshtml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
<Placement>
|
<Placement>
|
||||||
<Place Parts_DashboardSettings="Content:0" />
|
<Place Parts_DashboardSettings="Content:0" />
|
||||||
|
<Match DisplayType="Dashboard">
|
||||||
|
<Place
|
||||||
|
Parts_Common_Body="Content:0"
|
||||||
|
Parts_Common_Body_Summary="-"
|
||||||
|
Parts_Layout="Content:1" />
|
||||||
|
</Match>
|
||||||
</Placement>
|
</Placement>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Orchard.Dashboards.Services {
|
||||||
|
public class DashboardDescriptor {
|
||||||
|
public int Priority { get; set; }
|
||||||
|
public Func<dynamic, dynamic> DashboardFactory { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using Orchard.ContentManagement;
|
|
||||||
|
|
||||||
namespace Orchard.Dashboards.Services {
|
|
||||||
public class DashboardSelectorResult {
|
|
||||||
public int Priority { get; set; }
|
|
||||||
public IContent Dashboard { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.Dashboards.Models;
|
using Orchard.Dashboards.Models;
|
||||||
|
|
||||||
namespace Orchard.Dashboards.Services {
|
namespace Orchard.Dashboards.Services {
|
||||||
@@ -9,10 +8,18 @@ namespace Orchard.Dashboards.Services {
|
|||||||
_services = services;
|
_services = services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DashboardSelectorResult GetDashboard() {
|
public DashboardDescriptor GetDashboardDescriptor() {
|
||||||
var settings = _services.WorkContext.CurrentSite.As<DashboardSiteSettingsPart>();
|
var settings = _services.WorkContext.CurrentSite.As<DashboardSiteSettingsPart>();
|
||||||
var dashboardId = settings.DefaultDashboardId;
|
var dashboardId = settings.DefaultDashboardId;
|
||||||
var dashboard = dashboardId != null ? _services.ContentManager.Get(dashboardId.Value) : default(ContentItem);
|
var dashboard = dashboardId != null ? _services.ContentManager.Get(dashboardId.Value) : default(ContentItem);
|
||||||
|
var descriptor = new DashboardDescriptor { Priority = -10 };
|
||||||
|
|
||||||
|
if (dashboard == null)
|
||||||
|
descriptor.DashboardFactory = shapeFactory => shapeFactory.StaticDashboard();
|
||||||
|
else
|
||||||
|
descriptor.DashboardFactory = shapeFactory => _services.ContentManager.BuildDisplay(dashboard, displayType: "Dashboard");
|
||||||
|
|
||||||
|
return descriptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Orchard.Dashboards.Services {
|
namespace Orchard.Dashboards.Services {
|
||||||
public interface IDashboardSelector : IDependency {
|
public interface IDashboardSelector : IDependency {
|
||||||
DashboardSelectorResult GetDashboard();
|
DashboardDescriptor GetDashboardDescriptor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
|
||||||
|
namespace Orchard.Dashboards.Services {
|
||||||
|
public interface IDashboardService : IDependency {
|
||||||
|
dynamic GetDashboardShape();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DashboardService : IDashboardService {
|
||||||
|
private readonly Lazy<IEnumerable<IDashboardSelector>> _selectors;
|
||||||
|
private readonly IShapeFactory _shapeFactory;
|
||||||
|
|
||||||
|
public DashboardService(Lazy<IEnumerable<IDashboardSelector>> selectors, IShapeFactory shapeFactory) {
|
||||||
|
_selectors = selectors;
|
||||||
|
_shapeFactory = shapeFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public dynamic GetDashboardShape() {
|
||||||
|
var selectorQuery =
|
||||||
|
from selector in _selectors.Value
|
||||||
|
let descriptor = selector.GetDashboardDescriptor()
|
||||||
|
orderby descriptor.Priority descending
|
||||||
|
select descriptor;
|
||||||
|
|
||||||
|
var result = selectorQuery.First();
|
||||||
|
var factory = result.DashboardFactory ?? (shapeFactory => shapeFactory.StaticDashboard());
|
||||||
|
var shape = factory(_shapeFactory);
|
||||||
|
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
.dashboard h2 {
|
||||||
|
font-size: 16px;
|
||||||
|
background: #f1f1f2;
|
||||||
|
line-height: 2em;
|
||||||
|
padding: 0 20px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
@using Orchard.ContentManagement
|
||||||
|
@{
|
||||||
|
Style.Include("Dashboard.css");
|
||||||
|
}
|
||||||
|
@{
|
||||||
|
var contentItem = (ContentItem)Model.ContentItem;
|
||||||
|
var title = Html.ItemDisplayText(contentItem);
|
||||||
|
|
||||||
|
Layout.Title = title;
|
||||||
|
}
|
||||||
|
<article class="content-item dashboard">
|
||||||
|
@Display(Model.Content)
|
||||||
|
</article>
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
@Display.ContentPicker_Edit(
|
@Display.ContentPicker_Edit(
|
||||||
DisplayName: T("Default Dashboard").Text,
|
DisplayName: T("Default Dashboard").Text,
|
||||||
SelectedItemsFieldName: Html.FieldNameFor(m => m.SelectedDashboardId),
|
SelectedItemsFieldName: Html.FieldNameFor(m => m.SelectedDashboardId),
|
||||||
ContentItems: Model.SelectedDashboard != null ? new[] { Model.SelectedDashboard } : Enumerable.Empty<ContentItem>(),
|
ContentItems: Model.SelectedDashboard != null ? new[] {Model.SelectedDashboard} : Enumerable.Empty<ContentItem>(),
|
||||||
Hint: T("Select the content item to use as the dashboard.").Text)
|
Hint: T("Select the content item to use as the dashboard.").Text)
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
@model dynamic
|
@{ Layout.Title = T("Welcome to Orchard").ToString(); }
|
||||||
@{ Layout.Title = T("Welcome to my Custom Dashboard").ToString(); }
|
|
||||||
<section class="dashboard group">
|
<section class="dashboard group">
|
||||||
<div class="help-item">
|
<div class="help-item">
|
||||||
<h2 class="start">@T("Get up and running")</h2>
|
<h2 class="start">@T("Get up and running")</h2>
|
||||||
Reference in New Issue
Block a user