Skip to content

Commit

Permalink
Improving plugins list sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Sep 25, 2024
1 parent 7dceb43 commit d46eff4
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 106 deletions.
10 changes: 9 additions & 1 deletion dockerize/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,12 @@ dbseed:
@echo "------------------------------------------------------------------"
@echo "Seed db with JSON data from /fixtures/*.json"
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) exec devweb bash -c 'python manage.py loaddata fixtures/*.json'
@docker compose -p $(PROJECT_ID) exec devweb bash -c 'python manage.py loaddata fixtures/*.json'

loadmenu:
@echo
@echo "------------------------------------------------------------------"
@echo "Delete all simplemenu entries and load from fixtures/simplemenu.json"
@echo "------------------------------------------------------------------"
@docker compose -p $(PROJECT_ID) devweb python manage.py clear_simplemenu
@docker compose -p $(PROJECT_ID) devweb python manage.py loaddata fixtures/simplemenu.json
4 changes: 4 additions & 0 deletions dockerize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,7 @@ make devweb-runserver
make dbseed
```

- **loadmenu:** Clear all menu entries and load menu from JSON file at `fixtures/simplemenu.json`.
```sh
make loadmenu
```
18 changes: 18 additions & 0 deletions qgis-app/plugins/management/commands/clear_simplemenu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.core.management.base import BaseCommand
from django.apps import apps

class Command(BaseCommand):
help = 'Delete all objects from all models in the simplemenu app'

def handle(self, *args, **kwargs):
# Get all models in the 'simplemenu' app
app_models = apps.get_app_config('simplemenu').get_models()

for model in app_models:
# Delete all objects in the model
model_name = model.__name__
try:
deleted_count, _ = model.objects.all().delete()
self.stdout.write(f'Successfully deleted {deleted_count} objects from {model_name}.')
except Exception as e:
self.stderr.write(f'Failed to delete objects from {model_name}: {str(e)}')
106 changes: 1 addition & 105 deletions qgis-app/plugins/templates/plugins/plugin_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,111 +11,7 @@ <h2>{% trans "QGIS Python Plugins Repository"%}</h2>

{% block menu %}
{{ block.super }}
<nav id="sidebar" class="sidebar">
<ul class="content-wrapper">
<li>
<a class="button is-success is-medium" href="{% url "plugin_upload" %}"><i class="icon-upload icon-white icon-2x" style=" vertical-align: middle;"></i> {% trans "Upload a plugin" %}</a>
</li>
<hr/>
{% get_namedmenu Navigation as menu %}
{% for item in menu %}
<li>
<div>
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</div>
</li>
{% endfor %}
<li>
<div class="has-child">
<a href="">
New & Updated
</a>
</div>
<ul>
{% get_namedmenu New as new %}
{% for item in new %}
<li>
<div>
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</div>
</li>
{% endfor %}
</ul>
</li>
<li>
<div class="has-child">
<a href="">
Top
</a>
</div>
<ul>
{% get_namedmenu Top as Top %}
{% for item in Top %}
<li>
<div>
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</div>
</li>
{% endfor %}
</ul>
</li>
<li>
<div class="has-child">
<a href="">
Category
</a>
</div>
<ul>
{% get_namedmenu Category as Category %}
{% for item in Category %}
<li>
<div>
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</div>
</li>
{% endfor %}
</ul>
</li>
{% if user.is_authenticated and user.is_staff %}
<li>
<div class="has-child">
<a href="">
Under review
</a>
</div>
<ul>
{% get_namedmenu Unapproved as Unapproved %}
{% for item in Unapproved %}
<li>
<div>
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</div>
</li>
{% endfor %}
</ul>
</li>
{% endif %}

<li>
<div>
<a href="">
{% include_plugins_tagcloud_modal 'plugins.plugin' %}
</a>
</div>
</li>
</ul>
</nav>

{% include "plugins/plugin_sidebar.html" %}
{% endblock %}

{% block "credits" %}
Expand Down
148 changes: 148 additions & 0 deletions qgis-app/plugins/templates/plugins/plugin_sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{% load i18n plugins_tagcloud simplemenu_tags static %}
<nav id="sidebar" class="sidebar">
<ul class="content-wrapper">
<li>
<a class="button is-success is-medium" href="{% url "plugin_upload" %}">
<i class="fas fa-upload"></i>
{% trans "Upload a plugin" %}
</a>
</li>
<hr/>
{% get_namedmenu Navigation as menu %}
{% for item in menu %}
<li class="{% if request.path == item.page.url %}is-active{% endif %}">
<a href="{{ item.page.url }}">
{% if item.page.url == "/" %}
<i class="fas fa-home mr-3"></i>
{% elif item.page.url == "/plugins/" %}
<i class="fas fa-plug mr-3"></i>
{% elif item.page.url == "/plugins/my" %}
<i class="fas fa-user mr-3"></i>
{% endif %}
{{ item.name }}
</a>
</li>
{% endfor %}
<li>
<div class="has-child">
<a onclick="toggleSubMenu('news')">
<i class="fas fa-newspaper mr-3"></i>
New & Updated
</a>
<span onclick="toggleSubMenu('news')" class="drop-arrow"><img src="{% static "images/arrow.svg" %}"/></span>
</div>
<ul class="collapsed" id="news">
{% get_namedmenu New as new %}
{% for item in new %}
<li class="has-child {% if request.path == item.page.url %}is-active{% endif %}">
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</li>
{% endfor %}
</ul>
</li>
<li>
<div class="has-child">
<a onclick="toggleSubMenu('top')">
<i class="fas fa-star mr-3"></i>
Top
</a>
<span onclick="toggleSubMenu('top')" class="drop-arrow"><img src="{% static "images/arrow.svg" %}"/></span>
</div>
<ul class="collapsed" id="top">
{% get_namedmenu Top as Top %}
{% for item in Top %}
<li class="has-child {% if request.path == item.page.url %}is-active{% endif %}">
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</li>
{% endfor %}
</ul>
</li>
<li>
<div class="has-child">
<a onclick="toggleSubMenu('category')">
<i class="fas fa-list mr-3"></i>
Category
</a>
<span onclick="toggleSubMenu('category')" class="drop-arrow"><img src="{% static "images/arrow.svg" %}"/></span>
</div>
<ul class="collapsed" id="category">
{% get_namedmenu Category as Category %}
{% for item in Category %}
<li class="has-child {% if request.path == item.page.url %}is-active{% endif %}">
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% if user.is_authenticated and user.is_staff %}
<li>
<div class="has-child">
<a onclick="toggleSubMenu('unapproved')">
<i class="fas fa-check-circle mr-3"></i>
Under review
</a>
<span onclick="toggleSubMenu('unapproved')" class="drop-arrow"><img src="{% static "images/arrow.svg" %}"/></span>
</div>
<ul class="collapsed" id="unapproved">
{% get_namedmenu Unapproved as Unapproved %}
{% for item in Unapproved %}
<li class="has-child {% if request.path == item.page.url %}is-active{% endif %}">
<a href="{{ item.page.url }}">
{{ item.name }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endif %}

<li>
<div>
<a href="">
{% include_plugins_tagcloud_modal 'plugins.plugin' %}
</a>
</div>
</li>
</ul>
</nav>


<script>
function rotateArrow(e) {
e.previousElementSibling.querySelector('img').classList.toggle('rotated');
}

function toggleSubMenu(listId) {
console.log(listId)
let e = document.getElementById(listId);
e.classList.toggle('unfolded');
rotateArrow(e);
}

function toggleMenu() {
document.getElementById('sidebar').classList.toggle('visible');
document.getElementById('hamburger-btn').classList.toggle('open');
}

// compose title for menu button: contatenate parent section titles
{% comment %} let activeListItem = document.getElementsByClassName('is-active')[0];
let ham = document.getElementById('ham-title');
let hamTitle = activeListItem.querySelector('a').textContent;
if (activeListItem.parentElement.previousElementSibling != null) {
hamTitle = activeListItem.parentElement.previousElementSibling.querySelector('a').textContent + ' / ' + hamTitle;
}
ham.textContent = hamTitle; {% endcomment %}

// expand active section
document.querySelectorAll('li.is-active,li:has(.is-active)').forEach(li => {
if (e = li.querySelector('ul')) {
e.classList.toggle('unfolded');
}
});
</script>

0 comments on commit d46eff4

Please sign in to comment.