Skip to content

Commit de8a7d8

Browse files
authored
Merge branch 'main' into doc-calendar
2 parents 27a7a39 + ff28f9c commit de8a7d8

5 files changed

Lines changed: 63 additions & 109 deletions

File tree

src/BootstrapBlazor/Components/Filters/FilterKeyValueAction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -20,6 +20,7 @@ public class FilterKeyValueAction
2020
/// <summary>
2121
/// 获得/设置 Filter 项字段值
2222
/// </summary>
23+
[JsonConverter(typeof(ObjectWithTypeConverter))]
2324
public object? FieldValue { get; set; }
2425

2526
/// <summary>

src/BootstrapBlazor/Converter/JsonQueryPageOptionConverter.cs

Lines changed: 11 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -104,80 +104,14 @@ public class JsonQueryPageOptionsConverter : JsonConverter<QueryPageOptions>
104104
reader.Read();
105105
ret.IsVirtualScroll = reader.GetBoolean();
106106
}
107-
else if (propertyName == "searches")
107+
108+
else if (propertyName == "filterKeyValueAction")
108109
{
109110
reader.Read();
110-
if (reader.TokenType == JsonTokenType.StartArray)
111-
{
112-
while (reader.Read())
113-
{
114-
if (reader.TokenType == JsonTokenType.EndArray)
115-
{
116-
break;
117-
}
118-
var val = JsonSerializer.Deserialize<SearchFilterAction>(ref reader, options);
119-
if (val != null)
120-
{
121-
ret.Searches.Add(val);
122-
}
123-
}
124-
}
125-
}
126-
else if (propertyName == "customerSearches")
127-
{
128-
reader.Read();
129-
if (reader.TokenType == JsonTokenType.StartArray)
130-
{
131-
while (reader.Read())
132-
{
133-
if (reader.TokenType == JsonTokenType.EndArray)
134-
{
135-
break;
136-
}
137-
var val = JsonSerializer.Deserialize<SearchFilterAction>(ref reader, options);
138-
if (val != null)
139-
{
140-
ret.CustomerSearches.Add(val);
141-
}
142-
}
143-
}
144-
}
145-
else if (propertyName == "advanceSearches")
146-
{
147-
reader.Read();
148-
if (reader.TokenType == JsonTokenType.StartArray)
149-
{
150-
while (reader.Read())
151-
{
152-
if (reader.TokenType == JsonTokenType.EndArray)
153-
{
154-
break;
155-
}
156-
var val = JsonSerializer.Deserialize<SearchFilterAction>(ref reader, options);
157-
if (val != null)
158-
{
159-
ret.AdvanceSearches.Add(val);
160-
}
161-
}
162-
}
163-
}
164-
else if (propertyName == "filters")
165-
{
166-
reader.Read();
167-
if (reader.TokenType == JsonTokenType.StartArray)
111+
var val = JsonSerializer.Deserialize<FilterKeyValueAction>(ref reader, options);
112+
if (val != null)
168113
{
169-
while (reader.Read())
170-
{
171-
if (reader.TokenType == JsonTokenType.EndArray)
172-
{
173-
break;
174-
}
175-
var val = JsonSerializer.Deserialize<SearchFilterAction>(ref reader, options);
176-
if (val != null)
177-
{
178-
ret.Filters.Add(val);
179-
}
180-
}
114+
ret.FilterKeyValueAction = val;
181115
}
182116
}
183117
else if (propertyName == "isFirstQuery")
@@ -252,41 +186,12 @@ public override void Write(Utf8JsonWriter writer, QueryPageOptions value, JsonSe
252186
{
253187
writer.WriteBoolean("isVirtualScroll", value.IsVirtualScroll);
254188
}
255-
if (value.Searches.Count != 0)
256-
{
257-
writer.WriteStartArray("searches");
258-
foreach (var filter in value.Searches)
259-
{
260-
writer.WriteRawValue(JsonSerializer.Serialize(filter, options));
261-
}
262-
writer.WriteEndArray();
263-
}
264-
if (value.CustomerSearches.Count != 0)
265-
{
266-
writer.WriteStartArray("customerSearches");
267-
foreach (var filter in value.CustomerSearches)
268-
{
269-
writer.WriteRawValue(JsonSerializer.Serialize(filter, options));
270-
}
271-
writer.WriteEndArray();
272-
}
273-
if (value.AdvanceSearches.Count != 0)
274-
{
275-
writer.WriteStartArray("advanceSearches");
276-
foreach (var filter in value.AdvanceSearches)
277-
{
278-
writer.WriteRawValue(JsonSerializer.Serialize(filter, options));
279-
}
280-
writer.WriteEndArray();
281-
}
282-
if (value.Filters.Count != 0)
189+
190+
if (value.Searches.Count != 0||value.CustomerSearches.Count != 0||value.AdvanceSearches.Count != 0|| value.Filters.Count != 0)
283191
{
284-
writer.WriteStartArray("filters");
285-
foreach (var filter in value.Filters)
286-
{
287-
writer.WriteRawValue(JsonSerializer.Serialize(filter, options));
288-
}
289-
writer.WriteEndArray();
192+
writer.WritePropertyName("filterKeyValueAction");
193+
var filterKeyValueAction = value.ToFilter();
194+
writer.WriteRawValue(JsonSerializer.Serialize(filterKeyValueAction, options));
290195
}
291196
if (value.IsFirstQuery)
292197
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
5+
6+
using System.Text.Json;
7+
using System.Text.Json.Serialization;
8+
9+
namespace BootstrapBlazor.Components;
10+
11+
internal class ObjectWithTypeConverter : JsonConverter<object>
12+
{
13+
public override object? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
14+
{
15+
using var doc = JsonDocument.ParseValue(ref reader);
16+
17+
if (!doc.RootElement.TryGetProperty("$type", out var typeProp))
18+
return doc.RootElement.Clone(); // 无类型信息
19+
20+
var type = Type.GetType(typeProp.GetString()!)!;
21+
22+
var valueElement = doc.RootElement.GetProperty("value");
23+
return JsonSerializer.Deserialize(valueElement.GetRawText(), type, options);
24+
}
25+
26+
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
27+
{
28+
writer.WriteStartObject();
29+
writer.WriteString("$type", value.GetType().AssemblyQualifiedName);
30+
writer.WritePropertyName("value");
31+
JsonSerializer.Serialize(writer, value, value.GetType(), options);
32+
writer.WriteEndObject();
33+
}
34+
}

src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -19,6 +19,9 @@ public static class QueryPageOptionsExtensions
1919
/// <returns></returns>
2020
public static FilterKeyValueAction ToFilter(this QueryPageOptions option)
2121
{
22+
// 后续再更改
23+
if (option.FilterKeyValueAction != null) return option.FilterKeyValueAction;
24+
2225
var filter = new FilterKeyValueAction();
2326

2427
// 处理模糊搜索

src/BootstrapBlazor/Options/QueryPageOptions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -41,6 +41,7 @@ public class QueryPageOptions
4141
/// <summary>
4242
/// 获得 搜索条件绑定模型 未设置 <see cref="Table{TItem}.CustomerSearchModel"/> 时为 <see cref="Table{TItem}"/> 泛型模型
4343
/// </summary>
44+
[JsonConverter(typeof(ObjectWithTypeConverter))]
4445
public object? SearchModel { get; set; }
4546

4647
/// <summary>
@@ -79,6 +80,7 @@ public class QueryPageOptions
7980
/// <summary>
8081
/// 获得 通过列集合中的 <see cref="ITableColumn.Searchable"/> 列与 <see cref="SearchText"/> 拼装 IFilterAction 集合
8182
/// </summary>
83+
[JsonIgnore]
8284
public List<IFilterAction> Searches { get; } = new(20);
8385

8486
/// <summary>
@@ -91,6 +93,7 @@ public class QueryPageOptions
9193
/// <summary>
9294
/// 获得 <see cref="Table{TItem}.CustomerSearchModel"/> 中过滤条件 <see cref="Table{TItem}.SearchTemplate"/> 模板中的条件请使用 <see cref="AdvanceSearches" />获得
9395
/// </summary>
96+
[JsonIgnore]
9497
public List<IFilterAction> CustomerSearches { get; } = new(20);
9598

9699
/// <summary>
@@ -103,13 +106,21 @@ public class QueryPageOptions
103106
/// <summary>
104107
/// 获得 <see cref="Table{TItem}.SearchModel"/> 中过滤条件
105108
/// </summary>
109+
[JsonIgnore]
106110
public List<IFilterAction> AdvanceSearches { get; } = new(20);
107111

108112
/// <summary>
109113
/// 获得 过滤条件集合 等同于 <see cref="Table{TItem}.Filters"/> 值
110114
/// </summary>
115+
[JsonIgnore]
111116
public List<IFilterAction> Filters { get; } = new(20);
112117

118+
/// <summary>
119+
/// Gets or sets the action to take when filtering key-value pairs during processing.
120+
/// </summary>
121+
[JsonIgnore]
122+
internal FilterKeyValueAction? FilterKeyValueAction { get; set; }
123+
113124
/// <summary>
114125
/// 获得 是否为首次查询 默认 false
115126
/// </summary>

0 commit comments

Comments
 (0)