From c9d0c6852ee152e48d64d619a648527e658f1b50 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 14 Apr 2020 21:19:56 +0000 Subject: [PATCH] admin users: Use plain HTML and static dates. We want to avoid creating jQuery objects that just get turned right back into strings by the list widget, so we now have our template just include `last_active_date` instead of kludging it in after the fact, and we return the template string in `modifier` rather than wrapping it. To deal with plain HTML we switch to using `render_now`. Calling `render_now` leads to a more simple codepath than `render_date`, beyond just dealing with text. The `render_date` function has special-case logic that only applies to our time dividers in our message view, which is why we were passing the strange `undefined` parameter to it before this fix. The `render_date` function was also putting the dates into `update_list` for once-a-day updates, which is overkill for an admin screen. We don't use this logic for drafts or attachments either. I'm not sure how well tested that logic is, and it's prone to slow leaks. This commit sets us up to simplify the list widget not to have bit-rot-prone code related to jQuery objects. --- static/js/settings_users.js | 14 ++++++-------- static/templates/admin_user_list.hbs | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/static/js/settings_users.js b/static/js/settings_users.js index 216f0dd72b..80e2888152 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -197,28 +197,26 @@ function populate_users(realm_people_data) { }, }); - function get_rendered_last_activity(user) { + function get_last_active(user) { const last_active_date = presence.last_active_date(user.user_id); if (!last_active_date) { - return $("").text(i18n.t("Unknown")); + return i18n.t("Unknown"); } - const today = new XDate(); - return timerender.render_date(last_active_date, undefined, today); + return timerender.render_now(last_active_date).time_str; } const $users_table = $("#admin_users_table"); list_render.create($users_table, active_users, { name: "users_table_list", modifier: function (item) { - const $row = $(render_admin_user_list({ + return render_admin_user_list({ can_modify: page_params.is_admin, is_current_user: people.is_my_user_id(item.user_id), display_email: settings_data.email_for_user_settings(item), user: item, - })); - $row.find(".last_active").append(get_rendered_last_activity(item)); - return $row; + last_active_date: get_last_active(item), + }); }, filter: { element: $users_table.closest(".settings-section").find(".search"), diff --git a/static/templates/admin_user_list.hbs b/static/templates/admin_user_list.hbs index c726c32f8b..f8b1bdf704 100644 --- a/static/templates/admin_user_list.hbs +++ b/static/templates/admin_user_list.hbs @@ -37,6 +37,7 @@ {{else if is_active}} + {{ ../last_active_date }} {{/if}} {{#if ../can_modify}}