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

update musicfestival for latest form headless #140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
86 changes: 44 additions & 42 deletions samples/ManagementSite/Alloy.ManagementSite.csproj
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<NoWarn>NU5100;NU1803;NU1605;NU1504;</NoWarn>
<CmsUIVersion>12.23.0</CmsUIVersion>
<CmsCoreVersion>12.20.1</CmsCoreVersion>
<HeadlessFormVersion>0.1.1-inte-380</HeadlessFormVersion>
<ContentApiVersion>12.20.1</ContentApiVersion>
<FormVersion>5.8.2</FormVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPiServer.CMS.AspNetCore" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.HtmlHelpers" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.MVC" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.Routing" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.Templating" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.Core" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Forms" Version="$(FormVersion)" />
<PackageReference Include="EPiServer.Framework" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Framework.AspNetCore" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Hosting" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.TinyMce" Version="4.4.2" />
<PackageReference Include="EPiServer.CMS.UI" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.CMS.UI.Core" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.CMS.UI.VisitorGroups" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.CMS.UI.AspNetIdentity" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.ImageLibrary.ImageSharp" Version="2.0.1" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<NoWarn>NU5100;NU1803;NU1605;NU1504;</NoWarn>
<CmsUIVersion>12.30.0</CmsUIVersion>
<CmsCoreVersion>12.21.4</CmsCoreVersion>
<HeadlessFormVersion>1.0.0-pre-541</HeadlessFormVersion>
<ContentApiVersion>12.20.1</ContentApiVersion>
<FormVersion>5.9.0</FormVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPiServer.CMS.AspNetCore" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.HtmlHelpers" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.MVC" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.Routing" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.AspNetCore.Templating" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.Core" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Forms" Version="$(FormVersion)" />
<PackageReference Include="EPiServer.Framework" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Framework.AspNetCore" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.Hosting" Version="$(CmsCoreVersion)" />
<PackageReference Include="EPiServer.CMS.TinyMce" Version="4.4.2" />
<PackageReference Include="EPiServer.CMS.UI" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.CMS.UI.Core" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.CMS.UI.VisitorGroups" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.CMS.UI.AspNetIdentity" Version="$(CmsUIVersion)" />
<PackageReference Include="EPiServer.ImageLibrary.ImageSharp" Version="2.0.1" />
</ItemGroup>
<ItemGroup Label="HeadlessForm">
<PackageReference Include="Optimizely.Cms.Preview1.Content.EPiServer" Version="$(ContentApiVersion)" />
<PackageReference Include="Optimizely.Headless.Form.Service" Version="$(HeadlessFormVersion)" />
<PackageReference Include="Optimizely.Cms.Forms.ContentGraph" Version="$(HeadlessFormVersion)" />
<PackageReference Include="Optimizely.Cms.Forms.Core" Version="$(HeadlessFormVersion)" />
<PackageReference Include="Optimizely.Cms.Forms.Service" Version="$(HeadlessFormVersion)" />
<PackageReference Include="Optimizely.ContentGraph.Cms" Version="3.5.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EPiServer.ContentDefinitionsApi" Version="3.3.0" />
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.9.1" />
<PackageReference Include="EPiServer.OpenIDConnect" Version="3.3.0" />
<PackageReference Include="EPiServer.CloudPlatform.Cms" Version="1.2.0" />
</ItemGroup>
<PropertyGroup>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>NU5100;NU1803;NU1605;NU1504;</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPiServer.ContentDefinitionsApi" Version="3.3.0" />
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.9.1" />
<PackageReference Include="EPiServer.OpenIDConnect" Version="3.3.0" />
<PackageReference Include="EPiServer.CloudPlatform.Cms" Version="1.2.0" />
</ItemGroup>
<PropertyGroup>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>NU5100;NU1803;NU1605;NU1504;</NoWarn>
</PropertyGroup>
</Project>
41 changes: 26 additions & 15 deletions samples/ManagementSite/Controllers/ReactController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using EPiServer.Cms.Shell;
using EPiServer;
using EPiServer.Core;
using EPiServer.Forms.Implementation.Elements;
using EPiServer.ServiceLocation;
using EPiServer.SpecializedProperties;
using EPiServer.Web;
using EPiServer.Web.Routing;
using Microsoft.AspNetCore.Mvc;
using Optimizely.Cms.Preview1.Content;
using Optimizely.Cms.Preview1.Content.Models;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -13,11 +15,8 @@ namespace AlloyMvcTemplates.Controllers;
[ApiController]
public class ReactController : ControllerBase
{
private readonly IContentRepository _contentRepositoryInteApi;

public ReactController(IContentRepository contentRepositoryInteApi)
public ReactController()
{
_contentRepositoryInteApi = contentRepositoryInteApi;
}

[HttpGet("GetFormInPageByUrl")]
Expand All @@ -32,18 +31,30 @@ public async Task<IActionResult> GetFormInPageByUrl(string url)
}
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
var key = ContentKey.FormatAsKey(content.ContentGuid);

