Moves the grid configuration to a config class so it can be re-used. Updates the BackOfficeController to use the new config classes. Creates a new Grid property value converter (which can be overridden by user's ones) which merges the grid config values at runtime so we are not storing stale grid config values with the actual property value. Now we need to ensure that the grid doesn't post or persist these config values since they don't belong there.

This commit is contained in:
Shannon
2015-06-16 15:04:31 +02:00
parent fd6caf5cee
commit 1c0188351c
12 changed files with 289 additions and 47 deletions

View File

@@ -163,48 +163,14 @@ namespace Umbraco.Web.Editors
[HttpGet]
public JsonNetResult GetGridConfig()
{
Func<List<GridEditor>> getResult = () =>
{
var editors = new List<GridEditor>();
var gridConfig = Server.MapPath("~/Config/grid.editors.config.js");
if (System.IO.File.Exists(gridConfig))
{
try
{
var arr = JArray.Parse(System.IO.File.ReadAllText(gridConfig));
//ensure the contents parse correctly to objects
var parsed = ManifestParser.GetGridEditors(arr);
editors.AddRange(parsed);
}
catch (Exception ex)
{
LogHelper.Error<BackOfficeController>("Could not parse the contents of grid.editors.config.js into a JSON array", ex);
}
}
var gridConfig = UmbracoConfig.For.GridConfig(
Logger,
ApplicationContext.ApplicationCache.RuntimeCache,
new DirectoryInfo(Server.MapPath(SystemDirectories.AppPlugins)),
new DirectoryInfo(Server.MapPath(SystemDirectories.Config)),
HttpContext.IsDebuggingEnabled);
var plugins = new DirectoryInfo(Server.MapPath("~/App_Plugins"));
var parser = new ManifestParser(plugins, ApplicationContext.ApplicationCache.RuntimeCache);
var builder = new ManifestBuilder(ApplicationContext.ApplicationCache.RuntimeCache, parser);
foreach (var gridEditor in builder.GridEditors)
{
//no duplicates! (based on alias)
if (editors.Contains(gridEditor) == false)
{
editors.Add(gridEditor);
}
}
return editors;
};
//cache the result if debugging is disabled
var result = HttpContext.IsDebuggingEnabled
? getResult()
: ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem<List<GridEditor>>(
typeof(BackOfficeController) + "GetGridConfig",
() => getResult(),
new TimeSpan(0, 10, 0));
return new JsonNetResult { Data = result, Formatting = Formatting.Indented };
return new JsonNetResult { Data = gridConfig.EditorsConfig.Editors, Formatting = Formatting.Indented };
}
/// <summary>

View File

@@ -20,7 +20,7 @@ namespace Umbraco.Web
public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedProperty property, string framework = "bootstrap3")
{
var asString = property.Value as string;
if (asString.IsNullOrWhiteSpace()) return new MvcHtmlString(string.Empty);
if (asString != null && string.IsNullOrEmpty(asString)) return new MvcHtmlString(string.Empty);
var view = "Grid/" + framework;
return html.Partial(view, property.Value);
@@ -56,7 +56,7 @@ namespace Umbraco.Web
public static MvcHtmlString GetGridHtml(this IPublishedProperty property, HtmlHelper html, string framework = "bootstrap3")
{
var asString = property.Value as string;
if (asString.IsNullOrWhiteSpace()) return new MvcHtmlString(string.Empty);
if (asString != null && string.IsNullOrEmpty(asString)) return new MvcHtmlString(string.Empty);
var view = "Grid/" + framework;
return html.Partial(view, property.Value);
@@ -91,7 +91,7 @@ namespace Umbraco.Web
public static MvcHtmlString GetGridHtml(this IPublishedProperty property, string framework = "bootstrap3")
{
var asString = property.Value as string;
if (asString.IsNullOrWhiteSpace()) return new MvcHtmlString(string.Empty);
if (asString != null && string.IsNullOrEmpty(asString)) return new MvcHtmlString(string.Empty);
var htmlHelper = CreateHtmlHelper(property.Value);
return htmlHelper.GetGridHtml(property, framework);

View File

@@ -56,7 +56,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
catch (Exception ex)
{
LogHelper.Error<JsonValueConverter>("Could not parse the string " + sourceString + " to a json object", ex);
LogHelper.Error<RelatedLinksEditorValueConvertor>("Could not parse the string " + sourceString + " to a json object", ex);
}
}
@@ -95,7 +95,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
catch (Exception ex)
{
LogHelper.Error<JsonValueConverter>("Could not parse the string " + sourceString + " to a json object", ex);
LogHelper.Error<RelatedLinksEditorValueConvertor>("Could not parse the string " + sourceString + " to a json object", ex);
}
}