Skip to content

Commit

Permalink
Merge pull request #445 from UW-GAC/feature/gsr-sensitive-column-icon
Browse files Browse the repository at this point in the history
Change the appearance of the gsr_restricted field on the site
  • Loading branch information
amstilp authored Feb 16, 2024
2 parents 654564b + 37c2ff8 commit 12ac8b7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 23 deletions.
4 changes: 3 additions & 1 deletion primed/cdsa/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ class CDSAWorkspaceStaffTable(tables.Table):
verbose_name="DUO modifiers",
linkify_item=True,
)
cdsaworkspace__gsr_restricted = BooleanIconColumn(orderable=False)
cdsaworkspace__gsr_restricted = BooleanIconColumn(
orderable=False, true_icon="dash-circle-fill", true_color="#ffc107"
)
is_shared = WorkspaceSharedWithConsortiumColumn()

class Meta:
Expand Down
4 changes: 3 additions & 1 deletion primed/dbgap/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ class dbGaPWorkspaceStaffTable(tables.Table):
verbose_name="Approved DARs",
orderable=False,
)
dbgapworkspace__gsr_restricted = BooleanIconColumn(orderable=False)
dbgapworkspace__gsr_restricted = BooleanIconColumn(
orderable=False, true_icon="dash-circle-fill", true_color="#ffc107"
)
is_shared = WorkspaceSharedWithConsortiumColumn()

class Meta:
Expand Down
18 changes: 15 additions & 3 deletions primed/primed_anvil/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,32 @@ class BooleanIconColumn(tables.BooleanColumn):
# attrs = {"td": {"align": "center"}}
# attrs = {"th": {"class": "center"}}

def __init__(self, show_false_icon=False, **kwargs):
def __init__(
self,
show_false_icon=False,
true_color="green",
false_color="red",
true_icon="check-circle-fill",
false_icon="x-circle-fill",
**kwargs,
):
super().__init__(**kwargs)
self.show_false_icon = show_false_icon
self.true_color = true_color
self.false_color = false_color
self.true_icon = true_icon
self.false_icon = false_icon

def render(self, value, record, bound_column):
value = self._get_bool_value(record, value, bound_column)
if value:
rendered_value = format_html(
"""<i class="bi bi-check-circle-fill bi-align-center px-2" style="color: green;"></i>"""
f"""<i class="bi bi-{self.true_icon} bi-align-center px-2" style="color: {self.true_color};"></i>"""
)
else:
if self.show_false_icon:
rendered_value = format_html(
"""<i class="bi bi-x-circle-fill bi-align-center px-2" style="color: red;"></i>"""
f"""<i class="bi bi-{self.false_icon} bi-align-center px-2" style="color: {self.false_color};"></i>""" # noqa: E501
)
else:
rendered_value = ""
Expand Down
34 changes: 34 additions & 0 deletions primed/primed_anvil/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,40 @@ def test_render_show_false_icon(self):
self.assertIn("bi-x-circle-fill", value)
self.assertIn("red", value)

def test_true_color(self):
column = tables.BooleanIconColumn(true_color="blue")
value = column.render(True, None, None)
self.assertIn("bi-check-circle-fill", value)
self.assertIn("blue", value)
value = column.render(False, None, None)
self.assertEqual(value, "")

def test_true_icon(self):
column = tables.BooleanIconColumn(true_icon="dash")
value = column.render(True, None, None)
self.assertIn("bi-dash", value)
self.assertIn("green", value)
value = column.render(False, None, None)
self.assertEqual(value, "")

def test_false_color(self):
column = tables.BooleanIconColumn(show_false_icon=True, false_color="blue")
value = column.render(False, None, None)
self.assertIn("bi-x-circle-fill", value)
self.assertIn("blue", value)
value = column.render(True, None, None)
self.assertIn("bi-check-circle-fill", value)
self.assertIn("green", value)

def test_false_icon(self):
column = tables.BooleanIconColumn(show_false_icon=True, false_icon="dash")
value = column.render(False, None, None)
self.assertIn("bi-dash", value)
self.assertIn("red", value)
value = column.render(True, None, None)
self.assertIn("bi-check-circle-fill", value)
self.assertIn("green", value)


class WorkspaceSharedWithConsortiumColumnTest(TestCase):
"""Tests for the WorkspaceSharedWithConsortiumColumn class."""
Expand Down
10 changes: 1 addition & 9 deletions primed/templates/cdsa/cdsaworkspace_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

{% block pills %}
{% if workspace_data_object.gsr_restricted %}
<span class="badge bg-warning text-dark">
<span class="me-2 fa-solid fa-hand"></span>
GSR posting restricted
<span class="ms-2 fa-solid fa-circle-question"
data-bs-toggle="tooltip"
data-bs-placement="bottom"
data-bs-title="This workspace contains sensitive data and therefore public posting of Genomic Summary Results (GSR) is prohibited; see also NOT-19-023."
></span>
</span>
{% include "snippets/gsr_restricted_badge.html" %}
{% endif %}

{{ block.super }}
Expand Down
11 changes: 2 additions & 9 deletions primed/templates/dbgap/dbgapworkspace_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

{% block pills %}
{% if workspace_data_object.gsr_restricted %}
<span class="badge bg-warning text-dark">
<span class="me-2 fa-solid fa-hand"></span>
GSR posting restricted
<span class="ms-2 fa-solid fa-circle-question"
data-bs-toggle="tooltip"
data-bs-placement="bottom"
data-bs-title="This workspace contains sensitive data and therefore public posting of Genomic Summary Results (GSR) is prohibited; see also NOT-19-023."
></span>
</span>
{% include "snippets/gsr_restricted_badge.html" %}
{% endif %}


{{ block.super }}
{% endblock pills %}

Expand Down
9 changes: 9 additions & 0 deletions primed/templates/snippets/gsr_restricted_badge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<span class="badge bg-warning text-dark">
<span class="me-2 fa-solid fa-circle-minus"></span>
GSR posting restricted
<span class="ms-2 fa-solid fa-circle-question"
data-bs-toggle="tooltip"
data-bs-placement="bottom"
data-bs-title="This workspace contains sensitive data and therefore public posting of Genomic Summary Results (GSR) is prohibited; see also NOT-19-023."
></span>
</span>

0 comments on commit 12ac8b7

Please sign in to comment.