Skip to content

Commit

Permalink
Remove legacy vega-powered dashboard (#2105)
Browse files Browse the repository at this point in the history
This fixes #2104.
  • Loading branch information
toolness authored May 20, 2021
1 parent 2fd81bb commit 1e8ecc6
Show file tree
Hide file tree
Showing 16 changed files with 7 additions and 396 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*.shx filter=lfs diff=lfs merge=lfs -text
nycha/data/*.csv filter=lfs diff=lfs merge=lfs -text
findhelp/static/findhelp/vendor/**/*.* filter=lfs diff=lfs merge=lfs -text
project/static/vendor/vega/*.js filter=lfs diff=lfs merge=lfs -text
project/tests/test_git_lfs.js filter=lfs diff=lfs merge=lfs -text
frontend/design_sources/**/*.* filter=lfs diff=lfs merge=lfs -text
hpaction/static/hpaction/service-instructions/**/*.* filter=lfs diff=lfs merge=lfs -text
evictionfree/pdf/**/*.pdf filter=lfs diff=lfs merge=lfs -text
Expand Down
3 changes: 0 additions & 3 deletions project/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import frontend.views
from .frontapp import embeddable_in_frontapp
from .admin_download_data import DownloadDataViews
from .admin_dashboard import DashboardViews
from project.util.site_util import get_site_name
from loc.admin_views import LocAdminViews
from hpaction.admin_views import HPActionAdminViews
Expand All @@ -21,7 +20,6 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.loc_views = LocAdminViews(self)
self.download_data_views = DownloadDataViews(self)
self.dashboard_views = DashboardViews(self)
self.hpaction_views = HPActionAdminViews(self)
self.user_views = UserAdminViews(self)

Expand All @@ -32,7 +30,6 @@ def get_urls(self):
path("conversations/", frontend.views.react_rendered_view),
path("frontapp/", embeddable_in_frontapp(frontend.views.react_rendered_view)),
path("directory/", frontend.views.react_rendered_view),
*self.dashboard_views.get_urls(),
*self.download_data_views.get_urls(),
*self.loc_views.get_urls(),
*self.hpaction_views.get_urls(),
Expand Down
92 changes: 0 additions & 92 deletions project/admin_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import json
import functools
from typing import Dict, Any, List
from urllib.parse import urlparse
from pathlib import Path
from django.urls import path
from django.http import Http404
from django.utils.text import slugify
from django.template.response import TemplateResponse
from django.conf import settings
from csp.decorators import csp_update

from .admin_download_data import strict_get_data_download


MY_DIR = Path(__file__).parent.resolve()

SPECS_DIR = MY_DIR / "admin_dashboard"


def require_enabled_dashboard(view):
Expand Down Expand Up @@ -43,80 +28,3 @@ def get_django_admin_dashboard_urls(site):
]

return (urlpatterns, "", "")


class DashboardViews:
def __init__(self, site):
self.site = site

def get_urls(self):
return [
path(
"vega-dashboard/",
self.site.admin_view(
# Argh, it's really unfortunate that we have to break CSP
# in order to use Vega, which apparently uses eval(). :(
#
# But, since our datasets never contain arbitrary string data
# entered by untrusted users, this *should* be ok.
csp_update(SCRIPT_SRC="'unsafe-eval'")(self.dashboard_view)
),
name="dashboard",
),
]

def dashboard_view(self, request):
vizs = [Visualization(spec) for spec in get_vega_lite_specs()]
return TemplateResponse(
request,
"admin/justfix/dashboard.html",
{
**self.site.each_context(request),
"GA_TRACKING_ID": settings.GA_TRACKING_ID,
"vizs": vizs,
"viz_data": {viz.id: viz.spec for viz in vizs},
"title": "Dashboard",
},
)


class Visualization:
spec: Dict[str, Any]
id: str
title: str

def __init__(self, spec: Dict[str, Any]):
self.spec = spec
self.title = spec["title"]
self.anchor_id = slugify(self.title)
self.id = f"_{self.anchor_id}"

# We're going to show the title in the HTML, so remove it from the spec
# so it doesn't show twice.
del spec["title"]


def get_dataset_url(dataset: str) -> str:
return strict_get_data_download(dataset).json_url()


def convert_spec(raw_spec: Dict[str, Any]) -> Dict[str, Any]:
url = raw_spec["data"]["url"]
parsed = urlparse(url)
assert parsed.scheme == "dataset"
raw_spec["data"]["url"] = get_dataset_url(parsed.path)
return raw_spec


def get_vega_lite_specs() -> List[Dict[str, Any]]:
"""
Return a list of all Vega-Lite specifications to show on the dashboard.
Documentation on Vega-Lite can be found here:
https://vega.github.io/vega-lite/docs/
"""

specfiles = sorted(list(SPECS_DIR.glob("*.json")), key=lambda path: path.name)
specs = [convert_spec(json.loads(specfile.read_text())) for specfile in specfiles]
return specs
43 changes: 0 additions & 43 deletions project/admin_dashboard/01_users_by_lease_type.json

This file was deleted.

17 changes: 0 additions & 17 deletions project/admin_dashboard/02_issues_per_area.json

This file was deleted.

32 changes: 0 additions & 32 deletions project/admin_dashboard/03_loc_funnel_over_time.json

This file was deleted.

49 changes: 0 additions & 49 deletions project/admin_dashboard/04_time_to_complete_loc.json

This file was deleted.

5 changes: 0 additions & 5 deletions project/static/admin/justfix/dashboard-globals.d.ts

This file was deleted.

80 changes: 0 additions & 80 deletions project/static/admin/justfix/dashboard.js

This file was deleted.

3 changes: 0 additions & 3 deletions project/static/vendor/vega/vega-5.3.5.min.js

This file was deleted.

3 changes: 0 additions & 3 deletions project/static/vendor/vega/vega-embed-4.0.0.min.js

This file was deleted.

3 changes: 0 additions & 3 deletions project/static/vendor/vega/vega-lite-3.2.1.min.js

This file was deleted.

Loading

0 comments on commit 1e8ecc6

Please sign in to comment.