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)
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) {
@@ -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) {
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
return new HttpUnauthorizedResult();
@@ -325,7 +345,7 @@ namespace Orchard.ContentTypes.Controllers {
return View(viewModel);
}
return RedirectToAction("Index");
return RedirectToAction("ListParts");
}
public ActionResult AddFieldTo(string id) {

View File

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

View File

@@ -31,21 +31,24 @@ namespace Orchard.ContentTypes.Services {
return _contentDefinitionManager.GetTypeDefinition(name);
}
public void AddTypeDefinition(string displayName) {
var name = GenerateTypeName(displayName);
public ContentTypeDefinition AddTypeDefinition(string displayName) {
var name = GenerateName(displayName);
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
_contentDefinitionManager.StoreTypeDefinition(new ContentTypeDefinition(name) {DisplayName = displayName});
_contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition);
_contentDefinitionManager.AlterTypeDefinition(
name,
contentTypeDefinition.Name,
cfg => cfg.WithPart("CommonAspect")
//.WithPart("RoutableAspect") //need to go the new routable route
.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) {
@@ -70,8 +73,16 @@ namespace Orchard.ContentTypes.Services {
return _contentDefinitionManager.GetPartDefinition(name);
}
public void AddPartDefinition(ContentPartDefinition contentPartDefinition) {
throw new NotImplementedException();
public ContentPartDefinition AddPartDefinition(string name) {
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) {
@@ -87,7 +98,7 @@ namespace Orchard.ContentTypes.Services {
}
//gratuitously stolen from the RoutableService
private static string GenerateTypeName(string displayName) {
private static string GenerateName(string displayName) {
if (string.IsNullOrWhiteSpace(displayName))
return "";
@@ -104,7 +115,7 @@ namespace Orchard.ContentTypes.Services {
return name.ToLowerInvariant();
}
private static string VersionTypeName(string name) {
private static string VersionName(string name) {
int version;
var nameParts = name.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);

View File

@@ -6,13 +6,13 @@ namespace Orchard.ContentTypes.Services {
public interface IContentDefinitionService : IDependency {
IEnumerable<ContentTypeDefinition> GetTypeDefinitions();
ContentTypeDefinition GetTypeDefinition(string name);
void AddTypeDefinition(string displayName);
ContentTypeDefinition AddTypeDefinition(string displayName);
void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition);
void RemoveTypeDefinition(string name);
IEnumerable<ContentPartDefinition> GetPartDefinitions();
ContentPartDefinition GetPartDefinition(string name);
void AddPartDefinition(ContentPartDefinition contentPartDefinition);
ContentPartDefinition AddPartDefinition(string name);
void AlterPartDefinition(ContentPartDefinition contentPartDefinition);
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>" %>
<h1><%:Html.TitleForPage(T("New Content Type").ToString())%></h1><%
using (Html.BeginFormAntiForgeryPost()) { %>
<%: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>" %>
<%
Html.RegisterStyle("admin.css"); %>
<% Html.RegisterStyle("admin.css"); %>
<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()) { %>
<%:Html.ValidationSummary() %>
<fieldset>
<label for="Name"><%:T("Name") %></label>
<%--// 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>
<% Html.RenderTemplates(Model.Templates); %>
<h2><%:T("Fields") %></h2>

View File

@@ -1,6 +1,5 @@
<%@ 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>
<div class="manage">
<%:Html.ActionLink(T("Create new type").ToString(), "Create", new{Controller="Admin",Area="Orchard.ContentTypes"}, new { @class = "button primaryAction" }) %>