Add very basic user dashboard

This commit is contained in:
Yohan Boniface 2023-07-04 16:09:12 +02:00
parent 3592307b4e
commit 4d0ced9a98
8 changed files with 120 additions and 17 deletions

View file

@ -282,6 +282,26 @@ ul.umap-autocomplete {
} }
/* **************************** */
/* Dashboard */
/* **************************** */
table.maps {
width: 100%;
}
table.maps .map_fragment {
height: 100px;
width: 100%;
min-width: 200px;
}
table.maps tr:nth-child(even) {
background-color: #f4f4f4;
}
table.maps td {
text-align: center;
}
/* **************************** */ /* **************************** */
/* Override Leaflet.Storage */ /* Override Leaflet.Storage */
/* **************************** */ /* **************************** */

View file

@ -0,0 +1,29 @@
{% load umap_tags umap_tags i18n %}
<table class="maps">
<tr>
<th></th>
<th></th>
<th>{% blocktrans %}Status{% endblocktrans %}</th>
<th>{% blocktrans %}Last save{% endblocktrans %}</th>
<th>{% blocktrans %}Owner{% endblocktrans %}</th>
<th>{% blocktrans %}Actions{% endblocktrans %}</th>
</tr>
{% for map_inst in maps %}
<tr>
<td>{% map_fragment map_inst prefix=prefix page=request.GET.p %}</td>
<td>
<a href="{{ map_inst.get_absolute_url }}">{{ map_inst.name }}</a>
</td>
<td>{{ map_inst.get_edit_status_display }}</td>
<td>{{ map_inst.modified_at }}</td>
<td>
<a href="{{ map_inst.owner.get_url }}">{{ map_inst.owner }}</a>
</td>
<td>
<a href="{{ map_inst.get_absolute_url }}?onLoadPanel=share">{% translate "Share" %}</a>
<a href="{{ map_inst.get_absolute_url }}?edit">{% translate "Edit" %}</a>
<a href="{{ map_inst.get_absolute_url }}?download">{% translate "Download" %}</a>
</td>
</tr>
{% endfor %}
</table>

View file

@ -9,7 +9,7 @@
<ul> <ul>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li> <li>
<a href="{{ user.get_url }}">{% trans "My maps" %} ({{ user }})</a> <a href="{% url 'user_dashboard' %}">{% trans "My maps" %} ({{ user }})</a>
</li> </li>
<li> <li>
<a href="{{ user.get_stars_url }}">{% trans "Starred maps" %}</a> <a href="{{ user.get_stars_url }}">{% trans "Starred maps" %}</a>

View file

@ -4,7 +4,7 @@
{% include "umap/search_bar.html" %} {% include "umap/search_bar.html" %}
<div class="wrapper"> <div class="wrapper">
<div class="map_list row"> <div class="map_list row">
{% if q %} {% if request.GET.q %}
{% if maps %} {% if maps %}
<h2> <h2>
{% blocktranslate trimmed count counter=count %} {% blocktranslate trimmed count counter=count %}

View file

@ -1,12 +1,14 @@
{% load i18n %} {% load i18n %}
{% url "search" as search_url %}
{% trans "Search maps" as default_placeholder %}
<div class="wrapper search_wrapper"> <div class="wrapper search_wrapper">
<div class="row"> <div class="row">
<form action="{% url "search" %}" method="get"> <form action="{% firstof action search_url %}" method="get">
<div class="col two-third mwide"> <div class="col two-third mwide">
<input name="q" <input name="q"
type="search" type="search"
placeholder="{% trans "Search maps" %}" placeholder="{% firstof placeholder default_placeholder %}"
value="{{ q|default:"" }}" /> value="{{ request.GET.q|default:"" }}" />
</div> </div>
<div class="col third mwide"> <div class="col third mwide">
<input type="submit" value="{% trans "Search" %}" class="neutral" /> <input type="submit" value="{% trans "Search" %}" class="neutral" />

View file

@ -0,0 +1,20 @@
{% extends "umap/content.html" %}
{% load i18n %}
{% block maincontent %}
{% trans "Search my maps" as placeholder %}
<div class="col wide">
<h2 class="section">{% blocktrans %}My dashboard{% endblocktrans %}</h2>
{% include "umap/search_bar.html" with action=request.get_full_path placeholder=placeholder %}
</div>
<div class="wrapper">
<div class="row">
{% if maps %}
{% include "umap/map_table.html" %}
{% else %}
<div>
{% blocktrans %}You have no map yet.{% endblocktrans %} <a href="{% url 'map_new' %}">{% translate "Create a map" %}</a>
</div>
{% endif %}
</div>
</div>
{% endblock maincontent %}

