Add "hidden" property to global settings

- Allows certain settings to be hidden from the javascript files
This commit is contained in:
Oliver 2021-11-11 22:16:46 +11:00
parent 2f3772f3bf
commit 626637a06a
3 changed files with 18 additions and 3 deletions

View File

@ -69,7 +69,7 @@ class BaseInvenTreeSetting(models.Model):
super().save()
@classmethod
def allValues(cls, user=None):
def allValues(cls, user=None, exclude_hidden=False):
"""
Return a dict of "all" defined global settings.
@ -94,9 +94,15 @@ class BaseInvenTreeSetting(models.Model):
for key in cls.GLOBAL_SETTINGS.keys():
if key.upper() not in settings:
settings[key.upper()] = cls.get_setting_default(key)
if exclude_hidden:
hidden = cls.GLOBAL_SETTINGS[key].get('hidden', False)
if hidden:
# Remove hidden items
del settings[key.upper()]
for key, value in settings.items():
validator = cls.get_setting_validator(key)

View File

@ -251,6 +251,15 @@ def global_settings(*args, **kwargs):
return InvenTreeSetting.allValues()
@register.simple_tag()
def visible_global_settings(*args, **kwargs):
"""
Return any global settings which are not marked as 'hidden'
"""
return InvenTreeSetting.allValues(exclude_hidden=True)
@register.simple_tag()
def progress_bar(val, max, *args, **kwargs):
"""

View File

@ -13,7 +13,7 @@ const user_settings = {
{% endfor %}
};
{% global_settings as GLOBAL_SETTINGS %}
{% visible_global_settings as GLOBAL_SETTINGS %}
const global_settings = {
{% for key, value in GLOBAL_SETTINGS.items %}
{{ key }}: {% primitive_to_javascript value %},