From 436dd6e5775277e60e2a5adbe3609a47d4f6fb43 Mon Sep 17 00:00:00 2001 From: Gavin Sidebottom Date: Wed, 15 May 2019 12:31:51 -0400 Subject: [PATCH] Misc improvements - fixed dashboard style regressions, handled empty dashboard, added rule to serve course catalog at root route, added enrollment admin classes --- courses/admin.py | 16 +++++++++++++++- courses/views_test.py | 2 +- mitxpro/urls.py | 3 ++- mitxpro/urls_test.py | 2 +- static/js/containers/pages/DashboardPage.js | 18 +++++++++++++++++- .../js/containers/pages/DashboardPage_test.js | 18 ++++++++++++++++++ static/scss/dashboard.scss | 16 ++++++---------- 7 files changed, 60 insertions(+), 15 deletions(-) diff --git a/courses/admin.py b/courses/admin.py index 65b789c70..b38860ca6 100644 --- a/courses/admin.py +++ b/courses/admin.py @@ -4,7 +4,7 @@ from django.contrib import admin -from .models import Program, Course, CourseRun +from .models import Program, Course, CourseRun, ProgramEnrollment, CourseRunEnrollment class ProgramAdmin(admin.ModelAdmin): @@ -31,6 +31,20 @@ class CourseRunAdmin(admin.ModelAdmin): list_filter = ["live", "course"] +class ProgramEnrollmentAdmin(admin.ModelAdmin): + """Admin for ProgramEnrollment""" + + model = ProgramEnrollment + + +class CourseRunEnrollmentAdmin(admin.ModelAdmin): + """Admin for CourseRunEnrollment""" + + model = CourseRunEnrollment + + admin.site.register(Program, ProgramAdmin) admin.site.register(Course, CourseAdmin) admin.site.register(CourseRun, CourseRunAdmin) +admin.site.register(ProgramEnrollment, ProgramEnrollmentAdmin) +admin.site.register(CourseRunEnrollment, CourseRunEnrollmentAdmin) diff --git a/courses/views_test.py b/courses/views_test.py index 4a0ac8b5c..30c340a29 100644 --- a/courses/views_test.py +++ b/courses/views_test.py @@ -189,7 +189,7 @@ def test_course_catalog_view(client): CourseFactory.create(no_program=True, live=False) exp_programs = [program] exp_courses = [course_in_program, course_no_program] - resp = client.get(reverse("mitxpro-index")) + resp = client.get(reverse("mitxpro-catalog")) assert resp.templates[0].name == "catalog.html" assert list(resp.context["programs"]) == exp_programs assert list(resp.context["courses"]) == exp_courses diff --git a/mitxpro/urls.py b/mitxpro/urls.py index 279f9c161..ac30cff77 100644 --- a/mitxpro/urls.py +++ b/mitxpro/urls.py @@ -63,7 +63,8 @@ name="password-reset-confirm", ), path("terms-and-conditions/", index, name="terms-and-conditions"), - re_path(r"catalog/", CourseCatalogView.as_view(), name="mitxpro-index"), + re_path(r"^catalog/", CourseCatalogView.as_view(), name="mitxpro-catalog"), + re_path(r"^$", CourseCatalogView.as_view(), name="mitxpro-index"), re_path(r"^dashboard/", index, name="user-dashboard"), # Wagtail re_path(r"^cms/", include(wagtailadmin_urls)), diff --git a/mitxpro/urls_test.py b/mitxpro/urls_test.py index e9f1bfa1f..6ef6de5a2 100644 --- a/mitxpro/urls_test.py +++ b/mitxpro/urls_test.py @@ -9,4 +9,4 @@ class URLTests(TestCase): def test_urls(self): """Make sure URLs match with resolved names""" - assert reverse("mitxpro-index") == "/catalog/" + assert reverse("mitxpro-catalog") == "/catalog/" diff --git a/static/js/containers/pages/DashboardPage.js b/static/js/containers/pages/DashboardPage.js index 35837179b..9a16a2321 100644 --- a/static/js/containers/pages/DashboardPage.js +++ b/static/js/containers/pages/DashboardPage.js @@ -31,6 +31,16 @@ export class DashboardPage extends React.Component { collapseVisible: {} } + enrollmentsExist = (): boolean => { + const { enrollments } = this.props + + return ( + enrollments && + (enrollments.program_enrollments.length > 0 || + enrollments.course_run_enrollments.length > 0) + ) + } + onCollapseToggle = (programEnrollmentId: number): void => { this.setState({ collapseVisible: { @@ -160,12 +170,18 @@ export class DashboardPage extends React.Component { render() { const { enrollments } = this.props + const enrollmentsExist = this.enrollmentsExist() + return (

Dashboard

-

Courses and Programs

+ {enrollmentsExist ? ( +

Courses and Programs

+ ) : ( +

You are not yet enrolled in any courses or programs.

+ )}
{enrollments ? ( diff --git a/static/js/containers/pages/DashboardPage_test.js b/static/js/containers/pages/DashboardPage_test.js index 1454520ab..3965a16ec 100644 --- a/static/js/containers/pages/DashboardPage_test.js +++ b/static/js/containers/pages/DashboardPage_test.js @@ -70,6 +70,24 @@ describe("DashboardPage", () => { ) }) + it("shows a message if the user has no enrollments", async () => { + const { inner } = await renderPage({ + entities: { + enrollments: { + program_enrollments: [], + course_run_enrollments: [] + } + } + }) + + const header = inner.find(".user-dashboard .header") + assert.isTrue(header.exists()) + assert.include( + header.text(), + "You are not yet enrolled in any courses or programs" + ) + }) + it("shows specific date information", async () => { const { inner } = await renderPage() sinon.assert.calledWith( diff --git a/static/scss/dashboard.scss b/static/scss/dashboard.scss index 8f2fc5689..e352f2848 100644 --- a/static/scss/dashboard.scss +++ b/static/scss/dashboard.scss @@ -18,16 +18,17 @@ } h2 { - font-size: 1.75rem; + font-size: 2rem; font-weight: 600; + line-height: 2.75rem; @include media-breakpoint-down(sm) { - font-size: 1.25rem; + font-size: 1.6rem; } } h3 { - font-size: 1.25rem; + font-size: 1.75rem; font-weight: 600; color: $navy-blue; border-bottom: 1px solid $detail-grid-border-color; @@ -43,11 +44,11 @@ .user-dashboard, .collapse-toggle { - font-size: 20px; + font-size: 2rem; font-weight: 600; @include media-breakpoint-down(sm) { - font-size: 16px; + font-size: 1.6rem; } } @@ -99,11 +100,6 @@ .course-enrollment { margin-top: 15px; margin-bottom: 15px; - - h2 { - font-size: 20px; - font-weight: 600; - } } }