diff --git a/primed/cdsa/tables.py b/primed/cdsa/tables.py index ebf29da7..c5f9ab6d 100644 --- a/primed/cdsa/tables.py +++ b/primed/cdsa/tables.py @@ -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: diff --git a/primed/dbgap/tables.py b/primed/dbgap/tables.py index 889fe934..08443706 100644 --- a/primed/dbgap/tables.py +++ b/primed/dbgap/tables.py @@ -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: diff --git a/primed/primed_anvil/tables.py b/primed/primed_anvil/tables.py index 71fb7fac..30048579 100644 --- a/primed/primed_anvil/tables.py +++ b/primed/primed_anvil/tables.py @@ -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( - """""" + f"""""" ) else: if self.show_false_icon: rendered_value = format_html( - """""" + f"""""" # noqa: E501 ) else: rendered_value = "" diff --git a/primed/primed_anvil/tests/test_tables.py b/primed/primed_anvil/tests/test_tables.py index 4278c74e..60431ffa 100644 --- a/primed/primed_anvil/tests/test_tables.py +++ b/primed/primed_anvil/tests/test_tables.py @@ -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.""" diff --git a/primed/templates/cdsa/cdsaworkspace_detail.html b/primed/templates/cdsa/cdsaworkspace_detail.html index 9eaddd53..ef03f669 100644 --- a/primed/templates/cdsa/cdsaworkspace_detail.html +++ b/primed/templates/cdsa/cdsaworkspace_detail.html @@ -2,15 +2,7 @@ {% block pills %} {% if workspace_data_object.gsr_restricted %} - - - GSR posting restricted - - + {% include "snippets/gsr_restricted_badge.html" %} {% endif %} {{ block.super }} diff --git a/primed/templates/dbgap/dbgapworkspace_detail.html b/primed/templates/dbgap/dbgapworkspace_detail.html index 4bc0eef3..28a5f65a 100644 --- a/primed/templates/dbgap/dbgapworkspace_detail.html +++ b/primed/templates/dbgap/dbgapworkspace_detail.html @@ -2,17 +2,10 @@ {% block pills %} {% if workspace_data_object.gsr_restricted %} - - - GSR posting restricted - - + {% include "snippets/gsr_restricted_badge.html" %} {% endif %} + {{ block.super }} {% endblock pills %} diff --git a/primed/templates/snippets/gsr_restricted_badge.html b/primed/templates/snippets/gsr_restricted_badge.html new file mode 100644 index 00000000..f9ae4dba --- /dev/null +++ b/primed/templates/snippets/gsr_restricted_badge.html @@ -0,0 +1,9 @@ + + + GSR posting restricted + +