Skip to content

Commit

Permalink
fixed issue with datetime types in date filter
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlagunas committed Aug 7, 2023
1 parent d23bcea commit 2850568
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;

namespace Reveal.Sdk.Dom.Core.Serialization.Converters
{
internal class DateTimeConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value is DateTime dateTimeValue)
{
JObject jObject = new JObject
{
["_type"] = "date",
["value"] = dateTimeValue
};
jObject.WriteTo(writer);
}
else
{
throw new JsonSerializationException("Expected DateTime object.");
}
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject jObject = JObject.Load(reader);
var type = jObject["_type"].Value<string>();
if (type == "date")
{
var value = jObject["value"];
if (value != null)
{
return value.Value<DateTime>();
}
//todo: need to handle the option of XML date time which is a string
//this code logic can be found on line 248 of JsonUtility.cs in DataLayer.WPF
}

return null;
}

public override bool CanConvert(Type objectType)
{
return typeof(DateTime).IsAssignableFrom(objectType);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using Reveal.Sdk.Dom.Core.Constants;
using Newtonsoft.Json;
using Reveal.Sdk.Dom.Core.Constants;

namespace Reveal.Sdk.Dom.Filters
{
public sealed class DashboardDateFilterBindingTarget : BindingTarget
{
public string GlobalFilterFieldName { get; set; }
[JsonProperty("GlobalFilterId")]
public string DashboardFilterId { get; set; }

[JsonProperty("GlobalFilterFieldName")]
public string DashboardFilterFieldName { get; set; }

public DashboardDateFilterBindingTarget()
{
Expand Down
4 changes: 4 additions & 0 deletions src/Reveal.Sdk.Dom/Filters/DashboardFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ public abstract class DashboardFilter : SchemaType
{
public string Id { get; set; } = Guid.NewGuid().ToString();
public string Title { get; set; }

//todo: figure this out
[JsonProperty]
internal string CrossFilteringSourceWidgetId { get; set; }
}
}
7 changes: 6 additions & 1 deletion src/Reveal.Sdk.Dom/Primitives/DateRange.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System;
using Newtonsoft.Json;
using Reveal.Sdk.Dom.Core.Serialization.Converters;
using System;

namespace Reveal.Sdk.Dom
{
public sealed class DateRange
{
[JsonConverter(typeof(DateTimeConverter))]
public DateTime? From { get; set; }

[JsonConverter(typeof(DateTimeConverter))]
public DateTime? To { get; set; }
}
}

0 comments on commit 2850568

Please sign in to comment.