Skip to content

Commit 51575e5

Browse files
lauranetoAndyButlandCopilotnielslyngsoe
authored
Property Editors: New Date Time property editors (#19915)
* Started the implementation of the new date time property editor * Display picked time in local and UTC * Adjustments to the way the timezones are displayed and the picker is configured * Filter out `Etc/` (offset) timezones from the list * Additional adjustments * Introduced date format and time zone options (all, local or custom) * Adjustments to the property editor configuration and value converter * Use UUICombobox instead of UUISelect for displaying time zone options. Display UTC offset instead of short offset name in label. * Allow searching by offset * Ignore case when searching for time zone * Store dates consistently (always same format) * Add custom PropertyIndexValueFactory for the new property editor * Adjustments when switching between time zone modes * Small fixes and cleanup * Started improving time zone config selection * Small adjustments * Remove selected time zones from the list + display label instead of value * Localizing labels * Remove unwanted character * Fix incorrect order of custom time zones list * Small fixes (mostly validation) * Rename input time zone component * Small adjustments * Using model for stored value * Save examine value as ISO format * Adjusting class names for consistency * Small fixes * Add default data type configuration * Rename `TimeZone` to `UmbTimeZone` * Fix failing tests * Started adding unit tests for DateWithTimeZonePropertyEditor * Additional tests * Additional tests * Additional tests * Fixed searches with regex special characters throwing errors * Remove offset from generic UmbTimeZone type and added new type specific for the property editor * Adjust property editor to show error when selected time zone is no longer available, instead of pre-selecting another one * Do not preselect a time zone if a date is stored without time zone This most likely means that the configuration of the editor changed to add time zone support. In this case we want to force the editor to select the applicable time zone. * Fix failing backoffice build * Added tests for DateTimeWithTimeZonePropertyIndexValueFactory * Improved picker validation * Remove unused code * Move models to their corresponding places * Renaming `DateTimeWithTimeZone` to `DateTime2` * Fix data type count tests * Simplifying code + adjusting value converter to support old picker value * Adjustments to property editor unit tests * Fix validation issue * Fix default configuration for 'Date Time (Unspecified)' * Rename validator * Fix comment * Adjust database creator default DateTime2 data types * Update tests after adjusting default data types * Add integration test for DateTime2 returned value type * Apply suggestions from code review Co-authored-by: Andy Butland <[email protected]> * Aligning DateTime2Validator with other JSON validators. Added new model for API. * Removed unused code and updated tests * Fix validation error message * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * Splitting the new date time editor into multiple (per output type) * Adjust tests in DateTime2PropertyIndexValueFactoryTest * Update value converter tests * Group the new date time tests * Adjust new property editor tests * Adjust property editor integration tests * Update data editor count tests * Naming adjustments * Small fixes * Cleanup - Remove unused files - Remove 'None' option from configuration and update all the tests * Update luxon depedencies * Move GetValueFromSource to the value converter * Add new property editor examples to mock data * Re-organizing the code * Adjustments from code review * Place the date time property index value factories in their own files * Small adjustments for code consistency * Small adjustments * Minor adjustment * Small fix from copilot review * Completed the set of XML header comments. * use already existing query property * fail is form control element is null or undefined * using lit ref for querying and form control registration * state for timeZonePickerValue and remove _disableAddButton * Adjustments to form control registration * Remove unused declaration --------- Co-authored-by: Andy Butland <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Niels Lyngsø <[email protected]> Co-authored-by: Niels Lyngsø <[email protected]>
1 parent 07203b7 commit 51575e5

File tree

84 files changed

+4374
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4374
-5
lines changed

src/Umbraco.Core/Constants-DataTypes.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public static class Guids
111111
/// </summary>
112112
public const string DatePickerWithTime = "e4d66c0f-b935-4200-81f0-025f7256b89a";
113113

114+
/// <summary>
115+
/// Guid for Date Time Picker (with Timezone) as string
116+
/// </summary>
117+
public const string DateTimePickerWithTimeZone = "88E8A052-30EE-4D44-A507-59F2CDFC769C";
118+
114119
/// <summary>
115120
/// Guid for Approved Color as string
116121
/// </summary>
@@ -296,6 +301,11 @@ public static class Guids
296301
/// </summary>
297302
public static readonly Guid DatePickerWithTimeGuid = new(DatePickerWithTime);
298303

304+
/// <summary>
305+
/// Guid for Date Time Picker (with Timezone).
306+
/// </summary>
307+
public static readonly Guid DateTimePickerWithTimeZoneGuid = new(DateTimePickerWithTimeZone);
308+
299309
/// <summary>
300310
/// Guid for Approved Color
301311
/// </summary>

src/Umbraco.Core/Constants-PropertyEditors.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ public static class Aliases
7575
/// </summary>
7676
public const string DateTime = "Umbraco.DateTime";
7777

78+
/// <summary>
79+
/// Date Time (unspecified).
80+
/// </summary>
81+
public const string DateTimeUnspecified = "Umbraco.DateTimeUnspecified";
82+
83+
/// <summary>
84+
/// Date Time (with time zone).
85+
/// </summary>
86+
public const string DateTimeWithTimeZone = "Umbraco.DateTimeWithTimeZone";
87+
88+
/// <summary>
89+
/// Date Only.
90+
/// </summary>
91+
public const string DateOnly = "Umbraco.DateOnly";
92+
93+
/// <summary>
94+
/// Time Only.
95+
/// </summary>
96+
public const string TimeOnly = "Umbraco.TimeOnly";
97+
7898
/// <summary>
7999
/// DropDown List.
80100
/// </summary>

src/Umbraco.Core/EmbeddedResources/Lang/en.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@
376376
<key alias="invalidNull">Value cannot be null</key>
377377
<key alias="invalidEmpty">Value cannot be empty</key>
378378
<key alias="invalidPattern">Value is invalid, it does not match the correct pattern</key>
379+
<key alias="invalidDate">Invalid date</key>
379380
<key alias="entriesShort"><![CDATA[Minimum %0% entries, requires <strong>%1%</strong> more.]]></key>
380381
<key alias="entriesExceed"><![CDATA[Maximum %0% entries, you have entered <strong>%1%</strong> too many.]]></key>
381382
<key alias="stringLengthExceeded">The string length exceeds the maximum length of %0% characters, %1% too many.</key>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Umbraco.
2+
// See LICENSE for more details.
3+
4+
using System.Text.Json.Serialization;
5+
6+
namespace Umbraco.Cms.Core.PropertyEditors;
7+
8+
public class DateTimeConfiguration
9+
{
10+
/// <summary>
11+
/// Gets or sets the time zones configuration.
12+
/// </summary>
13+
[ConfigurationField("timeZones")]
14+
public TimeZonesConfiguration? TimeZones { get; set; }
15+
16+
public class TimeZonesConfiguration
17+
{
18+
/// <summary>
19+
/// The mode for time zones.
20+
/// </summary>
21+
public TimeZoneMode Mode { get; set; }
22+
23+
/// <summary>
24+
/// A list of time zones to use when the mode is set to Custom.
25+
/// </summary>
26+
public List<string> TimeZones { get; set; } = [];
27+
}
28+
29+
public enum TimeZoneMode
30+
{
31+
/// <summary>
32+
/// Display all time zones.
33+
/// </summary>
34+
[JsonStringEnumMemberName("all")]
35+
All,
36+
37+
/// <summary>
38+
/// Display only the local time zone of the user.
39+
/// </summary>
40+
[JsonStringEnumMemberName("local")]
41+
Local,
42+
43+
/// <summary>
44+
/// Display a custom list of time zones defined in the configuration.
45+
/// </summary>
46+
[JsonStringEnumMemberName("custom")]
47+
Custom,
48+
}
49+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Umbraco.Cms.Core.PropertyEditors;
2+
3+
/// <summary>
4+
/// Factory for creating index values for Date Only properties.
5+
/// </summary>
6+
public interface IDateOnlyPropertyIndexValueFactory : IPropertyIndexValueFactory;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Umbraco.Cms.Core.PropertyEditors;
2+
3+
/// <summary>
4+
/// Factory for creating index values for Date Time Unspecified properties.
5+
/// </summary>
6+
public interface IDateTimeUnspecifiedPropertyIndexValueFactory : IPropertyIndexValueFactory;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Umbraco.Cms.Core.PropertyEditors;
2+
3+
/// <summary>
4+
/// Factory for creating index values for Date Time with Time Zone properties.
5+
/// </summary>
6+
public interface IDateTimeWithTimeZonePropertyIndexValueFactory : IPropertyIndexValueFactory;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Umbraco.Cms.Core.PropertyEditors;
2+
3+
/// <summary>
4+
/// Factory for creating index values for Time Only properties.
5+
/// </summary>
6+
public interface ITimeOnlyPropertyIndexValueFactory : IPropertyIndexValueFactory;

src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ public static IUmbracoBuilder AddPropertyIndexValueFactories(this IUmbracoBuilde
263263
builder.Services.AddSingleton<IBlockValuePropertyIndexValueFactory, BlockValuePropertyIndexValueFactory>();
264264
builder.Services.AddSingleton<ITagPropertyIndexValueFactory, TagPropertyIndexValueFactory>();
265265
builder.Services.AddSingleton<IRichTextPropertyIndexValueFactory, RichTextPropertyIndexValueFactory>();
266+
builder.Services.AddSingleton<IDateOnlyPropertyIndexValueFactory, DateOnlyPropertyIndexValueFactory>();
267+
builder.Services.AddSingleton<ITimeOnlyPropertyIndexValueFactory, TimeOnlyPropertyIndexValueFactory>();
268+
builder.Services.AddSingleton<IDateTimeUnspecifiedPropertyIndexValueFactory, DateTimeUnspecifiedPropertyIndexValueFactory>();
269+
builder.Services.AddSingleton<IDateTimeWithTimeZonePropertyIndexValueFactory, DateTimeWithTimeZonePropertyIndexValueFactory>();
266270

267271
return builder;
268272
}

src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,25 @@ void InsertDataTypeNodeDto(int id, int sortOrder, string uniqueId, string text)
863863
},
864864
Constants.DatabaseSchema.Tables.Node,
865865
"id");
866+
ConditionalInsert(
867+
Constants.Configuration.NamedOptions.InstallDefaultData.DataTypes,
868+
Constants.DataTypes.Guids.DateTimePickerWithTimeZone,
869+
new NodeDto
870+
{
871+
NodeId = 1055,
872+
Trashed = false,
873+
ParentId = -1,
874+
UserId = -1,
875+
Level = 1,
876+
Path = "-1,1055",
877+
SortOrder = 2,
878+
UniqueId = Constants.DataTypes.Guids.DateTimePickerWithTimeZoneGuid,
879+
Text = "Date Time Picker (with time zone)",
880+
NodeObjectType = Constants.ObjectTypes.DataType,
881+
CreateDate = DateTime.UtcNow,
882+
},
883+
Constants.DatabaseSchema.Tables.Node,
884+
"id");
866885
}
867886

868887
private void CreateNodeDataForMediaTypes()
@@ -2302,6 +2321,22 @@ string GridCollectionView(string collectionViewType) =>
23022321
"\", \"multiple\": true}",
23032322
});
23042323
}
2324+
2325+
if (_database.Exists<NodeDto>(1055))
2326+
{
2327+
_database.Insert(
2328+
Constants.DatabaseSchema.Tables.DataType,
2329+
"pk",
2330+
false,
2331+
new DataTypeDto
2332+
{
2333+
NodeId = 1055,
2334+
EditorAlias = Constants.PropertyEditors.Aliases.DateTimeWithTimeZone,
2335+
EditorUiAlias = "Umb.PropertyEditorUi.DateTimeWithTimeZonePicker",
2336+
DbType = "Ntext",
2337+
Configuration = "{\"timeFormat\": \"HH:mm\", \"timeZones\": {\"mode\": \"all\"}}",
2338+
});
2339+
}
23052340
}
23062341

23072342
private void CreateRelationTypeData()

0 commit comments

Comments
 (0)