Make the sticky navbar an option

This commit is contained in:
Julian Pollinger
2021-01-07 18:49:11 +01:00
parent 19df1cf65d
commit 251bd88f70
7 changed files with 42 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ class UserPreferenceForm(forms.ModelForm):
class Meta:
model = UserPreference
fields = ('default_unit', 'use_fractions', 'theme', 'nav_color', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals', 'shopping_auto_sync', 'comments')
fields = ('default_unit', 'use_fractions', 'theme', 'nav_color', 'sticky_navbar', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals', 'shopping_auto_sync', 'comments')
help_texts = {
'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'),
@@ -42,7 +42,8 @@ class UserPreferenceForm(forms.ModelForm):
'comments': _('If you want to be able to create and see comments underneath recipes.'),
'shopping_auto_sync': _(
'Setting to 0 will disable auto sync. When viewing a shopping list the list is updated every set seconds to sync changes someone else might have made. Useful when shopping with multiple people but might use a little bit '
'of mobile data. If lower than instance limit it is reset when saving.')
'of mobile data. If lower than instance limit it is reset when saving.'),
'sticky_navbar': _('Makes the navbar stick to the top of the page.')
}
widgets = {

View File

@@ -0,0 +1,24 @@
# Generated by Django 3.1.5 on 2021-01-07 17:04
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0094_auto_20201231_1238'),
]
operations = [
migrations.AddField(
model_name='userpreference',
name='sticky_navbar',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='invitelink',
name='valid_until',
field=models.DateField(default=datetime.date(2021, 1, 21)),
),
]

View File

@@ -10,7 +10,7 @@ from django.utils.translation import gettext as _
from django.db import models
from django_random_queryset import RandomManager
from recipes.settings import COMMENT_PREF_DEFAULT, FRACTION_PREF_DEFAULT
from recipes.settings import COMMENT_PREF_DEFAULT, FRACTION_PREF_DEFAULT, STICKY_NAV_PREF_DEFAULT
def get_user_name(self):
@@ -78,6 +78,7 @@ class UserPreference(models.Model):
ingredient_decimals = models.IntegerField(default=2)
comments = models.BooleanField(default=COMMENT_PREF_DEFAULT)
shopping_auto_sync = models.IntegerField(default=5)
sticky_navbar = models.BooleanField(default=STICKY_NAV_PREF_DEFAULT)
def __str__(self):
return str(self.user)

View File

@@ -48,7 +48,7 @@
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-{% nav_color request %}" id="id_main_nav" style="position: sticky; top: 0; left: 0; z-index:1000">
<nav class="navbar navbar-expand-lg navbar-dark bg-{% nav_color request %}" id="id_main_nav" style="{% sticky_nav request %}">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>

View File

@@ -2,6 +2,7 @@ from django import template
from django.templatetags.static import static
from cookbook.models import UserPreference
from recipes.settings import STICKY_NAV_PREF_DEFAULT
register = template.Library()
@@ -29,6 +30,15 @@ def nav_color(request):
return request.user.userpreference.nav_color.lower()
@register.simple_tag
def sticky_nav(request):
if (not request.user.is_authenticated and STICKY_NAV_PREF_DEFAULT) or \
(request.user.is_authenticated and request.user.userpreference.sticky_navbar):
return 'position: sticky; top: 0; left: 0; z-index:1000'
else:
return ''
@register.simple_tag
def tabulator_theme_url(request):
if not request.user.is_authenticated:

View File

@@ -212,6 +212,7 @@ def user_settings(request):
up.ingredient_decimals = form.cleaned_data['ingredient_decimals']
up.comments = form.cleaned_data['comments']
up.use_fractions = form.cleaned_data['use_fractions']
up.sticky_navbar = form.cleaned_data['sticky_navbar']
up.shopping_auto_sync = form.cleaned_data['shopping_auto_sync']
if up.shopping_auto_sync < settings.SHOPPING_MIN_AUTOSYNC_INTERVAL:

View File

@@ -32,6 +32,7 @@ REVERSE_PROXY_AUTH = bool(int(os.getenv('REVERSE_PROXY_AUTH', False)))
# default value for user preference 'comment'
COMMENT_PREF_DEFAULT = bool(int(os.getenv('COMMENT_PREF_DEFAULT', True)))
FRACTION_PREF_DEFAULT = bool(int(os.getenv('FRACTION_PREF_DEFAULT', False)))
STICKY_NAV_PREF_DEFAULT = bool(int(os.getenv('STICKY_NAV_PREF_DEFAULT', True)))
# minimum interval that users can set for automatic sync of shopping lists
SHOPPING_MIN_AUTOSYNC_INTERVAL = int(os.getenv('SHOPPING_MIN_AUTOSYNC_INTERVAL', 5))