var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();

var pageContent = contentLoader.Get<IContent>(content.ContentGuid);

var pageModel = new PageModel();
var contentHeadless = await _contentRepositoryInteApi.GetAsync(key, content.LanguageBranch());

if (contentHeadless is not null)
if (pageContent is not null)
{
pageModel.Title = contentHeadless.DisplayName;
pageModel.Title = pageContent.Name;
pageModel.PageUrl = UrlResolver.Current.GetUrl(content.ContentLink);

if (contentHeadless.Properties.ContainsKey("MainContentArea"))
if (pageContent.Property.Keys.Contains("MainContentArea"))
{
pageModel.Childrens.AddRange(contentHeadless.Properties["MainContentArea"] as IList<IContentComponent>);
var contentArea = pageContent.Property["MainContentArea"] as PropertyContentArea;
foreach (var item in contentArea.PublicContentArea.FilteredItems)
{
var contentItem = contentLoader.Get<IContent>(item.ContentLink);

if(contentItem is FormContainerBlock)
{
pageModel.FormKeys.Add(contentItem.ContentGuid.ToString("N"));
}
}
}
}

Expand All @@ -55,5 +66,5 @@ public class PageModel
{
public string Title { get; set; }
public string PageUrl { get; set; }
public List<IContentComponent> Childrens { get; set; } = new List<IContentComponent>();
}
public List<string> FormKeys { get; set; } = new List<string>();
}
2 changes: 1 addition & 1 deletion samples/ManagementSite/Nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<package pattern="EPiServer.AddOns.*" />
</packageSource>
<packageSource key="headlessform.local">
<package pattern="Optimizely.Headless.*" />
<package pattern="Optimizely.Cms.Forms.*" />
</packageSource>
</packageSourceMapping>
</configuration>
2 changes: 1 addition & 1 deletion samples/ManagementSite/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "episerver/cms",
"applicationUrl": "http://localhost:8082",
"applicationUrl": "https://localhost:8082",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
28 changes: 15 additions & 13 deletions samples/ManagementSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Optimizely.Headless.Form.DependencyInjection;
using Optimizely.Headless.Form;
using EPiServer.OpenIDConnect;
using System;
using static OpenIddict.Abstractions.OpenIddictConstants;
using Microsoft.Extensions.Options;
using OpenIddict.Server;
using System.Linq;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Optimizely.Cms.DependencyInjection;
using EPiServer.DependencyInjection;
using Optimizely.Cms.Forms.DependencyInjection;
using Optimizely.Cms.Forms;

