Skip to content

Commit

Permalink
add portals ui
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Oct 24, 2024
1 parent 2c944a0 commit a66a1cf
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 33 deletions.
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
path("ht/", include("health_check.urls")),
path("csw/", include("metadata_catalogue.datasets.csw.urls")),
path("geoapi", landing_page),
path("map-portals/", include("metadata_catalogue.maps.urls", namespace="maps")),
path(
"geoapi/",
include("metadata_catalogue.datasets.geoapi.urls", namespace="geoapi"),
Expand Down
8 changes: 7 additions & 1 deletion metadata_catalogue/maps/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django_filters import rest_framework as filters

from .models import PortalMap
from .models import PortalMap, Portal


class PortalMapFilter(filters.FilterSet):
Expand All @@ -12,3 +12,9 @@ class Meta:

def portal_filter(self, queryset, name, value):
return queryset.filter(portal__uuid=value)


class PortalFilter(filters.FilterSet):
class Meta:
model = Portal
fields = ["visibility"]
17 changes: 17 additions & 0 deletions metadata_catalogue/maps/tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import django_tables2 as tables
from . import models
from django_tables2.utils import A


class PortalTable(tables.Table):
title = tables.LinkColumn("maps:portal-preview", kwargs={"slug": A("uuid")})

class Meta:
model = models.Portal
fields = (
"title",
"uuid",
"visibility",
"owner",
)
template_name = "django_tables2/bootstrap.html"
21 changes: 17 additions & 4 deletions metadata_catalogue/maps/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
from ninja import NinjaAPI
from django.urls import path

from .apis import maps_router
from .views import ConfigJSView, PortalListPage, PortalPreview

api = NinjaAPI()
api.add_router("/maps/", maps_router)
app_name = "maps"

urlpatterns = [
path(
"<uuid:slug>/preview/config.js",
ConfigJSView.as_view(),
name="portal-preview-config",
),
path(
"<uuid:slug>/preview/",
PortalPreview.as_view(),
name="portal-preview",
),
path("", PortalListPage.as_view(), name="portals-list"),
]
36 changes: 36 additions & 0 deletions metadata_catalogue/maps/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.views.generic import DetailView, TemplateView
from django_tables2.views import SingleTableMixin
from django_filters.views import FilterView

from .models import Portal, Visibility
from metadata_catalogue.maps import filters, tables


class ConfigJSView(DetailView):
model = Portal
template_name = "maps/config.js"
content_type = "application/javascript"
slug_field = "uuid"


class PortalPreview(TemplateView):
"""
This is a placeholder, the frontend app will proxied
"""

template_name = "404.html"


class PortalListPage(SingleTableMixin, FilterView):
model = Portal
table_class = tables.PortalTable
filterset_class = filters.PortalFilter
template_name = "maps/portal_list.html"

def get_queryset(self):
qs = super().get_queryset()

if not self.request.user.is_authenticated:
qs = qs.filter(visibility=Visibility.PUBLIC)

return qs
16 changes: 16 additions & 0 deletions metadata_catalogue/templates/maps/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const BASE_URL = window.location.origin;

window.API_URL = `/api/v1/`;
window.PORTAL_KEY = "{{ object.uuid }}";
window.BASE_PATH = "{% url 'maps:portal-preview' slug=object.uuid %}";

window.TRANSFORM_REQUEST = (url, resourceType) => {
if (resourceType === "Style" && url.startsWith(BASE_URL)) {
return {
url: url,
credentials: "include",
};
}
};

window.PLAUSIBLE = null;
18 changes: 18 additions & 0 deletions metadata_catalogue/templates/maps/portal_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'app.html' %}

{% load render_table from django_tables2 %}
{% load crispy_forms_tags %}

{% block article %}
<div>
<div class="flex my-5 justify-between items-center">
<h1 class="font-bold text-4xl">Map portals</h1>
</div>
{% if filter %}
<form action="" method="get" class="flex gap-8">
{% crispy filter.form %}
</form>
{% endif %}
{% render_table table %}
</div>
{% endblock article %}
3 changes: 3 additions & 0 deletions metadata_catalogue/templates/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<div>
<h1 class="text-4xl font-bold">Services Available</h1>
<ul class="list-disc pl-5">
<li>
<a href="{% url 'maps:portals-list' %}">Map portals</a>
</li>
<li>
<a href="{% url 'dataset-list' %}">Datasets</a>
</li>
Expand Down
4 changes: 4 additions & 0 deletions metadata_catalogue/theme/static_src/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@
select {
@apply pr-8 !important;
}

a {
@apply link link-primary;
}
33 changes: 5 additions & 28 deletions nginx/maps.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ server {
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;

location /static/ {
alias /statics/;
Expand All @@ -62,46 +63,22 @@ server {

location @proxy {
proxy_pass http://django_upstream;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
}

location /titiler/ {
proxy_pass http://titiler_upstream;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
}

location /admin/ {
# TODO: use a better solution to upload files, for example s3 + tusd
# allow upload of big file - this is a temporary solution
client_max_body_size 8000M;
client_body_buffer_size 8000M;
client_body_timeout 360;

proxy_pass http://django_upstream;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
location ~ ^\/map-portals\/[\w-]*\/preview\/(?!config\.js).*$ {
rewrite ^\/map-portals\/[\w-]*\/preview(.*)$ $1 break;
proxy_pass http://maps_upstream;
}

location /api/ {
# TODO: use a better solution to upload files, for example s3 + tusd
# allow upload of big file - this is a temporary solution
location / {
client_max_body_size 8000M;
client_body_buffer_size 8000M;
client_body_timeout 360;

proxy_pass http://django_upstream;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location / {
proxy_pass http://maps_upstream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}

0 comments on commit a66a1cf

Please sign in to comment.