mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Removed ShapePartRecord and implemented Name property as TitlePart.
This commit is contained in:
@@ -8,7 +8,6 @@ using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Templates.Helpers;
|
||||
using Orchard.Templates.Models;
|
||||
using Orchard.Templates.Services;
|
||||
using Orchard.Templates.ViewModels;
|
||||
@@ -38,14 +37,12 @@ namespace Orchard.Templates.Drivers {
|
||||
|
||||
protected override DriverResult Editor(ShapePart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
var viewModel = new ShapePartViewModel {
|
||||
Name = part.Name,
|
||||
Template = part.Template
|
||||
};
|
||||
|
||||
if (updater != null
|
||||
&& updater.TryUpdateModel(viewModel, Prefix, null, new[] { "AvailableLanguages" })
|
||||
&& ValidateShapeName(viewModel.Name, updater)) {
|
||||
part.Name = viewModel.Name.TrimSafe();
|
||||
&& ValidateShapeName(part, updater)) {
|
||||
part.Template = viewModel.Template;
|
||||
|
||||
try {
|
||||
@@ -62,27 +59,34 @@ namespace Orchard.Templates.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(ShapePart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Name", part.Name);
|
||||
context.Element(part.PartDefinition.Name).Add(new XCData(part.Template));
|
||||
}
|
||||
|
||||
protected override void Importing(ShapePart part, ImportContentContext context) {
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Name", x => part.Name = x);
|
||||
var shapeElement = context.Data.Element(part.PartDefinition.Name);
|
||||
|
||||
if(shapeElement != null)
|
||||
part.Template = shapeElement.Value;
|
||||
}
|
||||
|
||||
private bool ValidateShapeName(string name, IUpdateModel updater) {
|
||||
private bool ValidateShapeName(ShapePart part, IUpdateModel updater) {
|
||||
var titleViewModel = new TitleViewModel();
|
||||
if (!updater.TryUpdateModel(titleViewModel, "Title", null, null))
|
||||
return false;
|
||||
|
||||
var name = titleViewModel.Title;
|
||||
if (!string.IsNullOrWhiteSpace(name) &&
|
||||
name[0].IsLetter() &&
|
||||
name.All(c => c.IsLetter() || Char.IsDigit(c) || c == '.' || c == '-' )) {
|
||||
return true;
|
||||
}
|
||||
|
||||
updater.AddModelError("Name", T("Shape names can only contain alphanumerical, dot (.) or dash (-) characters and have to start with a letter."));
|
||||
updater.AddModelError("Title", T("{0} names can only contain alphanumerical, dot (.) or dash (-) characters and have to start with a letter.", part.ContentItem.TypeDefinition.DisplayName));
|
||||
return false;
|
||||
}
|
||||
|
||||
private class TitleViewModel {
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using Orchard.Caching;
|
||||
using Orchard.Compilation.Razor;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
using Orchard.Templates.Models;
|
||||
using Orchard.Templates.Services;
|
||||
|
||||
@@ -9,12 +8,8 @@ namespace Orchard.Templates.Handlers {
|
||||
public class ShapePartHandler : ContentHandler {
|
||||
private readonly IRazorTemplateHolder _razorTemplateHolder;
|
||||
|
||||
public ShapePartHandler(
|
||||
ISignals signals,
|
||||
IRepository<ShapePartRecord> repository,
|
||||
IRazorTemplateHolder razorTemplateHolder) {
|
||||
public ShapePartHandler(ISignals signals, IRazorTemplateHolder razorTemplateHolder) {
|
||||
_razorTemplateHolder = razorTemplateHolder;
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
|
||||
OnGetContentItemMetadata<ShapePart>((ctx, part) => ctx.Metadata.DisplayText = part.Name);
|
||||
OnUpdated<ShapePart>((ctx, part) => _razorTemplateHolder.Set(part.Name, part.Template));
|
||||
|
||||
@@ -5,10 +5,6 @@ using Orchard.Data.Migration;
|
||||
namespace Orchard.Templates {
|
||||
public class Migrations : DataMigrationImpl {
|
||||
public int Create() {
|
||||
SchemaBuilder.CreateTable("ShapePartRecord", table => table
|
||||
.ContentPartRecord()
|
||||
.Column<string>("Name", c => c.WithLength(100))
|
||||
.Column<string>("Template", c => c.Unlimited()));
|
||||
|
||||
ContentDefinitionManager.AlterPartDefinition("ShapePart", part => part
|
||||
.Attachable()
|
||||
@@ -17,6 +13,7 @@ namespace Orchard.Templates {
|
||||
ContentDefinitionManager.AlterTypeDefinition("Template", type => type
|
||||
.WithPart("CommonPart")
|
||||
.WithPart("IdentityPart")
|
||||
.WithPart("TitlePart")
|
||||
.WithPart("ShapePart", p => p
|
||||
.WithSetting("ShapePartSettings.Processor", "Razor"))
|
||||
.Draftable());
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Templates.Settings;
|
||||
|
||||
namespace Orchard.Templates.Models {
|
||||
public class ShapePart : ContentPart<ShapePartRecord> {
|
||||
public class ShapePart : ContentPart {
|
||||
public string Name {
|
||||
get { return Retrieve(x => x.Name); }
|
||||
set { Store(x => x.Name, value); }
|
||||
get { return this.As<ITitleAspect>().Title; }
|
||||
}
|
||||
|
||||
public string ProcessorName {
|
||||
@@ -13,8 +13,8 @@ namespace Orchard.Templates.Models {
|
||||
}
|
||||
|
||||
public string Template {
|
||||
get { return Retrieve(x => x.Template); }
|
||||
set { Store(x => x.Template, value); }
|
||||
get { return this.Retrieve(x => x.Template); }
|
||||
set { this.Store(x => x.Template, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.Templates.Models {
|
||||
public class ShapePartRecord : ContentPartRecord {
|
||||
public virtual string Name { get; set; }
|
||||
|
||||
[StringLengthMax]
|
||||
public virtual string Template { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,6 @@
|
||||
<Compile Include="Drivers\ShapePartDriver.cs" />
|
||||
<Compile Include="Models\ShapePart.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Models\ShapePartRecord.cs" />
|
||||
<Compile Include="Services\ITemplateProcessor.cs" />
|
||||
<Compile Include="Services\ITemplateService.cs" />
|
||||
<Compile Include="Services\TemplateProcessorImpl.cs" />
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Orchard.Templates.ViewModels {
|
||||
namespace Orchard.Templates.ViewModels {
|
||||
public class ShapePartViewModel {
|
||||
[StringLength(100)]
|
||||
public string Name { get; set; }
|
||||
public string Template { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,6 @@
|
||||
Script.Include("codemirror/mode/htmlembedded/htmlembedded.js");
|
||||
Script.Include("template-editor.js", "template-editor.min.js");
|
||||
}
|
||||
<fieldset>
|
||||
<div>
|
||||
@Html.LabelFor(m => m.Name, T("Name"))
|
||||
@Html.TextBoxFor(m => m.Name, new { @class = "text medium" })
|
||||
<span class="hint">@T("The name of this template, which can be used to reference from code (as when using shape type names) and tokens.")</span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div>
|
||||
@Html.TextAreaFor(m => m.Template, new { @class = "text large code-editor" })
|
||||
|
||||
Reference in New Issue
Block a user