Added Notifications element.

This commit is contained in:
Sipke Schoorstra
2015-04-19 18:43:27 +02:00
parent eb6285012a
commit 838cd0a99a
7 changed files with 82 additions and 0 deletions

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,8 @@
namespace Orchard.Layouts.Elements {
public class Notifications : UIElement {
public override bool HasEditor {
get { return false; }
}
}
}

View File

@@ -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"; }
}
}
}

View File

@@ -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

View File

@@ -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>

View File

@@ -0,0 +1,4 @@
<div class="layout-placeholder">
<span class="fa fa-circle"></span>
@T("Notifications")
</div>

View File

@@ -0,0 +1,6 @@
@{
var messages = (IEnumerable<dynamic>) Model.Messages;
}
@foreach (var message in messages) {
@Display(message)
}