Skip to content

Commit

Permalink
Merge pull request #15 from contentstack/bug/livepreview
Browse files Browse the repository at this point in the history
Live preview Query update issue resolved
  • Loading branch information
uttamukkoji authored Jan 14, 2022
2 parents fcd340d + 062c066 commit 7ca3557
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 42 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
### Version: 2.8.0
#### Date: Jan-11-2021

##### Bug fix:
- Live preview Query issue
##### New Feature:
- Entry
- IncludeOnlyReference function added
- IncludeExceptReference function added
- Query
- IncludeOnlyReference function added
- IncludeExceptReference function added

### Version: 2.7.0
#### Date: Oct-14-2021

Expand Down
2 changes: 1 addition & 1 deletion Contentstack.AspNetCore/Contentstack.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Copyright>Copyright (c) 2012-2020 Contentstack (http://app.contentstack.com). All Rights Reserved</Copyright>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageTags>v2.7.0</PackageTags>
<ReleaseVersion>2.7.0</ReleaseVersion>
<ReleaseVersion>2.8.0</ReleaseVersion>
<Configurations>Release;Debug</Configurations>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core.Tests/Contentstack.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
<ReleaseVersion>2.7.0</ReleaseVersion>
<ReleaseVersion>2.8.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Contentstack.Core/Contentstack.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<PackageId>contentstack.csharp</PackageId>
<Authors>Contentstack</Authors>
<Description>.NET SDK for the Contentstack Content Delivery API.</Description>
<PackageVersion>2.7.0</PackageVersion>
<PackageVersion>2.8.0</PackageVersion>
<Owners>Contentstack</Owners>
<PackageReleaseNotes>Live preview feature support added</PackageReleaseNotes>
<Copyright>Copyright © 2012-2021 Contentstack. All Rights Reserved</Copyright>
<Copyright>Copyright © 2012-2022 Contentstack. All Rights Reserved</Copyright>
<PackOnBuild>true</PackOnBuild>
<PackageTags>v2.7.0</PackageTags>
<PackageTags>v2.8.0</PackageTags>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<ReleaseVersion>2.7.0</ReleaseVersion>
<ReleaseVersion>2.8.0</ReleaseVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
20 changes: 12 additions & 8 deletions Contentstack.Core/ContentstackClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,18 @@ public void SetHeader(string key, string value)
/// </example>
public void LivePreviewQuery(Dictionary<string, string> query)
{
string contentTypeUID = null;
query.TryGetValue("content_type_uid", out contentTypeUID);
this.LivePreviewConfig.ContentTypeUID = contentTypeUID;

string hash = null;
query.TryGetValue("live_preview", out hash);
this.LivePreviewConfig.LivePreview = hash;

if (query.Keys.Contains("content_type_uid"))
{
string contentTypeUID = null;
query.TryGetValue("content_type_uid", out contentTypeUID);
this.LivePreviewConfig.ContentTypeUID = contentTypeUID;
}
if (query.Keys.Contains("live_preview"))
{
string hash = null;
query.TryGetValue("live_preview", out hash);
this.LivePreviewConfig.LivePreview = hash;
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2012-2021 Contentstack (http://app.contentstack.com). All Rights Reserved
Copyright (c) 2012-2022 Contentstack (http://app.contentstack.com). All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
44 changes: 20 additions & 24 deletions Contentstack.Core/Models/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -983,20 +983,18 @@ public Entry IncludeReference(String[] referenceFields)
/// </example>
public Entry IncludeOnlyReference(string[] keys, string referenceKey)
{
List<string> objectUidForOnly = new List<string>();
Dictionary<string, object> onlyValueJson = new Dictionary<string, object>();
if (keys != null && keys.Length > 0)
{

int count = keys.Length;
for (int i = 0; i < count; i++)
{
objectUidForOnly.Add(keys[i]);
var referenceKeys = new string[] { referenceKey };
if (UrlQueries.ContainsKey("include[]") == false)
{
UrlQueries.Add("", referenceKeys);

}
if (UrlQueries.ContainsKey($"only[{referenceKey}][]") == false)
{
UrlQueries.Add($"only[{referenceKey}][]", keys);
}
onlyValueJson.Add(referenceKey, objectUidForOnly);
UrlQueries.Add("include", new object[] { referenceKey });
UrlQueries.Add("only", onlyValueJson);

}

return this;
Expand Down Expand Up @@ -1184,22 +1182,20 @@ public Entry IncludeOwner()
/// </example>
public Entry IncludeExceptReference(string[] keys, string referenceKey)
{
List<string> objectUidForOnly = new List<string>();
Dictionary<string, object> onlyValueJson = new Dictionary<string, object>();

if (keys != null && keys.Length > 0)
{

int count = keys.Length;
for (int i = 0; i < count; i++)
{
objectUidForOnly.Add(keys[i]);
var referenceKeys = new string[] { referenceKey };
if (UrlQueries.ContainsKey("include[]") == false)
{
UrlQueries.Add("include[]", referenceKeys);

}
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
{
UrlQueries.Add($"except[{referenceKey}][]", keys);
}
onlyValueJson.Add(referenceKey, objectUidForOnly);
UrlQueries.Add("include", new object[] { referenceKey });
UrlQueries.Add("except", onlyValueJson);

}

return this;
}

Expand Down Expand Up @@ -1294,7 +1290,7 @@ public async Task<T> Fetch<T>()
}

HttpRequestHandler RequestHandler = new HttpRequestHandler();
var outputResult = await RequestHandler.ProcessRequest(_Url, headers, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, config: this.ContentTypeInstance.StackInstance.LivePreviewConfig);
var outputResult = await RequestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, config: this.ContentTypeInstance.StackInstance.LivePreviewConfig);
JObject obj = JObject.Parse(ContentstackConvert.ToString(outputResult, "{}"));
var serializedObject = obj.SelectToken("$.entry").ToObject<T>(this.ContentTypeInstance.StackInstance.Serializer);
if (serializedObject.GetType() == typeof(Entry))
Expand Down
72 changes: 70 additions & 2 deletions Contentstack.Core/Models/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,9 +1212,43 @@ public Query Only(String[] fieldUid)
Console.WriteLine("IOException source: {0}", e.Source);
}

return this;
}

/// <summary>
/// Specifies an array of only keys that would be included in the response.
/// </summary>
/// <param name="keys">Array of the only reference keys to be included in response.</param>
/// <param name="referenceKey">Key who has reference to some other class object.</param>
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
/// <example>
/// <code>
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
///
/// csQuery.IncludeOnlyReference(new String[]{&quot;name&quot;, &quot;description&quot;}, &quot;referenceUid&quot;);
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
/// //Your callback code.
/// });
/// </code>
/// </example>
public Query IncludeOnlyReference(string[] keys, string referenceKey)
{
if (keys != null && keys.Length > 0)
{
var referenceKeys = new string[] { referenceKey };
if (UrlQueries.ContainsKey("include[]") == false)
{
UrlQueries.Add("include[]", referenceKeys);

}
if (UrlQueries.ContainsKey($"only[{ referenceKey}][]") == false)
{
UrlQueries.Add($"only[{referenceKey}][]", keys);
}
}
return this;
}

/// <summary>
/// Specifies list of field uids that would be excluded from the response.
/// </summary>
Expand Down Expand Up @@ -1249,6 +1283,40 @@ public Query Except(String[] fieldUids)
return this;
}

/// <summary>
/// Specifies an array of except keys that would be excluded in the response.
/// </summary>
/// <param name="keys">Array of the except reference keys to be excluded in response.</param>
/// <param name="referenceKey">Key who has reference to some other class object.</param>
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
/// <example>
/// <code>
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
/// csQuery.IncludeExceptReference(new String[]{&quot;name&quot;, &quot;description&quot;},&quot;referenceUid&quot;);
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
/// //Your callback code.
/// });
/// </code>
/// </example>
public Query IncludeExceptReference(string[] keys, string referenceKey)
{
if (keys != null && keys.Length > 0)
{
var referenceKeys = new string[] { referenceKey };
if (UrlQueries.ContainsKey("include[]") == false)
{
UrlQueries.Add("include[]", referenceKeys);

}
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
{
UrlQueries.Add($"except[{referenceKey}][]", keys);
}
}
return this;
}

/// <summary>
/// Include fallback locale publish content, if specified locale content is not publish.
/// </summary>
Expand Down Expand Up @@ -1693,7 +1761,7 @@ private async Task<JObject> Exec()
try
{
HttpRequestHandler requestHandler = new HttpRequestHandler();
var outputResult = await requestHandler.ProcessRequest(_Url, headers, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, config: this.ContentTypeInstance.StackInstance.LivePreviewConfig);
var outputResult = await requestHandler.ProcessRequest(_Url, headerAll, mainJson, Branch: this.ContentTypeInstance.StackInstance.Config.Branch, config: this.ContentTypeInstance.StackInstance.LivePreviewConfig);
return JObject.Parse(ContentstackConvert.ToString(outputResult, "{}"));
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ Global
$0.XmlFormattingPolicy = $9
$9.scope = application/xml
$0.StandardHeader = $10
version = 2.7.0
version = 2.8.0
EndGlobalSection
EndGlobal

0 comments on commit 7ca3557

Please sign in to comment.