namespace Alloy.ManagementSite
{
Expand All @@ -33,7 +33,7 @@ public class Startup
private readonly string _allowedOrigins = "_allowedOrigins";
private const string TestClientId = "TestClient";
private const string TestClientSecret = "TestClientSecret";
private const string ClientEndpoint = "http://localhost:8082";
private const string ClientEndpoint = "https://localhost:8082";

public Startup(IWebHostEnvironment environment, IConfiguration configuration)
{
Expand All @@ -46,7 +46,7 @@ public void ConfigureServices(IServiceCollection services)
if (_environment.IsDevelopment())
{
//NETCORE: Consider add appsettings support for this

services.Configure<StaticFileOptions>(o =>
{
o.OnPrepareResponse = context =>
Expand All @@ -57,7 +57,8 @@ public void ConfigureServices(IServiceCollection services)
});
}

services.Configure<TelemetryOptions>(o => {
services.Configure<TelemetryOptions>(o =>
{
o.Enabled = false;
});

Expand Down Expand Up @@ -89,7 +90,8 @@ public void ConfigureServices(IServiceCollection services)
.AddContentDelivery(managementSiteOptions)
.ConfigureDxp(managementSiteOptions, _configuration);

services.AddCors(opts => {
services.AddCors(opts =>
{
opts.AddPolicy(name: _allowedOrigins, builder =>
{
builder.WithOrigins(managementSiteOptions.DeliverySite.Url)
Expand Down Expand Up @@ -121,15 +123,15 @@ public void ConfigureServices(IServiceCollection services)
});
});

services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<HeadlessFormServiceOptions>, HeadlessFormServiceOptionsPostConfigure>());
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<OptimizelyFormsServiceOptions>, HeadlessFormServiceOptionsPostConfigure>());

// Register the Optimizely Headless Form API Services
services.AddOptimizelyHeadlessFormService(options =>
services.AddOptimizelyFormsService(options =>
{
options.EnableOpenApiDocumentation = true;
options.FormCorsPolicy = new FormCorsPolicy
{
AllowOrigins = new string[] { "http://localhost:3000" }, //Enter '*' to allow any origins, multiple origins separate by comma
AllowOrigins = new string[] { "*" }, //Enter '*' to allow any origins, multiple origins separate by comma
AllowCredentials = true
};
options.OpenIDConnectClients.Add(new()
Expand All @@ -138,7 +140,7 @@ public void ConfigureServices(IServiceCollection services)
});
});

services.AddOptimizelyCmsContentOnEPiServerPreview1();
services.AddContentGraph(OpenIDConnectOptionsDefaults.AuthenticationScheme);

//Register ContentGraph for HeadlessForm
services.AddContentDeliveryApi(op =>
Expand Down Expand Up @@ -174,7 +176,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}
}

public class HeadlessFormServiceOptionsPostConfigure : IPostConfigureOptions<HeadlessFormServiceOptions>
public class HeadlessFormServiceOptionsPostConfigure : IPostConfigureOptions<OptimizelyFormsServiceOptions>
{
private readonly OpenIddictServerOptions _options;

Expand All @@ -183,7 +185,7 @@ public HeadlessFormServiceOptionsPostConfigure(IOptions<OpenIddictServerOptions>
_options = options.Value;
}

public void PostConfigure(string name, HeadlessFormServiceOptions options)
public void PostConfigure(string name, OptimizelyFormsServiceOptions options)
{
foreach (var client in options.OpenIDConnectClients)
{
Expand Down
8 changes: 4 additions & 4 deletions samples/ManagementSite/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
},
"Optimizely": {
"ContentGraph": {
"GatewayAddress": "https://dev.cg.optimizely.com",
"AppKey": "YOUR-APP-KEY",
"Secret": "YOUR-SECRET-KEY",
"SingleKey": "YOUR-SINGLE-KEY",
"GatewayAddress": "",
"AppKey": "",
"Secret": "",
"SingleKey": "",
"AllowSendingLog": "true",
"ContentVersionSyncMode": "DraftAndPublishedOnly",
"Include": {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Loading
Loading