Skip to content

Commit

Permalink
feat: positive logic to the stats view
Browse files Browse the repository at this point in the history
By default the view show all components. Then you can manage or filter which component
wouldnt be show setting it to false.

feat: use frontend as experience use it

This would be considered in future of the need of a refactor,
but by the moment is better to have the templates views that use react
with the same shape.

chore: apply suggestions from code review
  • Loading branch information
johanseto committed Jun 30, 2023
1 parent 3c81d49 commit d9090a8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions eox_nelp/stats/templates/tenant_stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<body>
<div id="tenant-stats"></div>
<script>
var showVideos = "true" === "${showVideos}";
var showCourses = "true" === "${showCourses}";
var showProblems = "true" === "${showProblems}";
var showLearners = "true" === "${showLearners}";
var showInstructors = "true" === "${showInstructors}";
var showVideos = "true" === "${videos}";
var showCourses = "true" === "${courses}";
var showProblems = "true" === "${problems}";
var showLearners = "true" === "${learners}";
var showInstructors = "true" === "${instructors}";
</script>
<script src="${static.url('tenant_stats/js/tenant_stats.js')}"></script>
</body>
Expand Down
12 changes: 6 additions & 6 deletions eox_nelp/stats/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ def test_get_default_stats(self):
- template name is as expected.
- tenant-stats div exist
"""
url_endpoint = reverse("stats:tenant")
url_endpoint = reverse("stats-frontend:tenant")

response = self.client.get(url_endpoint)

self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertEqual(self.template_name, response.templates[0].name)
self.assertContains(response, '<div id="tenant-stats"></div')

@data("showVideos", "showCourse", "showProblems", "showInstructors", "showLearners")
def test_get_specific_stat(self, query_param):
@data("videos", "courses", "problems", "instructors", "learners")
def test_filter_specific_stat(self, query_param):
"""
Test that the view render successfully when a query param is included
Expected behavior:
- Status code 200.
- template name is as expected.
- tenant-stats div exist
- the query param is 'true'
- the query param is 'false'
- CSS was included
- JS was included
"""
url_endpoint = f"{reverse('stats:tenant')}?{query_param}=true"
url_endpoint = f"{reverse('stats-frontend:tenant')}?{query_param}=false"

response = self.client.get(url_endpoint)

self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertEqual(self.template_name, response.templates[0].name)
self.assertContains(response, '<div id="tenant-stats"></div')
self.assertEqual("true", response.context[query_param])
self.assertEqual("false", response.context[query_param])
self.assertContains(response, "tenant_stats/css/tenant_stats.css")
self.assertContains(response, "tenant_stats/js/tenant_stats.js")
2 changes: 1 addition & 1 deletion eox_nelp/stats/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""frontend templates urls for course_experience"""
"""frontend templates urls for stats"""
from django.urls import path

from eox_nelp.stats.views import get_tenant_stats
Expand Down
26 changes: 13 additions & 13 deletions eox_nelp/stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ def get_tenant_stats(request):
By default this show nothing since this requires the specific query para to show the content.
Examples:
renders just video card /eox-nelp/stats/tenant/?showVideos=true
by default the view render all componets: /eox-nelp/stats/tenant/
render multiple components
/eox-nelp/stats/tenant/?showVideos=true&showCourses=true&showInstructors=true
filter components: eg dont show videos and courses.
/eox-nelp/stats/tenant/?videos=false&courses=false
The available options are:
showVideos
showCourses
showLearners
showInstructors
showProblems
videos
courses
learners
instructors
problems
"""

context = {
"showCourses": "false",
"showVideos": "false",
"showProblems": "false",
"showLearners": "false",
"showInstructors": "false",
"courses": "true",
"videos": "true",
"problems": "true",
"learners": "true",
"instructors": "true",
}
context.update(request.GET.dict())

Expand Down
2 changes: 1 addition & 1 deletion eox_nelp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
include('eox_nelp.course_experience.frontend.urls', namespace='course-experience-frontend'),
),
path('api/stats/', include('eox_nelp.stats.api.urls', namespace='stats-api')),
path('stats/', include('eox_nelp.stats.urls', namespace='stats')),
path('frontend/stats/', include('eox_nelp.stats.urls', namespace='stats-frontend')),
]

0 comments on commit d9090a8

Please sign in to comment.