filtering out tours.
This commit is contained in:
@@ -548,6 +548,7 @@
|
||||
<DependentUpon>HealthChecks.config</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<Content Include="Config\BackOfficeTours\my-tours.json" />
|
||||
<None Include="Config\umbracoSettings.Release.config">
|
||||
<DependentUpon>umbracoSettings.config</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
@@ -11,29 +15,46 @@ using Constants = Umbraco.Core.Constants;
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
[PluginController("UmbracoApi")]
|
||||
[UmbracoApplicationAuthorize(Constants.Applications.Content)]
|
||||
[UmbracoApplicationAuthorize(Constants.Applications.Content)]
|
||||
public class TourController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
//TODO: Strongly type this for final release!
|
||||
public JArray GetTours()
|
||||
public IEnumerable<Tour[]> GetTours()
|
||||
{
|
||||
//TODO: Add error checking to this for final release!
|
||||
|
||||
var result = new JArray();
|
||||
var tours = new List<Tour[]>();
|
||||
|
||||
if (UmbracoConfig.For.UmbracoSettings().BackOffice.Tours.EnableTours == false)
|
||||
return result;
|
||||
return tours;
|
||||
|
||||
var tourFiles = Directory.GetFiles(
|
||||
Path.Combine(IOHelper.MapPath(SystemDirectories.Config), "BackOfficeTours"), "*.json")
|
||||
var toursPath = Path.Combine(IOHelper.MapPath(SystemDirectories.Config), "BackOfficeTours");
|
||||
if (Directory.Exists(toursPath) == false)
|
||||
return tours;
|
||||
|
||||
var tourFiles = Directory.GetFiles(toursPath, "*.json")
|
||||
.OrderBy(x => x, StringComparer.InvariantCultureIgnoreCase);
|
||||
var disabledTours = TourFilterResolver.Current.DisabledTours;
|
||||
|
||||
foreach (var tourFile in tourFiles)
|
||||
{
|
||||
var contents = File.ReadAllText(tourFile);
|
||||
result.Add(JArray.Parse(contents));
|
||||
try
|
||||
{
|
||||
var contents = File.ReadAllText(tourFile);
|
||||
var tourArray = JsonConvert.DeserializeObject<Tour[]>(contents);
|
||||
tours.Add(tourArray.Where(x =>
|
||||
disabledTours.Contains(x.Alias, StringComparer.InvariantCultureIgnoreCase) == false).ToArray());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Logger.Error<TourController>("Error while trying to read file: " + tourFile, e);
|
||||
throw new IOException("Error while trying to read file: " + tourFile, e);
|
||||
}
|
||||
catch (JsonReaderException e)
|
||||
{
|
||||
Logger.Error<TourController>("Error while trying to parse content as tour data: " + tourFile, e);
|
||||
throw new JsonReaderException("Error while trying to parse content as tour data: " + tourFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return tours;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/Umbraco.Web/Editors/TourFilterResolver.cs
Normal file
33
src/Umbraco.Web/Editors/TourFilterResolver.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
//TODO: find out where this should live
|
||||
public class TourFilterResolver
|
||||
{
|
||||
private static TourFilterResolver _current;
|
||||
|
||||
private readonly HashSet<string> _disabledTours;
|
||||
|
||||
public TourFilterResolver()
|
||||
{
|
||||
_disabledTours = new HashSet<string>();
|
||||
}
|
||||
|
||||
public static TourFilterResolver Current
|
||||
{
|
||||
get { return _current ?? (_current = new TourFilterResolver()); }
|
||||
}
|
||||
|
||||
public void Disable(string tour)
|
||||
{
|
||||
_disabledTours.Add(tour);
|
||||
}
|
||||
|
||||
public IEnumerable<string> DisabledTours
|
||||
{
|
||||
get { return _disabledTours.ToArray(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/Umbraco.Web/Models/Tour.cs
Normal file
22
src/Umbraco.Web/Models/Tour.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A model representing a tour.
|
||||
/// </summary>
|
||||
[DataContract(Name = "tour", Namespace = "")]
|
||||
public class Tour
|
||||
{
|
||||
[DataMember(Name = "name")]
|
||||
public string Name { get; set; }
|
||||
[DataMember(Name = "alias")]
|
||||
public string Alias { get; set; }
|
||||
[DataMember(Name = "group")]
|
||||
public string Group { get; set; }
|
||||
[DataMember(Name = "groupOrder")]
|
||||
public int GroupOrder { get; set; }
|
||||
[DataMember(Name = "steps")]
|
||||
public TourStep[] Steps { get; set; }
|
||||
}
|
||||
}
|
||||
18
src/Umbraco.Web/Models/TourStep.cs
Normal file
18
src/Umbraco.Web/Models/TourStep.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A model representing a step in a tour.
|
||||
/// </summary>
|
||||
[DataContract(Name = "step", Namespace = "")]
|
||||
public class TourStep
|
||||
{
|
||||
[DataMember(Name = "title")]
|
||||
public string Title { get; set; }
|
||||
[DataMember(Name = "content")]
|
||||
public string Content { get; set; }
|
||||
[DataMember(Name = "type")]
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -328,6 +328,7 @@
|
||||
<Compile Include="Editors\ParameterSwapControllerActionSelector.cs" />
|
||||
<Compile Include="Editors\CodeFileController.cs" />
|
||||
<Compile Include="Editors\TourController.cs" />
|
||||
<Compile Include="Editors\TourFilterResolver.cs" />
|
||||
<Compile Include="Editors\UserEditorAuthorizationHelper.cs" />
|
||||
<Compile Include="Editors\UserGroupAuthorizationAttribute.cs" />
|
||||
<Compile Include="Editors\UserGroupEditorAuthorizationHelper.cs" />
|
||||
@@ -428,6 +429,8 @@
|
||||
<Compile Include="Models\SetPasswordModel.cs" />
|
||||
<Compile Include="Models\RequestPasswordResetModel.cs" />
|
||||
<Compile Include="Models\PublishedContentWithKeyBase.cs" />
|
||||
<Compile Include="Models\Tour.cs" />
|
||||
<Compile Include="Models\TourStep.cs" />
|
||||
<Compile Include="Models\UserTourStatus.cs" />
|
||||
<Compile Include="Models\ValidatePasswordResetCodeModel.cs" />
|
||||
<Compile Include="Mvc\ControllerContextExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user