Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Assigned Location Column to Application Status Report #34744

Merged
merged 20 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions corehq/apps/reports/standard/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,18 @@ def _get_formatted_assigned_location_names(self, user, user_loc_dict):

formatted_str = ', '.join(formatted_loc_names[:4])
all_str = ', '.join(formatted_loc_names)
eplise_str = _('...See more') if len(formatted_loc_names) > 4 else ''
view_all_str = _('...See more') if len(formatted_loc_names) > 4 else ''
view_less_str = _('...See less') if len(formatted_loc_names) > 4 else ''
out_str = ('''
<div>
<span class="locations-list">{}</span>
<a href="#" class="toggle-all-locations">{}</a>
<span class="all-locations-list" style="display:none">{}</span>
<a href="#" class="toggle-all-locations">
<span>{}</span>
<span style="display:none">{}</span>
</a>
</div>
''').format(formatted_str, eplise_str, all_str)
''').format(formatted_str, all_str, view_all_str, view_less_str)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code will be easier to follow if we add additional html elements later. And we are just adding empty nodes which can be avoided.
something like:

html_nodes = ['<span class="locations-list">{formatted_str}</span>']
if len(formatted_loc_names) > 4:
    html_nodes.append[
        '<span class="all-locations-list" style="display:none">{all_str}</span>',
        '...'
    ]
return format_html(f'<div>{''.join(html_nodes)}</div>')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this approach, a bit cleaner. I've done some refactoring in (ee88a55).

return format_html(out_str)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ hqDefine("reports/js/bootstrap3/application_status", [
$(function () {
$('#report-content').on('click', '.toggle-all-locations', function (e) {
$(this).prevAll('.locations-list').toggle();
$(this).toggle();
$(this).nextAll('.all-locations-list').toggle();
$(this).children('span').toggle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be nice to limit this by adding a specific class to this span to avoid conflicting with any other span getting added to the div in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(this).prevAll('.all-locations-list').toggle();
e.preventDefault();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ hqDefine("reports/js/bootstrap5/application_status", [
$(function () {
$('#report-content').on('click', '.toggle-all-locations', function (e) {
$(this).prevAll('.locations-list').toggle();
$(this).toggle();
$(this).nextAll('.all-locations-list').toggle();
$(this).children('span').toggle();
$(this).prevAll('.all-locations-list').toggle();
e.preventDefault();
});
});
Expand Down
Loading