From 02e4dbdb665234938d0a87498ba1d8f4b03552b8 Mon Sep 17 00:00:00 2001 From: Dave Reed Date: Tue, 5 Apr 2011 12:55:43 -0700 Subject: [PATCH 01/22] #17664: Edit media - New file name is not allowed. - Fixed view bugs when editing fails. - Improved error message when no extension was given. - Refactored actions --HG-- branch : 1.x --- .../Controllers/AdminController.cs | 17 ++++------------- .../Orchard.Media/Services/MediaService.cs | 5 ++++- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Media/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Media/Controllers/AdminController.cs index 12c865161..b49ffa56c 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Media/Controllers/AdminController.cs @@ -234,16 +234,8 @@ namespace Orchard.Media.Controllers { } } - public ActionResult EditMedia(string name, DateTime lastUpdated, long size, string folderName, string mediaPath) { - var model = new MediaItemEditViewModel(); - model.Name = name; - // todo: reimplement - //model.Caption = caption ?? String.Empty; - model.LastUpdated = lastUpdated; - model.Size = size; - model.FolderName = folderName; - model.MediaPath = mediaPath; - model.PublicUrl = _mediaService.GetPublicUrl(Path.Combine(mediaPath, name)); + public ActionResult EditMedia(MediaItemEditViewModel model) { + model.PublicUrl = _mediaService.GetPublicUrl(Path.Combine(model.MediaPath, model.Name)); return View(model); } @@ -294,9 +286,8 @@ namespace Orchard.Media.Controllers { mediaPath = viewModel.MediaPath }); } catch (Exception exception) { - this.Error(exception, T("Editing media file failed: {0}", exception.Message), Logger, Services.Notifier); - - return View(viewModel); + this.Error(exception, T("Editing media file failed."), Logger, Services.Notifier); + return EditMedia(viewModel); } } } diff --git a/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs b/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs index fe6d77ea7..60cefb0be 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs +++ b/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs @@ -140,7 +140,10 @@ namespace Orchard.Media.Services { Argument.ThrowIfNullOrEmpty(newFileName, "newFileName"); if (!FileAllowed(newFileName, false)) { - throw new ArgumentException(T("New file name {0} is not allowed", newFileName).ToString()); + if (string.IsNullOrEmpty(Path.GetExtension(newFileName))) { + throw new ArgumentException(T("New file name \"{0}\" is not allowed. Please provide a file extension.", newFileName).ToString()); + } + throw new ArgumentException(T("New file name \"{0}\" is not allowed.", newFileName).ToString()); } _storageProvider.RenameFile(_storageProvider.Combine(folderPath, currentFileName), _storageProvider.Combine(folderPath, newFileName)); From e964798de2b540e46698c00f1d1b8aac2eaf43d5 Mon Sep 17 00:00:00 2001 From: Dave Reed Date: Tue, 5 Apr 2011 15:01:43 -0700 Subject: [PATCH 02/22] #17666: having 1 (or more) content types containing ContainerPart but not RoutePart brings down entire ContainablePart - Containable does not rely on RoutePart to get the title, it just uses metadata. - Better display when a container is not routable. --HG-- branch : 1.x --- .../Containers/Drivers/ContainablePartDriver.cs | 2 +- .../Orchard.Lists/Controllers/AdminController.cs | 4 ++-- .../Modules/Orchard.Lists/Views/Admin/Choose.cshtml | 4 ++-- .../Modules/Orchard.Lists/Views/Admin/List.cshtml | 13 +++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Orchard.Web/Core/Containers/Drivers/ContainablePartDriver.cs b/src/Orchard.Web/Core/Containers/Drivers/ContainablePartDriver.cs index 65666c63f..d56e148d3 100644 --- a/src/Orchard.Web/Core/Containers/Drivers/ContainablePartDriver.cs +++ b/src/Orchard.Web/Core/Containers/Drivers/ContainablePartDriver.cs @@ -50,7 +50,7 @@ namespace Orchard.Core.Containers.Drivers { var listItems = new[] { new SelectListItem { Text = T("(None)").Text, Value = "0" } } .Concat(containers.Select(x => new SelectListItem { Value = Convert.ToString(x.Id), - Text = x.ContentItem.TypeDefinition.DisplayName + ": " + x.As().Title, + Text = x.ContentItem.TypeDefinition.DisplayName + ": " + _contentManager.GetItemMetadata(x.ContentItem).DisplayText, Selected = x.Id == model.ContainerId, })) .ToList(); diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Lists/Controllers/AdminController.cs index 2b895ee47..f8f607cff 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Lists/Controllers/AdminController.cs @@ -311,7 +311,7 @@ namespace Lists.Controllers { // ensure the item can be in that container. if (!string.IsNullOrEmpty(itemContentType) && item.ContentType != itemContentType) { Services.TransactionManager.Cancel(); - Services.Notifier.Information(T("One or more items could not be moved to '{0}' because it is restricted to containing items of type '{1}'.", _contentManager.GetItemMetadata(targetContainer).DisplayText, itemContentType)); + Services.Notifier.Information(T("One or more items could not be moved to '{0}' because it is restricted to containing items of type '{1}'.", _contentManager.GetItemMetadata(targetContainer).DisplayText ?? targetContainer.ContentItem.ContentType, itemContentType)); return true; // todo: transactions } @@ -319,7 +319,7 @@ namespace Lists.Controllers { FixItemPath(item); } Services.Notifier.Information(T("Content successfully moved to {1}.", - Url.Action("List", new { containerId = targetContainerId }), _contentManager.GetItemMetadata(targetContainer).DisplayText)); + Url.Action("List", new { containerId = targetContainerId }), _contentManager.GetItemMetadata(targetContainer).DisplayText ?? targetContainer.ContentItem.ContentType)); return true; } diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Views/Admin/Choose.cshtml b/src/Orchard.Web/Modules/Orchard.Lists/Views/Admin/Choose.cshtml index 392854f5c..1dd634cbe 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Views/Admin/Choose.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Lists/Views/Admin/Choose.cshtml @@ -8,14 +8,14 @@ var targetContainers = ((IEnumerable)Model.Containers).Select( contentItem => new SelectListItem { - Text = T("Move to {0}", contentItem.ContentManager.GetItemMetadata(contentItem).DisplayText).ToString(), + Text = T("Move to {0}", contentItem.ContentManager.GetItemMetadata(contentItem).DisplayText ?? contentItem.ContentType).ToString(), Value = contentItem.Id.ToString(System.Globalization.CultureInfo.InvariantCulture), Selected = contentItem.Id == targetContainerId }).ToList(); var sourceContainers = ((IEnumerable)Model.Containers).Select( contentItem => new SelectListItem { - Text = contentItem.ContentManager.GetItemMetadata(contentItem).DisplayText, + Text = contentItem.ContentManager.GetItemMetadata(contentItem).DisplayText ?? contentItem.ContentType, Value = contentItem.Id.ToString(System.Globalization.CultureInfo.InvariantCulture), Selected = contentItem.Id == sourceContainerId }).ToList(); diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Views/Admin/List.cshtml b/src/Orchard.Web/Modules/Orchard.Lists/Views/Admin/List.cshtml index 152acb3e1..6b915120f 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Views/Admin/List.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Lists/Views/Admin/List.cshtml @@ -31,15 +31,16 @@ @using (Html.BeginFormAntiForgeryPost()) { + var options = (ContentOptions) Model.Options;
@Html.DropDownList("TargetContainerId", lists, new { id = "TargetContainerId" }) From f61fda11902e45820d4d44da9666d84a9c25bd7d Mon Sep 17 00:00:00 2001 From: jowall Date: Wed, 6 Apr 2011 15:55:39 -0700 Subject: [PATCH 03/22] Updated titles on setttings screens. --HG-- branch : 1.x --- src/Orchard.Web/Core/Settings/Views/Admin/Index.cshtml | 3 +-- .../EditorTemplates/Parts.Settings.SiteSettingsPart.cshtml | 2 +- .../Views/EditorTemplates/Parts.Comments.SiteSettings.cshtml | 2 +- .../Modules/Orchard.Indexing/Views/Admin/Index.cshtml | 2 +- .../Views/EditorTemplates/Parts/Media.MediaSettings.cshtml | 2 +- .../Modules/Orchard.Packaging/Views/Gallery/Sources.cshtml | 3 ++- .../Views/EditorTemplates/Parts/Search.SiteSettings.cshtml | 2 +- .../EditorTemplates/Parts/Users.RegistrationSettings.cshtml | 2 +- .../Modules/Orchard.Warmup/Views/Admin/Index.cshtml | 4 ++-- src/Orchard.Web/Themes/TheAdmin/Styles/site.css | 5 +++-- 10 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Orchard.Web/Core/Settings/Views/Admin/Index.cshtml b/src/Orchard.Web/Core/Settings/Views/Admin/Index.cshtml index c5c22fb18..f20c11a9f 100644 --- a/src/Orchard.Web/Core/Settings/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Core/Settings/Views/Admin/Index.cshtml @@ -1,7 +1,6 @@ @using Orchard.ContentManagement @{ - GroupInfo groupInfo = Model.GroupInfo; - Layout.Title = (groupInfo != null ? T("Settings for {0}", groupInfo.Name) : T("General Settings")).ToString(); + Layout.Title = T("Settings").ToString(); } @using (Html.BeginFormAntiForgeryPost()) { diff --git a/src/Orchard.Web/Core/Settings/Views/EditorTemplates/Parts.Settings.SiteSettingsPart.cshtml b/src/Orchard.Web/Core/Settings/Views/EditorTemplates/Parts.Settings.SiteSettingsPart.cshtml index fc6d61a59..1a17f19bc 100644 --- a/src/Orchard.Web/Core/Settings/Views/EditorTemplates/Parts.Settings.SiteSettingsPart.cshtml +++ b/src/Orchard.Web/Core/Settings/Views/EditorTemplates/Parts.Settings.SiteSettingsPart.cshtml @@ -8,7 +8,7 @@ }, "Id", "Text", (int)Model.ResourceDebugMode); }
- @T("Enter Settings") + @T("General Settings")
@Html.EditorFor(m => m.SiteName) diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/EditorTemplates/Parts.Comments.SiteSettings.cshtml b/src/Orchard.Web/Modules/Orchard.Comments/Views/EditorTemplates/Parts.Comments.SiteSettings.cshtml index d10fd3998..29a2728c3 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/EditorTemplates/Parts.Comments.SiteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/EditorTemplates/Parts.Comments.SiteSettings.cshtml @@ -2,7 +2,7 @@ @using Orchard.Comments.Models;
- @T("Enter Settings") + @T("Settings for Comments")
@Html.EditorFor(m => m.ModerateComments) diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Indexing/Views/Admin/Index.cshtml index d8e557c4c..d0dd2bc00 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Views/Admin/Index.cshtml @@ -1,7 +1,7 @@ @model Orchard.Indexing.ViewModels.IndexViewModel @using Orchard.Indexing.Services; -@{ Layout.Title = T("Search Index Management").ToString(); } +@{ Layout.Title = T("Settings").ToString(); } @using (Html.BeginForm("update", "admin", FormMethod.Post, new {area = "Orchard.Indexing"})) {
diff --git a/src/Orchard.Web/Modules/Orchard.Media/Views/EditorTemplates/Parts/Media.MediaSettings.cshtml b/src/Orchard.Web/Modules/Orchard.Media/Views/EditorTemplates/Parts/Media.MediaSettings.cshtml index 9dbb35bd3..fdea4d4e9 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Views/EditorTemplates/Parts/Media.MediaSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Media/Views/EditorTemplates/Parts/Media.MediaSettings.cshtml @@ -1,7 +1,7 @@ @model Orchard.Media.Models.MediaSettingsPartRecord
- @T("Enter Settings") + @T("Settings for Media")
@Html.LabelFor(m => m.UploadAllowedFileTypeWhitelist, T("Upload allowed file types (list of extensions separated by spaces)")) @Html.TextBoxFor(m => m.UploadAllowedFileTypeWhitelist, new { @class = "textMedium" }) diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/Sources.cshtml b/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/Sources.cshtml index 556e72c93..e0571d301 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/Sources.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/Sources.cshtml @@ -1,7 +1,8 @@ @model Orchard.Packaging.ViewModels.PackagingSourcesViewModel -@{ Layout.Title = T("Settings for Gallery").ToString(); } +@{ Layout.Title = T("Settings").ToString(); } +

@T("Settings for Gallery")

@Html.ActionLink(T("Add Feed").Text, "AddSource", new { }, new { @class = "button primaryAction" })
diff --git a/src/Orchard.Web/Modules/Orchard.Search/Views/EditorTemplates/Parts/Search.SiteSettings.cshtml b/src/Orchard.Web/Modules/Orchard.Search/Views/EditorTemplates/Parts/Search.SiteSettings.cshtml index 8cedcbd4b..4c9e85d67 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Views/EditorTemplates/Parts/Search.SiteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Search/Views/EditorTemplates/Parts/Search.SiteSettings.cshtml @@ -2,7 +2,7 @@ @using Orchard.Search.ViewModels;
- @T("Enter Settings") + @T("Settings for Search")
@{var entryIndex = 0;} diff --git a/src/Orchard.Web/Modules/Orchard.Users/Views/EditorTemplates/Parts/Users.RegistrationSettings.cshtml b/src/Orchard.Web/Modules/Orchard.Users/Views/EditorTemplates/Parts/Users.RegistrationSettings.cshtml index 3947b1275..d83aad4e2 100644 --- a/src/Orchard.Web/Modules/Orchard.Users/Views/EditorTemplates/Parts/Users.RegistrationSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Users/Views/EditorTemplates/Parts/Users.RegistrationSettings.cshtml @@ -1,7 +1,7 @@ @model Orchard.Users.Models.RegistrationSettingsPartRecord
- @T("Enter Settings") + @T("Settings for Users")
@Html.EditorFor(m => m.UsersCanRegister) diff --git a/src/Orchard.Web/Modules/Orchard.Warmup/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Warmup/Views/Admin/Index.cshtml index e3959fb81..31ed92bd5 100644 --- a/src/Orchard.Web/Modules/Orchard.Warmup/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Warmup/Views/Admin/Index.cshtml @@ -2,13 +2,13 @@ @using Orchard.Utility.Extensions; @using Orchard.Warmup.Models; -@{ Layout.Title = T("Settings for Warmup").ToString(); } +@{ Layout.Title = T("Settings").ToString(); } @using (Html.BeginFormAntiForgeryPost()) { @Html.ValidationSummary()
- @T("Enter Settings") + @T("Settings for Warmup")
@Html.TextAreaFor(m => m.Urls, new { @class = "textMedium" }) diff --git a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css index eb86061a0..684920f9c 100644 --- a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css +++ b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css @@ -544,7 +544,7 @@ span.message { form { margin: 0; padding: 0;} legend { font-size: 1.231em; font-weight: normal; border:none;} -fieldset { padding:6px 0 0; margin:0 0 1em 0; border: 0px solid #dbdbdb; } +fieldset { padding:6px 0 0; margin:0 0 12px 0; border: 0px solid #dbdbdb; } label { font-weight:normal; display:block; padding: 0 0 0.3em 0; } label.forcheckbox { margin:0 0 0 .4em; display:inline; } @@ -1032,7 +1032,8 @@ html.dyn #submit-pager, html.dyn .apply-bulk-actions-auto { display:none; } margin:.5em 0; } .settings legend { - margin:0 0 -.4em; + margin:0 0 0 0; + font-size:18px; } /* Core Contents and Orchard.PublishLater */ From 1277d21a0d89a861989acec92e6ebbe666db73c6 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Wed, 6 Apr 2011 15:56:40 -0700 Subject: [PATCH 04/22] #17585: Adding recipe commands. --HG-- branch : 1.x --- .../Commands/RecipesCommands.cs | 77 +++++++++++++++++++ .../Orchard.Recipes/Orchard.Recipes.csproj | 1 + 2 files changed, 78 insertions(+) create mode 100644 src/Orchard.Web/Modules/Orchard.Recipes/Commands/RecipesCommands.cs diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/Commands/RecipesCommands.cs b/src/Orchard.Web/Modules/Orchard.Recipes/Commands/RecipesCommands.cs new file mode 100644 index 000000000..343c9962f --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Recipes/Commands/RecipesCommands.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Orchard.Commands; +using Orchard.Environment.Extensions; +using Orchard.Environment.Extensions.Models; +using Orchard.Recipes.Models; +using Orchard.Recipes.Services; + +namespace Orchard.Recipes.Commands { + public class RecipesCommands : DefaultOrchardCommandHandler { + private readonly IRecipeHarvester _recipeHarvester; + private readonly IRecipeManager _recipeManager; + private readonly IExtensionManager _extensionManager; + + public RecipesCommands(IRecipeHarvester recipeHarvester, IRecipeManager recipeManager, IExtensionManager extensionManager) { + _recipeHarvester = recipeHarvester; + _recipeManager = recipeManager; + _extensionManager = extensionManager; + } + + [CommandHelp("recipes harvest \r\n\t" + "Display list of available recipes for an extension")] + [CommandName("recipes harvest")] + public void HarvestRecipes(string extensionId) { + ExtensionDescriptor extensionDescriptor = _extensionManager.GetExtension(extensionId); + if (extensionDescriptor == null) { + throw new OrchardException(T("Could not discover recipes because module '{0}' was not found.", extensionId)); + } + + IEnumerable recipes = _recipeHarvester.HarvestRecipes(extensionId); + if (recipes == null) { + throw new OrchardException(T("No recipes found for extension {0}.", extensionId)); + } + + Context.Output.WriteLine(T("List of available recipes")); + Context.Output.WriteLine(T("--------------------------")); + Context.Output.WriteLine(); + + foreach (Recipe recipe in recipes) { + Context.Output.WriteLine(T("Recipe: {0}", recipe.Name)); + Context.Output.WriteLine(T(" Version: {0}", recipe.Version)); + Context.Output.WriteLine(T(" Tags: {0}", recipe.Tags)); + Context.Output.WriteLine(T(" Description: {0}", recipe.Description)); + Context.Output.WriteLine(T(" Author: {0}", recipe.Author)); + Context.Output.WriteLine(T(" Website: {0}", recipe.WebSite)); + } + } + + [CommandHelp("recipes execute \r\n\t" + "Executes a recipe from a module")] + [CommandName("recipes execute")] + public void ExecuteRecipe(string extensionId, string recipeName) { + ExtensionDescriptor extensionDescriptor = _extensionManager.GetExtension(extensionId); + if (extensionDescriptor == null) { + throw new OrchardException(T("Could not discover recipes because module '{0}' was not found.", extensionId)); + } + + IEnumerable recipes = _recipeHarvester.HarvestRecipes(extensionId); + if (recipes == null) { + throw new OrchardException(T("No recipes found for extension {0}.", extensionId)); + } + + Recipe recipe = recipes.FirstOrDefault(r => r.Name.Equals(recipeName, StringComparison.OrdinalIgnoreCase)); + if (recipe == null) { + throw new OrchardException(T("Invalid recipe name {0}.", recipeName)); + } + + try { + _recipeManager.Execute(recipe); + + Context.Output.WriteLine(T("Recipe scheduled for execution successfully.").Text); + } + catch { + Context.Output.WriteLine(T("Recipe failed to execute.").Text); + } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/Orchard.Recipes.csproj b/src/Orchard.Web/Modules/Orchard.Recipes/Orchard.Recipes.csproj index d93306612..21af2b12a 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/Orchard.Recipes.csproj +++ b/src/Orchard.Web/Modules/Orchard.Recipes/Orchard.Recipes.csproj @@ -51,6 +51,7 @@ + From 39a463ea220f16dfb1613ddba3dd8f7e4ef86d1c Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Wed, 6 Apr 2011 16:14:13 -0700 Subject: [PATCH 05/22] Fixing Model navigation in shape tracing --HG-- branch : 1.x --- .../orchard-designertools-shapetracing.js | 3 +- .../Services/ObjectDumper.cs | 171 ++++++++---------- .../Services/ShapeTracingFactory.cs | 27 +-- .../Views/ShapeTracingMeta.cshtml | 6 +- .../Views/ShapeTracingWrapper.cshtml | 3 +- 5 files changed, 85 insertions(+), 125 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js b/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js index b12dd051a..e7478c3dc 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Scripts/orchard-designertools-shapetracing.js @@ -4,7 +4,6 @@ if (!window.shapeTracingMetadataHost) { window.shapeTracingMetadataHost.placement = { 'n/a': 'n/a' }; - window.shapeTracingMetadataHost.references = {}; } jQuery(function ($) { @@ -407,7 +406,7 @@ jQuery(function ($) { }); // open the root node (Model) - openExpando(shapeTracingMetaContent.find('.expando-glyph-container:first')) + shapeTracingMetaContent.find('.expando-glyph-container:first').click(); defaultTab = displayTabModel; }; diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs index 24edc99a4..9f4679693 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; using System.Xml.Linq; using ClaySharp; using ClaySharp.Behaviors; @@ -11,25 +10,22 @@ using Orchard.ContentManagement; using Orchard.DisplayManagement; namespace Orchard.DesignerTools.Services { - + public class ObjectDumper { private const int MaxStringLength = 60; private readonly Stack _parents = new Stack(); private readonly Stack _currents = new Stack(); private readonly int _levels; - private readonly Dictionary _local; - private readonly Dictionary _global; private readonly XDocument _xdoc; private XElement _current; // object/key/dump - public ObjectDumper(int levels, Dictionary local, Dictionary global) { + public ObjectDumper(int levels) + { _levels = levels; - _local = local; - _global = global; _xdoc = new XDocument(); _xdoc.Add(_current = new XElement("ul")); } @@ -40,6 +36,7 @@ namespace Orchard.DesignerTools.Services { } _parents.Push(o); + // starts a new container EnterNode("li"); @@ -51,20 +48,11 @@ namespace Orchard.DesignerTools.Services { DumpValue(o, name); } else { - int hashCode = RuntimeHelpers.GetHashCode(o); - // if the object has already been processed, return a named ref to it - if (_global.ContainsKey(hashCode)) { - _current.Add( - new XElement("h1", new XText(name)), - new XElement("span", FormatType(o)), - new XElement("a", new XAttribute("href", hashCode.ToString())) - ); - } - else { - _global.Add(hashCode, _current); - _local.Add(hashCode, _current); - DumpObject(o, name); + if (_parents.Count >= _levels) { + return _current; } + + DumpObject(o, name); } } finally { @@ -87,29 +75,31 @@ namespace Orchard.DesignerTools.Services { _current.Add( new XElement("h1", new XText(name)), new XElement("span", FormatType(o)) - ); + ); + + EnterNode("ul"); - if (_parents.Count >= _levels) { - return; - } + try { + if (o is IDictionary) { + DumpDictionary((IDictionary) o); + } + else if (o is IShape) { + DumpShape((IShape) o); - if (o is IDictionary) { - DumpDictionary((IDictionary)o); - } - else if (o is IShape) { - DumpShape((IShape)o); - - // a shape can also be IEnumerable - if (o is IEnumerable) { + // a shape can also be IEnumerable + if (o is IEnumerable) { + DumpEnumerable((IEnumerable) o); + } + } + else if (o is IEnumerable) { DumpEnumerable((IEnumerable) o); } + else { + DumpMembers(o); + } } - else if (o is IEnumerable) - { - DumpEnumerable((IEnumerable)o); - } - else { - DumpMembers(o); + finally { + RestoreCurrentNode(); } } @@ -124,55 +114,41 @@ namespace Orchard.DesignerTools.Services { return; } - EnterNode("ul"); - - try{ - foreach (var member in members) { - if (o is ContentItem && member.Name == "ContentManager" - || o is Delegate) { - continue; - } - SafeCall(() => DumpMember(o, member)); + foreach (var member in members) { + if (o is ContentItem && member.Name == "ContentManager" + || o is Delegate) { + continue; } + SafeCall(() => DumpMember(o, member)); + } - // process ContentItem.Parts specifically - foreach (var member in members) { - if (o is ContentItem && member.Name == "Parts") { - foreach (var part in ((ContentItem) o).Parts) { - SafeCall(() => Dump(part, part.PartDefinition.Name)); - } - } - } - - foreach (var member in members) { - // process ContentPart.Fields specifically - if (o is ContentPart && member.Name == "Fields") { - foreach (var field in ((ContentPart) o).Fields) { - SafeCall(() => Dump(field, field.Name)); - } + // process ContentItem.Parts specifically + foreach (var member in members) { + if (o is ContentItem && member.Name == "Parts") { + foreach (var part in ((ContentItem) o).Parts) { + SafeCall(() => Dump(part, part.PartDefinition.Name)); } } } - finally { - RestoreCurrentNode(); + + foreach (var member in members) { + // process ContentPart.Fields specifically + if (o is ContentPart && member.Name == "Fields") { + foreach (var field in ((ContentPart) o).Fields) { + SafeCall(() => Dump(field, field.Name)); + } + } } } private void DumpEnumerable(IEnumerable enumerable) { - if(!enumerable.GetEnumerator().MoveNext()) { + if (!enumerable.GetEnumerator().MoveNext()) { return; } - EnterNode("ul"); - - try { - int i = 0; - foreach (var child in enumerable) { - Dump(child, string.Format("[{0}]", i++)); - } - } - finally { - RestoreCurrentNode(); + int i = 0; + foreach (var child in enumerable) { + Dump(child, string.Format("[{0}]", i++)); } } @@ -181,21 +157,14 @@ namespace Orchard.DesignerTools.Services { return; } - EnterNode("ul"); - - try { - foreach (var key in dictionary.Keys) { - Dump(dictionary[key], string.Format("[\"{0}\"]", key)); - } - } - finally { - RestoreCurrentNode(); + foreach (var key in dictionary.Keys) { + Dump(dictionary[key], string.Format("[\"{0}\"]", key)); } } private void DumpShape(IShape shape) { - var b = ((IClayBehaviorProvider)(dynamic)shape).Behavior as ClayBehaviorCollection; + var b = ((IClayBehaviorProvider) (dynamic) shape).Behavior as ClayBehaviorCollection; if (b == null) return; @@ -216,19 +185,12 @@ namespace Orchard.DesignerTools.Services { return; } - EnterNode("ul"); - - try { - foreach (var key in props.Keys) { - // ignore private members (added dynmically by the shape wrapper) - if (key.ToString().StartsWith("_")) { - continue; - } - Dump(props[key], key.ToString()); + foreach (var key in props.Keys) { + // ignore private members (added dynmically by the shape wrapper) + if (key.ToString().StartsWith("_")) { + continue; } - } - finally { - RestoreCurrentNode(); + Dump(props[key], key.ToString()); } } @@ -305,9 +267,22 @@ namespace Orchard.DesignerTools.Services { _current = _currents.Pop(); } - private void EnterNode(string tag) { + private XElement EnterNode(string tag) { SaveCurrentNode(); _current.Add(_current = new XElement(tag)); + return _current; + } + + private int MaxNodesLength(XElement el) { + int max = 1; + var local = 0; + foreach(var node in el.Elements()) { + local = Math.Max(local, MaxNodesLength(node)); + } + + return max + local; } } + + public class DumpMap : Dictionary {} } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs index 80530069e..f169f8ed6 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ShapeTracingFactory.cs @@ -23,7 +23,7 @@ namespace Orchard.DesignerTools.Services { private readonly IWebSiteFolder _webSiteFolder; private readonly IAuthorizer _authorizer; private int _shapeId; - private readonly Dictionary _dumped = new Dictionary(1000); + private readonly DumpMap _dumped = new DumpMap(); public ShapeTracingFactory( WorkContext workContext, @@ -96,17 +96,11 @@ namespace Orchard.DesignerTools.Services { var descriptor = shapeTable.Descriptors[shapeMetadata.Type]; // dump the Shape's content - var local = new Dictionary(); - new ObjectDumper(6, local, _dumped).Dump(context.Shape, "Model"); - context.Shape.Reference = RuntimeHelpers.GetHashCode(context.Shape); + var dump = new ObjectDumper(6).Dump(context.Shape, "Model"); var sb = new StringBuilder(); - context.Shape.LocalReferences = new Dictionary(); - foreach (var key in local.Keys) { - sb.Clear(); - ConvertToJSon(local[key], sb); - ((Dictionary) context.Shape.LocalReferences)[key] = sb.ToString(); - } + ConvertToJSon(dump, sb); + shape.Dump = sb.ToString(); shape.Template = null; shape.OriginalTemplate = descriptor.BindingSource; @@ -158,7 +152,7 @@ namespace Orchard.DesignerTools.Services { public void Displayed(ShapeDisplayedContext context) { } - private static void ConvertToJSon(XElement x, StringBuilder sb) { + public static void ConvertToJSon(XElement x, StringBuilder sb) { if(x == null) { return; } @@ -177,21 +171,18 @@ namespace Orchard.DesignerTools.Services { sb.AppendFormat("name: \"{0}\", ", FormatJsonValue(name)); sb.AppendFormat("value: \"{0}\"", FormatJsonValue(value)); - var a = x.Element("a"); - if (a != null) { - sb.AppendFormat(", children: shapeTracingMetadataHost.references[{0}]", a.Attribute("href").Value); - } - var ul = x.Element("ul"); - if (ul != null) { + if (ul != null && ul.Descendants().Any()) { sb.Append(", children: ["); foreach (var li in ul.Elements()) { sb.Append("{ "); ConvertToJSon(li, sb); - sb.Append(" },"); + sb.Append(" }"); + sb.Append(", "); } sb.Append("]"); } + break; } } diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml b/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml index a52d4d669..d861c8aef 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Views/ShapeTracingMeta.cshtml @@ -20,10 +20,6 @@