From eaee939c590e5536fb038992f9532f4858205b23 Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Fri, 16 Feb 2024 13:40:24 -0800 Subject: [PATCH 1/4] Allow user to specify icon and color for BooleanIconColumn --- primed/primed_anvil/tables.py | 18 ++++++++++--- primed/primed_anvil/tests/test_tables.py | 34 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) 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.""" From 6ad708449750c34b88ce5aef7fe70bf6d20f0390 Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Fri, 16 Feb 2024 13:41:01 -0800 Subject: [PATCH 2/4] Use a yellow dash icon for gsr_restricted column This is a little clearer - a green check implies that it is ok to post GSRs but actually it means they are restricted. --- primed/cdsa/tables.py | 4 +++- primed/dbgap/tables.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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: From 7737874974e9bd19f82565ad12ad176ec114dbb7 Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Fri, 16 Feb 2024 13:42:37 -0800 Subject: [PATCH 3/4] Use a consistent icon for gsr_restricted Use the same circle-minus icon on the detail page as in thetatbles. --- primed/templates/cdsa/cdsaworkspace_detail.html | 2 +- primed/templates/dbgap/dbgapworkspace_detail.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/primed/templates/cdsa/cdsaworkspace_detail.html b/primed/templates/cdsa/cdsaworkspace_detail.html index 9eaddd53..45f5408b 100644 --- a/primed/templates/cdsa/cdsaworkspace_detail.html +++ b/primed/templates/cdsa/cdsaworkspace_detail.html @@ -3,7 +3,7 @@ {% block pills %} {% if workspace_data_object.gsr_restricted %} - + GSR posting restricted - + GSR posting restricted Date: Fri, 16 Feb 2024 13:45:07 -0800 Subject: [PATCH 4/4] Split gsr_restricted badge into a separate snippet This snippet can be reused in multiple places on the site, instead of duplicating the same html for both the dbGaPworkspace detail page and the CDSAWorkspace detail page. --- primed/templates/cdsa/cdsaworkspace_detail.html | 10 +--------- primed/templates/dbgap/dbgapworkspace_detail.html | 11 ++--------- primed/templates/snippets/gsr_restricted_badge.html | 9 +++++++++ 3 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 primed/templates/snippets/gsr_restricted_badge.html diff --git a/primed/templates/cdsa/cdsaworkspace_detail.html b/primed/templates/cdsa/cdsaworkspace_detail.html index 45f5408b..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 883d2f49..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 + +