From 98bf36dbc86fb5bf69ed63ac597bdffd7561f563 Mon Sep 17 00:00:00 2001 From: Tallyrald Date: Mon, 15 Nov 2021 20:05:10 +0100 Subject: [PATCH] Replace Timeago with momentjs (#1687) * Replaced timeago with moment.fromNow * Fixed datetime when best_before_date is empty * Removed the now unnecessary timeago package * Removed not longer localization strings * Check for empty instead of string comparison Co-authored-by: Bernd Bestel --- localization/component_translations.pot | 6 ------ package.json | 1 - public/js/grocy.js | 3 +-- public/viewjs/components/batterycard.js | 1 - public/viewjs/components/chorecard.js | 1 - public/viewjs/components/datetimepicker.js | 1 - public/viewjs/components/datetimepicker2.js | 1 - public/viewjs/components/productcard.js | 2 -- views/layout/default.blade.php | 2 -- views/stockentries.blade.php | 4 ++-- views/stockoverview.blade.php | 2 +- yarn.lock | 9 +-------- 12 files changed, 5 insertions(+), 28 deletions(-) diff --git a/localization/component_translations.pot b/localization/component_translations.pot index f65749a6..82296d60 100644 --- a/localization/component_translations.pot +++ b/localization/component_translations.pot @@ -12,12 +12,6 @@ msgstr "" "Language: en\n" "X-Domain: grocy/component_translations\n" -msgid "timeago_locale" -msgstr "" - -msgid "timeago_nan" -msgstr "" - msgid "moment_locale" msgstr "" diff --git a/package.json b/package.json index 5d4fdd8a..faa38e88 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "summernote": "^0.8.18", "swagger-ui-dist": "^3.32.1", "tempusdominus-bootstrap-4": "https://github.com/berrnd/tempusdominus-bootstrap-4.git#master", - "timeago": "^1.6.7", "toastr": "^2.1.4" }, "scripts": { diff --git a/public/js/grocy.js b/public/js/grocy.js index e44fe019..8b3123af 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -316,7 +316,6 @@ if (window.localStorage.getItem("sidebar_state") === "collapsed") $("#sidenavToggler").click(); } -$.timeago.settings.allowFuture = true; RefreshContextualTimeago = function(rootSelector = "#page-content") { $(rootSelector + " time.timeago").each(function() @@ -352,7 +351,7 @@ RefreshContextualTimeago = function(rootSelector = "#page-content") } else { - element.timeago("update", timestamp); + element.text(moment(timestamp).fromNow()); } if (isDateWithoutTime) diff --git a/public/viewjs/components/batterycard.js b/public/viewjs/components/batterycard.js index e4ad85ab..6533628d 100644 --- a/public/viewjs/components/batterycard.js +++ b/public/viewjs/components/batterycard.js @@ -16,7 +16,6 @@ Grocy.Components.BatteryCard.Refresh = function(batteryId) $('#batterycard-battery-edit-button').removeClass("disabled"); $('#batterycard-battery-journal-button').removeClass("disabled"); - EmptyElementWhenMatches('#batterycard-battery-last-charged-timeago', __t('timeago_nan')); RefreshContextualTimeago(".batterycard"); }, function(xhr) diff --git a/public/viewjs/components/chorecard.js b/public/viewjs/components/chorecard.js index 861eaa51..64767375 100644 --- a/public/viewjs/components/chorecard.js +++ b/public/viewjs/components/chorecard.js @@ -25,7 +25,6 @@ Grocy.Components.ChoreCard.Refresh = function(choreId) $("#chorecard-chore-last-tracked-timeago").removeClass("timeago-date-only"); } - EmptyElementWhenMatches('#chorecard-chore-last-tracked-timeago', __t('timeago_nan')); RefreshContextualTimeago(".chorecard"); }, function(xhr) diff --git a/public/viewjs/components/datetimepicker.js b/public/viewjs/components/datetimepicker.js index 4acb74f8..c8951ab8 100644 --- a/public/viewjs/components/datetimepicker.js +++ b/public/viewjs/components/datetimepicker.js @@ -270,7 +270,6 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keyup', function(e) Grocy.Components.DateTimePicker.GetInputElement().on('input', function(e) { $('#datetimepicker-timeago').attr("datetime", Grocy.Components.DateTimePicker.GetValue()); - EmptyElementWhenMatches('#datetimepicker-timeago', __t('timeago_nan')); RefreshContextualTimeago(".datetimepicker-wrapper"); }); diff --git a/public/viewjs/components/datetimepicker2.js b/public/viewjs/components/datetimepicker2.js index 5995fc48..787929f4 100644 --- a/public/viewjs/components/datetimepicker2.js +++ b/public/viewjs/components/datetimepicker2.js @@ -270,7 +270,6 @@ Grocy.Components.DateTimePicker2.GetInputElement().on('keyup', function(e) Grocy.Components.DateTimePicker2.GetInputElement().on('input', function(e) { $('#datetimepicker2-timeago').attr("datetime", Grocy.Components.DateTimePicker2.GetValue()); - EmptyElementWhenMatches('#datetimepicker2-timeago', __t('timeago_nan')); RefreshContextualTimeago(".datetimepicker2-wrapper"); }); diff --git a/public/viewjs/components/productcard.js b/public/viewjs/components/productcard.js index 86ef0f24..97436a25 100644 --- a/public/viewjs/components/productcard.js +++ b/public/viewjs/components/productcard.js @@ -110,8 +110,6 @@ Grocy.Components.ProductCard.Refresh = function(productId) $("#productcard-product-picture").addClass("d-none"); } - EmptyElementWhenMatches('#productcard-product-last-purchased-timeago', __t('timeago_nan')); - EmptyElementWhenMatches('#productcard-product-last-used-timeago', __t('timeago_nan')); RefreshContextualTimeago(".productcard"); }, function(xhr) diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 68738939..4eb3fb8d 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -697,8 +697,6 @@ - - diff --git a/views/stockentries.blade.php b/views/stockentries.blade.php index 211296a9..ea944465 100644 --- a/views/stockentries.blade.php +++ b/views/stockentries.blade.php @@ -241,7 +241,7 @@ {{ $stockEntry->best_before_date }} + @if($stockEntry->best_before_date != "") datetime="{{ $stockEntry->best_before_date }} 23:59:59" @endif> {{ $stockEntry->purchased_date }} + @if(!empty($stockEntry->purchased_date)) datetime="{{ $stockEntry->purchased_date }} 23:59:59" @endif> {{ $stockEntry->purchased_date }} diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index da4103d9..1bfd9ddb 100755 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -352,7 +352,7 @@ {{ $currentStockEntry->best_before_date }} + @if(!empty($currentStockEntry->best_before_date)) datetime="{{ $currentStockEntry->best_before_date }} 23:59:59" @endif> @foreach(FindAllObjectsInArrayByPropertyValue($currentStockLocations, 'product_id', $currentStockEntry->product_id) as $locationsForProduct) diff --git a/yarn.lock b/yarn.lock index 0dd94024..b0e6f09d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -498,7 +498,7 @@ jquery@3.5.1: resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.5.1.tgz#d7b4d08e1bfdb86ad2f1a3d039ea17304717abb5" integrity sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg== -jquery@>=1.12.0, "jquery@>=1.5.0 <4.0", jquery@>=1.7, jquery@>=1.7.2, jquery@^3.0, jquery@^3.5.1: +jquery@>=1.12.0, jquery@>=1.7, jquery@>=1.7.2, jquery@^3.0, jquery@^3.5.1: version "3.6.0" resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470" integrity sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw== @@ -743,13 +743,6 @@ through@^2.3.4: resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= -timeago@^1.6.7: - version "1.6.7" - resolved "https://registry.yarnpkg.com/timeago/-/timeago-1.6.7.tgz#afd467c29a911e697fc22a81888c7c3022783cb5" - integrity sha512-FikcjN98+ij0siKH4VO4dZ358PR3oDDq4Vdl1+sN9gWz1/+JXGr3uZbUShYH/hL7bMhcTpPbplJU5Tej4b4jbQ== - dependencies: - jquery ">=1.5.0 <4.0" - toastr@^2.1.4: version "2.1.4" resolved "https://registry.yarnpkg.com/toastr/-/toastr-2.1.4.tgz#8b43be64fb9d0c414871446f2db8e8ca4e95f181"