Skip to content

Commit 98bf36d

Browse files
Tallyraldberrnd
andauthored
Replace Timeago with momentjs (grocy#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 <[email protected]>
1 parent b83e4f5 commit 98bf36d

12 files changed

+5
-28
lines changed

localization/component_translations.pot

-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ msgstr ""
1212
"Language: en\n"
1313
"X-Domain: grocy/component_translations\n"
1414

15-
msgid "timeago_locale"
16-
msgstr ""
17-
18-
msgid "timeago_nan"
19-
msgstr ""
20-
2115
msgid "moment_locale"
2216
msgstr ""
2317

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"summernote": "^0.8.18",
3434
"swagger-ui-dist": "^3.32.1",
3535
"tempusdominus-bootstrap-4": "https://github.com/berrnd/tempusdominus-bootstrap-4.git#master",
36-
"timeago": "^1.6.7",
3736
"toastr": "^2.1.4"
3837
},
3938
"scripts": {

public/js/grocy.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ if (window.localStorage.getItem("sidebar_state") === "collapsed")
316316
$("#sidenavToggler").click();
317317
}
318318

319-
$.timeago.settings.allowFuture = true;
320319
RefreshContextualTimeago = function(rootSelector = "#page-content")
321320
{
322321
$(rootSelector + " time.timeago").each(function()
@@ -352,7 +351,7 @@ RefreshContextualTimeago = function(rootSelector = "#page-content")
352351
}
353352
else
354353
{
355-
element.timeago("update", timestamp);
354+
element.text(moment(timestamp).fromNow());
356355
}
357356

358357
if (isDateWithoutTime)

public/viewjs/components/batterycard.js

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Grocy.Components.BatteryCard.Refresh = function(batteryId)
1616
$('#batterycard-battery-edit-button').removeClass("disabled");
1717
$('#batterycard-battery-journal-button').removeClass("disabled");
1818

19-
EmptyElementWhenMatches('#batterycard-battery-last-charged-timeago', __t('timeago_nan'));
2019
RefreshContextualTimeago(".batterycard");
2120
},
2221
function(xhr)

public/viewjs/components/chorecard.js

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Grocy.Components.ChoreCard.Refresh = function(choreId)
2525
$("#chorecard-chore-last-tracked-timeago").removeClass("timeago-date-only");
2626
}
2727

28-
EmptyElementWhenMatches('#chorecard-chore-last-tracked-timeago', __t('timeago_nan'));
2928
RefreshContextualTimeago(".chorecard");
3029
},
3130
function(xhr)

public/viewjs/components/datetimepicker.js

-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keyup', function(e)
270270
Grocy.Components.DateTimePicker.GetInputElement().on('input', function(e)
271271
{
272272
$('#datetimepicker-timeago').attr("datetime", Grocy.Components.DateTimePicker.GetValue());
273-
EmptyElementWhenMatches('#datetimepicker-timeago', __t('timeago_nan'));
274273
RefreshContextualTimeago(".datetimepicker-wrapper");
275274
});
276275

public/viewjs/components/datetimepicker2.js

-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ Grocy.Components.DateTimePicker2.GetInputElement().on('keyup', function(e)
270270
Grocy.Components.DateTimePicker2.GetInputElement().on('input', function(e)
271271
{
272272
$('#datetimepicker2-timeago').attr("datetime", Grocy.Components.DateTimePicker2.GetValue());
273-
EmptyElementWhenMatches('#datetimepicker2-timeago', __t('timeago_nan'));
274273
RefreshContextualTimeago(".datetimepicker2-wrapper");
275274
});
276275

public/viewjs/components/productcard.js

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ Grocy.Components.ProductCard.Refresh = function(productId)
110110
$("#productcard-product-picture").addClass("d-none");
111111
}
112112

113-
EmptyElementWhenMatches('#productcard-product-last-purchased-timeago', __t('timeago_nan'));
114-
EmptyElementWhenMatches('#productcard-product-last-used-timeago', __t('timeago_nan'));
115113
RefreshContextualTimeago(".productcard");
116114
},
117115
function(xhr)

views/layout/default.blade.php

-2
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,6 @@ class="col content-text">
697697
<script src="{{ $U('/node_modules/datatables.net-rowgroup-bs4/js/rowGroup.bootstrap4.min.js?v=', true) }}{{ $version }}"></script>
698698
<script src="{{ $U('/node_modules/datatables.net-select/js/dataTables.select.min.js?v=', true) }}{{ $version }}"></script>
699699
<script src="{{ $U('/node_modules/datatables.net-select-bs4/js/select.bootstrap4.min.js?v=', true) }}{{ $version }}"></script>
700-
<script src="{{ $U('/node_modules/timeago/jquery.timeago.js?v=', true) }}{{ $version }}"></script>
701-
<script src="{{ $U('/node_modules', true) }}/timeago/locales/jquery.timeago.{{ $__t('timeago_locale') }}.js?v={{ $version }}"></script>
702700
<script src="{{ $U('/node_modules/toastr/build/toastr.min.js?v=', true) }}{{ $version }}"></script>
703701
<script src="{{ $U('/node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.js?v=', true) }}{{ $version }}"></script>
704702
<script src="{{ $U('/node_modules/sprintf-js/dist/sprintf.min.js?v=', true) }}{{ $version }}"></script>

views/stockentries.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class="small font-italic">@if($stockEntry->open == 1){{ $__t('Opened') }}@endif<
241241
<span id="stock-{{ $stockEntry->id }}-due-date">{{ $stockEntry->best_before_date }}</span>
242242
<time id="stock-{{ $stockEntry->id }}-due-date-timeago"
243243
class="timeago timeago-contextual"
244-
datetime="{{ $stockEntry->best_before_date }} 23:59:59"></time>
244+
@if($stockEntry->best_before_date != "") datetime="{{ $stockEntry->best_before_date }} 23:59:59" @endif></time>
245245
</td>
246246
<td id="stock-{{ $stockEntry->id }}-location"
247247
class="@if(!GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) d-none @endif"
@@ -265,7 +265,7 @@ class="locale-number locale-number-currency"
265265
<span id="stock-{{ $stockEntry->id }}-purchased-date">{{ $stockEntry->purchased_date }}</span>
266266
<time id="stock-{{ $stockEntry->id }}-purchased-date-timeago"
267267
class="timeago timeago-contextual"
268-
datetime="{{ $stockEntry->purchased_date }} 23:59:59"></time>
268+
@if(!empty($stockEntry->purchased_date)) datetime="{{ $stockEntry->purchased_date }} 23:59:59" @endif></time>
269269
</td>
270270
<td class="d-none">{{ $stockEntry->purchased_date }}</td>
271271
<td>

views/stockoverview.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class="locale-number locale-number-currency">{{ $currentStockEntry->value }}</sp
352352
<span id="product-{{ $currentStockEntry->product_id }}-next-due-date">{{ $currentStockEntry->best_before_date }}</span>
353353
<time id="product-{{ $currentStockEntry->product_id }}-next-due-date-timeago"
354354
class="timeago timeago-contextual"
355-
datetime="{{ $currentStockEntry->best_before_date }} 23:59:59"></time>
355+
@if(!empty($currentStockEntry->best_before_date)) datetime="{{ $currentStockEntry->best_before_date }} 23:59:59" @endif></time>
356356
</td>
357357
<td class="d-none">
358358
@foreach(FindAllObjectsInArrayByPropertyValue($currentStockLocations, 'product_id', $currentStockEntry->product_id) as $locationsForProduct)

yarn.lock

+1-8
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ [email protected]:
498498
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.5.1.tgz#d7b4d08e1bfdb86ad2f1a3d039ea17304717abb5"
499499
integrity sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==
500500

501-
jquery@>=1.12.0, "jquery@>=1.5.0 <4.0", jquery@>=1.7, jquery@>=1.7.2, jquery@^3.0, jquery@^3.5.1:
501+
jquery@>=1.12.0, jquery@>=1.7, jquery@>=1.7.2, jquery@^3.0, jquery@^3.5.1:
502502
version "3.6.0"
503503
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470"
504504
integrity sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==
@@ -743,13 +743,6 @@ through@^2.3.4:
743743
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
744744
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
745745

746-
timeago@^1.6.7:
747-
version "1.6.7"
748-
resolved "https://registry.yarnpkg.com/timeago/-/timeago-1.6.7.tgz#afd467c29a911e697fc22a81888c7c3022783cb5"
749-
integrity sha512-FikcjN98+ij0siKH4VO4dZ358PR3oDDq4Vdl1+sN9gWz1/+JXGr3uZbUShYH/hL7bMhcTpPbplJU5Tej4b4jbQ==
750-
dependencies:
751-
jquery ">=1.5.0 <4.0"
752-
753746
toastr@^2.1.4:
754747
version "2.1.4"
755748
resolved "https://registry.yarnpkg.com/toastr/-/toastr-2.1.4.tgz#8b43be64fb9d0c414871446f2db8e8ca4e95f181"

0 commit comments

Comments
 (0)