Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Site settings Deployment Step #6570

Merged
merged 22 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Admin.Controllers;
using OrchardCore.Admin.Drivers;
using OrchardCore.Admin.Models;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Theming;
using OrchardCore.Environment.Shell.Configuration;
Expand All @@ -18,6 +21,7 @@
using OrchardCore.Navigation;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
using OrchardCore.Settings.Deployment;

namespace OrchardCore.Admin
{
Expand Down Expand Up @@ -81,4 +85,15 @@ public override void ConfigureServices(IServiceCollection services)
});
}
}

[RequireFeatures("OrchardCore.Deployment")]
public class DeploymentStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();
var S = serviceProvider.GetService<IStringLocalizer<Startup>>();
services.AddSingleton<IDeploymentStepFactory>(s => new GenericSiteSettingsDeploymentStepFactory(nameof(AdminSettings), S["Admin settings"], S["Exports the admin site settings."]));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Settings.ViewModels;

namespace OrchardCore.Settings.Deployment
{
public class GenericSiteSettingsDeploymentStepDriver : DisplayDriver<DeploymentStep, GenericSiteSettingsDeploymentStep>
{
public override IDisplayResult Display(GenericSiteSettingsDeploymentStep step)
{
return
Combine(
View("GenericSiteSettingsDeploymentStep_Fields_Summary", step).Location("Summary", "Content"),
View("GenericSiteSettingsDeploymentStep_Fields_Thumbnail", step).Location("Thumbnail", "Content")
);
}

public override IDisplayResult Edit(GenericSiteSettingsDeploymentStep step)
{
return Initialize<GenericSiteSettingsDeploymentStepViewModel>("GenericSiteSettingsDeploymentStep_Fields_Edit", model =>
{
model.Title = step.Title;
model.Description = step.Description;
}).Location("Content");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using OrchardCore.Deployment;

namespace OrchardCore.Settings.Deployment
{
public class GenericSiteSettingsDeploymentSource : IDeploymentSource
{
private readonly ISiteService _siteService;

public GenericSiteSettingsDeploymentSource(ISiteService siteService)
{
_siteService = siteService;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
{
var settingsStep = step as GenericSiteSettingsDeploymentStep;
if (settingsStep == null)
{
return;
}

var site = await _siteService.GetSiteSettingsAsync();

var data = new JObject(new JProperty("name", "Settings"));
JToken value;

if (site.Properties.TryGetValue(step.Name, out value))
{
data.Add(new JProperty(step.Name, value));
}

result.Steps.Add(data);

return;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.Localization;
using OrchardCore.Deployment;

namespace OrchardCore.Settings.Deployment
{
/// <summary>
/// Adds a generic site settings to a <see cref="DeploymentPlanResult"/>.
/// </summary>
public class GenericSiteSettingsDeploymentStep : DeploymentStep
{
public GenericSiteSettingsDeploymentStep()
{
}

public GenericSiteSettingsDeploymentStep(string name, string title, string description)
{
Name = name;
Title = title;
Description = description;
}

public string Title { get; set; } // LocalizedString
public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.Extensions.Localization;
using OrchardCore.Deployment;

namespace OrchardCore.Settings.Deployment
{
public class GenericSiteSettingsDeploymentStepFactory: IDeploymentStepFactory
{
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }

public GenericSiteSettingsDeploymentStepFactory(string name, string title, string description)
{
Name = name;
Title = title;
Description = description;
}

public DeploymentStep Create()
{
return new GenericSiteSettingsDeploymentStep(Name, Title, Description);
}
}
}
3 changes: 3 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Settings/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public override void ConfigureServices(IServiceCollection services)
services.AddTransient<IDeploymentSource, SiteSettingsDeploymentSource>();
services.AddSingleton<IDeploymentStepFactory>(new DeploymentStepFactory<SiteSettingsDeploymentStep>());
services.AddScoped<IDisplayDriver<DeploymentStep>, SiteSettingsDeploymentStepDriver>();

services.AddTransient<IDeploymentSource, GenericSiteSettingsDeploymentSource>();
services.AddScoped<IDisplayDriver<DeploymentStep>, GenericSiteSettingsDeploymentStepDriver>();
}

public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OrchardCore.Settings.ViewModels
{
public class GenericSiteSettingsDeploymentStepViewModel
{
public string Title { get; set; }
public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@model GenericSiteSettingsDeploymentStepViewModel
<h5>@Model.Title</h5>

<div class="form-group">
<span class="hint">@Model.Description</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@model OrchardCore.DisplayManagement.Views.ShapeViewModel<OrchardCore.Settings.Deployment.GenericSiteSettingsDeploymentStep>

<h5>@Model.Value.Title</h5>
<span>@Model.Value.Description</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@model OrchardCore.DisplayManagement.Views.ShapeViewModel<OrchardCore.Settings.Deployment.GenericSiteSettingsDeploymentStep>

<h4 class="card-title">@Model.Value.Title</h4>
<p>@Model.Value.Description</p>