Skip to content

Commit

Permalink
Merge pull request #35077 from dimagi/jls/kill-timeago
Browse files Browse the repository at this point in the history
Removed jquery-timeago
  • Loading branch information
orangejenny authored Sep 2, 2024
2 parents 18c8ee0 + caefbfe commit a35a189
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 76 deletions.
14 changes: 0 additions & 14 deletions corehq/apps/hqwebapp/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,6 @@ def dispatch(self, request, *args, **kwargs):
return set_request_flag(view_func, 'use_nvd3_v3')


def use_timeago(view_func):
"""Use this decorator on the dispatch method of a TemplateView subclass
to enable the inclusion of the timeago library at the base template
level.
Example:
@use_timeago
def dispatch(self, request, *args, **kwargs):
return super(MyView, self).dispatch(request, *args, **kwargs)
"""
return set_request_flag(view_func, 'use_timeago')


def use_datatables(view_func):
"""Use this decorator on the dispatch method of a TemplateView subclass
to enable the inclusion of the datatables library at the base template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ hqDefine("hqwebapp/js/bootstrap3/hq.helpers", [
$(this).parents('.alert').hide(150);
});

if ($.timeago) {
$.timeago.settings.allowFuture = true;
$(".timeago").timeago();
}

window.onerror = function (message, file, line, col, error) {
var stack = error ? error.stack : null;
if (!stack && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ hqDefine("hqwebapp/js/bootstrap5/hq.helpers", [
$(this).parents('.alert').hide(150);
});

if ($.timeago) {
$.timeago.settings.allowFuture = true;
$(".timeago").timeago();
}

window.onerror = function (message, file, line, col, error) {
var stack = error ? error.stack : null;
if (!stack && (
Expand Down
4 changes: 0 additions & 4 deletions corehq/apps/hqwebapp/templates/hqwebapp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,6 @@
{% endcompress %}
{% endif %}

{% if request.use_timeago and not use_js_bundler %}
<script src="{% static 'jquery-timeago/jquery.timeago.js' %}"></script>
{% endif %}

{% if request.use_multiselect and not use_js_bundler %}
{% compress js %}
<script src="{% static 'multiselect/js/jquery.multi-select.js' %}"></script>
Expand Down
19 changes: 7 additions & 12 deletions corehq/apps/hqwebapp/templatetags/proptable_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import collections
import datetime
from itertools import zip_longest

import attr
from django import template
Expand All @@ -23,7 +22,6 @@
from jsonobject.exceptions import BadValueError

from dimagi.ext.jsonobject import DateProperty
from dimagi.utils.chunked import chunked
from dimagi.utils.dates import safe_strftime

from corehq.apps.hqwebapp.doc_info import get_doc_info_by_id
Expand Down Expand Up @@ -88,12 +86,13 @@ def _format_slug_string_for_display(key):
return key.replace('_', ' ').replace('-', ' ')


def _to_html(val, key=None, level=0, timeago=False):
def _to_html(val, key=None, level=0):
"""
Recursively convert a value to its HTML representation using <dl>s for
dictionaries and <ul>s for lists.
"""
recurse = lambda k, v: _to_html(v, key=k, level=level + 1, timeago=timeago)
def _recurse(k, v):
return _to_html(v, key=k, level=level + 1)

def _key_format(k, v):
if not _is_list_like(v):
Expand All @@ -108,14 +107,14 @@ def _key_format(k, v):
format_html_join(
"",
"<dt>{}</dt><dd>{}</dd>",
[(_key_format(k, v), recurse(k, v)) for k, v in val.items()]
[(_key_format(k, v), _recurse(k, v)) for k, v in val.items()]
)
)

elif _is_list_like(val):
ret = format_html(
"<dl>{}</dl>",
format_html_join("", "<dt>{}</dt><dd>{}</dd>", [(key, recurse(None, v)) for v in val])
format_html_join("", "<dt>{}</dt><dd>{}</dd>", [(key, _recurse(None, v)) for v in val])
)

elif isinstance(val, datetime.date):
Expand All @@ -125,8 +124,7 @@ def _key_format(k, v):
fmt = USER_DATE_FORMAT

iso = val.isoformat()
ret = format_html("<time{timeago} title='{title}' datetime='{iso}'>{display}</time>".format(
timeago=mark_safe(" class='timeago'") if timeago else "", # nosec: no user input
ret = format_html("<time title='{title}' datetime='{iso}'>{display}</time>".format(
title=iso,
iso=iso,
display=safe_strftime(val, fmt)
Expand Down Expand Up @@ -159,9 +157,6 @@ class DisplayConfig:
# String to use as the output format e.g. "<b>{}</b>"
format = attr.ib(default=None)

# add 'timeago' class to <time/> elements
timeago = attr.ib(default=False)

# property that is passed through in the return result
has_history = attr.ib(default=False)

Expand Down Expand Up @@ -195,7 +190,7 @@ def get_display_data(data: dict, prop_def: DisplayConfig, timezone=pytz.utc):
val = PhoneTime(val, timezone).user_time(timezone).done()

if not processor or not processor.returns_html:
val = _to_html(val, timeago=prop_def.timeago)
val = _to_html(val)

if prop_def.format:
val = format_html(prop_def.format, val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
) {
// disable-on-submit is a class for form submit buttons so they're automatically disabled when the form is submitted
$(document).on('submit', 'form', function (ev) {
@@ -59,19 +61,6 @@
@@ -54,19 +56,6 @@
return false; // let default handler run
};

Expand All @@ -38,7 +38,7 @@
$.fn.hqHelp = function (opts) {
var self = this;
self.each(function (i) {
@@ -88,22 +77,19 @@
@@ -83,22 +72,19 @@
if (opts) {
options = _.extend(options, opts);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
self.hqLoading = $(self.loaderClass);
self.reportContent.html(data.report);
@@ -174,7 +174,7 @@
@@ -171,7 +171,7 @@

if (!initialLoad || !self.standardReport.needsFilters) {
self.standardReport.filterSubmitButton
Expand All @@ -42,7 +42,7 @@
setTimeout(function () {
// Bootstrap clears all btn styles except btn on reset
// This gets around it by waiting 10ms.
@@ -186,7 +186,7 @@
@@ -183,7 +183,7 @@
}, 10);
} else {
self.standardReport.filterSubmitButton
Expand All @@ -51,7 +51,7 @@
.addClass('btn-primary')
.removeClass('disabled')
.prop('disabled', false);
@@ -205,10 +205,10 @@
@@ -202,10 +202,10 @@
self.loadingIssueModal.find('.report-error-status').html('<strong>' + data.status + '</strong> ' +
((humanReadable) ? humanReadable : ""));
if (self.issueAttempts > 0) {
Expand All @@ -64,7 +64,7 @@
} else {
self.hqLoading = $(self.loaderClass);
self.hqLoading.find('h4').text(gettext("Loading Stopped"));
@@ -216,7 +216,7 @@
@@ -213,7 +213,7 @@
}
},
beforeSend: function () {
Expand All @@ -73,7 +73,7 @@
$('.loading-backdrop').fadeIn();
if (self.hqLoading) {
self.hqLoading.attr('style', 'position: absolute; top: 30px; left: 40%;');
@@ -228,7 +228,7 @@
@@ -225,7 +225,7 @@
};

$(document).on('click', '.try-again', function () {
Expand Down
21 changes: 3 additions & 18 deletions corehq/apps/hqwebapp/tests/test_proptable_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def test_get_display_data_no_name(self):
})

def test_get_display_data_function(self):
get_color = lambda x: x['color']
column = DisplayConfig(name='favorite color', expr=get_color)
def _get_color(x):
return x['color']
column = DisplayConfig(name='favorite color', expr=_get_color)
data = {
'color': 'red'
}
Expand Down Expand Up @@ -119,22 +120,6 @@ def test_get_display_process_date(self):
'has_history': False,
})

def test_get_display_process_timeago(self):
column = DisplayConfig(expr='date', process="date", timeago=True)
data = {'date': "2021-03-16T14:37:22Z"}
expected_value = (
"<time class='timeago' title='2021-03-16T14:37:22+00:00' datetime='2021-03-16T14:37:22+00:00'>"
"Mar 16, 2021 14:37 UTC"
"</time>"
)
self.assertEqual(get_display_data(data, column), {
'expr': 'date',
'name': 'date',
'description': None,
'value': expected_value,
'has_history': False,
})

@override_settings(PHONE_TIMEZONES_HAVE_BEEN_PROCESSED=True)
def test_get_display_process_phonetime(self):
column = DisplayConfig(expr='date', process="date", is_phone_time=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ hqDefine("reports/js/bootstrap3/reports.async", function () {

// Assorted UI cleanup/initialization
$('.hq-report-time-notice').removeClass('hide');
if ($.timeago) {
$(".timeago").timeago();
}

$('.loading-backdrop').fadeOut();
self.hqLoading.fadeOut();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ hqDefine("reports/js/bootstrap5/reports.async", function () {

// Assorted UI cleanup/initialization
$('.hq-report-time-notice').removeClass('hide');
if ($.timeago) {
$(".timeago").timeago();
}

$('.loading-backdrop').fadeOut();
self.hqLoading.fadeOut();
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"jquery-form": "4.2.2",
"jquery-memoized-ajax": "0.5.0",
"jquery-textchange": "jmalonzo/bower-jquery-textchange#0.2.3",
"jquery-timeago": "rmm5t/jquery-timeago#1.2.0",
"jquery-tiny-pubsub": "cowboy/jquery-tiny-pubsub#~0.7.0",
"jquery-treetable": "ludo/jquery-treetable#3.2.0",
"jquery-ui": "1.13.2",
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3679,10 +3679,6 @@ jquery-textchange@jmalonzo/bower-jquery-textchange#0.2.3:
version "0.0.0"
resolved "https://codeload.github.com/jmalonzo/bower-jquery-textchange/tar.gz/fd7d7c0ac5116861759cd467135307dc9aab7cdc"

jquery-timeago@rmm5t/jquery-timeago#1.2.0:
version "0.0.0"
resolved "https://codeload.github.com/rmm5t/jquery-timeago/tar.gz/f2afbeaf787a93f01822d062fc80a571f4ebda48"

jquery-tiny-pubsub@cowboy/jquery-tiny-pubsub#~0.7.0:
version "0.0.0-ignored"
resolved "https://codeload.github.com/cowboy/jquery-tiny-pubsub/tar.gz/d9b4a093221f43d1119aac088258c8d0ea2b183b"
Expand Down

0 comments on commit a35a189

Please sign in to comment.