Add very basic user dashboard
This commit is contained in:
parent
3592307b4e
commit
4d0ced9a98
8 changed files with 120 additions and 17 deletions
|
@ -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 */
|
||||
/* **************************** */
|
||||
|
|
29
umap/templates/umap/map_table.html
Normal file
29
umap/templates/umap/map_table.html
Normal 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>
|
|
@ -9,7 +9,7 @@
|
|||
<ul>
|
||||
{% if user.is_authenticated %}
|
||||
<li>
|
||||
<a href="{{ user.get_url }}">{% trans "My maps" %} ({{ user }})</a>
|
||||
<a href="{% url 'user_dashboard' %}">{% trans "My maps" %} ({{ user }})</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ user.get_stars_url }}">{% trans "Starred maps" %}</a>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{% include "umap/search_bar.html" %}
|
||||
<div class="wrapper">
|
||||
<div class="map_list row">
|
||||
{% if q %}
|
||||
{% if request.GET.q %}
|
||||
{% if maps %}
|
||||
<h2>
|
||||
{% blocktranslate trimmed count counter=count %}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
{% load i18n %}
|
||||
{% url "search" as search_url %}
|
||||
{% trans "Search maps" as default_placeholder %}
|
||||
<div class="wrapper search_wrapper">
|
||||
<div class="row">
|
||||
<form action="{% url "search" %}" method="get">
|
||||
<form action="{% firstof action search_url %}" method="get">
|
||||
<div class="col two-third mwide">
|
||||
<input name="q"
|
||||
type="search"
|
||||
placeholder="{% trans "Search maps" %}"
|
||||
value="{{ q|default:"" }}" />
|
||||
placeholder="{% firstof placeholder default_placeholder %}"
|
||||
value="{{ request.GET.q|default:"" }}" />
|
||||
</div>
|
||||
<div class="col third mwide">
|
||||
<input type="submit" value="{% trans "Search" %}" class="neutral" />
|
||||
|
|
20
umap/templates/umap/user_dashboard.html
Normal file
20
umap/templates/umap/user_dashboard.html
Normal 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 %}
|
|
@ -98,6 +98,11 @@ i18n_urls += decorated_patterns(
|
|||
views.ToggleMapStarStatus.as_view(),
|
||||
name="map_star",
|
||||
),
|
||||
re_path(
|
||||
r"^me$",
|
||||
views.user_dashboard,
|
||||
name="user_dashboard",
|
||||
),
|
||||
)
|
||||
map_urls = [
|
||||
re_path(
|
||||
|
|
|
@ -96,7 +96,6 @@ class PaginatorMixin(object):
|
|||
|
||||
|
||||
class PublicMapsMixin(object):
|
||||
|
||||
def get_public_maps(self):
|
||||
qs = Map.public
|
||||
if (
|
||||
|
@ -216,26 +215,32 @@ class UserStars(UserMaps):
|
|||
user_stars = UserStars.as_view()
|
||||
|
||||
|
||||
class Search(TemplateView, PublicMapsMixin, PaginatorMixin):
|
||||
template_name = "umap/search.html"
|
||||
list_template_name = "umap/map_list.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
class SearchMixin:
|
||||
def get_search_queryset(self, **kwargs):
|
||||
q = self.request.GET.get("q")
|
||||
qs_count = 0
|
||||
results = []
|
||||
if q:
|
||||
vector = SearchVector("name", config=settings.UMAP_SEARCH_CONFIGURATION)
|
||||
query = SearchQuery(
|
||||
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_count = qs.count()
|
||||
results = self.paginate(qs)
|
||||
else:
|
||||
results = self.get_public_maps()[:settings.UMAP_MAPS_PER_SEARCH]
|
||||
kwargs.update({"maps": results, "count": qs_count, "q": q})
|
||||
results = self.get_public_maps()[: settings.UMAP_MAPS_PER_SEARCH]
|
||||
kwargs.update({"maps": results, "count": qs_count})
|
||||
return kwargs
|
||||
|
||||
def get_template_names(self):
|
||||
|
@ -255,6 +260,28 @@ class Search(TemplateView, PublicMapsMixin, PaginatorMixin):
|
|||
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):
|
||||
def get(self, *args, **kwargs):
|
||||
maps = Map.public.filter(center__distance_gt=(DEFAULT_CENTER, D(km=1)))
|
||||
|
@ -436,7 +463,7 @@ class MapDetailMixin:
|
|||
properties["user"] = {
|
||||
"id": user.pk,
|
||||
"name": str(user),
|
||||
"url": user.get_url(),
|
||||
"url": reverse("user_dashboard"),
|
||||
}
|
||||
map_settings = self.get_geojson()
|
||||
if "properties" not in map_settings:
|
||||
|
|
Loading…
Reference in a new issue