mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -7,15 +7,14 @@ namespace Orchard.Core.Common.DataMigrations {
|
||||
public int Create() {
|
||||
//CREATE TABLE Common_BodyRecord (Id INTEGER not null, Text TEXT, Format TEXT, ContentItemRecord_id INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("BodyRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartVersionRecord()
|
||||
.Column<string>("Text")
|
||||
.Column<string>("Format")
|
||||
.Column<int>("ContentItemRecord_id")
|
||||
);
|
||||
|
||||
//CREATE TABLE Common_CommonRecord (Id INTEGER not null, OwnerId INTEGER, CreatedUtc DATETIME, PublishedUtc DATETIME, ModifiedUtc DATETIME, Container_id INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("CommonRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<int>("OwnerId")
|
||||
.Column<DateTime>("CreatedUtc")
|
||||
.Column<DateTime>("PublishedUtc")
|
||||
@@ -25,20 +24,18 @@ namespace Orchard.Core.Common.DataMigrations {
|
||||
|
||||
//CREATE TABLE Common_CommonVersionRecord (Id INTEGER not null, CreatedUtc DATETIME, PublishedUtc DATETIME, ModifiedUtc DATETIME, ContentItemRecord_id INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("CommonVersionRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartVersionRecord()
|
||||
.Column<DateTime>("CreatedUtc")
|
||||
.Column<DateTime>("PublishedUtc")
|
||||
.Column<DateTime>("ModifiedUtc")
|
||||
.Column<int>("ContentItemRecord_id")
|
||||
);
|
||||
|
||||
//CREATE TABLE Common_RoutableRecord (Id INTEGER not null, Title TEXT, Slug TEXT, Path TEXT, ContentItemRecord_id INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("RoutableRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartVersionRecord()
|
||||
.Column<string>("Title")
|
||||
.Column<string>("Slug")
|
||||
.Column<string>("Path")
|
||||
.Column<int>("ContentItemRecord_id")
|
||||
);
|
||||
|
||||
return 0010;
|
||||
|
@@ -6,7 +6,7 @@ namespace Orchard.Core.Localization.DataMigrations {
|
||||
public int Create() {
|
||||
//CREATE TABLE Localization_LocalizedRecord (Id INTEGER not null, CultureId INTEGER, MasterContentItemId INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("LocalizedRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<int>("CultureId")
|
||||
.Column<int>("MasterContentItemId")
|
||||
);
|
||||
|
@@ -6,13 +6,13 @@ namespace Orchard.Core.Navigation.DataMigrations {
|
||||
public int Create() {
|
||||
//CREATE TABLE Navigation_MenuItemRecord (Id INTEGER not null, Url TEXT, primary key (Id));
|
||||
SchemaBuilder.CreateTable("MenuItemRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("Url")
|
||||
);
|
||||
|
||||
//CREATE TABLE Navigation_MenuPartRecord (Id INTEGER not null, MenuText TEXT, MenuPosition TEXT, OnMainMenu INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("MenuPartRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("MenuText")
|
||||
.Column<string>("MenuPosition")
|
||||
.Column<bool>("OnMainMenu")
|
||||
|
@@ -82,7 +82,7 @@ namespace Orchard.Core.Settings.DataMigrations {
|
||||
|
||||
//CREATE TABLE Settings_SiteSettingsRecord (Id INTEGER not null, SiteSalt TEXT, SiteName TEXT, SuperUser TEXT, PageTitleSeparator TEXT, HomePage TEXT, SiteCulture TEXT, primary key (Id));
|
||||
SchemaBuilder.CreateTable("SiteSettingsRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("SiteSalt")
|
||||
.Column<string>("SiteName")
|
||||
.Column<string>("SuperUser")
|
||||
|
@@ -86,6 +86,7 @@ namespace Orchard.Core.Settings.Metadata {
|
||||
}
|
||||
|
||||
private void Apply(ContentTypeDefinition model, ContentTypeDefinitionRecord record) {
|
||||
record.DisplayName = model.DisplayName;
|
||||
record.Settings = _settingsWriter.Map(model.Settings).ToString();
|
||||
|
||||
var toRemove = record.ContentTypePartDefinitionRecords
|
||||
|
@@ -1,5 +1,6 @@
|
||||
.site-cultures {
|
||||
font-size:1.2em;
|
||||
font-size:1.4em;
|
||||
line-height:1.8em;
|
||||
overflow:auto;
|
||||
}
|
||||
.site-cultures li {
|
||||
@@ -14,5 +15,5 @@
|
||||
}
|
||||
.site-cultures div {
|
||||
float:left;
|
||||
width:6em;
|
||||
width:8em;
|
||||
}
|
@@ -1,18 +1,19 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SiteCulturesViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Settings.ViewModels" %><%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Supported Cultures").ToString()) %></h1>
|
||||
<h1><%:Html.TitleForPage(T("Cultures").ToString()) %></h1>
|
||||
<p class="breadcrumb"><%:Html.ActionLink(T("Manage Settings").Text, "index") %><%:T(" > ") %><%:T("Supported Cultures")%></p>
|
||||
<h2><%:T("Cultures this site supports") %></h2>
|
||||
<h3><%:T("Available Cultures") %></h3>
|
||||
<% using (Html.BeginFormAntiForgeryPost("AddCulture")) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
<fieldset class="addCulture">
|
||||
<label for="CultureName"><%:T("Add a culture...") %></label>
|
||||
<%:Html.DropDownList("CultureName", new SelectList(Model.AvailableSystemCultures.OrderBy(s => s), Model.CurrentCulture))%>
|
||||
<button class="primaryAction" type="submit"><%:T("Add") %></button>
|
||||
</fieldset>
|
||||
<% } %>
|
||||
<h3><%:T("Cultures this site supports") %></h3>
|
||||
<%: Html.UnorderedList(
|
||||
Model.SiteCultures.OrderBy(s => s),
|
||||
(s, i) => Html.DisplayFor(scvm => s, s == Model.CurrentCulture ? "CurrentCulture" : "RemovableCulture", ""),
|
||||
"site-cultures", "culture", "odd")%>
|
||||
<% using (Html.BeginFormAntiForgeryPost("AddCulture")) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
<label for="CultureName"><%:T("Add a culture...") %></label>
|
||||
<%:Html.DropDownList("CultureName", new SelectList(Model.AvailableSystemCultures.OrderBy(s => s), Model.CurrentCulture)) %>
|
||||
<button class="primaryAction" type="submit"><%:T("Add") %></button>
|
||||
</fieldset>
|
||||
<% } %>
|
||||
"site-cultures", "culture", "odd")%>
|
@@ -11,7 +11,7 @@ namespace Futures.Widgets.DataMigrations {
|
||||
|
||||
//CREATE TABLE Futures_Widgets_WidgetRecord (Id INTEGER not null, Zone TEXT, Position TEXT, Scope_id INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("WidgetRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("Zone")
|
||||
.Column<string>("Position")
|
||||
.Column<int>("Scope_id")
|
||||
|
@@ -13,7 +13,7 @@ namespace Orchard.Comments.DataMigrations {
|
||||
|
||||
//CREATE TABLE Orchard_Comments_CommentRecord (Id INTEGER not null, Author TEXT, SiteName TEXT, UserName TEXT, Email TEXT, Status TEXT, CommentDateUtc DATETIME, CommentText TEXT, CommentedOn INTEGER, CommentedOnContainer INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("CommentRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("Author")
|
||||
.Column<string>("SiteName")
|
||||
.Column<string>("UserName")
|
||||
@@ -27,7 +27,7 @@ namespace Orchard.Comments.DataMigrations {
|
||||
|
||||
//CREATE TABLE Orchard_Comments_CommentSettingsRecord (Id INTEGER not null, ModerateComments INTEGER, EnableSpamProtection INTEGER, AkismetKey TEXT, AkismetUrl TEXT, primary key (Id));
|
||||
SchemaBuilder.CreateTable("CommentSettingsRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<bool>("ModerateComments")
|
||||
.Column<bool>("EnableSpamProtection")
|
||||
.Column<string>("AkismetKey")
|
||||
@@ -36,7 +36,7 @@ namespace Orchard.Comments.DataMigrations {
|
||||
|
||||
//CREATE TABLE Orchard_Comments_HasCommentsRecord (Id INTEGER not null, CommentsShown INTEGER, CommentsActive INTEGER, primary key (Id));
|
||||
SchemaBuilder.CreateTable("HasCommentsRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<bool>("CommentsShown")
|
||||
.Column<bool>("CommentsActive")
|
||||
);
|
||||
|
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentTypes.Services;
|
||||
using Orchard.ContentTypes.ViewModels;
|
||||
@@ -11,34 +9,25 @@ using Orchard.Mvc.Results;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.ContentTypes.Controllers {
|
||||
public class AdminController : Controller {
|
||||
public class AdminController : Controller, IUpdateModel {
|
||||
private readonly IContentDefinitionService _contentDefinitionService;
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
private readonly IContentDefinitionEditorEvents _extendViewModels;
|
||||
|
||||
public AdminController(
|
||||
IOrchardServices orchardServices,
|
||||
IContentDefinitionService contentDefinitionService,
|
||||
IContentDefinitionManager contentDefinitionManager,
|
||||
IContentDefinitionEditorEvents extendViewModels) {
|
||||
public AdminController(IOrchardServices orchardServices, IContentDefinitionService contentDefinitionService) {
|
||||
Services = orchardServices;
|
||||
_contentDefinitionService = contentDefinitionService;
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
_extendViewModels = extendViewModels;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public IOrchardServices Services { get; private set; }
|
||||
public Localizer T { get; set; }
|
||||
public ActionResult Index() {
|
||||
return List();
|
||||
}
|
||||
|
||||
public ActionResult Index() { return List(); }
|
||||
|
||||
#region Types
|
||||
|
||||
public ActionResult List() {
|
||||
return View("List", new ListContentTypesViewModel {
|
||||
Types = _contentDefinitionService.GetTypeDefinitions()
|
||||
Types = _contentDefinitionService.GetTypes()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,117 +43,51 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return View(viewModel);
|
||||
|
||||
var definition = _contentDefinitionService.AddTypeDefinition(viewModel.DisplayName);
|
||||
|
||||
return RedirectToAction("Edit", new { id = definition.Name });
|
||||
}
|
||||
|
||||
public ActionResult Edit(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
|
||||
if (contentTypeDefinition == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var viewModel = new EditTypeViewModel(contentTypeDefinition) {
|
||||
Templates = _extendViewModels.TypeEditor(contentTypeDefinition)
|
||||
};
|
||||
|
||||
foreach (var part in viewModel.Parts) {
|
||||
part.Templates = _extendViewModels.TypePartEditor(new ContentTypeDefinition.Part(part.PartDefinition.Definition, part.Settings));
|
||||
foreach (var field in part.PartDefinition.Fields)
|
||||
field.Templates = _extendViewModels.PartFieldEditor(new ContentPartDefinition.Field(field.FieldDefinition.Definition, field.Name, field.Settings));
|
||||
}
|
||||
|
||||
if (viewModel.Fields.Any()) {
|
||||
foreach (var field in viewModel.Fields)
|
||||
field.Templates = _extendViewModels.PartFieldEditor(new ContentPartDefinition.Field(field.FieldDefinition.Definition, field.Name, field.Settings));
|
||||
}
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Edit")]
|
||||
public ActionResult EditPOST(EditTypeViewModel viewModel) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(viewModel.Name);
|
||||
|
||||
if (contentTypeDefinition == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var updater = new Updater(this);
|
||||
_contentDefinitionManager.AlterTypeDefinition(viewModel.Name, typeBuilder => {
|
||||
|
||||
typeBuilder.DisplayedAs(viewModel.DisplayName);
|
||||
|
||||
// allow extensions to alter type configuration
|
||||
viewModel.Templates = _extendViewModels.TypeEditorUpdate(typeBuilder, updater);
|
||||
|
||||
foreach (var entry in viewModel.Parts.Select((part, index) => new { part, index })) {
|
||||
var partViewModel = entry.part;
|
||||
|
||||
// enable updater to be aware of changing part prefix
|
||||
// todo: stick this info on the view model so the strings don't need to be in code & view
|
||||
var firstHalf = "Parts[" + entry.index + "].";
|
||||
updater._prefix = secondHalf => firstHalf + secondHalf;
|
||||
|
||||
// allow extensions to alter typePart configuration
|
||||
typeBuilder.WithPart(entry.part.PartDefinition.Name, typePartBuilder => {
|
||||
partViewModel.Templates = _extendViewModels.TypePartEditorUpdate(typePartBuilder, updater);
|
||||
});
|
||||
|
||||
if (!partViewModel.PartDefinition.Fields.Any())
|
||||
continue;
|
||||
|
||||
_contentDefinitionManager.AlterPartDefinition(partViewModel.PartDefinition.Name, partBuilder => {
|
||||
foreach (var fieldEntry in partViewModel.PartDefinition.Fields.Select((field, index) => new { field, index })) {
|
||||
partViewModel.PartDefinition.Fields = partViewModel.PartDefinition.Fields.ToArray();
|
||||
var fieldViewModel = fieldEntry.field;
|
||||
|
||||
// enable updater to be aware of changing field prefix
|
||||
var firstHalfFieldName = firstHalf + "PartDefinition.Fields[" + fieldEntry.index + "].";
|
||||
updater._prefix = secondHalf => firstHalfFieldName + secondHalf;
|
||||
|
||||
// allow extensions to alter partField configuration
|
||||
partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => {
|
||||
fieldViewModel.Templates = _extendViewModels.PartFieldEditorUpdate(partFieldBuilder, updater);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (viewModel.Fields.Any()) {
|
||||
_contentDefinitionManager.AlterPartDefinition(viewModel.Name, partBuilder => {
|
||||
viewModel.Fields = viewModel.Fields.ToArray();
|
||||
foreach (var fieldEntry in viewModel.Fields.Select((field, index) => new { field, index })) {
|
||||
var fieldViewModel = fieldEntry.field;
|
||||
|
||||
// enable updater to be aware of changing field prefix
|
||||
var firstHalfFieldName = "Fields[" + fieldEntry.index + "].";
|
||||
updater._prefix = secondHalf => firstHalfFieldName + secondHalf;
|
||||
|
||||
// allow extensions to alter partField configuration
|
||||
partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => {
|
||||
fieldViewModel.Templates = _extendViewModels.PartFieldEditorUpdate(partFieldBuilder, updater);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
var typeViewModel = _contentDefinitionService.AddType(viewModel);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("\"{0}\" settings have been saved.", viewModel.DisplayName));
|
||||
Services.Notifier.Information(T("The \"{0}\" content type has been created.", typeViewModel.DisplayName));
|
||||
|
||||
return RedirectToAction("Edit", new { id = typeViewModel.Name });
|
||||
}
|
||||
|
||||
public ActionResult Edit(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var typeViewModel = _contentDefinitionService.GetType(id);
|
||||
|
||||
if (typeViewModel == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
return View(typeViewModel);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Edit")]
|
||||
public ActionResult EditPOST(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var typeViewModel = _contentDefinitionService.GetType(id);
|
||||
|
||||
if (typeViewModel == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
if (!TryUpdateModel(typeViewModel))
|
||||
return View(typeViewModel);
|
||||
|
||||
_contentDefinitionService.AlterType(typeViewModel, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
return View(typeViewModel);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("\"{0}\" settings have been saved.", typeViewModel.DisplayName));
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
@@ -173,16 +96,16 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
var typeViewModel = _contentDefinitionService.GetType(id);
|
||||
|
||||
if (contentTypeDefinition == null)
|
||||
if (typeViewModel == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var viewModel = new AddPartsViewModel {
|
||||
Type = new EditTypeViewModel(contentTypeDefinition),
|
||||
PartSelections = _contentDefinitionService.GetPartDefinitions()
|
||||
.Where(cpd => !contentTypeDefinition.Parts.Any(p => p.PartDefinition.Name == cpd.Name))
|
||||
.Select(cpd => new PartSelectionViewModel {PartName = cpd.Name})
|
||||
Type = typeViewModel,
|
||||
PartSelections = _contentDefinitionService.GetParts()
|
||||
.Where(cpd => !typeViewModel.Parts.Any(p => p.PartDefinition.Name == cpd.Name))
|
||||
.Select(cpd => new PartSelectionViewModel { PartName = cpd.Name })
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
@@ -193,24 +116,28 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
var typeViewModel = _contentDefinitionService.GetType(id);
|
||||
|
||||
if (contentTypeDefinition == null)
|
||||
if (typeViewModel == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var viewModel = new AddPartsViewModel();
|
||||
TryUpdateModel(viewModel);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
viewModel.Type = new EditTypeViewModel(contentTypeDefinition);
|
||||
if (!TryUpdateModel(viewModel)) {
|
||||
viewModel.Type = typeViewModel;
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
_contentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, typeBuilder => {
|
||||
var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName);
|
||||
foreach (var partToAdd in partsToAdd)
|
||||
typeBuilder.WithPart(partToAdd);
|
||||
});
|
||||
var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName);
|
||||
foreach (var partToAdd in partsToAdd) {
|
||||
_contentDefinitionService.AddPartToType(partToAdd, typeViewModel.Name);
|
||||
Services.Notifier.Information(T("The \"{0}\" part has been added.", partToAdd));
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel(); ;
|
||||
viewModel.Type = typeViewModel;
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
return RedirectToAction("Edit", new {id});
|
||||
}
|
||||
@@ -219,15 +146,15 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
var typeViewModel = _contentDefinitionService.GetType(id);
|
||||
|
||||
var viewModel = new RemovePartViewModel();
|
||||
if (contentTypeDefinition == null
|
||||
if (typeViewModel == null
|
||||
|| !TryUpdateModel(viewModel)
|
||||
|| !contentTypeDefinition.Parts.Any(p => p.PartDefinition.Name == viewModel.Name))
|
||||
|| !typeViewModel.Parts.Any(p => p.PartDefinition.Name == viewModel.Name))
|
||||
return new NotFoundResult();
|
||||
|
||||
viewModel.Type = new EditTypeViewModel { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName };
|
||||
viewModel.Type = typeViewModel;
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
@@ -236,20 +163,22 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
var typeViewModel = _contentDefinitionService.GetType(id);
|
||||
|
||||
var viewModel = new RemovePartViewModel();
|
||||
if (contentTypeDefinition == null
|
||||
if (typeViewModel == null
|
||||
|| !TryUpdateModel(viewModel)
|
||||
|| !contentTypeDefinition.Parts.Any(p => p.PartDefinition.Name == viewModel.Name))
|
||||
|| !typeViewModel.Parts.Any(p => p.PartDefinition.Name == viewModel.Name))
|
||||
return new NotFoundResult();
|
||||
|
||||
_contentDefinitionService.RemovePartFromType(viewModel.Name, typeViewModel.Name);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
viewModel.Type = new EditTypeViewModel { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName };
|
||||
Services.TransactionManager.Cancel();
|
||||
viewModel.Type = typeViewModel;
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
_contentDefinitionManager.AlterTypeDefinition(id, typeBuilder => typeBuilder.RemovePart(viewModel.Name));
|
||||
Services.Notifier.Information(T("The \"{0}\" part has been removed.", viewModel.Name));
|
||||
|
||||
return RedirectToAction("Edit", new {id});
|
||||
@@ -261,7 +190,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
|
||||
public ActionResult ListParts() {
|
||||
return View(new ListContentPartsViewModel {
|
||||
Parts = _contentDefinitionService.GetPartDefinitions()
|
||||
Parts = _contentDefinitionService.GetParts()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -277,51 +206,50 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var partViewModel = _contentDefinitionService.AddPart(viewModel);
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return View(viewModel);
|
||||
|
||||
var definition = _contentDefinitionService.AddPartDefinition(viewModel.Name);
|
||||
Services.Notifier.Information(T("The \"{0}\" content part has been created.", partViewModel.Name));
|
||||
|
||||
return RedirectToAction("EditPart", new { id = definition.Name });
|
||||
return RedirectToAction("EditPart", new { id = partViewModel.Name });
|
||||
}
|
||||
|
||||
public ActionResult EditPart(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
var partViewModel = _contentDefinitionService.GetPart(id);
|
||||
|
||||
if (contentPartDefinition == null)
|
||||
if (partViewModel == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var viewModel = new EditPartViewModel(contentPartDefinition) {
|
||||
Templates = _extendViewModels.PartEditor(contentPartDefinition)
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
return View(partViewModel);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("EditPart")]
|
||||
public ActionResult EditPartPOST(EditPartViewModel viewModel) {
|
||||
public ActionResult EditPartPOST(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(viewModel.Name);
|
||||
var partViewModel = _contentDefinitionService.GetPart(id);
|
||||
|
||||
if (contentPartDefinition == null)
|
||||
if (partViewModel == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var updater = new Updater(this);
|
||||
_contentDefinitionManager.AlterPartDefinition(viewModel.Name, partBuilder => {
|
||||
// allow extensions to alter part configuration
|
||||
viewModel.Templates = _extendViewModels.PartEditorUpdate(partBuilder, updater);
|
||||
});
|
||||
if (!TryUpdateModel(partViewModel))
|
||||
return View(partViewModel);
|
||||
|
||||
_contentDefinitionService.AlterPart(partViewModel, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
return View(viewModel);
|
||||
return View(partViewModel);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("\"{0}\" settings have been saved.", partViewModel.Name));
|
||||
|
||||
return RedirectToAction("ListParts");
|
||||
}
|
||||
|
||||
@@ -329,20 +257,20 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
var partViewModel = _contentDefinitionService.GetPart(id);
|
||||
|
||||
if (contentPartDefinition == null) {
|
||||
if (partViewModel == null) {
|
||||
//id passed in might be that of a type w/ no implicit field
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
if (contentTypeDefinition != null)
|
||||
contentPartDefinition = new ContentPartDefinition(id);
|
||||
var typeViewModel = _contentDefinitionService.GetType(id);
|
||||
if (typeViewModel != null)
|
||||
partViewModel = new EditPartViewModel(new ContentPartDefinition(id));
|
||||
else
|
||||
return new NotFoundResult();
|
||||
}
|
||||
|
||||
var viewModel = new AddFieldViewModel {
|
||||
Part = new EditPartViewModel(contentPartDefinition),
|
||||
Fields = _contentDefinitionService.GetFieldDefinitions()
|
||||
Part = partViewModel,
|
||||
Fields = _contentDefinitionService.GetFields()
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
@@ -353,42 +281,36 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var viewModel = new AddFieldViewModel();
|
||||
TryUpdateModel(viewModel);
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return AddFieldTo(id);
|
||||
|
||||
if (contentPartDefinition == null) {
|
||||
var partViewModel = _contentDefinitionService.GetPart(id);
|
||||
var typeViewModel = _contentDefinitionService.GetType(id);
|
||||
if (partViewModel == null) {
|
||||
//id passed in might be that of a type w/ no implicit field
|
||||
if (contentTypeDefinition != null) {
|
||||
contentPartDefinition = new ContentPartDefinition(id);
|
||||
var contentTypeDefinitionParts = contentTypeDefinition.Parts.ToList();
|
||||
contentTypeDefinitionParts.Add(new ContentTypeDefinition.Part(contentPartDefinition, null));
|
||||
_contentDefinitionService.AlterTypeDefinition(
|
||||
new ContentTypeDefinition(
|
||||
contentTypeDefinition.Name,
|
||||
contentTypeDefinition.DisplayName,
|
||||
contentTypeDefinitionParts,
|
||||
contentTypeDefinition.Settings
|
||||
)
|
||||
);
|
||||
if (typeViewModel != null) {
|
||||
partViewModel = new EditPartViewModel { Name = typeViewModel.Name };
|
||||
_contentDefinitionService.AddPart(new CreatePartViewModel { Name = partViewModel.Name });
|
||||
_contentDefinitionService.AddPartToType(partViewModel.Name, typeViewModel.Name);
|
||||
}
|
||||
else {
|
||||
return new NotFoundResult();
|
||||
}
|
||||
}
|
||||
|
||||
var contentPartFields = contentPartDefinition.Fields.ToList();
|
||||
contentPartFields.Add(new ContentPartDefinition.Field(new ContentFieldDefinition(viewModel.FieldTypeName), viewModel.DisplayName, null));
|
||||
_contentDefinitionService.AlterPartDefinition(new ContentPartDefinition(contentPartDefinition.Name, contentPartFields, contentPartDefinition.Settings));
|
||||
var viewModel = new AddFieldViewModel();
|
||||
if (!TryUpdateModel(viewModel)) {
|
||||
Services.TransactionManager.Cancel();
|
||||
return AddFieldTo(id);
|
||||
}
|
||||
|
||||
_contentDefinitionService.AddFieldToPart(viewModel.DisplayName, viewModel.FieldTypeName, partViewModel.Name);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
return AddFieldTo(id);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("The \"{0}\" field has been added.", viewModel.DisplayName));
|
||||
|
||||
if (contentTypeDefinition != null)
|
||||
if (typeViewModel != null)
|
||||
return RedirectToAction("Edit", new { id });
|
||||
|
||||
return RedirectToAction("EditPart", new { id });
|
||||
@@ -399,15 +321,15 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
var partViewModel = _contentDefinitionService.GetPart(id);
|
||||
|
||||
var viewModel = new RemoveFieldViewModel();
|
||||
if (contentPartDefinition == null
|
||||
if (partViewModel == null
|
||||
|| !TryUpdateModel(viewModel)
|
||||
|| !contentPartDefinition.Fields.Any(p => p.Name == viewModel.Name))
|
||||
|| !partViewModel.Fields.Any(p => p.Name == viewModel.Name))
|
||||
return new NotFoundResult();
|
||||
|
||||
viewModel.Part = new EditPartViewModel { Name = contentPartDefinition.Name };
|
||||
viewModel.Part = partViewModel;
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
@@ -416,23 +338,25 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content part.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentPartDefinition = _contentDefinitionService.GetPartDefinition(id);
|
||||
var partViewModel = _contentDefinitionService.GetPart(id);
|
||||
|
||||
var viewModel = new RemoveFieldViewModel();
|
||||
if (contentPartDefinition == null
|
||||
if (partViewModel == null
|
||||
|| !TryUpdateModel(viewModel)
|
||||
|| !contentPartDefinition.Fields.Any(p => p.Name == viewModel.Name))
|
||||
|| !partViewModel.Fields.Any(p => p.Name == viewModel.Name))
|
||||
return new NotFoundResult();
|
||||
|
||||
_contentDefinitionService.RemoveFieldFromPart(viewModel.Name, partViewModel.Name);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
viewModel.Part = new EditPartViewModel { Name = contentPartDefinition.Name };
|
||||
Services.TransactionManager.Cancel();
|
||||
viewModel.Part = partViewModel;
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
_contentDefinitionManager.AlterPartDefinition(id, typeBuilder => typeBuilder.RemoveField(viewModel.Name));
|
||||
Services.Notifier.Information(T("The \"{0}\" field has been removed.", viewModel.Name));
|
||||
|
||||
if (_contentDefinitionService.GetTypeDefinition(id) != null)
|
||||
if (_contentDefinitionService.GetType(id) != null)
|
||||
return RedirectToAction("Edit", new { id });
|
||||
|
||||
return RedirectToAction("EditPart", new { id });
|
||||
@@ -440,23 +364,12 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
|
||||
#endregion
|
||||
|
||||
class Updater : IUpdateModel {
|
||||
private readonly AdminController _thunk;
|
||||
|
||||
public Updater(AdminController thunk) {
|
||||
_thunk = thunk;
|
||||
}
|
||||
|
||||
public Func<string, string> _prefix = x => x;
|
||||
|
||||
public bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class {
|
||||
return _thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties);
|
||||
}
|
||||
|
||||
public void AddModelError(string key, LocalizedString errorMessage) {
|
||||
_thunk.ModelState.AddModelError(_prefix(key), errorMessage.ToString());
|
||||
}
|
||||
public new bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class {
|
||||
return base.TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
||||
}
|
||||
|
||||
public void AddModelError(string key, LocalizedString errorMessage) {
|
||||
ModelState.AddModelError(key, errorMessage.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -99,8 +99,8 @@
|
||||
<Content Include="Views\Admin\EditPart.ascx" />
|
||||
<Content Include="Views\Admin\Edit.ascx" />
|
||||
<Content Include="Views\Admin\List.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\ContentTypeDefinition.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\ContentPartDefinition.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\EditTypeViewModel.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\EditPartViewModel.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Field.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Fields.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Settings.ascx" />
|
||||
|
@@ -2,79 +2,172 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentTypes.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.ContentTypes.Services {
|
||||
public class ContentDefinitionService : IContentDefinitionService {
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
private readonly IEnumerable<IContentPartDriver> _contentPartDrivers;
|
||||
private readonly IEnumerable<IContentFieldDriver> _contentFieldDrivers;
|
||||
private readonly IContentDefinitionEditorEvents _contentDefinitionEditorEvents;
|
||||
|
||||
public ContentDefinitionService(IOrchardServices services, IContentDefinitionManager contentDefinitionManager, IEnumerable<IContentFieldDriver> contentFieldDrivers) {
|
||||
public ContentDefinitionService(
|
||||
IOrchardServices services,
|
||||
IContentDefinitionManager contentDefinitionManager,
|
||||
IEnumerable<IContentPartDriver> contentPartDrivers,
|
||||
IEnumerable<IContentFieldDriver> contentFieldDrivers,
|
||||
IContentDefinitionEditorEvents contentDefinitionEditorEvents)
|
||||
{
|
||||
Services = services;
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
_contentPartDrivers = contentPartDrivers;
|
||||
_contentFieldDrivers = contentFieldDrivers;
|
||||
_contentDefinitionEditorEvents = contentDefinitionEditorEvents;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public IOrchardServices Services { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public IEnumerable<ContentTypeDefinition> GetTypeDefinitions() {
|
||||
return _contentDefinitionManager.ListTypeDefinitions();
|
||||
public IEnumerable<EditTypeViewModel> GetTypes() {
|
||||
return _contentDefinitionManager.ListTypeDefinitions().Select(ctd => new EditTypeViewModel(ctd));
|
||||
}
|
||||
|
||||
public ContentTypeDefinition GetTypeDefinition(string name) {
|
||||
return _contentDefinitionManager.GetTypeDefinition(name);
|
||||
public EditTypeViewModel GetType(string name) {
|
||||
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(name);
|
||||
|
||||
if (contentTypeDefinition == null)
|
||||
return null;
|
||||
|
||||
var viewModel = new EditTypeViewModel(contentTypeDefinition) {
|
||||
Templates = _contentDefinitionEditorEvents.TypeEditor(contentTypeDefinition)
|
||||
};
|
||||
|
||||
foreach (var part in viewModel.Parts) {
|
||||
part.Templates = _contentDefinitionEditorEvents.TypePartEditor(part._Definition);
|
||||
foreach (var field in part.PartDefinition.Fields)
|
||||
field.Templates = _contentDefinitionEditorEvents.PartFieldEditor(field._Definition);
|
||||
}
|
||||
|
||||
if (viewModel.Fields.Any()) {
|
||||
foreach (var field in viewModel.Fields)
|
||||
field.Templates = _contentDefinitionEditorEvents.PartFieldEditor(field._Definition);
|
||||
}
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public ContentTypeDefinition AddTypeDefinition(string displayName) {
|
||||
var name = GenerateName(displayName);
|
||||
public EditTypeViewModel AddType(CreateTypeViewModel typeViewModel) {
|
||||
var name = GenerateName(typeViewModel.DisplayName);
|
||||
|
||||
while (_contentDefinitionManager.GetTypeDefinition(name) != null)
|
||||
name = VersionName(name);
|
||||
|
||||
var contentTypeDefinition = new ContentTypeDefinition(name) { DisplayName = displayName };
|
||||
//just giving the new type some default parts for now
|
||||
_contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition);
|
||||
_contentDefinitionManager.AlterTypeDefinition(
|
||||
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.", contentTypeDefinition.DisplayName));
|
||||
|
||||
return contentTypeDefinition;
|
||||
}
|
||||
|
||||
public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) {
|
||||
var contentTypeDefinition = new ContentTypeDefinition(name, typeViewModel.DisplayName);
|
||||
_contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition);
|
||||
|
||||
var implicitTypePart = contentTypeDefinition.Parts.SingleOrDefault(p => p.PartDefinition.Name == contentTypeDefinition.Name);
|
||||
if (implicitTypePart != null) {
|
||||
AlterPartDefinition(implicitTypePart.PartDefinition);
|
||||
}
|
||||
return new EditTypeViewModel(contentTypeDefinition);
|
||||
}
|
||||
|
||||
public void RemoveTypeDefinition(string name) {
|
||||
public void AlterType(EditTypeViewModel typeViewModel, IUpdateModel updateModel) {
|
||||
var updater = new Updater(updateModel);
|
||||
_contentDefinitionManager.AlterTypeDefinition(typeViewModel.Name, typeBuilder => {
|
||||
typeBuilder.DisplayedAs(typeViewModel.DisplayName);
|
||||
|
||||
// allow extensions to alter type configuration
|
||||
typeViewModel.Templates = _contentDefinitionEditorEvents.TypeEditorUpdate(typeBuilder, updater);
|
||||
|
||||
foreach (var part in typeViewModel.Parts) {
|
||||
var partViewModel = part;
|
||||
|
||||
// enable updater to be aware of changing part prefix
|
||||
updater._prefix = secondHalf => string.Format("{0}.{1}", partViewModel.Prefix, secondHalf);
|
||||
|
||||
// allow extensions to alter typePart configuration
|
||||
typeBuilder.WithPart(partViewModel.PartDefinition.Name, typePartBuilder => {
|
||||
partViewModel.Templates = _contentDefinitionEditorEvents.TypePartEditorUpdate(typePartBuilder, updater);
|
||||
});
|
||||
|
||||
if (!partViewModel.PartDefinition.Fields.Any())
|
||||
continue;
|
||||
|
||||
_contentDefinitionManager.AlterPartDefinition(partViewModel.PartDefinition.Name, partBuilder => {
|
||||
var fieldFirstHalf = string.Format("{0}.{1}", partViewModel.Prefix, partViewModel.PartDefinition.Prefix);
|
||||
foreach (var field in partViewModel.PartDefinition.Fields) {
|
||||
var fieldViewModel = field;
|
||||
|
||||
// enable updater to be aware of changing field prefix
|
||||
updater._prefix = secondHalf =>
|
||||
string.Format("{0}.{1}.{2}", fieldFirstHalf, fieldViewModel.Prefix, secondHalf);
|
||||
// allow extensions to alter partField configuration
|
||||
partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => {
|
||||
fieldViewModel.Templates = _contentDefinitionEditorEvents.PartFieldEditorUpdate(partFieldBuilder, updater);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (typeViewModel.Fields.Any()) {
|
||||
_contentDefinitionManager.AlterPartDefinition(typeViewModel.Name, partBuilder => {
|
||||
foreach (var field in typeViewModel.Fields) {
|
||||
var fieldViewModel = field;
|
||||
|
||||
// enable updater to be aware of changing field prefix
|
||||
updater._prefix = secondHalf =>
|
||||
string.Format("{0}.{1}", fieldViewModel.Prefix, secondHalf);
|
||||
|
||||
// allow extensions to alter partField configuration
|
||||
partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => {
|
||||
fieldViewModel.Templates = _contentDefinitionEditorEvents.PartFieldEditorUpdate(partFieldBuilder, updater);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void RemoveType(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ContentPartDefinition> GetPartDefinitions() {
|
||||
var typeNames = GetTypeDefinitions().Select(ctd => ctd.Name);
|
||||
return _contentDefinitionManager.ListPartDefinitions().Where(cpd => !typeNames.Contains(cpd.Name));
|
||||
public void AddPartToType(string partName, string typeName) {
|
||||
_contentDefinitionManager.AlterTypeDefinition(typeName, typeBuilder => typeBuilder.WithPart(partName));
|
||||
}
|
||||
|
||||
public ContentPartDefinition GetPartDefinition(string name) {
|
||||
return _contentDefinitionManager.GetPartDefinition(name);
|
||||
public void RemovePartFromType(string partName, string typeName) {
|
||||
_contentDefinitionManager.AlterTypeDefinition(typeName, typeBuilder => typeBuilder.RemovePart(partName));
|
||||
}
|
||||
|
||||
public ContentPartDefinition AddPartDefinition(string name) {
|
||||
name = GenerateName(name);
|
||||
public IEnumerable<EditPartViewModel> GetParts() {
|
||||
var typeNames = GetTypes().Select(ctd => ctd.Name);
|
||||
// code-defined parts
|
||||
var codeDefinedParts = _contentPartDrivers.SelectMany(d => d.GetPartInfo().Select(cpi => new EditPartViewModel {Name = cpi.PartName}));
|
||||
// user-defined parts
|
||||
var contentParts = _contentDefinitionManager.ListPartDefinitions().Where(cpd => !codeDefinedParts.Any(m => m.Name == cpd.Name)).Select(cpd => new EditPartViewModel(cpd));
|
||||
// all together now, except for those parts with the same name as a type (implicit type's part or a mistake)
|
||||
return contentParts.Where(m => !typeNames.Contains(m.Name)).Union(codeDefinedParts).OrderBy(m => m.Name);
|
||||
}
|
||||
|
||||
public EditPartViewModel GetPart(string name) {
|
||||
var contentPartDefinition = _contentDefinitionManager.GetPartDefinition(name);
|
||||
|
||||
if (contentPartDefinition == null)
|
||||
return null;
|
||||
|
||||
var viewModel = new EditPartViewModel(contentPartDefinition) {
|
||||
Templates = _contentDefinitionEditorEvents.PartEditor(contentPartDefinition)
|
||||
};
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public EditPartViewModel AddPart(CreatePartViewModel partViewModel) {
|
||||
var name = GenerateName(partViewModel.Name);
|
||||
|
||||
while (_contentDefinitionManager.GetPartDefinition(name) != null)
|
||||
name = VersionName(name);
|
||||
@@ -82,21 +175,34 @@ namespace Orchard.ContentTypes.Services {
|
||||
var contentPartDefinition = new ContentPartDefinition(name);
|
||||
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
|
||||
|
||||
return contentPartDefinition;
|
||||
return new EditPartViewModel(contentPartDefinition);
|
||||
}
|
||||
|
||||
public void AlterPartDefinition(ContentPartDefinition contentPartDefinition) {
|
||||
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
|
||||
public void AlterPart(EditPartViewModel partViewModel, IUpdateModel updateModel) {
|
||||
var updater = new Updater(updateModel);
|
||||
_contentDefinitionManager.AlterPartDefinition(partViewModel.Name, partBuilder => {
|
||||
partViewModel.Templates = _contentDefinitionEditorEvents.PartEditorUpdate(partBuilder, updater);
|
||||
});
|
||||
}
|
||||
|
||||
public void RemovePartDefinition(string name) {
|
||||
public void RemovePart(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ContentFieldInfo> GetFieldDefinitions() {
|
||||
public IEnumerable<ContentFieldInfo> GetFields() {
|
||||
return _contentFieldDrivers.SelectMany(d => d.GetFieldInfo());
|
||||
}
|
||||
|
||||
public void AddFieldToPart(string fieldName, string fieldTypeName, string partName) {
|
||||
_contentDefinitionManager.AlterPartDefinition(partName, partBuilder =>
|
||||
partBuilder.WithField(fieldName, fieldBuilder => fieldBuilder.OfType(fieldTypeName))
|
||||
);
|
||||
}
|
||||
|
||||
public void RemoveFieldFromPart(string fieldName, string partName) {
|
||||
_contentDefinitionManager.AlterPartDefinition(partName, typeBuilder => typeBuilder.RemoveField(fieldName));
|
||||
}
|
||||
|
||||
//gratuitously stolen from the RoutableService
|
||||
private static string GenerateName(string displayName) {
|
||||
if (string.IsNullOrWhiteSpace(displayName))
|
||||
@@ -130,5 +236,23 @@ namespace Orchard.ContentTypes.Services {
|
||||
|
||||
return string.Format("{0}-{1}", name, version);
|
||||
}
|
||||
|
||||
class Updater : IUpdateModel {
|
||||
private readonly IUpdateModel _thunk;
|
||||
|
||||
public Updater(IUpdateModel thunk) {
|
||||
_thunk = thunk;
|
||||
}
|
||||
|
||||
public Func<string, string> _prefix = x => x;
|
||||
|
||||
public bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class {
|
||||
return _thunk.TryUpdateModel(model, _prefix(prefix), includeProperties, excludeProperties);
|
||||
}
|
||||
|
||||
public void AddModelError(string key, LocalizedString errorMessage) {
|
||||
_thunk.AddModelError(_prefix(key), errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,21 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentTypes.ViewModels;
|
||||
|
||||
namespace Orchard.ContentTypes.Services {
|
||||
public interface IContentDefinitionService : IDependency {
|
||||
IEnumerable<ContentTypeDefinition> GetTypeDefinitions();
|
||||
ContentTypeDefinition GetTypeDefinition(string name);
|
||||
ContentTypeDefinition AddTypeDefinition(string displayName);
|
||||
void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition);
|
||||
void RemoveTypeDefinition(string name);
|
||||
IEnumerable<EditTypeViewModel> GetTypes();
|
||||
EditTypeViewModel GetType(string name);
|
||||
EditTypeViewModel AddType(CreateTypeViewModel typeViewModel);
|
||||
void AlterType(EditTypeViewModel typeViewModel, IUpdateModel updater);
|
||||
void RemoveType(string name);
|
||||
void AddPartToType(string partName, string typeName);
|
||||
void RemovePartFromType(string partName, string typeName);
|
||||
|
||||
IEnumerable<ContentPartDefinition> GetPartDefinitions();
|
||||
ContentPartDefinition GetPartDefinition(string name);
|
||||
ContentPartDefinition AddPartDefinition(string name);
|
||||
void AlterPartDefinition(ContentPartDefinition contentPartDefinition);
|
||||
void RemovePartDefinition(string name);
|
||||
IEnumerable<EditPartViewModel> GetParts();
|
||||
EditPartViewModel GetPart(string name);
|
||||
EditPartViewModel AddPart(CreatePartViewModel partViewModel);
|
||||
void AlterPart(EditPartViewModel partViewModel, IUpdateModel updater);
|
||||
void RemovePart(string name);
|
||||
|
||||
IEnumerable<ContentFieldInfo> GetFieldDefinitions();
|
||||
IEnumerable<ContentFieldInfo> GetFields();
|
||||
void AddFieldToPart(string fieldName, string fieldTypeName, string partName);
|
||||
void RemoveFieldFromPart(string fieldName, string partName);
|
||||
}
|
||||
}
|
@@ -11,34 +11,36 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
Fields = new List<EditPartFieldViewModel>();
|
||||
Parts = new List<EditTypePartViewModel>();
|
||||
}
|
||||
|
||||
public EditTypeViewModel(ContentTypeDefinition contentTypeDefinition) {
|
||||
Name = contentTypeDefinition.Name;
|
||||
DisplayName = contentTypeDefinition.DisplayName;
|
||||
Settings = contentTypeDefinition.Settings;
|
||||
Fields = GetTypeFields(contentTypeDefinition).ToList();
|
||||
Parts = GetTypeParts(contentTypeDefinition).ToList();
|
||||
Definition = contentTypeDefinition;
|
||||
_Definition = contentTypeDefinition;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public ContentTypeDefinition Definition { get; private set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
public IEnumerable<EditPartFieldViewModel> Fields { get; set; }
|
||||
public IEnumerable<EditTypePartViewModel> Parts { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public ContentTypeDefinition _Definition { get; private set; }
|
||||
|
||||
private IEnumerable<EditPartFieldViewModel> GetTypeFields(ContentTypeDefinition contentTypeDefinition) {
|
||||
var implicitTypePart = contentTypeDefinition.Parts.SingleOrDefault(p => p.PartDefinition.Name == Name);
|
||||
|
||||
return implicitTypePart == null
|
||||
? Enumerable.Empty<EditPartFieldViewModel>()
|
||||
: implicitTypePart.PartDefinition.Fields.Select(f => new EditPartFieldViewModel(f) { Part = new EditPartViewModel(implicitTypePart.PartDefinition) });
|
||||
: implicitTypePart.PartDefinition.Fields.Select((f, i) => new EditPartFieldViewModel(i, f) { Part = new EditPartViewModel(implicitTypePart.PartDefinition) });
|
||||
}
|
||||
|
||||
private IEnumerable<EditTypePartViewModel> GetTypeParts(ContentTypeDefinition contentTypeDefinition) {
|
||||
return contentTypeDefinition.Parts.Where(p => p.PartDefinition.Name != Name).Select(p => new EditTypePartViewModel(p) { Type = this });
|
||||
return contentTypeDefinition.Parts
|
||||
.Where(p => p.PartDefinition.Name != Name)
|
||||
.Select((p, i) => new EditTypePartViewModel(i, p) { Type = this });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,15 +48,21 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
public EditTypePartViewModel() {
|
||||
Settings = new SettingsDictionary();
|
||||
}
|
||||
public EditTypePartViewModel(ContentTypeDefinition.Part part) {
|
||||
|
||||
public EditTypePartViewModel(int index, ContentTypeDefinition.Part part) {
|
||||
Index = index;
|
||||
PartDefinition = new EditPartViewModel(part.PartDefinition);
|
||||
Settings = part.Settings;
|
||||
_Definition = part;
|
||||
}
|
||||
|
||||
public EditTypeViewModel Type { get; set; }
|
||||
public int Index { get; set; }
|
||||
public string Prefix { get { return "Parts[" + Index + "]"; } }
|
||||
public EditPartViewModel PartDefinition { get; set; }
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
public EditTypeViewModel Type { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public ContentTypeDefinition.Part _Definition { get; private set; }
|
||||
}
|
||||
|
||||
public class EditPartViewModel : BaseViewModel {
|
||||
@@ -62,45 +70,56 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
Fields = new List<EditPartFieldViewModel>();
|
||||
Settings = new SettingsDictionary();
|
||||
}
|
||||
|
||||
public EditPartViewModel(ContentPartDefinition contentPartDefinition) {
|
||||
Name = contentPartDefinition.Name;
|
||||
Fields = contentPartDefinition.Fields.Select(f => new EditPartFieldViewModel(f) { Part = this }).ToList();
|
||||
Fields = contentPartDefinition.Fields.Select((f, i) => new EditPartFieldViewModel(i, f) { Part = this }).ToList();
|
||||
Settings = contentPartDefinition.Settings;
|
||||
Definition = contentPartDefinition;
|
||||
_Definition = contentPartDefinition;
|
||||
}
|
||||
|
||||
public string Prefix { get { return "PartDefinition"; } }
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public IEnumerable<EditPartFieldViewModel> Fields { get; set; }
|
||||
public ContentPartDefinition Definition { get; private set; }
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
public ContentPartDefinition _Definition { get; private set; }
|
||||
}
|
||||
|
||||
public class EditPartFieldViewModel {
|
||||
|
||||
public EditPartFieldViewModel() {
|
||||
Settings = new SettingsDictionary();
|
||||
}
|
||||
public EditPartFieldViewModel(ContentPartDefinition.Field field) {
|
||||
|
||||
public EditPartFieldViewModel(int index, ContentPartDefinition.Field field) {
|
||||
Index = index;
|
||||
Name = field.Name;
|
||||
FieldDefinition = new EditFieldViewModel(field.FieldDefinition);
|
||||
Settings = field.Settings;
|
||||
_Definition = field;
|
||||
}
|
||||
|
||||
public int Index { get; set; }
|
||||
public string Prefix { get { return "Fields[" + Index + "]"; } }
|
||||
public EditPartViewModel Part { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public EditFieldViewModel FieldDefinition { get; set; }
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
public ContentPartDefinition.Field _Definition { get; private set; }
|
||||
}
|
||||
|
||||
public class EditFieldViewModel {
|
||||
public EditFieldViewModel() { }
|
||||
|
||||
public EditFieldViewModel(ContentFieldDefinition contentFieldDefinition) {
|
||||
Name = contentFieldDefinition.Name;
|
||||
Definition = contentFieldDefinition;
|
||||
_Definition = contentFieldDefinition;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public ContentFieldDefinition Definition { get; private set; }
|
||||
public ContentFieldDefinition _Definition { get; private set; }
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.ContentTypes.ViewModels {
|
||||
public class ListContentPartsViewModel : BaseViewModel {
|
||||
public IEnumerable<ContentPartDefinition> Parts { get; set; }
|
||||
public IEnumerable<EditPartViewModel> Parts { get; set; }
|
||||
}
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.ContentTypes.ViewModels {
|
||||
public class ListContentTypesViewModel : BaseViewModel {
|
||||
public IEnumerable<ContentTypeDefinition> Types { get; set; }
|
||||
public IEnumerable<EditTypeViewModel> Types { get; set; }
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
string.Format(
|
||||
"{0} <label for=\"{1}\" class=\"forcheckbox\">{2}</label>{3}",
|
||||
Html.CheckBox(fieldNameStart + "IsSelected"),
|
||||
fieldNameStart + "IsSelected",
|
||||
ViewData.TemplateInfo.GetFullHtmlFieldId(fieldNameStart + "IsSelected"),
|
||||
partSelection.PartName,
|
||||
Html.Hidden(fieldNameStart + "PartName", partSelection.PartName)));
|
||||
},
|
||||
|
@@ -17,12 +17,12 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.HiddenFor(m => m.Name) %>
|
||||
</fieldset><%
|
||||
Html.RenderTemplates(Model.Templates); %>
|
||||
<h2><%:T("Parts") %></h2>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddPartsTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" })%></div><%:
|
||||
Html.EditorFor(m => m.Parts, "TypeParts", "") %>
|
||||
<h2><%:T("Fields") %></h2>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %></div><%:
|
||||
Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||
<h2><%:T("Parts") %></h2>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddPartsTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" })%></div><%:
|
||||
Html.EditorFor(m => m.Parts, "TypeParts", "") %>
|
||||
<fieldset class="action">
|
||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||
</fieldset>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentManagement.MetaData.Models.ContentPartDefinition>" %>
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditPartViewModel>" %>
|
||||
<div class="summary">
|
||||
<div class="properties">
|
||||
<h3><%:Model.Name%></h3>
|
@@ -1,4 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentManagement.MetaData.Models.ContentTypeDefinition>" %>
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditTypeViewModel>" %>
|
||||
<div class="summary">
|
||||
<div class="properties">
|
||||
<h3><%:Model.DisplayName%></h3>
|
@@ -4,6 +4,8 @@
|
||||
<div class="manage">
|
||||
<%:Html.ActionLink(T("Remove").Text, "RemoveFieldFrom", new { area = "Orchard.ContentTypes", id = Model.Part.Name, Model.Name }, new { itemprop = "RemoveUrl UnsafeUrl" })%><%--// <- some experimentation--%>
|
||||
</div><%
|
||||
Html.RenderTemplates(Model.Templates); %>
|
||||
<%:Html.HiddenFor(m => m.Name) %><%:Html.HiddenFor(m => m.FieldDefinition.Name) %>
|
||||
Html.RenderTemplates(Model.Templates);
|
||||
%><%:Html.HiddenFor(m => m.Name)
|
||||
%><%:Html.HiddenFor(m => m.FieldDefinition.Name)
|
||||
%><%:Html.HiddenFor(m => m.Index) %>
|
||||
</fieldset>
|
@@ -2,11 +2,9 @@
|
||||
<%
|
||||
if (Model.Any()) { %>
|
||||
<fieldset><%
|
||||
var fi = 0;
|
||||
foreach (var field in Model) {
|
||||
var f = field;
|
||||
var htmlFieldName = string.Format("Fields[{0}]", fi++); %>
|
||||
<%:Html.EditorFor(m => f, "Field", htmlFieldName) %><%
|
||||
var f = field; %>
|
||||
<%:Html.EditorFor(m => f, "Field", field.Prefix) %><%
|
||||
} %>
|
||||
</fieldset><%
|
||||
} %>
|
@@ -12,5 +12,6 @@
|
||||
<div class="manage minor"><%:Html.ActionLink(T("Edit global part config").Text, "EditPart", new { area = "Orchard.ContentTypes", id = Model.PartDefinition.Name })%></div>
|
||||
<%:Html.DisplayFor(m => m.PartDefinition.Settings, "Settings", "PartDefinition")
|
||||
%><%:Html.EditorFor(m => m.PartDefinition.Fields, "TypePartFields", "PartDefinition")
|
||||
%><%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %>
|
||||
%><%:Html.HiddenFor(m => m.PartDefinition.Name)
|
||||
%><%:Html.HiddenFor(m => m.Index) %>
|
||||
</fieldset>
|
@@ -6,5 +6,7 @@
|
||||
Html.RenderTemplates(Model.Templates); %>
|
||||
</div><%
|
||||
} %>
|
||||
<%:Html.HiddenFor(m => m.Name) %><%:Html.HiddenFor(m => m.FieldDefinition.Name) %>
|
||||
<%:Html.HiddenFor(m => m.Name)
|
||||
%><%:Html.HiddenFor(m => m.FieldDefinition.Name)
|
||||
%><%:Html.HiddenFor(m => m.Index) %>
|
||||
</fieldset>
|
@@ -1,10 +1,8 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<IEnumerable<Orchard.ContentTypes.ViewModels.EditPartFieldViewModel>>" %>
|
||||
<%
|
||||
if (Model.Any()) {
|
||||
var fi = 0;
|
||||
foreach (var field in Model) {
|
||||
var f = field;
|
||||
var htmlFieldName = string.Format("Fields[{0}]", fi++); %>
|
||||
<%:Html.EditorFor(m => f, "TypePartField", htmlFieldName) %><%
|
||||
var f = field; %>
|
||||
<%:Html.EditorFor(m => f, "TypePartField", f.Prefix) %><%
|
||||
}
|
||||
} %>
|
@@ -2,11 +2,9 @@
|
||||
<%
|
||||
if (Model.Any()) { %>
|
||||
<fieldset><%
|
||||
var pi = 0;
|
||||
foreach (var part in Model) {
|
||||
var p = part;
|
||||
var htmlFieldName = string.Format("Parts[{0}]", pi++); %>
|
||||
<%:Html.EditorFor(m => p, "TypePart", htmlFieldName) %><%
|
||||
var p = part; %>
|
||||
<%:Html.EditorFor(m => p, "TypePart", p.Prefix) %><%
|
||||
} %>
|
||||
</fieldset><%
|
||||
} %>
|
@@ -32,6 +32,7 @@ namespace Orchard.DevTools.Commands {
|
||||
string dataMigrationsPath = HostingEnvironment.MapPath("~/Modules/" + extension.Name + "/DataMigrations/");
|
||||
string dataMigrationPath = dataMigrationsPath + extension.DisplayName + "DataMigration.cs";
|
||||
string templatesPath = HostingEnvironment.MapPath("~/Modules/Orchard.DevTools/ScaffoldingTemplates/");
|
||||
string moduleCsProjPath = HostingEnvironment.MapPath(string.Format("~/Modules/{0}/{0}.csproj", extension.Name));
|
||||
if ( !Directory.Exists(dataMigrationsPath) ) {
|
||||
Directory.CreateDirectory(dataMigrationsPath);
|
||||
}
|
||||
@@ -55,7 +56,20 @@ namespace Orchard.DevTools.Commands {
|
||||
dataMigrationText = dataMigrationText.Replace("$$ClassName$$", extension.DisplayName);
|
||||
dataMigrationText = dataMigrationText.Replace("$$Commands$$", stringWriter.ToString());
|
||||
File.WriteAllText(dataMigrationPath, dataMigrationText);
|
||||
Context.Output.WriteLine(T("Data migration created successfully in Module {0}", extension.DisplayName));
|
||||
|
||||
string projectFileText = File.ReadAllText(moduleCsProjPath);
|
||||
// The string searches in solution/project files can be made aware of comment lines.
|
||||
if ( projectFileText.Contains("<Compile Include") ) {
|
||||
string compileReference = string.Format("<Compile Include=\"{0}\" />\r\n ", "DataMigrations\\" + extension.DisplayName + "DataMigration.cs");
|
||||
projectFileText = projectFileText.Insert(projectFileText.LastIndexOf("<Compile Include"), compileReference);
|
||||
}
|
||||
else {
|
||||
string itemGroupReference = string.Format("</ItemGroup>\r\n <ItemGroup>\r\n <Compile Include=\"{0}\" />\r\n ", "DataMigrations\\" + extension.DisplayName + "DataMigration.cs");
|
||||
projectFileText = projectFileText.Insert(projectFileText.LastIndexOf("</ItemGroup>"), itemGroupReference);
|
||||
}
|
||||
File.WriteAllText(moduleCsProjPath, projectFileText);
|
||||
|
||||
Context.Output.WriteLine(T("Data migration created successfully in Module {0}", extension.Name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ namespace $$FeatureName$$.DataMigrations {
|
||||
public class $$ClassName$$DataMigration : DataMigrationImpl {
|
||||
|
||||
public int Create() {
|
||||
$$Commands$$
|
||||
$$Commands$$
|
||||
|
||||
return 0100;
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ namespace Orchard.DevTools.Services {
|
||||
}
|
||||
|
||||
public override void Visit(CreateTableCommand command) {
|
||||
_output.WriteLine("// Creating table {0}", command.Name);
|
||||
_output.WriteLine("\t\t\t// Creating table {0}", command.Name);
|
||||
_output.WriteLine("\t\t\tSchemaBuilder.CreateTable(\"{0}\", table => table", command.Name);
|
||||
|
||||
foreach ( var createColumn in command.TableCommands.OfType<CreateColumnCommand>() ) {
|
||||
@@ -22,7 +22,7 @@ namespace Orchard.DevTools.Services {
|
||||
var options = new List<string>();
|
||||
|
||||
if ( createColumn.IsPrimaryKey ) {
|
||||
options.Add(string.Format("WithLength({0})", createColumn.Length));
|
||||
options.Add("PrimaryKey()");
|
||||
}
|
||||
|
||||
if ( createColumn.IsUnique ) {
|
||||
@@ -33,10 +33,6 @@ namespace Orchard.DevTools.Services {
|
||||
options.Add("NotNull()");
|
||||
}
|
||||
|
||||
if ( createColumn.IsPrimaryKey ) {
|
||||
options.Add("PrimaryKey()");
|
||||
}
|
||||
|
||||
if ( createColumn.Length.HasValue ) {
|
||||
options.Add(string.Format("WithLength({0})", createColumn.Length ));
|
||||
}
|
||||
|
@@ -83,8 +83,8 @@ namespace Orchard.Indexing.Commands {
|
||||
Context.Output.WriteLine("│ {0} │ {1,6} │", "Title" + new string(' ', 60 - "Title".Length), "Score");
|
||||
Context.Output.WriteLine("├──────────────────────────────────────────────────────────────┼────────┤");
|
||||
foreach ( var searchHit in results ) {
|
||||
var title = searchHit.GetString("title");
|
||||
title = title.Substring(0, Math.Min(60, title.Length)) ?? "- no title -";
|
||||
var title = searchHit.GetString("title") ?? "- no title -";
|
||||
title = title.Substring(0, Math.Min(60, title.Length));
|
||||
var score = searchHit.Score;
|
||||
Context.Output.WriteLine("│ {0} │ {1,6} │", title + new string(' ', 60 - title.Length), score);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ namespace Orchard.Media.DataMigrations {
|
||||
public int Create() {
|
||||
//CREATE TABLE Orchard_Media_MediaSettingsRecord (Id INTEGER not null, RootMediaFolder TEXT, primary key (Id));
|
||||
SchemaBuilder.CreateTable("MediaSettingsRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("RootMediaFolder")
|
||||
);
|
||||
|
||||
|
@@ -56,6 +56,12 @@
|
||||
.features.summary-view .disabled.feature {
|
||||
border-color:#CCC;
|
||||
}
|
||||
.features .update.feature {
|
||||
background:#ECC;
|
||||
}
|
||||
.features.summary-view .update.feature {
|
||||
border-color:#E77;
|
||||
}
|
||||
.features.detail-view .feature {
|
||||
border-bottom:1px solid #CCC;
|
||||
}
|
||||
@@ -109,26 +115,7 @@
|
||||
right:.4em;
|
||||
top:.4em;
|
||||
}
|
||||
|
||||
a.update {
|
||||
.features .feature .actions form.inline.link,
|
||||
.features .feature .actions a {
|
||||
margin-left:.5em;
|
||||
}
|
||||
.features .update.feature {
|
||||
background:#ecc;
|
||||
}
|
||||
.features.summary-view .update.feature {
|
||||
border-color:#e77;
|
||||
}
|
||||
|
||||
.cathedral {
|
||||
bottom:0;
|
||||
font-size:.8em;
|
||||
position:absolute;
|
||||
right:3px;
|
||||
}
|
||||
.cathedral a,
|
||||
.cathedral a:link,
|
||||
.cathedral a:visited,
|
||||
.cathedral form.inline.link button {
|
||||
color:#aeaeae;
|
||||
}
|
||||
}
|
@@ -5,12 +5,12 @@ namespace Orchard.Sandbox.DataMigrations {
|
||||
|
||||
public int Create() {
|
||||
SchemaBuilder.CreateTable("SandboxPageRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("Name")
|
||||
);
|
||||
|
||||
SchemaBuilder.CreateTable("SandboxSettingsRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<bool>("AllowAnonymousEdits")
|
||||
);
|
||||
|
||||
|
@@ -6,7 +6,7 @@ namespace Orchard.Search.DataMigrations {
|
||||
public int Create() {
|
||||
|
||||
SchemaBuilder.CreateTable("SearchSettingsRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<bool>("FilterCulture")
|
||||
.Column<string>("SearchedFields")
|
||||
);
|
||||
|
@@ -6,7 +6,7 @@ namespace Orchard.Search.Models {
|
||||
public virtual string SearchedFields { get; set; }
|
||||
|
||||
public SearchSettingsRecord() {
|
||||
FilterCulture = true;
|
||||
FilterCulture = false;
|
||||
SearchedFields = "body, title";
|
||||
}
|
||||
}
|
||||
|
@@ -160,7 +160,7 @@ namespace Orchard.Setup.Services {
|
||||
// add default culture
|
||||
var cultureManager = environment.Resolve<ICultureManager>();
|
||||
cultureManager.AddCulture("en-US");
|
||||
cultureManager.AddCulture("fr-FR");
|
||||
cultureManager.AddCulture("fr");
|
||||
|
||||
var contentManager = environment.Resolve<IContentManager>();
|
||||
|
||||
|
@@ -6,7 +6,7 @@ namespace Orchard.Themes.DataMigrations {
|
||||
public int Create() {
|
||||
//CREATE TABLE Orchard_Themes_ThemeRecord (Id INTEGER not null, ThemeName TEXT, DisplayName TEXT, Description TEXT, Version TEXT, Author TEXT, HomePage TEXT, Tags TEXT, primary key (Id));
|
||||
SchemaBuilder.CreateTable("ThemeRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("ThemeName")
|
||||
.Column<string>("DisplayName")
|
||||
.Column<string>("Description")
|
||||
@@ -18,7 +18,7 @@ namespace Orchard.Themes.DataMigrations {
|
||||
|
||||
//CREATE TABLE Orchard_Themes_ThemeSiteSettingsRecord (Id INTEGER not null, CurrentThemeName TEXT, primary key (Id));
|
||||
SchemaBuilder.CreateTable("ThemeSiteSettingsRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("CurrentThemeName")
|
||||
);
|
||||
|
||||
|
@@ -6,7 +6,7 @@ namespace Orchard.Users.DataMigrations {
|
||||
public int Create() {
|
||||
//CREATE TABLE Orchard_Users_UserRecord (Id INTEGER not null, UserName TEXT, Email TEXT, NormalizedUserName TEXT, Password TEXT, PasswordFormat TEXT, PasswordSalt TEXT, primary key (Id));
|
||||
SchemaBuilder.CreateTable("UserRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey())
|
||||
.ContentPartRecord()
|
||||
.Column<string>("UserName")
|
||||
.Column<string>("Email")
|
||||
.Column<string>("NormalizedUserName")
|
||||
|
@@ -397,8 +397,8 @@ label input {
|
||||
}
|
||||
/* todo: (heskew) try to get .text on stuff like .text-box */
|
||||
select, textarea, input.text, input.textMedium, input.text-box {
|
||||
padding:2px;
|
||||
border:1px solid #bdbcbc;
|
||||
padding:1px;
|
||||
border:1px solid #bdbcbc;
|
||||
}
|
||||
input.text, input.textMedium, input.text-box {
|
||||
line-height:1.2em;
|
||||
|
Reference in New Issue
Block a user