From 2c8e1fa851c0e82aeb23378a865ceec2c75ba01a Mon Sep 17 00:00:00 2001 From: Markus Johansson Date: Mon, 20 Jan 2020 13:51:47 +0100 Subject: [PATCH 1/5] Solved issue #33 and fixed issue where scope.model.value is empty string or is string --- .../Controllers/OpeningHoursEditor.js | 10 +++++++ .../OpeningHours/Directives/Weekdays.js | 30 +++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/Our.Umbraco.OpeningHours/App_Plugins/OpeningHours/Controllers/OpeningHoursEditor.js b/src/Our.Umbraco.OpeningHours/App_Plugins/OpeningHours/Controllers/OpeningHoursEditor.js index 6307124..97f9fa3 100644 --- a/src/Our.Umbraco.OpeningHours/App_Plugins/OpeningHours/Controllers/OpeningHoursEditor.js +++ b/src/Our.Umbraco.OpeningHours/App_Plugins/OpeningHours/Controllers/OpeningHoursEditor.js @@ -1,5 +1,15 @@ angular.module("umbraco").controller("OpeningHours.Controllers.OpeningHoursController", function ($scope) { + // Double-check that we're getting the model back in the expected format + // (ie.Nested Content might init the property editor with a string) + if (typeof ($scope.model.value) === 'string') { + if ($scope.model.value === '') { + $scope.model.value = {}; + } else { + $scope.model.value = JSON.parse($scope.model.value); + } + } + function parseBoolean(str) { str = str + ''; return str == '1' || str == 'true'; diff --git a/src/Our.Umbraco.OpeningHours/App_Plugins/OpeningHours/Directives/Weekdays.js b/src/Our.Umbraco.OpeningHours/App_Plugins/OpeningHours/Directives/Weekdays.js index 32e6c0e..09bf136 100644 --- a/src/Our.Umbraco.OpeningHours/App_Plugins/OpeningHours/Directives/Weekdays.js +++ b/src/Our.Umbraco.OpeningHours/App_Plugins/OpeningHours/Directives/Weekdays.js @@ -9,8 +9,10 @@ templateUrl: '/App_Plugins/OpeningHours/Views/Directives/Weekdays.html', link: function (scope) { - function parseBoolean(str) { - str = str + ''; + + + function parseBoolean(str) { + str = str + ''; return str == '1' || str == 'true'; } @@ -22,14 +24,20 @@ scope.weekdays = []; scope.times = ['00:00', '00:05', '00:10', '00:15', '00:20', '00:25', '00:30', '00:35', '00:40', '00:45', '00:50', '00:55', '01:00', '01:05', '01:10', '01:15', '01:20', '01:25', '01:30', '01:35', '01:40', '01:45', '01:50', '01:55', '02:00', '02:05', '02:10', '02:15', '02:20', '02:25', '02:30', '02:35', '02:40', '02:45', '02:50', '02:55', '03:00', '03:05', '03:10', '03:15', '03:20', '03:25', '03:30', '03:35', '03:40', '03:45', '03:50', '03:55', '04:00', '04:05', '04:10', '04:15', '04:20', '04:25', '04:30', '04:35', '04:40', '04:45', '04:50', '04:55', '05:00', '05:05', '05:10', '05:15', '05:20', '05:25', '05:30', '05:35', '05:40', '05:45', '05:50', '05:55', '06:00', '06:05', '06:10', '06:15', '06:20', '06:25', '06:30', '06:35', '06:40', '06:45', '06:50', '06:55', '07:00', '07:05', '07:10', '07:15', '07:20', '07:25', '07:30', '07:35', '07:40', '07:45', '07:50', '07:55', '08:00', '08:05', '08:10', '08:15', '08:20', '08:25', '08:30', '08:35', '08:40', '08:45', '08:50', '08:55', '09:00', '09:05', '09:10', '09:15', '09:20', '09:25', '09:30', '09:35', '09:40', '09:45', '09:50', '09:55', '10:00', '10:05', '10:10', '10:15', '10:20', '10:25', '10:30', '10:35', '10:40', '10:45', '10:50', '10:55', '11:00', '11:05', '11:10', '11:15', '11:20', '11:25', '11:30', '11:35', '11:40', '11:45', '11:50', '11:55', '12:00', '12:05', '12:10', '12:15', '12:20', '12:25', '12:30', '12:35', '12:40', '12:45', '12:50', '12:55', '13:00', '13:05', '13:10', '13:15', '13:20', '13:25', '13:30', '13:35', '13:40', '13:45', '13:50', '13:55', '14:00', '14:05', '14:10', '14:15', '14:20', '14:25', '14:30', '14:35', '14:40', '14:45', '14:50', '14:55', '15:00', '15:05', '15:10', '15:15', '15:20', '15:25', '15:30', '15:35', '15:40', '15:45', '15:50', '15:55', '16:00', '16:05', '16:10', '16:15', '16:20', '16:25', '16:30', '16:35', '16:40', '16:45', '16:50', '16:55', '17:00', '17:05', '17:10', '17:15', '17:20', '17:25', '17:30', '17:35', '17:40', '17:45', '17:50', '17:55', '18:00', '18:05', '18:10', '18:15', '18:20', '18:25', '18:30', '18:35', '18:40', '18:45', '18:50', '18:55', '19:00', '19:05', '19:10', '19:15', '19:20', '19:25', '19:30', '19:35', '19:40', '19:45', '19:50', '19:55', '20:00', '20:05', '20:10', '20:15', '20:20', '20:25', '20:30', '20:35', '20:40', '20:45', '20:50', '20:55', '21:00', '21:05', '21:10', '21:15', '21:20', '21:25', '21:30', '21:35', '21:40', '21:45', '21:50', '21:55', '22:00', '22:05', '22:10', '22:15', '22:20', '22:25', '22:30', '22:35', '22:40', '22:45', '22:50', '22:55', '23:00', '23:05', '23:10', '23:15', '23:20', '23:25', '23:30', '23:35', '23:40', '23:45', '23:50', '23:55']; + // We're watching the "value" comming from the parent scope, since this object is updated on save/publish we need to reinit the view when this happens. + // scope.value is also changed when the view loads so this also works as the "init"-call when loading the directive. + scope.$watch('value', function() { + initModel(); + initShadowModel(); + }); + // Initializes an empty day - function initDay() { + function initDay() { return { label: null, items: [] }; } // Function for initializing the model (AKA "value" from the directive attribute) function initModel() { - // Convert legacy values (beta1 didn't support multiple times) if (scope.value && typeof (scope.value) == 'object') { angular.forEach(scope.value, function (value, key) { @@ -56,7 +64,6 @@ // Initializes a shadow array to be used in the UI function initShadowModel() { - // Some hardcoded days (currently "Monday" is always the first day of the week) var weekdays = [ { id: 1, name: 'Monday', alias: 'monday' }, @@ -66,8 +73,11 @@ { id: 5, name: "Friday", alias: 'friday' }, { id: 6, name: "Saturday", alias: 'saturday' }, { id: 0, name: "Sunday", alias: 'sunday' } - ]; + ]; + // if need to clear the weekdays-array on the scope so that we don't just append new + // items if initShadowModel is called after a save/publish. + scope.weekdays = []; // Populate the shadow array of weekdays angular.forEach(weekdays, function (day) { scope.value[day.id].label = day.name; @@ -78,7 +88,7 @@ } // Adds a new item to the specified day - scope.addItem = function (day) { + scope.addItem = function (day) { day.items.push({ opens: '09:00', closes: '17:00' @@ -86,13 +96,9 @@ }; // Removes an item for day at the specified index - scope.removeItem = function (day, index) { + scope.removeItem = function (day, index) { day.items.splice(index, 1); }; - - initModel(); - initShadowModel(); - } }; }); \ No newline at end of file From 56b3771599ad691176d7e43b1ea67e6b79c8e63f Mon Sep 17 00:00:00 2001 From: Markus Johansson Date: Mon, 20 Jan 2020 13:55:18 +0100 Subject: [PATCH 2/5] Removed old dependencies and bumped .net framework --- .gitignore | 2 + .../Our.Umbraco.OpeningHours.csproj | 147 +----------------- src/Our.Umbraco.OpeningHours/packages.config | 25 +-- 3 files changed, 8 insertions(+), 166 deletions(-) diff --git a/.gitignore b/.gitignore index 877b4d6..24b834f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ artifacts/ src/packages/ node_modules/ releases/files/ +src/.vs/Our.Umbraco.OpeningHours/v16/ +src/.vs/Our.Umbraco.OpeningHours/config/ diff --git a/src/Our.Umbraco.OpeningHours/Our.Umbraco.OpeningHours.csproj b/src/Our.Umbraco.OpeningHours/Our.Umbraco.OpeningHours.csproj index 4a6954b..c0c89c9 100644 --- a/src/Our.Umbraco.OpeningHours/Our.Umbraco.OpeningHours.csproj +++ b/src/Our.Umbraco.OpeningHours/Our.Umbraco.OpeningHours.csproj @@ -13,13 +13,15 @@ Properties Our.Umbraco.OpeningHours Our.Umbraco.OpeningHours - v4.5 + v4.7.2 true + + true @@ -39,89 +41,7 @@ 4 - - ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll - - - ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll - True - - - ..\packages\UmbracoCms.Core.7.2.0\lib\businesslogic.dll - - - ..\packages\ClientDependency.1.8.2.1\lib\net45\ClientDependency.Core.dll - - - ..\packages\ClientDependency-Mvc.1.8.0.0\lib\net45\ClientDependency.Core.Mvc.dll - - - ..\packages\UmbracoCms.Core.7.2.0\lib\cms.dll - True - - - ..\packages\UmbracoCms.Core.7.2.0\lib\controls.dll - - - ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll - - - ..\packages\Examine.0.1.57.2941\lib\Examine.dll - - - ..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll - - - ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll - - - ..\packages\ImageProcessor.1.9.5.0\lib\ImageProcessor.dll - - - ..\packages\ImageProcessor.Web.3.3.1.0\lib\net45\ImageProcessor.Web.dll - - - ..\packages\UmbracoCms.Core.7.2.0\lib\interfaces.dll - - - ..\packages\UmbracoCms.Core.7.2.0\lib\log4net.dll - True - - - ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll - - - ..\packages\UmbracoCms.Core.7.2.0\lib\Microsoft.ApplicationBlocks.Data.dll - - - - ..\packages\UmbracoCms.Core.7.2.0\lib\Microsoft.Web.Helpers.dll - - - True - ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - - - ..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll - - - ..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll - - - ..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll - - - False - ..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll - - - ..\packages\Skybrud.Essentials.1.0.8\lib\net45\Skybrud.Essentials.dll - True - - - ..\packages\UmbracoCms.Core.7.2.0\lib\SQLCE4Umbraco.dll - True - + True ..\packages\UmbracoCms.Core.7.2.0\lib\System.Data.SqlServerCe.dll @@ -140,13 +60,7 @@ - - - - True - ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll - True ..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll @@ -159,64 +73,13 @@ False ..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll - - True - ..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll - - - True - ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll - - - ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll - True - - - True - ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll - - - - ..\packages\UmbracoCms.Core.7.2.0\lib\TidyNet.dll - - - False - ..\packages\UmbracoCms.Core.7.2.0\lib\umbraco.dll - - - False - ..\packages\UmbracoCms.Core.7.2.0\lib\Umbraco.Core.dll - - - ..\packages\UmbracoCms.Core.7.2.0\lib\umbraco.DataLayer.dll - True - - - ..\packages\UmbracoCms.Core.7.2.0\lib\umbraco.editorControls.dll - - - ..\packages\UmbracoCms.Core.7.2.0\lib\umbraco.MacroEngines.dll - True - - - ..\packages\UmbracoCms.Core.7.2.0\lib\umbraco.providers.dll - - - ..\packages\UmbracoCms.Core.7.2.0\lib\Umbraco.Web.UI.dll - - - ..\packages\UmbracoCms.Core.7.2.0\lib\UmbracoExamine.dll - True - - - ..\packages\UmbracoCms.Core.7.2.0\lib\UrlRewritingNet.UrlRewriter.dll - + diff --git a/src/Our.Umbraco.OpeningHours/packages.config b/src/Our.Umbraco.OpeningHours/packages.config index 62e1ab4..6e62391 100644 --- a/src/Our.Umbraco.OpeningHours/packages.config +++ b/src/Our.Umbraco.OpeningHours/packages.config @@ -1,27 +1,4 @@  - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file From 79b5bd109782563c5f049824b1f57c43d6eaccb8 Mon Sep 17 00:00:00 2001 From: Markus Johansson Date: Mon, 20 Jan 2020 15:39:54 +0100 Subject: [PATCH 3/5] Worked on V8-upgrade --- .../Composition/OpeningHoursComposer.cs | 19 ++ .../Converters/OpeningHoursValueConverter.cs | 43 +++- .../Extensions/JArrayExtensions.cs | 32 +++ .../Extensions/JTokenExtensions.cs | 130 +++++++++++ .../Extensions/OpeningHoursExtensions.cs | 3 +- .../Json/JsonObjectBase.cs | 40 ++++ .../Model/Items/OpeningHoursHolidayItem.cs | 16 +- .../Model/Items/OpeningHoursTimeSlot.cs | 2 +- .../Model/Items/OpeningHoursWeekdayItem.cs | 9 +- .../Model/Json/OpeningHoursJsonObject.cs | 2 +- .../Model/OpeningHoursDay.cs | 4 +- .../Model/OpeningHoursModel.cs | 2 +- .../Our.Umbraco.OpeningHours.csproj | 213 ++++++++++++++++-- src/Our.Umbraco.OpeningHours/packages.config | 54 ++++- 14 files changed, 526 insertions(+), 43 deletions(-) create mode 100644 src/Our.Umbraco.OpeningHours/Composition/OpeningHoursComposer.cs create mode 100644 src/Our.Umbraco.OpeningHours/Extensions/JArrayExtensions.cs create mode 100644 src/Our.Umbraco.OpeningHours/Extensions/JTokenExtensions.cs create mode 100644 src/Our.Umbraco.OpeningHours/Json/JsonObjectBase.cs diff --git a/src/Our.Umbraco.OpeningHours/Composition/OpeningHoursComposer.cs b/src/Our.Umbraco.OpeningHours/Composition/OpeningHoursComposer.cs new file mode 100644 index 0000000..33eff5c --- /dev/null +++ b/src/Our.Umbraco.OpeningHours/Composition/OpeningHoursComposer.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Our.Umbraco.OpeningHours.Converters; +using Umbraco.Core; +using Umbraco.Core.Composing; + +namespace Our.Umbraco.OpeningHours.Composition +{ + public class OpeningHoursComposer : IUserComposer + { + public void Compose(global::Umbraco.Core.Composing.Composition composition) + { + // Appending property value converter + composition.PropertyValueConverters().Append(); + } + } +} \ No newline at end of file diff --git a/src/Our.Umbraco.OpeningHours/Converters/OpeningHoursValueConverter.cs b/src/Our.Umbraco.OpeningHours/Converters/OpeningHoursValueConverter.cs index 07415a4..0f97967 100644 --- a/src/Our.Umbraco.OpeningHours/Converters/OpeningHoursValueConverter.cs +++ b/src/Our.Umbraco.OpeningHours/Converters/OpeningHoursValueConverter.cs @@ -7,28 +7,53 @@ namespace Our.Umbraco.OpeningHours.Converters { - [PropertyValueType(typeof(OpeningHoursModel))] - [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] - public class OpeningHoursValueConverter : PropertyValueConverterBase + public class OpeningHoursValueConverter : IPropertyValueConverter { - public override bool IsConverter(PublishedPropertyType propertyType) + private readonly ILogger _logger; + + public OpeningHoursValueConverter(ILogger logger) + { + _logger = logger; + } + + public bool IsConverter(PublishedPropertyType propertyType) { - return propertyType.PropertyEditorAlias.InvariantEquals("OpeningHours"); + return propertyType.EditorAlias.Equals("OpeningHours"); + } + + public bool? IsValue(object value, PropertyValueLevel level) + { + return true; } - public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + public Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof(OpeningHoursModel); + + public object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview) + { + return source; + } + + public object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) { try { - return Model.OpeningHoursModel.Deserialize(source as string); + return OpeningHoursModel.Deserialize(inter as string); } catch (Exception e) { - LogHelper.Error("Error converting value", e); + _logger.Error("Error converting value", e); } // Create default model - return new Model.OpeningHoursModel(); + return new OpeningHoursModel(); } + + public object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) + { + return inter.ToString(); + } + + public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType) => PropertyCacheLevel.Element; + } } diff --git a/src/Our.Umbraco.OpeningHours/Extensions/JArrayExtensions.cs b/src/Our.Umbraco.OpeningHours/Extensions/JArrayExtensions.cs new file mode 100644 index 0000000..f0dc3bf --- /dev/null +++ b/src/Our.Umbraco.OpeningHours/Extensions/JArrayExtensions.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Newtonsoft.Json.Linq; + +namespace Our.Umbraco.OpeningHours.Extensions +{ + public static class JArrayExtensions + { + + /// + /// Gets an array of from the token matching the specified , + /// using the specified delegate for parsing each item in the array. + /// + /// The instance of . + /// A that contains a JPath expression. + /// A callback function used for parsing or converting the token value. + public static T[] GetArray(this JObject obj, string path, Func callback) + { + + if (!(obj?.SelectToken(path) is JArray token)) return null; + + return ( + from child in token + where child is JObject + select callback((JObject)child) + ).ToArray(); + + } + } +} \ No newline at end of file diff --git a/src/Our.Umbraco.OpeningHours/Extensions/JTokenExtensions.cs b/src/Our.Umbraco.OpeningHours/Extensions/JTokenExtensions.cs new file mode 100644 index 0000000..fd1fb35 --- /dev/null +++ b/src/Our.Umbraco.OpeningHours/Extensions/JTokenExtensions.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Newtonsoft.Json.Linq; + +namespace Our.Umbraco.OpeningHours.Extensions +{ + + public static class JObjectExtensions + { + /// + /// Gets an object from a token matching the specified . + /// + /// The parent object. + /// A that contains a JPath expression. + /// The delegate (callback method) used for parsing the object. + /// An instance of , or the default value of if not + /// found. + public static T GetObject(this JObject obj, string path, Func func) + { + return obj == null ? default(T) : func(obj.SelectToken(path) as JObject); + } + + /// + /// Gets the string value of the token matching the specified , or null if + /// doesn't match a token. + /// + /// The parent object. + /// A that contains a JPath expression. + /// An instance of , or null. + public static string GetString(this JObject obj, string path) + { + if (obj == null) return null; + JToken token = GetSimpleTypeTokenFromPath(obj, path); + return token?.Value(); + } + + /// + /// Gets the value of the token matching the specified , or null if + /// doesn't match a token. + /// + /// The parent object. + /// A that contains a JPath expression. + /// The callback used for converting the string value. + /// An instance of , or null. + public static T GetString(this JObject obj, string path, Func callback) + { + if (obj == null) return default(T); + JToken token = GetSimpleTypeTokenFromPath(obj, path); + return token == null ? default(T) : callback(token.Value()); + } + + /// + /// Gets the value of the token matching the specified , or + /// 0 if doesn't match a token. + /// + /// The parent object. + /// A that contains a JPath expression. + /// An instance of . + public static bool GetBoolean(this JObject obj, string path) + { + return GetBoolean(obj, path, x => x); + } + + /// + /// Gets the value of the token matching the specified and parses + /// it into an instance of , or the default value of if + /// doesn't match a token. + /// + /// The parent object. + /// A that contains a JPath expression. + /// A callback function used for parsing or converting the token value. + /// An instance of , or false if + /// doesn't match a token. + public static T GetBoolean(this JObject obj, string path, Func callback) + { + + // Get the token from the path + JToken token = GetSimpleTypeTokenFromPath(obj, path); + + // Check whether the token is null + if (token == null || token.Type == JTokenType.Null) return default(T); + + // Convert the value to a boolean + bool value = token.ToString().Equals("true",StringComparison.InvariantCultureIgnoreCase); + + // Invoke the callback and return the value + return callback(value); + + } + + /// + /// Gets the at the specified . If the type of the token is either + /// or , the method will return + /// null instead. + /// + /// The instance of . + /// A that contains a JPath expression. + /// An instance of , or null. + private static JToken GetSimpleTypeTokenFromPath(JObject obj, string path) + { + JToken token = obj?.SelectToken(path); + return token == null || token.Type == JTokenType.Object || token.Type == JTokenType.Array ? null : token; + } + + /// + /// Gets the items of the from the token matching the specfied . + /// + /// The instance of . + /// A that contains a JPath expression. + /// A callback function used for parsing or converting the token value. + /// An array of . If the a matching token isn't found, an empty array will + /// still be returned. + public static T[] GetArrayItems(this JObject obj, string path, Func callback) + { + + if (!(obj?.SelectToken(path) is JArray token)) return new T[0]; + + return ( + from JObject child in token + select callback(child) + ).ToArray(); + + } + + + } + +} \ No newline at end of file diff --git a/src/Our.Umbraco.OpeningHours/Extensions/OpeningHoursExtensions.cs b/src/Our.Umbraco.OpeningHours/Extensions/OpeningHoursExtensions.cs index 7142c9c..97b05ef 100644 --- a/src/Our.Umbraco.OpeningHours/Extensions/OpeningHoursExtensions.cs +++ b/src/Our.Umbraco.OpeningHours/Extensions/OpeningHoursExtensions.cs @@ -4,6 +4,7 @@ using Our.Umbraco.OpeningHours.Model.Items; using Our.Umbraco.OpeningHours.Model.Offset; using Umbraco.Core.Models; +using Umbraco.Core.Models.PublishedContent; using Umbraco.Web; namespace Our.Umbraco.OpeningHours.Extensions { @@ -30,7 +31,7 @@ public static OpeningHoursModel GetOpeningHours(this IPublishedContent content) /// The alias of the property. /// Returns an instance of . public static OpeningHoursModel GetOpeningHours(this IPublishedContent content, string propertyAlias) { - OpeningHoursModel openingHours = content == null ? null : content.GetPropertyValue(propertyAlias); + OpeningHoursModel openingHours = content == null ? null : content.Value(propertyAlias); return openingHours ?? new OpeningHoursModel(); } diff --git a/src/Our.Umbraco.OpeningHours/Json/JsonObjectBase.cs b/src/Our.Umbraco.OpeningHours/Json/JsonObjectBase.cs new file mode 100644 index 0000000..37d7340 --- /dev/null +++ b/src/Our.Umbraco.OpeningHours/Json/JsonObjectBase.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Our.Umbraco.OpeningHours.Json +{ + /// + /// Class representing an object that was parsed from an instance of . + /// + public class JsonObjectBase + { + + #region Properties + + /// + /// Gets the internal the object was created from. + /// + [JsonIgnore] + public JObject JObject { get; } + + #endregion + + #region Constructor + + /// + /// Initializes a new instance from the specified . + /// + /// The instance of representing the object. + protected JsonObjectBase(JObject obj) + { + JObject = obj; + } + + #endregion + + } +} \ No newline at end of file diff --git a/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursHolidayItem.cs b/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursHolidayItem.cs index 1c4d8eb..88088d8 100644 --- a/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursHolidayItem.cs +++ b/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursHolidayItem.cs @@ -2,7 +2,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Our.Umbraco.OpeningHours.Json; -using Skybrud.Essentials.Json.Extensions; namespace Our.Umbraco.OpeningHours.Model.Items { @@ -38,8 +37,11 @@ public bool IsValid { #region Constructors - protected OpeningHoursHolidayItem(JObject obj) : base(obj, default(DayOfWeek)) { - Date = obj.GetString("date", ParseDate); + protected OpeningHoursHolidayItem(JObject obj) : base(obj, default(DayOfWeek)) + { + + Date = ParseDate(obj["date"]); + //Date = obj.GetString("date", ParseDate); DayOfWeek = Date.DayOfWeek; } @@ -47,9 +49,13 @@ public bool IsValid { #region Static methods - private DateTime ParseDate(string str) { + private DateTime ParseDate(JToken objDate) + { + if (objDate == null) + return default(DateTime); + DateTime date; - return DateTime.TryParse(str ?? "", out date) ? date : default(DateTime); + return DateTime.TryParse(objDate.Value() ?? "", out date) ? date : default(DateTime); } /// diff --git a/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursTimeSlot.cs b/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursTimeSlot.cs index ee8615c..57aebc8 100644 --- a/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursTimeSlot.cs +++ b/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursTimeSlot.cs @@ -1,9 +1,9 @@ using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Our.Umbraco.OpeningHours.Extensions; using Our.Umbraco.OpeningHours.Json; using Our.Umbraco.OpeningHours.Model.Json; -using Skybrud.Essentials.Json.Extensions; namespace Our.Umbraco.OpeningHours.Model.Items { diff --git a/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursWeekdayItem.cs b/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursWeekdayItem.cs index c755ce7..2d10250 100644 --- a/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursWeekdayItem.cs +++ b/src/Our.Umbraco.OpeningHours/Model/Items/OpeningHoursWeekdayItem.cs @@ -2,9 +2,12 @@ using System.Globalization; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +//using Newtonsoft.Json.Linq; +//using Newtonsoft.Json; +//using Newtonsoft.Json.Linq; +using Our.Umbraco.OpeningHours.Extensions; using Our.Umbraco.OpeningHours.Model.Json; -using Skybrud.Essentials.Json.Extensions; -using Skybrud.Essentials.Strings.Extensions; +using Umbraco.Core; namespace Our.Umbraco.OpeningHours.Model.Items { @@ -64,7 +67,7 @@ public virtual string WeekDayName { /// [JsonIgnore] public virtual string WeekDayNameFirstCharToUpper { - get { return WeekDayName.FirstCharToUpper(); } + get { return WeekDayName.ToFirstUpper(); } } #endregion diff --git a/src/Our.Umbraco.OpeningHours/Model/Json/OpeningHoursJsonObject.cs b/src/Our.Umbraco.OpeningHours/Model/Json/OpeningHoursJsonObject.cs index 2fbba21..4f3c507 100644 --- a/src/Our.Umbraco.OpeningHours/Model/Json/OpeningHoursJsonObject.cs +++ b/src/Our.Umbraco.OpeningHours/Model/Json/OpeningHoursJsonObject.cs @@ -1,5 +1,5 @@ using Newtonsoft.Json.Linq; -using Skybrud.Essentials.Json; +using Our.Umbraco.OpeningHours.Json; namespace Our.Umbraco.OpeningHours.Model.Json { diff --git a/src/Our.Umbraco.OpeningHours/Model/OpeningHoursDay.cs b/src/Our.Umbraco.OpeningHours/Model/OpeningHoursDay.cs index 9655730..765d725 100644 --- a/src/Our.Umbraco.OpeningHours/Model/OpeningHoursDay.cs +++ b/src/Our.Umbraco.OpeningHours/Model/OpeningHoursDay.cs @@ -3,7 +3,7 @@ using System.Linq; using Our.Umbraco.OpeningHours.Extensions; using Our.Umbraco.OpeningHours.Model.Items; -using Skybrud.Essentials.Strings.Extensions; +using Umbraco.Core; namespace Our.Umbraco.OpeningHours.Model { @@ -88,7 +88,7 @@ public string WeekDayName { /// the name will always be uppercase. /// public string WeekDayNameFirstCharToUpper { - get { return WeekDayName.FirstCharToUpper(); } + get { return WeekDayName.ToFirstUpper(); } } /// diff --git a/src/Our.Umbraco.OpeningHours/Model/OpeningHoursModel.cs b/src/Our.Umbraco.OpeningHours/Model/OpeningHoursModel.cs index ab79390..f96447b 100644 --- a/src/Our.Umbraco.OpeningHours/Model/OpeningHoursModel.cs +++ b/src/Our.Umbraco.OpeningHours/Model/OpeningHoursModel.cs @@ -3,11 +3,11 @@ using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Our.Umbraco.OpeningHours.Extensions; using Our.Umbraco.OpeningHours.Json; using Our.Umbraco.OpeningHours.Model.Items; using Our.Umbraco.OpeningHours.Model.Json; using Our.Umbraco.OpeningHours.Model.Offset; -using Skybrud.Essentials.Json.Extensions; using Umbraco.Core; namespace Our.Umbraco.OpeningHours.Model { diff --git a/src/Our.Umbraco.OpeningHours/Our.Umbraco.OpeningHours.csproj b/src/Our.Umbraco.OpeningHours/Our.Umbraco.OpeningHours.csproj index c0c89c9..a0c5d8d 100644 --- a/src/Our.Umbraco.OpeningHours/Our.Umbraco.OpeningHours.csproj +++ b/src/Our.Umbraco.OpeningHours/Our.Umbraco.OpeningHours.csproj @@ -22,6 +22,8 @@ + + true @@ -41,18 +43,155 @@ 4 + + ..\packages\AutoMapper.8.0.0\lib\net461\AutoMapper.dll + + + ..\packages\ClientDependency.1.9.7\lib\net45\ClientDependency.Core.dll + + + ..\packages\ClientDependency-Mvc5.1.8.0.0\lib\net45\ClientDependency.Core.Mvc.dll + + + ..\packages\CSharpTest.Net.Collections.14.906.1403.1082\lib\net40\CSharpTest.Net.Collections.dll + + + ..\packages\Examine.1.0.0\lib\net452\Examine.dll + + + ..\packages\HtmlAgilityPack.1.8.14\lib\Net45\HtmlAgilityPack.dll + + + ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + + + ..\packages\ImageProcessor.2.7.0.100\lib\net452\ImageProcessor.dll + + + ..\packages\LightInject.5.4.0\lib\net46\LightInject.dll + + + ..\packages\LightInject.Annotation.1.1.0\lib\net46\LightInject.Annotation.dll + + + ..\packages\LightInject.Mvc.2.0.0\lib\net46\LightInject.Mvc.dll + + + ..\packages\LightInject.Web.2.0.0\lib\net46\LightInject.Web.dll + + + ..\packages\LightInject.WebApi.2.0.0\lib\net46\LightInject.WebApi.dll + + + ..\packages\Lucene.Net.3.0.3\lib\NET40\Lucene.Net.dll + + + ..\packages\Markdown.2.2.1\lib\net451\Markdown.dll + + + ..\packages\Microsoft.AspNet.Identity.Core.2.2.2\lib\net45\Microsoft.AspNet.Identity.Core.dll + + + ..\packages\Microsoft.AspNet.Identity.Owin.2.2.2\lib\net45\Microsoft.AspNet.Identity.Owin.dll + + + ..\packages\Microsoft.AspNet.SignalR.Core.2.4.0\lib\net45\Microsoft.AspNet.SignalR.Core.dll + + + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\packages\Microsoft.Owin.4.0.1\lib\net45\Microsoft.Owin.dll + + + ..\packages\Microsoft.Owin.Host.SystemWeb.4.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll + + + ..\packages\Microsoft.Owin.Security.4.0.1\lib\net45\Microsoft.Owin.Security.dll + + + ..\packages\Microsoft.Owin.Security.Cookies.4.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll + + + ..\packages\Microsoft.Owin.Security.OAuth.4.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll + + + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + + ..\packages\MiniProfiler.4.0.138\lib\net461\MiniProfiler.dll + + + ..\packages\MiniProfiler.Shared.4.0.138\lib\net461\MiniProfiler.Shared.dll + + + ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\NPoco.3.9.4\lib\net45\NPoco.dll + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + + + ..\packages\Semver.2.0.4\lib\net452\Semver.dll + + + ..\packages\Serilog.2.8.0\lib\net46\Serilog.dll + + + ..\packages\Serilog.Enrichers.Process.2.0.1\lib\net45\Serilog.Enrichers.Process.dll + + + ..\packages\Serilog.Enrichers.Thread.3.0.0\lib\net45\Serilog.Enrichers.Thread.dll + + + ..\packages\Serilog.Filters.Expressions.2.0.0\lib\net45\Serilog.Filters.Expressions.dll + + + ..\packages\Serilog.Formatting.Compact.1.0.0\lib\net45\Serilog.Formatting.Compact.dll + + + ..\packages\Serilog.Formatting.Compact.Reader.1.0.3\lib\net45\Serilog.Formatting.Compact.Reader.dll + + + ..\packages\Serilog.Settings.AppSettings.2.2.2\lib\net45\Serilog.Settings.AppSettings.dll + + + ..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.dll + + + ..\packages\Superpower.2.0.0\lib\net45\Superpower.dll + - - True - ..\packages\UmbracoCms.Core.7.2.0\lib\System.Data.SqlServerCe.dll + + + ..\packages\Umbraco.SqlServerCE.4.0.0.1\lib\net472\System.Data.SqlServerCe.dll + + + ..\packages\Umbraco.SqlServerCE.4.0.0.1\lib\net472\System.Data.SqlServerCe.Entity.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll - - True - ..\packages\UmbracoCms.Core.7.2.0\lib\System.Data.SqlServerCe.Entity.dll + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll - - True - ..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll + + + + + + + ..\packages\System.Threading.Tasks.Dataflow.4.9.0\lib\netstandard2.0\System.Threading.Tasks.Dataflow.dll + + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -61,30 +200,58 @@ - - True - ..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll - - - True - ..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.30506.0\lib\net40\System.Web.Http.WebHost.dll + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll - - False - ..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll + + + ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll + + + ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll + + + ..\packages\UmbracoCms.Core.8.0.0\lib\net472\Umbraco.Core.dll + + + ..\packages\UmbracoCms.Web.8.0.0\lib\net472\Umbraco.Examine.dll + + + ..\packages\UmbracoCms.Web.8.0.0\lib\net472\Umbraco.Web.dll + + + ..\packages\UmbracoCms.Web.8.0.0\lib\net472\Umbraco.Web.UI.dll + + + + + @@ -130,6 +297,7 @@ + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) @@ -158,6 +326,13 @@ "$(SolutionDir)..\build\UpdateAssemblyInfoJson.exe" "$(ProjectPath)" "$(TargetPath)" + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +