From df529c3c0befd526ce707e31d3cc0a386d70cb12 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 6 Jul 2019 15:43:54 +0200 Subject: [PATCH] Show 2999-12-31 as "Never" everywhere (closes #296) --- changelog/50_2.4.3_2019-xx-xx.md | 1 + localization/strings.pot | 3 + public/js/grocy.js | 204 ++++++++++++++++--------------- 3 files changed, 110 insertions(+), 98 deletions(-) diff --git a/changelog/50_2.4.3_2019-xx-xx.md b/changelog/50_2.4.3_2019-xx-xx.md index 792d434b..9e2a1526 100644 --- a/changelog/50_2.4.3_2019-xx-xx.md +++ b/changelog/50_2.4.3_2019-xx-xx.md @@ -3,3 +3,4 @@ - Fixed that the "week costs" were wrong after removing a meal plan entry - Fixed wrong recipes costs calculation with nested recipes when the base recipe servings are > 1 (also affected the meal plan when adding such a recipe there) - Improved recipes API - added new endpoints to get stock fulfillment information (thanks @Aerex) +- Improved date display for products that never expires (instead of "2999-12-31" now just "Never" will be shown) diff --git a/localization/strings.pot b/localization/strings.pot index ad48c99c..80af570c 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1271,3 +1271,6 @@ msgstr "" msgid "per serving" msgstr "" + +msgid "Never" +msgstr "" diff --git a/public/js/grocy.js b/public/js/grocy.js index c87747b0..ba7fe5d8 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -1,101 +1,4 @@ -Grocy.Translator = new Translator(Grocy.GettextPo); -__t = function(text, ...placeholderValues) -{ - if (Grocy.Mode === "dev") - { - var text2 = text; - Grocy.Api.Post('system/log-missing-localization', { "text": text2 }); - } - - return Grocy.Translator.__(text, ...placeholderValues) -} -__n = function(number, singularForm, pluralForm) -{ - if (Grocy.Mode === "dev") - { - var singularForm2 = singularForm; - Grocy.Api.Post('system/log-missing-localization', { "text": singularForm2 }); - } - - return Grocy.Translator.n__(singularForm, pluralForm, number, number) -} - -U = function(relativePath) -{ - return Grocy.BaseUrl.replace(/\/$/, '') + relativePath; -} - -if (!Grocy.ActiveNav.isEmpty()) -{ - var menuItem = $('#sidebarResponsive').find("[data-nav-for-page='" + Grocy.ActiveNav + "']"); - menuItem.addClass('active-page'); - - var parentMenuSelector = menuItem.data("sub-menu-of"); - if (typeof parentMenuSelector !== "undefined") - { - $(parentMenuSelector).collapse("show"); - $(parentMenuSelector).prev(".nav-link-collapse").addClass("active-page"); - } -} - -var observer = new MutationObserver(function(mutations) -{ - mutations.forEach(function(mutation) - { - if (mutation.attributeName === "class") - { - var attributeValue = $(mutation.target).prop(mutation.attributeName); - if (attributeValue.contains("sidenav-toggled")) - { - window.localStorage.setItem("sidebar_state", "collapsed"); - } - else - { - window.localStorage.setItem("sidebar_state", "expanded"); - } - } - }); -}); -observer.observe(document.body, { - attributes: true -}); -if (window.localStorage.getItem("sidebar_state") === "collapsed") -{ - $("#sidenavToggler").click(); -} - -$.timeago.settings.allowFuture = true; -RefreshContextualTimeago = function() -{ - $("time.timeago").each(function() - { - var element = $(this); - var timestamp = element.attr("datetime"); - element.timeago("update", timestamp); - }); -} -RefreshContextualTimeago(); - -toastr.options = { - toastClass: 'alert', - closeButton: true, - timeOut: 20000, - extendedTimeOut: 5000 -}; - -window.FontAwesomeConfig = { - searchPseudoElements: true -} - -// Don't show tooltips on touch input devices -if (IsTouchInputDevice()) -{ - var css = document.createElement("style"); - css.innerHTML = ".tooltip { display: none; }"; - document.body.appendChild(css); -} - -Grocy.Api = { }; +Grocy.Api = { }; Grocy.Api.Get = function(apiFunction, success, error) { var xhr = new XMLHttpRequest(); @@ -323,6 +226,111 @@ Grocy.Api.DeleteFile = function(fileName, group, success, error) xhr.send(); }; +Grocy.Translator = new Translator(Grocy.GettextPo); +__t = function(text, ...placeholderValues) +{ + if (Grocy.Mode === "dev") + { + var text2 = text; + Grocy.Api.Post('system/log-missing-localization', { "text": text2 }); + } + + return Grocy.Translator.__(text, ...placeholderValues) +} +__n = function(number, singularForm, pluralForm) +{ + if (Grocy.Mode === "dev") + { + var singularForm2 = singularForm; + Grocy.Api.Post('system/log-missing-localization', { "text": singularForm2 }); + } + + return Grocy.Translator.n__(singularForm, pluralForm, number, number) +} + +U = function(relativePath) +{ + return Grocy.BaseUrl.replace(/\/$/, '') + relativePath; +} + +if (!Grocy.ActiveNav.isEmpty()) +{ + var menuItem = $('#sidebarResponsive').find("[data-nav-for-page='" + Grocy.ActiveNav + "']"); + menuItem.addClass('active-page'); + + var parentMenuSelector = menuItem.data("sub-menu-of"); + if (typeof parentMenuSelector !== "undefined") + { + $(parentMenuSelector).collapse("show"); + $(parentMenuSelector).prev(".nav-link-collapse").addClass("active-page"); + } +} + +var observer = new MutationObserver(function(mutations) +{ + mutations.forEach(function(mutation) + { + if (mutation.attributeName === "class") + { + var attributeValue = $(mutation.target).prop(mutation.attributeName); + if (attributeValue.contains("sidenav-toggled")) + { + window.localStorage.setItem("sidebar_state", "collapsed"); + } + else + { + window.localStorage.setItem("sidebar_state", "expanded"); + } + } + }); +}); +observer.observe(document.body, { + attributes: true +}); +if (window.localStorage.getItem("sidebar_state") === "collapsed") +{ + $("#sidenavToggler").click(); +} + +$.timeago.settings.allowFuture = true; +RefreshContextualTimeago = function() +{ + $("time.timeago").each(function() + { + var element = $(this); + var timestamp = element.attr("datetime"); + var isNever = timestamp && timestamp.substring(0, 10) == "2999-12-31"; + if (isNever) + { + element.prev().text(__t("Never")); + } + else + { + element.timeago("update", timestamp); + } + }); +} +RefreshContextualTimeago(); + +toastr.options = { + toastClass: 'alert', + closeButton: true, + timeOut: 20000, + extendedTimeOut: 5000 +}; + +window.FontAwesomeConfig = { + searchPseudoElements: true +} + +// Don't show tooltips on touch input devices +if (IsTouchInputDevice()) +{ + var css = document.createElement("style"); + css.innerHTML = ".tooltip { display: none; }"; + document.body.appendChild(css); +} + Grocy.FrontendHelpers = { }; Grocy.FrontendHelpers.ValidateForm = function(formId) {