mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Added Notifications element.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Layouts.Elements;
|
||||
using Orchard.Layouts.Framework.Display;
|
||||
using Orchard.Layouts.Framework.Drivers;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Layouts.Drivers {
|
||||
[OrchardFeature("Orchard.Layouts.UI")]
|
||||
public class NotificationsElementDriver : ElementDriver<Notifications> {
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
public NotificationsElementDriver(IHttpContextAccessor httpContextAccessor, IShapeFactory shapeFactory) {
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
New = shapeFactory;
|
||||
}
|
||||
|
||||
public dynamic New { get; set; }
|
||||
|
||||
protected override void OnCreatingDisplay(Notifications element, ElementCreatingDisplayShapeContext context) {
|
||||
var httpContext = _httpContextAccessor.Current();
|
||||
var messageEntries = httpContext.Items[NotifyFilter.TempDataMessages] as IList<NotifyEntry> ?? new List<NotifyEntry>();
|
||||
|
||||
context.Cancel = !messageEntries.Any();
|
||||
}
|
||||
|
||||
protected override void OnDisplaying(Notifications element, ElementDisplayingContext context) {
|
||||
var httpContext = _httpContextAccessor.Current();
|
||||
var messageEntries = httpContext.Items[NotifyFilter.TempDataMessages] as IList<NotifyEntry> ?? new List<NotifyEntry>();
|
||||
var shapes = messageEntries.Select(x => New.Message(x)).ToList();
|
||||
|
||||
context.ElementShape.Messages = shapes;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
namespace Orchard.Layouts.Elements {
|
||||
public class Notifications : UIElement {
|
||||
|
||||
public override bool HasEditor {
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
using Orchard.Layouts.Framework.Elements;
|
||||
|
||||
namespace Orchard.Layouts.Elements {
|
||||
public abstract class UIElement : Element {
|
||||
public override string Category {
|
||||
get { return "UI"; }
|
||||
}
|
||||
|
||||
public override string ToolboxIcon {
|
||||
get { return "\uf0c8"; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,3 +32,8 @@ Features:
|
||||
Description: Provides an element token provider that enables elements to be rendered using a token and enables tokens to be used inside of various elements such as Html, Text and Paragraph.
|
||||
Category: Layout
|
||||
Dependencies: Orchard.Layouts, Orchard.Tokens
|
||||
Orchard.Layouts.UI:
|
||||
Name: UI Elements
|
||||
Description: Adds UI elements to the system, such as Notifications and Menu.
|
||||
Category: Layout
|
||||
Dependencies: Orchard.Layouts
|
@@ -423,10 +423,13 @@
|
||||
<Compile Include="Controllers\BlueprintAdminController.cs" />
|
||||
<Compile Include="Controllers\TemplateController.cs" />
|
||||
<Compile Include="Drivers\CanvasElementDriver.cs" />
|
||||
<Compile Include="Drivers\NotificationsElementDriver.cs" />
|
||||
<Compile Include="Drivers\ShapeElementDriver.cs" />
|
||||
<Compile Include="Elements\Canvas.cs" />
|
||||
<Compile Include="Elements\ContentElement.cs" />
|
||||
<Compile Include="Elements\Notifications.cs" />
|
||||
<Compile Include="Elements\Shape.cs" />
|
||||
<Compile Include="Elements\UIElement.cs" />
|
||||
<Compile Include="Filters\TokensFilter.cs" />
|
||||
<Compile Include="Framework\Display\ElementDisplayedContext.cs" />
|
||||
<Compile Include="Framework\Drivers\ImportContentContextWrapper.cs" />
|
||||
@@ -625,6 +628,12 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\LayoutEditor.Template.Rule.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Elements\Notifications.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Elements\Notifications.Design.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
@@ -0,0 +1,4 @@
|
||||
<div class="layout-placeholder">
|
||||
<span class="fa fa-circle"></span>
|
||||
@T("Notifications")
|
||||
</div>
|
@@ -0,0 +1,6 @@
|
||||
@{
|
||||
var messages = (IEnumerable<dynamic>) Model.Messages;
|
||||
}
|
||||
@foreach (var message in messages) {
|
||||
@Display(message)
|
||||
}
|
Reference in New Issue
Block a user