mirror of https://github.com/Squidex/squidex.git
60 changed files with 188 additions and 54 deletions
@ -0,0 +1,17 @@ |
|||
// ==========================================================================
|
|||
// MyUIOptions.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
|
|||
namespace Squidex.Config |
|||
{ |
|||
public sealed class MyUIOptions |
|||
{ |
|||
public Dictionary<string, string> RegexSuggestions { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// ==========================================================================
|
|||
// UIRegexSuggestionDto.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Squidex.Controllers.Api.UI.Models |
|||
{ |
|||
public sealed class UIRegexSuggestionDto |
|||
{ |
|||
/// <summary>
|
|||
/// The name of the suggestion.
|
|||
/// </summary>
|
|||
[Required] |
|||
public string Name { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// The regex pattern.
|
|||
/// </summary>
|
|||
[Required] |
|||
public string Pattern { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
// ==========================================================================
|
|||
// UISettingsDto.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Squidex.Controllers.Api.UI.Models |
|||
{ |
|||
public sealed class UISettingsDto |
|||
{ |
|||
/// <summary>
|
|||
/// The regex suggestions.
|
|||
/// </summary>
|
|||
[Required] |
|||
public List<UIRegexSuggestionDto> RegexSuggestions { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
// ==========================================================================
|
|||
// UIController.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Options; |
|||
using NSwag.Annotations; |
|||
using Squidex.Config; |
|||
using Squidex.Controllers.Api.UI.Models; |
|||
using Squidex.Pipeline; |
|||
|
|||
namespace Squidex.Controllers.Api.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Manages ui settings and configs.
|
|||
/// </summary>
|
|||
[ApiExceptionFilter] |
|||
[SwaggerTag("UI")] |
|||
public sealed class UIController : Controller |
|||
{ |
|||
private readonly MyUIOptions uiOptions; |
|||
|
|||
public UIController(IOptions<MyUIOptions> uiOptions) |
|||
{ |
|||
this.uiOptions = uiOptions.Value; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Get ui settings.
|
|||
/// </summary>
|
|||
[HttpGet] |
|||
[Route("ui/settings/")] |
|||
[ProducesResponseType(typeof(UISettingsDto), 200)] |
|||
[ApiCosts(0)] |
|||
public IActionResult GetSettings() |
|||
{ |
|||
var dto = new UISettingsDto |
|||
{ |
|||
RegexSuggestions = |
|||
uiOptions?.RegexSuggestions.Where(x => |
|||
!string.IsNullOrWhiteSpace(x.Key) && |
|||
!string.IsNullOrWhiteSpace(x.Value)) |
|||
.Select(x => new UIRegexSuggestionDto { Name = x.Key, Pattern = x.Value }) |
|||
.ToList() |
|||
?? new List<UIRegexSuggestionDto>() |
|||
}; |
|||
|
|||
return Ok(dto); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue