Skip to content

Commit

Permalink
Color badge differently if an active data prep workspace exists
Browse files Browse the repository at this point in the history
If an active data prep workspace exists, color the badge green on
the workspace detail pages; otherwise, color it grey.
  • Loading branch information
amstilp committed Mar 14, 2024
1 parent bf13f82 commit 4ed89f5
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 3 deletions.
3 changes: 3 additions & 0 deletions primed/cdsa/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ def get_extra_detail_context_data(self, workspace, request):
extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceTable(
associated_data_prep
)
extra_context["data_prep_active"] = associated_data_prep.filter(
dataprepworkspace__is_active=True
).exists()
return extra_context
43 changes: 43 additions & 0 deletions primed/cdsa/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7267,6 +7267,9 @@ def test_associated_data_prep_workspaces_context_exists(self):
self.client.force_login(self.user)
response = self.client.get(obj.get_absolute_url())
self.assertIn("associated_data_prep_workspaces", response.context_data)
import ipdb

ipdb.set_trace()
self.assertIsInstance(
response.context_data["associated_data_prep_workspaces"],
DataPrepWorkspaceTable,
Expand Down Expand Up @@ -7311,6 +7314,46 @@ def test_show_two_associated_data_prep_workspaces(self):
response.context_data["associated_data_prep_workspaces"].data,
)

def test_context_data_prep_active_with_no_prep_workspace(self):
instance = factories.CDSAWorkspaceFactory.create()
self.client.force_login(self.user)
response = self.client.get(instance.get_absolute_url())
self.assertIn("data_prep_active", response.context_data)
self.assertFalse(response.context["data_prep_active"])

def test_context_data_prep_active_with_one_inactive_prep_workspace(self):
instance = factories.CDSAWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(
target_workspace=instance.workspace, is_active=False
)
self.client.force_login(self.user)
response = self.client.get(instance.get_absolute_url())
self.assertIn("data_prep_active", response.context_data)
self.assertFalse(response.context["data_prep_active"])

def test_context_data_prep_active_with_one_active_prep_workspace(self):
instance = factories.CDSAWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(
target_workspace=instance.workspace, is_active=True
)
self.client.force_login(self.user)
response = self.client.get(instance.get_absolute_url())
self.assertIn("data_prep_active", response.context_data)
self.assertTrue(response.context["data_prep_active"])

def test_context_data_prep_active_with_one_active_one_inactive_prep_workspace(self):
instance = factories.CDSAWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(
target_workspace=instance.workspace, is_active=True
)
DataPrepWorkspaceFactory.create(
target_workspace=instance.workspace, is_active=True
)
self.client.force_login(self.user)
response = self.client.get(instance.get_absolute_url())
self.assertIn("data_prep_active", response.context_data)
self.assertTrue(response.context["data_prep_active"])


class CDSAWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase):
"""Tests of the WorkspaceCreate view from ACM with this app's CDSAWorkspace model."""
Expand Down
3 changes: 3 additions & 0 deletions primed/dbgap/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ def get_extra_detail_context_data(self, workspace, request):
extra_context["associated_data_prep_workspaces"] = DataPrepWorkspaceTable(
associated_data_prep
)
extra_context["data_prep_active"] = associated_data_prep.filter(
dataprepworkspace__is_active=True
).exists()
return extra_context
40 changes: 40 additions & 0 deletions primed/dbgap/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,46 @@ def test_show_two_associated_data_prep_workspaces(self):
response.context_data["associated_data_prep_workspaces"].data,
)

def test_context_data_prep_active_with_no_prep_workspace(self):
instance = factories.dbGaPWorkspaceFactory.create()
self.client.force_login(self.user)
response = self.client.get(instance.get_absolute_url())
self.assertIn("data_prep_active", response.context_data)
self.assertFalse(response.context["data_prep_active"])

def test_context_data_prep_active_with_one_inactive_prep_workspace(self):
instance = factories.dbGaPWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(
target_workspace=instance.workspace, is_active=False
)
self.client.force_login(self.user)
response = self.client.get(instance.get_absolute_url())
self.assertIn("data_prep_active", response.context_data)
self.assertFalse(response.context["data_prep_active"])

def test_context_data_prep_active_with_one_active_prep_workspace(self):
instance = factories.dbGaPWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(
target_workspace=instance.workspace, is_active=True
)
self.client.force_login(self.user)
response = self.client.get(instance.get_absolute_url())
self.assertIn("data_prep_active", response.context_data)
self.assertTrue(response.context["data_prep_active"])

def test_context_data_prep_active_with_one_active_one_inactive_prep_workspace(self):
instance = factories.dbGaPWorkspaceFactory.create()
DataPrepWorkspaceFactory.create(
target_workspace=instance.workspace, is_active=True
)
DataPrepWorkspaceFactory.create(
target_workspace=instance.workspace, is_active=True
)
self.client.force_login(self.user)
response = self.client.get(instance.get_absolute_url())
self.assertIn("data_prep_active", response.context_data)
self.assertTrue(response.context["data_prep_active"])


class dbGaPWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase):
"""Tests of the WorkspaceCreate view from ACM with this app's dbGaPWorkspace model."""
Expand Down
2 changes: 1 addition & 1 deletion primed/templates/cdsa/cdsaworkspace_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h2 class="accordion-header" id="headingAcknowledgments">
</div>
</div>

{% include "snippets/data_prep_workspace_table.html" with table=associated_data_prep_workspaces %}
{% include "snippets/data_prep_workspace_table.html" with table=associated_data_prep_workspaces is_active=data_prep_active %}

{{block.super}}
{% endblock after_panel %}
2 changes: 1 addition & 1 deletion primed/templates/dbgap/dbgapworkspace_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h2 class="accordion-header" id="headingAcknowledgments">
</div>
</div>

{% include "snippets/data_prep_workspace_table.html" with table=associated_data_prep_workspaces %}
{% include "snippets/data_prep_workspace_table.html" with table=associated_data_prep_workspaces is_active=data_prep_active %}

{{block.super}}
{% endblock after_panel %}
Expand Down
2 changes: 1 addition & 1 deletion primed/templates/snippets/data_prep_workspace_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2 class="accordion-header" id="headingDataPrepWorkspace">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseDataPrepWorkspace" aria-expanded="false" aria-controls="collapseDataPrepWorkspace">
<span class="fa-solid fa-spinner mx-2"></span>
Associated data prep workspaces
<span class="badge mx-2 bg-secondary pill"> {{ table.rows|length }}</span>
<span class="badge mx-2 bg-{% if is_active %}success{% else %}secondary{% endif %} pill"> {{ table.rows|length }}</span>
</button>
</h2>
<div id="collapseDataPrepWorkspace" class="accordion-collapse collapse" aria-labelledby="headingDataPrepWorkspace" data-bs-parent="#accordionDataPrepWorkspace">
Expand Down

0 comments on commit 4ed89f5

Please sign in to comment.