Added part creation and tidied up the content type management flow a little

- could make use of a redirectUrl for a little better experience

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-07-02 16:07:43 -07:00
parent 5214c80cdf
commit d892e88d09
9 changed files with 72 additions and 22 deletions

View File

@@ -57,9 +57,9 @@ namespace Orchard.ContentTypes.Controllers {
if (!ModelState.IsValid) if (!ModelState.IsValid)
return View(viewModel); return View(viewModel);
_contentDefinitionService.AddTypeDefinition(viewModel.DisplayName); var definition = _contentDefinitionService.AddTypeDefinition(viewModel.DisplayName);
return RedirectToAction("Index"); return RedirectToAction("Edit", new { id = definition.Name });
} }
public ActionResult Edit(string id) { public ActionResult Edit(string id) {
@@ -288,6 +288,26 @@ namespace Orchard.ContentTypes.Controllers {
}); });
} }
public ActionResult CreatePart() {
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content part.")))
return new HttpUnauthorizedResult();
return View(new CreatePartViewModel());
}
[HttpPost, ActionName("CreatePart")]
public ActionResult CreatePartPOST(CreatePartViewModel viewModel) {
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content part.")))
return new HttpUnauthorizedResult();
if (!ModelState.IsValid)
return View(viewModel);
var definition = _contentDefinitionService.AddPartDefinition(viewModel.Name);
return RedirectToAction("EditPart", new { id = definition.Name });
}
public ActionResult EditPart(string id) { public ActionResult EditPart(string id) {
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part."))) if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -325,7 +345,7 @@ namespace Orchard.ContentTypes.Controllers {
return View(viewModel); return View(viewModel);
} }
return RedirectToAction("Index"); return RedirectToAction("ListParts");
} }
public ActionResult AddFieldTo(string id) { public ActionResult AddFieldTo(string id) {

View File

@@ -77,6 +77,7 @@
<Compile Include="Services\ContentDefinitionService.cs" /> <Compile Include="Services\ContentDefinitionService.cs" />
<Compile Include="Services\IContentDefinitionService.cs" /> <Compile Include="Services\IContentDefinitionService.cs" />
<Compile Include="ViewModels\AddFieldViewModel.cs" /> <Compile Include="ViewModels\AddFieldViewModel.cs" />
<Compile Include="ViewModels\CreatePartViewModel.cs" />
<Compile Include="ViewModels\ListContentPartsViewModel.cs" /> <Compile Include="ViewModels\ListContentPartsViewModel.cs" />
<Compile Include="ViewModels\RemoveFieldViewModel.cs" /> <Compile Include="ViewModels\RemoveFieldViewModel.cs" />
<Compile Include="ViewModels\RemovePartViewModel.cs" /> <Compile Include="ViewModels\RemovePartViewModel.cs" />
@@ -90,6 +91,7 @@
<Content Include="Styles\admin.css" /> <Content Include="Styles\admin.css" />
<Content Include="Views\Admin\AddFieldTo.ascx" /> <Content Include="Views\Admin\AddFieldTo.ascx" />
<Content Include="Views\Admin\AddPartsTo.ascx" /> <Content Include="Views\Admin\AddPartsTo.ascx" />
<Content Include="Views\Admin\CreatePart.ascx" />
<Content Include="Views\Admin\ListParts.ascx" /> <Content Include="Views\Admin\ListParts.ascx" />
<Content Include="Views\Admin\RemoveFieldFrom.ascx" /> <Content Include="Views\Admin\RemoveFieldFrom.ascx" />
<Content Include="Views\Admin\RemovePartFrom.ascx" /> <Content Include="Views\Admin\RemovePartFrom.ascx" />

View File

@@ -31,21 +31,24 @@ namespace Orchard.ContentTypes.Services {
return _contentDefinitionManager.GetTypeDefinition(name); return _contentDefinitionManager.GetTypeDefinition(name);
} }
public void AddTypeDefinition(string displayName) { public ContentTypeDefinition AddTypeDefinition(string displayName) {
var name = GenerateTypeName(displayName); var name = GenerateName(displayName);
while (_contentDefinitionManager.GetTypeDefinition(name) != null) while (_contentDefinitionManager.GetTypeDefinition(name) != null)
name = VersionTypeName(name); name = VersionName(name);
var contentTypeDefinition = new ContentTypeDefinition(name) { DisplayName = displayName };
//just giving the new type some default parts for now //just giving the new type some default parts for now
_contentDefinitionManager.StoreTypeDefinition(new ContentTypeDefinition(name) {DisplayName = displayName}); _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition);
_contentDefinitionManager.AlterTypeDefinition( _contentDefinitionManager.AlterTypeDefinition(
name, contentTypeDefinition.Name,
cfg => cfg.WithPart("CommonAspect") cfg => cfg.WithPart("CommonAspect")
//.WithPart("RoutableAspect") //need to go the new routable route //.WithPart("RoutableAspect") //need to go the new routable route
.WithPart("BodyAspect")); .WithPart("BodyAspect"));
Services.Notifier.Information(T("The \"{0}\" content type has created.", displayName)); Services.Notifier.Information(T("The \"{0}\" content type has created.", contentTypeDefinition.DisplayName));
return contentTypeDefinition;
} }
public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) { public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) {
@@ -70,8 +73,16 @@ namespace Orchard.ContentTypes.Services {
return _contentDefinitionManager.GetPartDefinition(name); return _contentDefinitionManager.GetPartDefinition(name);
} }
public void AddPartDefinition(ContentPartDefinition contentPartDefinition) { public ContentPartDefinition AddPartDefinition(string name) {
throw new NotImplementedException(); name = GenerateName(name);
while (_contentDefinitionManager.GetPartDefinition(name) != null)
name = VersionName(name);
var contentPartDefinition = new ContentPartDefinition(name);
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
return contentPartDefinition;
} }
public void AlterPartDefinition(ContentPartDefinition contentPartDefinition) { public void AlterPartDefinition(ContentPartDefinition contentPartDefinition) {
@@ -87,7 +98,7 @@ namespace Orchard.ContentTypes.Services {
} }
//gratuitously stolen from the RoutableService //gratuitously stolen from the RoutableService
private static string GenerateTypeName(string displayName) { private static string GenerateName(string displayName) {
if (string.IsNullOrWhiteSpace(displayName)) if (string.IsNullOrWhiteSpace(displayName))
return ""; return "";
@@ -104,7 +115,7 @@ namespace Orchard.ContentTypes.Services {
return name.ToLowerInvariant(); return name.ToLowerInvariant();
} }
private static string VersionTypeName(string name) { private static string VersionName(string name) {
int version; int version;
var nameParts = name.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries); var nameParts = name.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);

View File

@@ -6,13 +6,13 @@ namespace Orchard.ContentTypes.Services {
public interface IContentDefinitionService : IDependency { public interface IContentDefinitionService : IDependency {
IEnumerable<ContentTypeDefinition> GetTypeDefinitions(); IEnumerable<ContentTypeDefinition> GetTypeDefinitions();
ContentTypeDefinition GetTypeDefinition(string name); ContentTypeDefinition GetTypeDefinition(string name);
void AddTypeDefinition(string displayName); ContentTypeDefinition AddTypeDefinition(string displayName);
void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition); void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition);
void RemoveTypeDefinition(string name); void RemoveTypeDefinition(string name);
IEnumerable<ContentPartDefinition> GetPartDefinitions(); IEnumerable<ContentPartDefinition> GetPartDefinitions();
ContentPartDefinition GetPartDefinition(string name); ContentPartDefinition GetPartDefinition(string name);
void AddPartDefinition(ContentPartDefinition contentPartDefinition); ContentPartDefinition AddPartDefinition(string name);
void AlterPartDefinition(ContentPartDefinition contentPartDefinition); void AlterPartDefinition(ContentPartDefinition contentPartDefinition);
void RemovePartDefinition(string name); void RemovePartDefinition(string name);

View File

@@ -0,0 +1,7 @@
using Orchard.Mvc.ViewModels;
namespace Orchard.ContentTypes.ViewModels {
public class CreatePartViewModel : BaseViewModel {
public string Name { get; set; }
}
}

View File

@@ -1,5 +1,4 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.CreateTypeViewModel>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.CreateTypeViewModel>" %>
<h1><%:Html.TitleForPage(T("New Content Type").ToString())%></h1><% <h1><%:Html.TitleForPage(T("New Content Type").ToString())%></h1><%
using (Html.BeginFormAntiForgeryPost()) { %> using (Html.BeginFormAntiForgeryPost()) { %>
<%:Html.ValidationSummary() %> <%:Html.ValidationSummary() %>

View File

@@ -0,0 +1,12 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.CreatePartViewModel>" %>
<h1><%:Html.TitleForPage(T("New Content Part").ToString())%></h1><%
using (Html.BeginFormAntiForgeryPost()) { %>
<%:Html.ValidationSummary() %>
<fieldset>
<label for="DisplayName"><%:T("Name") %></label>
<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium", autofocus = "autofocus"}) %>
</fieldset>
<fieldset>
<button class="primaryAction" type="submit"><%:T("Create") %></button>
</fieldset><%
} %>

View File

@@ -1,14 +1,14 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditPartViewModel>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditPartViewModel>" %>
<% <% Html.RegisterStyle("admin.css"); %>
Html.RegisterStyle("admin.css"); %>
<h1><%:Html.TitleForPage(T("Edit Part").ToString()) %></h1> <h1><%:Html.TitleForPage(T("Edit Part").ToString()) %></h1>
<p class="breadcrumb"><%:Html.ActionLink(T("Content Types").Text, "index") %><%:T(" &#62; ") %><%:T("Edit Part") %></p><% <p class="breadcrumb"><%:Html.ActionLink(T("Content Types").Text, "index") %><%:T(" &#62; ") %><%:Html.ActionLink(T("Content Parts").Text, "listparts") %><%:T(" &#62; ") %><%:T("Edit Part") %></p><%
using (Html.BeginFormAntiForgeryPost()) { %> using (Html.BeginFormAntiForgeryPost()) { %>
<%:Html.ValidationSummary() %> <%:Html.ValidationSummary() %>
<fieldset> <fieldset>
<label for="Name"><%:T("Name") %></label> <label for="Name"><%:T("Name") %></label>
<%--// has unintended consequences (renamging the part) - changing the name creates a new part of that name--%> <%--// has unintended consequences (renamging the part) - changing the name creates a new part of that name--%>
<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium"}) %> <%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium", disabled = "disabled"}) %>
<%:Html.HiddenFor(m => m.Name) %>
</fieldset> </fieldset>
<% Html.RenderTemplates(Model.Templates); %> <% Html.RenderTemplates(Model.Templates); %>
<h2><%:T("Fields") %></h2> <h2><%:T("Fields") %></h2>

View File

@@ -1,6 +1,5 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.ListContentTypesViewModel>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.ListContentTypesViewModel>" %>
<% <% Html.RegisterStyle("admin.css"); %>
Html.RegisterStyle("admin.css"); %>
<h1><%:Html.TitleForPage(T("Content Types").ToString())%></h1> <h1><%:Html.TitleForPage(T("Content Types").ToString())%></h1>
<div class="manage"> <div class="manage">
<%:Html.ActionLink(T("Create new type").ToString(), "Create", new{Controller="Admin",Area="Orchard.ContentTypes"}, new { @class = "button primaryAction" }) %> <%:Html.ActionLink(T("Create new type").ToString(), "Create", new{Controller="Admin",Area="Orchard.ContentTypes"}, new { @class = "button primaryAction" }) %>