View file

@ -98,6 +98,11 @@ i18n_urls += decorated_patterns(
views.ToggleMapStarStatus.as_view(), views.ToggleMapStarStatus.as_view(),
name="map_star", name="map_star",
), ),
re_path(
r"^me$",
views.user_dashboard,
name="user_dashboard",
),
) )
map_urls = [ map_urls = [
re_path( re_path(

View file

@ -96,7 +96,6 @@ class PaginatorMixin(object):
class PublicMapsMixin(object): class PublicMapsMixin(object):
def get_public_maps(self): def get_public_maps(self):
qs = Map.public qs = Map.public
if ( if (
@ -216,26 +215,32 @@ class UserStars(UserMaps):
user_stars = UserStars.as_view() user_stars = UserStars.as_view()
class Search(TemplateView, PublicMapsMixin, PaginatorMixin): class SearchMixin:
template_name = "umap/search.html" def get_search_queryset(self, **kwargs):
list_template_name = "umap/map_list.html"
def get_context_data(self, **kwargs):
q = self.request.GET.get("q") q = self.request.GET.get("q")
qs_count = 0
results = []
if q: if q:
vector = SearchVector("name", config=settings.UMAP_SEARCH_CONFIGURATION) vector = SearchVector("name", config=settings.UMAP_SEARCH_CONFIGURATION)
query = SearchQuery( query = SearchQuery(
q, config=settings.UMAP_SEARCH_CONFIGURATION, search_type="websearch" q, config=settings.UMAP_SEARCH_CONFIGURATION, search_type="websearch"
) )
qs = Map.objects.annotate(search=vector).filter(search=query) return Map.objects.annotate(search=vector).filter(search=query)
class Search(TemplateView, PublicMapsMixin, PaginatorMixin, SearchMixin):
template_name = "umap/search.html"
list_template_name = "umap/map_list.html"
def get_context_data(self, **kwargs):
qs = self.get_search_queryset()
qs_count = 0
results = []
if qs:
qs = qs.filter(share_status=Map.PUBLIC).order_by("-modified_at") qs = qs.filter(share_status=Map.PUBLIC).order_by("-modified_at")
qs_count = qs.count() qs_count = qs.count()
results = self.paginate(qs) results = self.paginate(qs)
else: else:
results = self.get_public_maps()[: settings.UMAP_MAPS_PER_SEARCH] results = self.get_public_maps()[: settings.UMAP_MAPS_PER_SEARCH]
kwargs.update({"maps": results, "count": qs_count, "q": q}) kwargs.update({"maps": results, "count": qs_count})
return kwargs return kwargs
def get_template_names(self): def get_template_names(self):
@ -255,6 +260,28 @@ class Search(TemplateView, PublicMapsMixin, PaginatorMixin):
search = Search.as_view() search = Search.as_view()
class UserDashboard(DetailView, PaginatorMixin, SearchMixin):
model = User
template_name = "umap/user_dashboard.html"
def get_object(self):
return self.get_queryset().get(pk=self.request.user.pk)
def get_maps(self):
qs = self.get_search_queryset() or Map.objects.all()
qs = qs.filter(Q(owner=self.object) | Q(editors=self.object))
return qs.order_by("-modified_at")
def get_context_data(self, **kwargs):
kwargs.update(
{"maps": self.paginate(self.get_maps(), settings.UMAP_MAPS_PER_PAGE_OWNER)}
)
return super().get_context_data(**kwargs)
user_dashboard = UserDashboard.as_view()
class MapsShowCase(View): class MapsShowCase(View):
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
maps = Map.public.filter(center__distance_gt=(DEFAULT_CENTER, D(km=1))) maps = Map.public.filter(center__distance_gt=(DEFAULT_CENTER, D(km=1)))
@ -436,7 +463,7 @@ class MapDetailMixin:
properties["user"] = { properties["user"] = {
"id": user.pk, "id": user.pk,
"name": str(user), "name": str(user),
"url": user.get_url(), "url": reverse("user_dashboard"),
} }
map_settings = self.get_geojson() map_settings = self.get_geojson()
if "properties" not in map_settings: if "properties" not in map_settings: