mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Working towards definition import/export
Reader and writer mapping definition to infoset Devtools placeholder providing way to see/alter metadata Reader on builder over existing content definition provides merge capabilies on import --HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.DevTools.ViewModels;
|
||||
|
||||
namespace Orchard.DevTools.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class MetadataController : Controller {
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
private readonly IContentDefinitionWriter _contentDefinitionWriter;
|
||||
private readonly IContentDefinitionReader _contentDefinitionReader;
|
||||
|
||||
public MetadataController(
|
||||
IContentDefinitionManager contentDefinitionManager,
|
||||
IContentDefinitionWriter contentDefinitionWriter,
|
||||
IContentDefinitionReader contentDefinitionReader) {
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
_contentDefinitionWriter = contentDefinitionWriter;
|
||||
_contentDefinitionReader = contentDefinitionReader;
|
||||
}
|
||||
|
||||
public ActionResult Index() {
|
||||
var model = new MetadataIndexViewModel {
|
||||
TypeDefinitions = _contentDefinitionManager.ListTypeDefinitions(),
|
||||
PartDefinitions = _contentDefinitionManager.ListPartDefinitions()
|
||||
};
|
||||
var types = new XElement("Types");
|
||||
foreach (var type in model.TypeDefinitions) {
|
||||
types.Add(_contentDefinitionWriter.Export(type));
|
||||
}
|
||||
|
||||
var parts = new XElement("Parts");
|
||||
foreach (var part in model.PartDefinitions) {
|
||||
parts.Add(_contentDefinitionWriter.Export(part));
|
||||
}
|
||||
|
||||
var stringWriter = new StringWriter();
|
||||
using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true, IndentChars = " " })) {
|
||||
if (xmlWriter != null) {
|
||||
new XElement("Orchard", types, parts).WriteTo(xmlWriter);
|
||||
}
|
||||
}
|
||||
model.ExportText = stringWriter.ToString();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Index(MetadataIndexViewModel model) {
|
||||
var root = XElement.Parse(model.ExportText);
|
||||
foreach (var element in root.Elements("Types").Elements()) {
|
||||
var typeElement = element;
|
||||
var typeName = XmlConvert.DecodeName(element.Name.LocalName);
|
||||
_contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration));
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
}
|
@@ -73,6 +73,7 @@
|
||||
<Compile Include="Commands\ProfilingCommands.cs" />
|
||||
<Compile Include="Controllers\ContentController.cs" />
|
||||
<Compile Include="Controllers\HomeController.cs" />
|
||||
<Compile Include="Controllers\MetadataController.cs" />
|
||||
<Compile Include="Handlers\DebugLinkHandler.cs" />
|
||||
<Compile Include="Models\ShowDebugLink.cs" />
|
||||
<Compile Include="Models\Simple.cs" />
|
||||
@@ -80,6 +81,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ViewModels\ContentIndexViewModel.cs" />
|
||||
<Compile Include="ViewModels\ContentDetailsViewModel.cs" />
|
||||
<Compile Include="ViewModels\MetadataIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Module.txt" />
|
||||
@@ -90,6 +92,7 @@
|
||||
<Content Include="Views\Home\Index.aspx" />
|
||||
<Content Include="Views\DisplayTemplates\Parts\DevTools.ShowDebugLink.ascx" />
|
||||
<Content Include="Views\EditorTemplates\Parts\DevTools.ShowDebugLink.ascx" />
|
||||
<Content Include="Views\Metadata\Index.aspx" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
|
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.DevTools.ViewModels {
|
||||
public class MetadataIndexViewModel : BaseViewModel {
|
||||
public IEnumerable<ContentTypeDefinition> TypeDefinitions { get; set; }
|
||||
public IEnumerable<ContentPartDefinition> PartDefinitions { get; set; }
|
||||
public string ExportText { get; set; }
|
||||
}
|
||||
}
|
@@ -2,4 +2,5 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<h1><%=Html.TitleForPage(T("Dev Tools").ToString()) %></h1>
|
||||
<p><%=Html.ActionLink(T("Contents").ToString(), "Index", "Content") %></p>
|
||||
<p><%=Html.ActionLink(T("Metadata").ToString(), "Index", "Metadata") %></p>
|
||||
<p><%=Html.ActionLink(T("Test Unauthorized Request").ToString(), "NotAuthorized", "Home")%></p>
|
||||
|
@@ -0,0 +1,44 @@
|
||||
<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage<MetadataIndexViewModel>" %>
|
||||
|
||||
<%@ Import Namespace="Orchard.DevTools.ViewModels" %>
|
||||
<style title="text/css">
|
||||
ul
|
||||
{
|
||||
margin-left: 12px;
|
||||
}
|
||||
</style>
|
||||
<h1>
|
||||
Metadata</h1>
|
||||
<h2>
|
||||
Content Type Definitions</h2>
|
||||
<ul>
|
||||
<%foreach (var type in Model.TypeDefinitions) {%>
|
||||
<li>
|
||||
<%:type.Name %>
|
||||
<ul>
|
||||
<%foreach (var part in type.Parts) {%>
|
||||
<li>
|
||||
<%:part.PartDefinition.Name %></li>
|
||||
<%
|
||||
}%>
|
||||
</ul>
|
||||
</li>
|
||||
<%
|
||||
}%>
|
||||
</ul>
|
||||
<h2>
|
||||
Content Part Definitions</h2>
|
||||
<ul>
|
||||
<%foreach (var part in Model.PartDefinitions) {%>
|
||||
<li>
|
||||
<%:part.Name %></li>
|
||||
<%
|
||||
}%>
|
||||
</ul>
|
||||
<h2>
|
||||
Exported as xml</h2>
|
||||
<% using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.TextAreaFor(m=>m.ExportText, new{style="width:100%;height:640px;"}) %>
|
||||
<br />
|
||||
<input class="button primaryAction" type="submit" value="<%=_Encoded("Merge Changes") %>" />
|
||||
<%} %>
|
@@ -96,6 +96,7 @@
|
||||
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
|
||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||
<Name>Orchard.Framework</Name>
|
||||
<Private>False</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
@@ -10,6 +10,7 @@ using Orchard.Users.Services;
|
||||
using Orchard.Users.ViewModels;
|
||||
|
||||
namespace Orchard.Users.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class AdminController : Controller, IUpdateModel {
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IUserService _userService;
|
||||
|
Reference in New Issue
Block a user