Organize settings into categories

This commit is contained in:
James Taylor 2020-10-22 15:00:06 -07:00
parent 5f4884dce8
commit 9f1b69d22f
2 changed files with 32 additions and 5 deletions

View File

@ -20,18 +20,21 @@ SETTINGS_INFO = collections.OrderedDict([
(1, 'On, except video'), (1, 'On, except video'),
(2, 'On, including video (see warnings)'), (2, 'On, including video (see warnings)'),
], ],
'category': 'network',
}), }),
('tor_port', { ('tor_port', {
'type': int, 'type': int,
'default': 9150, 'default': 9150,
'comment': '', 'comment': '',
'category': 'network',
}), }),
('port_number', { ('port_number', {
'type': int, 'type': int,
'default': 8080, 'default': 8080,
'comment': '', 'comment': '',
'category': 'network',
}), }),
('allow_foreign_addresses', { ('allow_foreign_addresses', {
@ -40,6 +43,7 @@ SETTINGS_INFO = collections.OrderedDict([
'comment': '''This will allow others to connect to your Youtube Local instance as a website. 'comment': '''This will allow others to connect to your Youtube Local instance as a website.
For security reasons, enabling this is not recommended.''', For security reasons, enabling this is not recommended.''',
'hidden': True, 'hidden': True,
'category': 'network',
}), }),
('subtitles_mode', { ('subtitles_mode', {
@ -54,12 +58,14 @@ For security reasons, enabling this is not recommended.''',
(1, 'Manually created only'), (1, 'Manually created only'),
(2, 'Automatic if manual unavailable'), (2, 'Automatic if manual unavailable'),
], ],
'category': 'playback',
}), }),
('subtitles_language', { ('subtitles_language', {
'type': str, 'type': str,
'default': 'en', 'default': 'en',
'comment': '''ISO 639 language code: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes''', 'comment': '''ISO 639 language code: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes''',
'category': 'playback',
}), }),
('related_videos_mode', { ('related_videos_mode', {
@ -73,6 +79,7 @@ For security reasons, enabling this is not recommended.''',
(1, 'Always shown'), (1, 'Always shown'),
(2, 'Shown by clicking button'), (2, 'Shown by clicking button'),
], ],
'category': 'interface',
}), }),
('comments_mode', { ('comments_mode', {
@ -86,12 +93,14 @@ For security reasons, enabling this is not recommended.''',
(1, 'Always shown'), (1, 'Always shown'),
(2, 'Shown by clicking button'), (2, 'Shown by clicking button'),
], ],
'category': 'interface',
}), }),
('enable_comment_avatars', { ('enable_comment_avatars', {
'type': bool, 'type': bool,
'default': True, 'default': True,
'comment': '', 'comment': '',
'category': 'interface',
}), }),
('default_comment_sorting', { ('default_comment_sorting', {
@ -109,6 +118,7 @@ For security reasons, enabling this is not recommended.''',
'type': bool, 'type': bool,
'default': True, 'default': True,
'comment': '', 'comment': '',
'category': 'interface',
}), }),
('default_resolution', { ('default_resolution', {
@ -119,6 +129,7 @@ For security reasons, enabling this is not recommended.''',
(360, '360p'), (360, '360p'),
(720, '720p'), (720, '720p'),
], ],
'category': 'playback',
}), }),
('use_video_hotkeys', { ('use_video_hotkeys', {
@ -126,6 +137,7 @@ For security reasons, enabling this is not recommended.''',
'type': bool, 'type': bool,
'default': True, 'default': True,
'comment': '', 'comment': '',
'category': 'interface',
}), }),
('proxy_images', { ('proxy_images', {
@ -133,6 +145,7 @@ For security reasons, enabling this is not recommended.''',
'type': bool, 'type': bool,
'default': True, 'default': True,
'comment': '', 'comment': '',
'category': 'network',
}), }),
('use_comments_js', { ('use_comments_js', {
@ -140,6 +153,7 @@ For security reasons, enabling this is not recommended.''',
'type': bool, 'type': bool,
'default': True, 'default': True,
'comment': '', 'comment': '',
'category': 'interface',
}), }),
('use_sponsorblock_js', { ('use_sponsorblock_js', {
@ -147,6 +161,7 @@ For security reasons, enabling this is not recommended.''',
'type': bool, 'type': bool,
'default': False, 'default': False,
'comment': '', 'comment': '',
'category': 'playback',
}), }),
('theme', { ('theme', {
@ -158,6 +173,7 @@ For security reasons, enabling this is not recommended.''',
(1, 'Gray'), (1, 'Gray'),
(2, 'Dark'), (2, 'Dark'),
], ],
'category': 'interface',
}), }),
('font', { ('font', {
@ -171,6 +187,7 @@ For security reasons, enabling this is not recommended.''',
(3, 'Verdana'), (3, 'Verdana'),
(4, 'Tahoma'), (4, 'Tahoma'),
], ],
'category': 'interface',
}), }),
('autocheck_subscriptions', { ('autocheck_subscriptions', {
@ -362,11 +379,18 @@ set_img_prefix()
add_setting_changed_hook('proxy_images', set_img_prefix) add_setting_changed_hook('proxy_images', set_img_prefix)
categories = ['network', 'interface', 'playback', 'other']
def settings_page(): def settings_page():
if request.method == 'GET': if request.method == 'GET':
settings_by_category = {categ: [] for categ in categories}
for setting_name, setting_info in SETTINGS_INFO.items():
categ = setting_info.get('category', 'other')
settings_by_category[categ].append(
(setting_name, setting_info, current_settings_dict[setting_name])
)
return flask.render_template('settings.html', return flask.render_template('settings.html',
settings = [(setting_name, setting_info, current_settings_dict[setting_name]) for setting_name, setting_info in SETTINGS_INFO.items()] categories = categories,
settings_by_category = settings_by_category,
) )
elif request.method == 'POST': elif request.method == 'POST':
for key, value in request.values.items(): for key, value in request.values.items():

View File

@ -27,8 +27,10 @@
{% block main %} {% block main %}
<form method="POST" class="settings-form"> <form method="POST" class="settings-form">
{% for categ in categories %}
<h2>{{ categ|capitalize }}</h2>
<ul class="settings-list"> <ul class="settings-list">
{% for setting_name, setting_info, value in settings %} {% for setting_name, setting_info, value in settings_by_category[categ] %}
{% if not setting_info.get('hidden', false) %} {% if not setting_info.get('hidden', false) %}
<li class="setting-item"> <li class="setting-item">
{% if 'label' is in(setting_info) %} {% if 'label' is in(setting_info) %}
@ -60,6 +62,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
{% endfor %}
<input type="submit" value="Save settings"> <input type="submit" value="Save settings">
</form> </form>
{% endblock main %} {% endblock main %}