2017-07-20 11:21:28 +02:00
|
|
|
|
using System;
|
2015-06-16 15:04:31 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
using Umbraco.Core.Cache;
|
2018-01-24 11:44:44 +01:00
|
|
|
|
using Umbraco.Core.Composing;
|
2015-06-16 15:04:31 +02:00
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.Manifest;
|
|
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Configuration.Grid
|
|
|
|
|
|
{
|
2017-09-15 18:22:19 +02:00
|
|
|
|
internal class GridEditorsConfig : IGridEditorsConfig
|
2015-06-16 15:04:31 +02:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger _logger;
|
2019-01-17 11:01:23 +01:00
|
|
|
|
private readonly IAppPolicedCache _runtimeCache;
|
2015-06-16 15:04:31 +02:00
|
|
|
|
private readonly DirectoryInfo _configFolder;
|
|
|
|
|
|
private readonly bool _isDebug;
|
|
|
|
|
|
|
2019-01-17 11:01:23 +01:00
|
|
|
|
public GridEditorsConfig(ILogger logger, IAppPolicedCache runtimeCache, DirectoryInfo configFolder, bool isDebug)
|
2015-06-16 15:04:31 +02:00
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_runtimeCache = runtimeCache;
|
|
|
|
|
|
_configFolder = configFolder;
|
|
|
|
|
|
_isDebug = isDebug;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<IGridEditorConfig> Editors
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2019-01-07 10:43:28 +01:00
|
|
|
|
List<GridEditor> GetResult()
|
2015-06-16 15:04:31 +02:00
|
|
|
|
{
|
2018-01-19 19:08:12 +01:00
|
|
|
|
// fixme - should use the common one somehow! + ignoring _appPlugins here!
|
2018-01-24 11:44:44 +01:00
|
|
|
|
var parser = new ManifestParser(_runtimeCache, Current.ManifestValidators, _logger);
|
2015-12-18 13:29:12 +01:00
|
|
|
|
|
2015-06-16 15:04:31 +02:00
|
|
|
|
var editors = new List<GridEditor>();
|
|
|
|
|
|
var gridConfig = Path.Combine(_configFolder.FullName, "grid.editors.config.js");
|
|
|
|
|
|
if (File.Exists(gridConfig))
|
|
|
|
|
|
{
|
2018-08-16 12:00:12 +01:00
|
|
|
|
var sourceString = File.ReadAllText(gridConfig);
|
|
|
|
|
|
|
2015-06-16 15:04:31 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2018-08-16 12:00:12 +01:00
|
|
|
|
editors.AddRange(parser.ParseGridEditors(sourceString));
|
2015-06-16 15:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2018-08-17 15:41:58 +01:00
|
|
|
|
_logger.Error<GridEditorsConfig>(ex, "Could not parse the contents of grid.editors.config.js into a JSON array '{Json}", sourceString);
|
2015-06-16 15:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-19 19:08:12 +01:00
|
|
|
|
// add manifest editors, skip duplicates
|
|
|
|
|
|
foreach (var gridEditor in parser.Manifest.GridEditors)
|
2015-06-16 15:04:31 +02:00
|
|
|
|
{
|
2019-01-07 10:43:28 +01:00
|
|
|
|
if (editors.Contains(gridEditor) == false) editors.Add(gridEditor);
|
2015-06-16 15:04:31 +02:00
|
|
|
|
}
|
2018-01-19 19:08:12 +01:00
|
|
|
|
|
2015-06-16 15:04:31 +02:00
|
|
|
|
return editors;
|
2019-01-07 10:43:28 +01:00
|
|
|
|
}
|
2015-06-16 15:04:31 +02:00
|
|
|
|
|
|
|
|
|
|
//cache the result if debugging is disabled
|
|
|
|
|
|
var result = _isDebug
|
2019-01-07 10:43:28 +01:00
|
|
|
|
? GetResult()
|
|
|
|
|
|
: _runtimeCache.GetCacheItem<List<GridEditor>>(typeof(GridEditorsConfig) + ".Editors",GetResult, TimeSpan.FromMinutes(10));
|
2015-06-16 15:04:31 +02:00
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
2015-06-16 15:04:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|