-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from umbraco/feature/automatic-deserialize-models
Automatic deserialize JSON to IContent implementations
- Loading branch information
Showing
49 changed files
with
652 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "3.1.404" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
...adless.Client.Samples.Web/Umbraco.Headless.Client.Samples.Web/Models/ContentExtensions.cs
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...braco.Headless.Client.Samples.Web/Umbraco.Headless.Client.Samples.Web/Models/Frontpage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Umbraco.Headless.Client.Net.Delivery.Models; | ||
|
||
namespace Umbraco.Headless.Client.Samples.Web.Models | ||
{ | ||
public class Frontpage : Content, IHideInNavigation | ||
{ | ||
public string HeroTitle { get; set; } | ||
public string HeroSubtitle { get; set; } | ||
public Image HeroImage { get; set; } | ||
|
||
public string UniqueSellingPointsTitle { get; set; } | ||
public IEnumerable<UniqueSellingPoint> UniqueSellingPoints { get; set; } | ||
|
||
public IEnumerable<IElement> Elements { get; set; } | ||
|
||
public string FooterTitle { get; set; } | ||
public IEnumerable<MultiUrlPickerLink> FooterLinks { get; set; } | ||
|
||
[JsonProperty("umbracoNaviHide")] | ||
public bool HideInNavigation { get; set; } | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...adless.Client.Samples.Web/Umbraco.Headless.Client.Samples.Web/Models/IHideInNavigation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Umbraco.Headless.Client.Samples.Web.Models | ||
{ | ||
public interface IHideInNavigation | ||
{ | ||
bool HideInNavigation { get; set; } | ||
} | ||
} |
9 changes: 7 additions & 2 deletions
9
...co.Headless.Client.Samples.Web/Umbraco.Headless.Client.Samples.Web/Models/TextAndImage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
using Microsoft.AspNetCore.Html; | ||
using Newtonsoft.Json; | ||
using Umbraco.Headless.Client.Net.Delivery.Models; | ||
using Umbraco.Headless.Client.Samples.Web.Serialization; | ||
|
||
namespace Umbraco.Headless.Client.Samples.Web.Models | ||
{ | ||
public class TextAndImage | ||
public class TextAndImage : Element | ||
{ | ||
public string Title { get; set; } | ||
|
||
[JsonConverter(typeof(HtmlContentConverter))] | ||
public IHtmlContent Text { get; set; } | ||
public string ImageUrl { get; set; } | ||
public Image Image { get; set; } | ||
public bool ShowLargeImage { get; set; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...mbraco.Headless.Client.Samples.Web/Umbraco.Headless.Client.Samples.Web/Models/Textpage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Umbraco.Headless.Client.Net.Delivery.Models; | ||
|
||
namespace Umbraco.Headless.Client.Samples.Web.Models | ||
{ | ||
public class Textpage : Content, IHideInNavigation | ||
{ | ||
public string HeroTitle { get; set; } | ||
public string HeroSubtitle { get; set; } | ||
public Image HeroImage { get; set; } | ||
|
||
public IEnumerable<Element> Elements { get; set; } | ||
|
||
[JsonProperty("umbracoNaviHide")] | ||
public bool HideInNavigation { get; set; } | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
...dless.Client.Samples.Web/Umbraco.Headless.Client.Samples.Web/Models/UniqueSellingPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
using Microsoft.AspNetCore.Html; | ||
using Newtonsoft.Json; | ||
using Umbraco.Headless.Client.Net.Delivery.Models; | ||
using Umbraco.Headless.Client.Samples.Web.Serialization; | ||
|
||
namespace Umbraco.Headless.Client.Samples.Web.Models | ||
{ | ||
public class UniqueSellingPoint | ||
{ | ||
public string Title { get; set; } | ||
|
||
[JsonConverter(typeof(HtmlContentConverter))] | ||
public IHtmlContent Text { get; set; } | ||
public MultiUrlPickerLink Link { get; set; } | ||
public string ImageUrl { get; set; } | ||
public Image Image { get; set; } | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ent.Samples.Web/Umbraco.Headless.Client.Samples.Web/Serialization/HtmlContentConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Html; | ||
using Newtonsoft.Json; | ||
|
||
namespace Umbraco.Headless.Client.Samples.Web.Serialization | ||
{ | ||
public class HtmlContentConverter : JsonConverter | ||
{ | ||
public override bool CanWrite { get; } = false; | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
var value = serializer.Deserialize<string>(reader); | ||
return new HtmlString(value); | ||
} | ||
|
||
public override bool CanConvert(Type objectType) => typeof(IHtmlContent).IsAssignableFrom(objectType); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
...mples.Web/Umbraco.Headless.Client.Samples.Web/ViewComponents/TextAndImageViewComponent.cs
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
...eb/Umbraco.Headless.Client.Samples.Web/ViewComponents/UniqueSellingPointsViewComponent.cs
This file was deleted.
Oops, something went wrong.
17 changes: 8 additions & 9 deletions
17
...ent.Samples.Web/Umbraco.Headless.Client.Samples.Web/Views/DefaultUmbraco/Frontpage.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
@using Umbraco.Headless.Client.Net.Delivery.Models | ||
@model Umbraco.Headless.Client.Net.Delivery.Models.Content | ||
@model Frontpage | ||
|
||
@await Component.InvokeAsync("Hero", new | ||
{ | ||
title = Model.Value<string>("heroTitle"), | ||
subTitle = Model.Value<string>("heroSubtitle"), | ||
image = Model.Value<Image>("heroImage") | ||
title = Model.HeroTitle, | ||
subTitle = Model.HeroSubtitle, | ||
image = Model.HeroImage | ||
}) | ||
|
||
@await Component.InvokeAsync("UniqueSellingPoints", new | ||
@await Html.PartialAsync("_UniqueSellingPoints", new UniqueSellingPointsViewModel | ||
{ | ||
title = Model.Value<string>("uniqueSellingPointsTitle"), | ||
contents = Model.Value<IEnumerable<Content>>("uniqueSellingPoints") | ||
Title = Model.UniqueSellingPointsTitle, | ||
UniqueSellingPoints = Model.UniqueSellingPoints | ||
}) | ||
|
||
@await Html.PartialAsync("_Elements", Model.Value<IEnumerable<Element>>("elements")) | ||
@await Html.PartialAsync("_Elements", Model.Elements) |
11 changes: 5 additions & 6 deletions
11
...ient.Samples.Web/Umbraco.Headless.Client.Samples.Web/Views/DefaultUmbraco/Textpage.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
@using Umbraco.Headless.Client.Net.Delivery.Models | ||
@model Umbraco.Headless.Client.Net.Delivery.Models.Content | ||
@model Textpage | ||
|
||
@await Component.InvokeAsync("Hero", new { | ||
title = Model.Value<string>("heroTitle"), | ||
subTitle = Model.Value<string>("heroSubtitle"), | ||
image = Model.Value<Image>("heroImage") | ||
title = Model.HeroTitle, | ||
subTitle = Model.HeroSubtitle, | ||
image = Model.HeroImage, | ||
}) | ||
|
||
@await Html.PartialAsync("_Elements", Model.Value<IEnumerable<Element>>("elements")) | ||
@await Html.PartialAsync("_Elements", Model.Elements) |
2 changes: 1 addition & 1 deletion
2
...Umbraco.Headless.Client.Samples.Web/Views/Shared/Components/MainNavigation/Default.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.