From 75d7f6bc6865904a686f5e2b8d2a7788232f68dd Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Wed, 7 Jul 2010 10:16:30 -0700 Subject: [PATCH 1/8] A bit of content type management refactoring - put the controller on a diet - made type display name changes take - pulled some hard-coded template prefix strings into the view model --HG-- branch : dev --- .../Metadata/ContentDefinitionManager.cs | 1 + .../Controllers/AdminController.cs | 365 +++++++----------- .../Orchard.ContentTypes.csproj | 4 +- .../Services/ContentDefinitionService.cs | 183 +++++++-- .../Services/IContentDefinitionService.cs | 29 +- .../ViewModels/EditTypeViewModel.cs | 47 ++- .../ViewModels/ListContentPartsViewModel.cs | 3 +- .../ViewModels/ListContentTypesViewModel.cs | 3 +- .../Views/Admin/Edit.ascx | 6 +- ...Definition.ascx => EditPartViewModel.ascx} | 2 +- ...Definition.ascx => EditTypeViewModel.ascx} | 2 +- .../Views/EditorTemplates/Field.ascx | 6 +- .../Views/EditorTemplates/Fields.ascx | 6 +- .../Views/EditorTemplates/TypePart.ascx | 3 +- .../Views/EditorTemplates/TypePartField.ascx | 4 +- .../Views/EditorTemplates/TypePartFields.ascx | 6 +- .../Views/EditorTemplates/TypeParts.ascx | 6 +- .../Builders/ContentTypeDefinitionBuilder.cs | 2 +- .../MetaData/IContentDefinitionManager.cs | 2 +- .../MetaData/Models/ContentTypeDefinition.cs | 5 +- 20 files changed, 371 insertions(+), 314 deletions(-) rename src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/{ContentPartDefinition.ascx => EditPartViewModel.ascx} (79%) rename src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/{ContentTypeDefinition.ascx => EditTypeViewModel.ascx} (87%) diff --git a/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs b/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs index 37a63908b..01abe216d 100644 --- a/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs +++ b/src/Orchard.Web/Core/Settings/Metadata/ContentDefinitionManager.cs @@ -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 diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs index 70d10e341..7e3fe0e52 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Controllers/AdminController.cs @@ -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 _prefix = x => x; - - public bool TryUpdateModel(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 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()); + } } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj index b079e5db4..ab8dca7c2 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Orchard.ContentTypes.csproj @@ -99,8 +99,8 @@ - - + + diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs index a39cfdb92..fdfac77f1 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs @@ -2,42 +2,69 @@ 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 _contentFieldDrivers; + private readonly IContentDefinitionEditorEvents _contentDefinitionEditorEvents; - public ContentDefinitionService(IOrchardServices services, IContentDefinitionManager contentDefinitionManager, IEnumerable contentFieldDrivers) { + public ContentDefinitionService( + IOrchardServices services, + IContentDefinitionManager contentDefinitionManager, + IEnumerable contentFieldDrivers, + IContentDefinitionEditorEvents contentDefinitionEditorEvents) { Services = services; _contentDefinitionManager = contentDefinitionManager; _contentFieldDrivers = contentFieldDrivers; + _contentDefinitionEditorEvents = contentDefinitionEditorEvents; T = NullLocalizer.Instance; } public IOrchardServices Services { get; set; } public Localizer T { get; set; } - public IEnumerable GetTypeDefinitions() { - return _contentDefinitionManager.ListTypeDefinitions(); + public IEnumerable 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 }; + var contentTypeDefinition = new ContentTypeDefinition(name, typeViewModel.DisplayName); //just giving the new type some default parts for now _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition); _contentDefinitionManager.AlterTypeDefinition( @@ -45,36 +72,99 @@ namespace Orchard.ContentTypes.Services { 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; + return new EditTypeViewModel(contentTypeDefinition); } - public void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition) { - _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition); + public void AlterType(EditTypeViewModel typeViewModel, IUpdateModel updateModel) { + var updater = new Updater(updateModel); + _contentDefinitionManager.AlterTypeDefinition(typeViewModel.Name, typeBuilder => { + typeBuilder.DisplayedAs(typeViewModel.DisplayName); - var implicitTypePart = contentTypeDefinition.Parts.SingleOrDefault(p => p.PartDefinition.Name == contentTypeDefinition.Name); - if (implicitTypePart != null) { - AlterPartDefinition(implicitTypePart.PartDefinition); - } + // 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 RemoveTypeDefinition(string name) { + public void RemoveType(string name) { throw new NotImplementedException(); } - public IEnumerable 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 GetParts() { + var typeNames = GetTypes().Select(ctd => ctd.Name); + return _contentDefinitionManager.ListPartDefinitions().Where(cpd => !typeNames.Contains(cpd.Name)).Select(cpd => new EditPartViewModel(cpd)); + } + + 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 +172,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 GetFieldDefinitions() { + public IEnumerable 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 +233,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 _prefix = x => x; + + public bool TryUpdateModel(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); + } + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs index 62be29138..70c59e4a7 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/IContentDefinitionService.cs @@ -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 GetTypeDefinitions(); - ContentTypeDefinition GetTypeDefinition(string name); - ContentTypeDefinition AddTypeDefinition(string displayName); - void AlterTypeDefinition(ContentTypeDefinition contentTypeDefinition); - void RemoveTypeDefinition(string name); + IEnumerable 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 GetPartDefinitions(); - ContentPartDefinition GetPartDefinition(string name); - ContentPartDefinition AddPartDefinition(string name); - void AlterPartDefinition(ContentPartDefinition contentPartDefinition); - void RemovePartDefinition(string name); + IEnumerable GetParts(); + EditPartViewModel GetPart(string name); + EditPartViewModel AddPart(CreatePartViewModel partViewModel); + void AlterPart(EditPartViewModel partViewModel, IUpdateModel updater); + void RemovePart(string name); - IEnumerable GetFieldDefinitions(); + IEnumerable GetFields(); + void AddFieldToPart(string fieldName, string fieldTypeName, string partName); + void RemoveFieldFromPart(string fieldName, string partName); } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs index 53a1ff8a7..7e92bc80c 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/EditTypeViewModel.cs @@ -11,34 +11,36 @@ namespace Orchard.ContentTypes.ViewModels { Fields = new List(); Parts = new List(); } + 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 Templates { get; set; } - public SettingsDictionary Settings { get; set; } public IEnumerable Fields { get; set; } public IEnumerable Parts { get; set; } + public IEnumerable Templates { get; set; } + public ContentTypeDefinition _Definition { get; private set; } private IEnumerable GetTypeFields(ContentTypeDefinition contentTypeDefinition) { var implicitTypePart = contentTypeDefinition.Parts.SingleOrDefault(p => p.PartDefinition.Name == Name); return implicitTypePart == null ? Enumerable.Empty() - : 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 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 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(); 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 Templates { get; set; } public IEnumerable 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 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; } } } diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/ListContentPartsViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/ListContentPartsViewModel.cs index 309cf1c3e..35b1c5cd9 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/ListContentPartsViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/ListContentPartsViewModel.cs @@ -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 Parts { get; set; } + public IEnumerable Parts { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/ListContentTypesViewModel.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/ListContentTypesViewModel.cs index df9bce874..3dc4fa9f3 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/ListContentTypesViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/ViewModels/ListContentTypesViewModel.cs @@ -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 Types { get; set; } + public IEnumerable Types { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx index 96458cbdc..00a8ddf3e 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/Edit.ascx @@ -17,12 +17,12 @@ using (Html.BeginFormAntiForgeryPost()) { %> <%:Html.HiddenFor(m => m.Name) %> <% Html.RenderTemplates(Model.Templates); %> -

<%:T("Parts") %>

-
<%: Html.ActionLink(T("Add").Text, "AddPartsTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" })%>
<%: - Html.EditorFor(m => m.Parts, "TypeParts", "") %>

<%:T("Fields") %>

<%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %>
<%: Html.EditorFor(m => m.Fields, "Fields", "") %> +

<%:T("Parts") %>

+
<%: Html.ActionLink(T("Add").Text, "AddPartsTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" })%>
<%: + Html.EditorFor(m => m.Parts, "TypeParts", "") %>
diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/ContentPartDefinition.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditPartViewModel.ascx similarity index 79% rename from src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/ContentPartDefinition.ascx rename to src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditPartViewModel.ascx index c785c1215..5cb9a042e 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/ContentPartDefinition.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditPartViewModel.ascx @@ -1,4 +1,4 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>

<%:Model.Name%>

diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/ContentTypeDefinition.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditTypeViewModel.ascx similarity index 87% rename from src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/ContentTypeDefinition.ascx rename to src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditTypeViewModel.ascx index 9e896922c..d0b8456bf 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/ContentTypeDefinition.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/DisplayTemplates/EditTypeViewModel.ascx @@ -1,4 +1,4 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %>

<%:Model.DisplayName%>

diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx index ddfe0a09e..65e6fc7e8 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Field.ascx @@ -4,6 +4,8 @@
<%:Html.ActionLink(T("Remove").Text, "RemoveFieldFrom", new { area = "Orchard.ContentTypes", id = Model.Part.Name, Model.Name }, new { itemprop = "RemoveUrl UnsafeUrl" })%><%--// <- some experimentation--%>
<% - 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) %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx index dba3f94eb..29b577a43 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/Fields.ascx @@ -2,11 +2,9 @@ <% 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, "Field", htmlFieldName) %><% + var f = field; %> + <%:Html.EditorFor(m => f, "Field", field.Prefix) %><% } %>
<% } %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx index d2382be7d..256ba7e85 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePart.ascx @@ -12,5 +12,6 @@
<%:Html.ActionLink(T("Edit global part config").Text, "EditPart", new { area = "Orchard.ContentTypes", id = Model.PartDefinition.Name })%>
<%: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) %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartField.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartField.ascx index f7f933c7d..2b236a4a3 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartField.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartField.ascx @@ -6,5 +6,7 @@ Html.RenderTemplates(Model.Templates); %>
<% } %> - <%: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) %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartFields.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartFields.ascx index 5c270aa45..a1c1b86e6 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartFields.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypePartFields.ascx @@ -1,10 +1,8 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> <% 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) %><% } } %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypeParts.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypeParts.ascx index cc41743b0..c6035fba2 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypeParts.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/EditorTemplates/TypeParts.ascx @@ -2,11 +2,9 @@ <% if (Model.Any()) { %>
<% - 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) %><% } %>
<% } %> \ No newline at end of file diff --git a/src/Orchard/ContentManagement/MetaData/Builders/ContentTypeDefinitionBuilder.cs b/src/Orchard/ContentManagement/MetaData/Builders/ContentTypeDefinitionBuilder.cs index dfe1747aa..c0df7d18f 100644 --- a/src/Orchard/ContentManagement/MetaData/Builders/ContentTypeDefinitionBuilder.cs +++ b/src/Orchard/ContentManagement/MetaData/Builders/ContentTypeDefinitionBuilder.cs @@ -11,7 +11,7 @@ namespace Orchard.ContentManagement.MetaData.Builders { private readonly SettingsDictionary _settings; public ContentTypeDefinitionBuilder() - : this(new ContentTypeDefinition(null)) { + : this(new ContentTypeDefinition(null, null)) { } public ContentTypeDefinitionBuilder(ContentTypeDefinition existing) { diff --git a/src/Orchard/ContentManagement/MetaData/IContentDefinitionManager.cs b/src/Orchard/ContentManagement/MetaData/IContentDefinitionManager.cs index a17decb2b..076cb99f1 100644 --- a/src/Orchard/ContentManagement/MetaData/IContentDefinitionManager.cs +++ b/src/Orchard/ContentManagement/MetaData/IContentDefinitionManager.cs @@ -18,7 +18,7 @@ namespace Orchard.ContentManagement.MetaData { public static class ContentDefinitionManagerExtensions{ public static void AlterTypeDefinition(this IContentDefinitionManager manager, string name, Action alteration) { - var typeDefinition = manager.GetTypeDefinition(name) ?? new ContentTypeDefinition(name); + var typeDefinition = manager.GetTypeDefinition(name) ?? new ContentTypeDefinition(name, name); var builder = new ContentTypeDefinitionBuilder(typeDefinition); alteration(builder); manager.StoreTypeDefinition(builder.Build()); diff --git a/src/Orchard/ContentManagement/MetaData/Models/ContentTypeDefinition.cs b/src/Orchard/ContentManagement/MetaData/Models/ContentTypeDefinition.cs index 09406bc04..cc1e00675 100644 --- a/src/Orchard/ContentManagement/MetaData/Models/ContentTypeDefinition.cs +++ b/src/Orchard/ContentManagement/MetaData/Models/ContentTypeDefinition.cs @@ -11,8 +11,9 @@ namespace Orchard.ContentManagement.MetaData.Models { Settings = settings; } - public ContentTypeDefinition(string name) { + public ContentTypeDefinition(string name, string displayName) { Name = name; + DisplayName = displayName; Parts = Enumerable.Empty(); Settings = new SettingsDictionary(); } @@ -20,7 +21,7 @@ namespace Orchard.ContentManagement.MetaData.Models { [StringLength(128)] public string Name { get; private set; } [Required, StringLength(1024)] - public string DisplayName { get; set; } + public string DisplayName { get; private set; } public IEnumerable Parts { get; private set; } public SettingsDictionary Settings { get; private set; } From 2ccd28fea1cdba48e68278a38c4c97c9488235f7 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Wed, 7 Jul 2010 11:15:05 -0700 Subject: [PATCH 2/8] Some features management CSS cleanup --HG-- branch : dev --- .../Modules/Orchard.Modules/styles/admin.css | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Modules/styles/admin.css b/src/Orchard.Web/Modules/Orchard.Modules/styles/admin.css index 6c98fa853..3ceabbae5 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/styles/admin.css +++ b/src/Orchard.Web/Modules/Orchard.Modules/styles/admin.css @@ -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; -} +} \ No newline at end of file From 857c59de45bf4891a63dd8bbc744524266b9b184 Mon Sep 17 00:00:00 2001 From: Suha Can Date: Wed, 7 Jul 2010 11:15:48 -0700 Subject: [PATCH 3/8] - Adding a culture command handler with a few commands related to culture management. - Moving fr-FR culture to fr --HG-- branch : dev --- .../{fr-FR => fr}/orchard.core.po | 0 .../Orchard.Setup/Services/SetupService.cs | 2 +- .../Localization/Commands/CultureCommands.cs | 49 +++++++++++++++++++ .../Services/DefaultCultureManager.cs | 2 +- .../Localization/Services/ICultureManager.cs | 1 + src/Orchard/Orchard.Framework.csproj | 1 + 6 files changed, 53 insertions(+), 2 deletions(-) rename src/Orchard.Web/Core/App_Data/Localization/{fr-FR => fr}/orchard.core.po (100%) create mode 100644 src/Orchard/Localization/Commands/CultureCommands.cs diff --git a/src/Orchard.Web/Core/App_Data/Localization/fr-FR/orchard.core.po b/src/Orchard.Web/Core/App_Data/Localization/fr/orchard.core.po similarity index 100% rename from src/Orchard.Web/Core/App_Data/Localization/fr-FR/orchard.core.po rename to src/Orchard.Web/Core/App_Data/Localization/fr/orchard.core.po diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index 089dca490..b4c7569f8 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -160,7 +160,7 @@ namespace Orchard.Setup.Services { // add default culture var cultureManager = environment.Resolve(); cultureManager.AddCulture("en-US"); - cultureManager.AddCulture("fr-FR"); + cultureManager.AddCulture("fr"); var contentManager = environment.Resolve(); diff --git a/src/Orchard/Localization/Commands/CultureCommands.cs b/src/Orchard/Localization/Commands/CultureCommands.cs new file mode 100644 index 000000000..841187d55 --- /dev/null +++ b/src/Orchard/Localization/Commands/CultureCommands.cs @@ -0,0 +1,49 @@ +using System.Linq; +using JetBrains.Annotations; +using Orchard.Commands; +using Orchard.Localization.Services; +using Orchard.Settings; + +namespace Orchard.Localization.Commands { + public class CultureCommands : DefaultOrchardCommandHandler { + private readonly ICultureManager _cultureManager; + + protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } + + public CultureCommands(ICultureManager cultureManager) { + _cultureManager = cultureManager; + } + + [CommandHelp("cultures list \r\n\t" + "List site cultures")] + [CommandName("cultures list")] + public void ListCultures() { + Context.Output.WriteLine(T("Listing Cultures:")); + + string cultures = _cultureManager.ListCultures().Aggregate(null, (current, culture) => current + culture + " "); + + Context.Output.WriteLine(cultures); + } + + + [CommandHelp("cultures get site culture \r\n\t" + "Get culture for the site")] + [CommandName("cultures get site culture")] + public void GetSiteCulture() { + Context.Output.WriteLine(T("Site Culture is {0}", CurrentSite.SiteCulture)); + } + + [CommandHelp("cultures set site culture \r\n\t" + "Set culture for the site")] + [CommandName("cultures set site culture")] + public void SetSiteCulture(string cultureName) { + Context.Output.WriteLine(T("Setting site culture to {0}", cultureName)); + + if (!_cultureManager.IsValidCulture(cultureName)) { + Context.Output.WriteLine(T("Supplied culture name {0} is not valid.", cultureName)); + return; + } + CurrentSite.SiteCulture = cultureName; + + Context.Output.WriteLine(T("Site culture set to {0} successfully", cultureName)); + } + } +} + diff --git a/src/Orchard/Localization/Services/DefaultCultureManager.cs b/src/Orchard/Localization/Services/DefaultCultureManager.cs index e689ab82b..c1a7e1523 100644 --- a/src/Orchard/Localization/Services/DefaultCultureManager.cs +++ b/src/Orchard/Localization/Services/DefaultCultureManager.cs @@ -71,7 +71,7 @@ namespace Orchard.Localization.Services { // "" or // "-" or // "--" - private static bool IsValidCulture(string cultureName) { + public bool IsValidCulture(string cultureName) { Regex cultureRegex = new Regex(@"\w{2}(-\w{2,})*"); if (cultureRegex.IsMatch(cultureName)) { return true; diff --git a/src/Orchard/Localization/Services/ICultureManager.cs b/src/Orchard/Localization/Services/ICultureManager.cs index 0ae822a42..e866e78c6 100644 --- a/src/Orchard/Localization/Services/ICultureManager.cs +++ b/src/Orchard/Localization/Services/ICultureManager.cs @@ -10,5 +10,6 @@ namespace Orchard.Localization.Services { string GetCurrentCulture(HttpContext requestContext); CultureRecord GetCultureById(int id); string GetSiteCulture(); + bool IsValidCulture(string cultureName); } } diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index e9337076f..b94b67613 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -406,6 +406,7 @@ + From 9597712701e1123b526ea762c4e960f47eaa9ac3 Mon Sep 17 00:00:00 2001 From: Suha Can Date: Wed, 7 Jul 2010 11:30:43 -0700 Subject: [PATCH 4/8] - Invalidating cultures cache when site cultures are modified (add,delete). --HG-- branch : dev --- .../Localization/Services/DefaultCultureManager.cs | 10 ++++++++-- .../Localization/Services/DefaultResourceManager.cs | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Orchard/Localization/Services/DefaultCultureManager.cs b/src/Orchard/Localization/Services/DefaultCultureManager.cs index c1a7e1523..86f4cfcbf 100644 --- a/src/Orchard/Localization/Services/DefaultCultureManager.cs +++ b/src/Orchard/Localization/Services/DefaultCultureManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Web; using JetBrains.Annotations; +using Orchard.Caching; using Orchard.Data; using Orchard.Localization.Records; using Orchard.Settings; @@ -12,10 +13,12 @@ namespace Orchard.Localization.Services { public class DefaultCultureManager : ICultureManager { private readonly IRepository _cultureRepository; private readonly IEnumerable _cultureSelectors; + private readonly ISignals _signals; - public DefaultCultureManager(IRepository cultureRepository, IEnumerable cultureSelectors) { + public DefaultCultureManager(IRepository cultureRepository, IEnumerable cultureSelectors, ISignals signals) { _cultureRepository = cultureRepository; _cultureSelectors = cultureSelectors; + _signals = signals; } protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } @@ -30,6 +33,7 @@ namespace Orchard.Localization.Services { throw new ArgumentException("cultureName"); } _cultureRepository.Create(new CultureRecord { Culture = cultureName }); + _signals.Trigger("culturesChanged"); } public void DeleteCulture(string cultureName) { @@ -38,8 +42,10 @@ namespace Orchard.Localization.Services { } var culture = _cultureRepository.Get(cr => cr.Culture == cultureName); - if (culture != null) + if (culture != null) { _cultureRepository.Delete(culture); + _signals.Trigger("culturesChanged"); + } } public string GetCurrentCulture(HttpContext requestContext) { diff --git a/src/Orchard/Localization/Services/DefaultResourceManager.cs b/src/Orchard/Localization/Services/DefaultResourceManager.cs index 3f0871041..a51be91e2 100644 --- a/src/Orchard/Localization/Services/DefaultResourceManager.cs +++ b/src/Orchard/Localization/Services/DefaultResourceManager.cs @@ -14,6 +14,7 @@ namespace Orchard.Localization.Services { private readonly IExtensionManager _extensionManager; private readonly ICacheManager _cacheManager; private readonly ShellSettings _shellSettings; + private readonly ISignals _signals; const string CoreLocalizationFilePathFormat = "/Core/App_Data/Localization/{0}/orchard.core.po"; const string ModulesLocalizationFilePathFormat = "/Modules/{0}/App_Data/Localization/{1}/orchard.module.po"; const string RootLocalizationFilePathFormat = "/App_Data/Localization/{0}/orchard.root.po"; @@ -24,12 +25,14 @@ namespace Orchard.Localization.Services { IWebSiteFolder webSiteFolder, IExtensionManager extensionManager, ICacheManager cacheManager, - ShellSettings shellSettings) { + ShellSettings shellSettings, + ISignals signals) { _cultureManager = cultureManager; _webSiteFolder = webSiteFolder; _extensionManager = extensionManager; _cacheManager = cacheManager; _shellSettings = shellSettings; + _signals = signals; } // This will translate a string into a string in the target cultureName. @@ -96,6 +99,7 @@ namespace Orchard.Localization.Services { Translations = LoadTranslationsForCulture(culture, ctx) }); } + ctx.Monitor(_signals.When("culturesChanged")); return cultures; }); From 8da1423511574cfc9cf01b510e2734b58d692d67 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Wed, 7 Jul 2010 11:47:18 -0700 Subject: [PATCH 5/8] Changed new content types to be part-free on creation --HG-- branch : dev --- .../Services/ContentDefinitionService.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs index fdfac77f1..07fded3a2 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs @@ -65,13 +65,7 @@ namespace Orchard.ContentTypes.Services { name = VersionName(name); var contentTypeDefinition = new ContentTypeDefinition(name, typeViewModel.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")); return new EditTypeViewModel(contentTypeDefinition); } From fd95b7284f6301c591b3b2c4376e68526b78860b Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Wed, 7 Jul 2010 12:29:30 -0700 Subject: [PATCH 6/8] Getting at available parts (to hook on to content types) differently to include appropriate code- and user-defined parts --HG-- branch : dev --- .../Services/ContentDefinitionService.cs | 13 +++++++++++-- .../Views/Admin/AddPartsTo.ascx | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs index 07fded3a2..2667690bd 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Services/ContentDefinitionService.cs @@ -12,16 +12,20 @@ using Orchard.Localization; namespace Orchard.ContentTypes.Services { public class ContentDefinitionService : IContentDefinitionService { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly IEnumerable _contentPartDrivers; private readonly IEnumerable _contentFieldDrivers; private readonly IContentDefinitionEditorEvents _contentDefinitionEditorEvents; public ContentDefinitionService( IOrchardServices services, IContentDefinitionManager contentDefinitionManager, + IEnumerable contentPartDrivers, IEnumerable contentFieldDrivers, - IContentDefinitionEditorEvents contentDefinitionEditorEvents) { + IContentDefinitionEditorEvents contentDefinitionEditorEvents) + { Services = services; _contentDefinitionManager = contentDefinitionManager; + _contentPartDrivers = contentPartDrivers; _contentFieldDrivers = contentFieldDrivers; _contentDefinitionEditorEvents = contentDefinitionEditorEvents; T = NullLocalizer.Instance; @@ -141,7 +145,12 @@ namespace Orchard.ContentTypes.Services { public IEnumerable GetParts() { var typeNames = GetTypes().Select(ctd => ctd.Name); - return _contentDefinitionManager.ListPartDefinitions().Where(cpd => !typeNames.Contains(cpd.Name)).Select(cpd => new EditPartViewModel(cpd)); + // 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) { diff --git a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddPartsTo.ascx b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddPartsTo.ascx index 7f70491e7..b9055c5fd 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddPartsTo.ascx +++ b/src/Orchard.Web/Modules/Orchard.ContentTypes/Views/Admin/AddPartsTo.ascx @@ -13,7 +13,7 @@ using (Html.BeginFormAntiForgeryPost()) { %> string.Format( "{0} {3}", Html.CheckBox(fieldNameStart + "IsSelected"), - fieldNameStart + "IsSelected", + ViewData.TemplateInfo.GetFullHtmlFieldId(fieldNameStart + "IsSelected"), partSelection.PartName, Html.Hidden(fieldNameStart + "PartName", partSelection.PartName))); }, From ef02c6d66d729ca091c95f855259f62851a80f6c Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 7 Jul 2010 15:01:51 -0700 Subject: [PATCH 7/8] Corrected Azure project - Removes automatically teh system.extensions tags which prevents MVC from working on Azure - Updated web.config with Orchard.Web's one - Added a machineKey for server farm scenarios --HG-- branch : dev --- AzurePackage.proj | 8 +- .../Orchard.Azure.CloudService.sln | 146 ++++++++++++++ .../Orchard.Azure.Web/Global.asax.cs | 10 +- .../Orchard.Azure.Web.csproj | 178 ++++++++++++++++-- .../Orchard.Azure.Web/Web.Debug.config | 8 + .../Orchard.Azure.Web/Web.Release.config | 8 + .../Orchard.Azure.Web/Web.config | 163 ++++++++-------- 7 files changed, 417 insertions(+), 104 deletions(-) create mode 100644 src/Orchard.Azure/Orchard.Azure.Web/Web.Debug.config create mode 100644 src/Orchard.Azure/Orchard.Azure.Web/Web.Release.config diff --git a/AzurePackage.proj b/AzurePackage.proj index 0dade831c..41afd884f 100644 --- a/AzurePackage.proj +++ b/AzurePackage.proj @@ -33,6 +33,7 @@ + @@ -92,7 +93,7 @@ - + @@ -135,7 +136,10 @@ SourceFiles="$(SrcFolder)\Orchard.Azure\Orchard.Azure.CloudService\ServiceConfiguration.cscfg" DestinationFolder="$(StageFolder)" /> - + + + + loadedMvcVersion != allowed) ) { @@ -79,7 +78,7 @@ namespace Orchard.Azure.Web { } } - private Version ReadAssemblyFileVersion(Assembly assembly) { + private static Version ReadAssemblyFileVersion(Assembly assembly) { object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true); if ( attributes == null || attributes.Length != 1 ) { string message = string.Format("Assembly \"{0}\" doesn't have a \"{1}\" attribute", @@ -99,6 +98,5 @@ namespace Orchard.Azure.Web { builder.RegisterInstance(ModelMetadataProviders.Current); builder.RegisterInstance(ViewEngines.Engines); } - } -} \ No newline at end of file +} diff --git a/src/Orchard.Azure/Orchard.Azure.Web/Orchard.Azure.Web.csproj b/src/Orchard.Azure/Orchard.Azure.Web/Orchard.Azure.Web.csproj index 140a03b09..80bec95df 100644 --- a/src/Orchard.Azure/Orchard.Azure.Web/Orchard.Azure.Web.csproj +++ b/src/Orchard.Azure/Orchard.Azure.Web/Orchard.Azure.Web.csproj @@ -47,6 +47,12 @@ False ..\..\..\lib\autofac\Autofac.Configuration.dll + + ..\..\..\lib\autofac\Autofac.Integration.Web.dll + + + ..\..\..\lib\autofac\Autofac.Integration.Web.Mvc.dll + False ..\..\..\lib\Castle Windsor 2.0\bin\Castle.Core.dll @@ -55,36 +61,80 @@ False ..\..\..\lib\Castle Windsor 2.0\bin\Castle.DynamicProxy2.dll + + False + True - - + + ..\..\..\lib\fluentnhibernate\NHibernate.ByteCode.Castle.dll + + + False + + + False + 3.5 + False + + + False + + + ..\..\..\lib\sqlite\x64\System.Data.SQLite.DLL + + + False + + + False + + + False + + + False - - - - - False ..\..\..\..\..\..\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\\Assemblies\System.Web.Mvc.dll True - - - - - - - - - - + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + @@ -95,7 +145,6 @@ - @@ -115,16 +164,109 @@ {9916839C-39FC-4CEB-A5AF-89CA7E87119F} Orchard.Core + + {E65E5633-C0FF-453C-A906-481C14F969D6} + Futures.Widgets + + + {63FBD4D9-E1DA-4A7B-AA6A-D6074FE50867} + Orchard.Blogs + + + {14C049FD-B35B-415A-A824-87F26B26E7FD} + Orchard.Comments + + + {0E7646E8-FE8F-43C1-8799-D97860925EC4} + Orchard.ContentTypes + + + {67C1D3AF-A0EC-46B2-BAE1-DF1DA8E0B890} + Orchard.DevTools + + + {EA2B9121-EF54-40A6-A53E-6593C86EE696} + Orchard.Indexing + + + {D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB} + Orchard.Media + + + {23E04990-2A8D-41B8-9908-6DDB71EA3B23} + Orchard.MetaData + + + {17F86780-9A1F-4AA1-86F1-875EEC2730C7} + Orchard.Modules + + + {72457126-E118-4171-A08F-9A709EE4B7FC} + Orchard.MultiTenancy + + + {4A9C04A6-0986-4A92-A610-5F59FF273FB9} + Orchard.Pages + + + {D10AD48F-407D-4DB5-A328-173EC7CB010F} + Orchard.Roles + + + {17C44253-65A2-4597-98C7-16EE576824B6} + Orchard.Sandbox + + + {4BE4EB01-AC56-4048-924E-2CA77F509ABA} + Orchard.Search + + + {8C7FCBC2-E6E1-405E-BFB5-D8D9E67A09C4} + Orchard.Setup + + + {5D0F00F0-26C9-4785-AD61-B85710C60EB0} + Orchard.Tags + + + {CDE24A24-01D3-403C-84B9-37722E18DFB7} + Orchard.Themes + + + {79AED36E-ABD0-4747-93D3-8722B042454B} + Orchard.Users + + + {954CA994-D204-468B-9D69-51F6AD3E1C29} + TinyMce + {2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6} Orchard.Framework False + + {33B1BC8D-E292-4972-A363-22056B207156} + Orchard + {2505AA84-65A6-43D0-9C27-4F44FD576284} Orchard.Azure + + + + + + Web.config + + + + + Web.config + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + From b13c42557aa624832f7c79333ad8e5cfb18e1701 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 7 Jul 2010 15:02:45 -0700 Subject: [PATCH 8/8] Corrected Search command --HG-- branch : dev --- .hgignore | 1 + .../Modules/Orchard.Indexing/Commands/IndexingCommands.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.hgignore b/.hgignore index 9782256f0..ed3674036 100644 --- a/.hgignore +++ b/.hgignore @@ -15,3 +15,4 @@ glob:profiling glob:src/*.ReSharper glob:*.orig glob:*.suo +glob:*.itrace.csdef diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Commands/IndexingCommands.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Commands/IndexingCommands.cs index 292546ab1..f5b587871 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Commands/IndexingCommands.cs +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Commands/IndexingCommands.cs @@ -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); }