summaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/web_ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/proxy/web_ui')
-rw-r--r--src/hydrilla/proxy/web_ui/options.py70
-rw-r--r--src/hydrilla/proxy/web_ui/root.py36
-rw-r--r--src/hydrilla/proxy/web_ui/templates/base.html.jinja1
-rw-r--r--src/hydrilla/proxy/web_ui/templates/index.html.jinja89
-rw-r--r--src/hydrilla/proxy/web_ui/templates/options.html.jinja112
5 files changed, 119 insertions, 189 deletions
diff --git a/src/hydrilla/proxy/web_ui/options.py b/src/hydrilla/proxy/web_ui/options.py
deleted file mode 100644
index 7d59375..0000000
--- a/src/hydrilla/proxy/web_ui/options.py
+++ /dev/null
@@ -1,70 +0,0 @@
-# SPDX-License-Identifier: GPL-3.0-or-later
-
-# Proxy web UI options page.
-#
-# This file is part of Hydrilla&Haketilo.
-#
-# Copyright (C) 2022 Wojtek Kosior
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <https://www.gnu.org/licenses/>.
-#
-#
-# I, Wojtek Kosior, thereby promise not to sue for violation of this
-# file's license. Although I request that you do not make use of this
-# code in a proprietary program, I am not going to enforce this in
-# court.
-
-# Enable using with Python 3.7.
-from __future__ import annotations
-
-import typing as t
-
-import flask
-import werkzeug
-
-from .. import state as st
-from . import _app
-
-
-bp = flask.Blueprint('options', __package__)
-
-@bp.route('/options', methods=['GET'])
-def options(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response:
- html = flask.render_template('options.html.jinja', **errors)
- return flask.make_response(html, 200)
-
-@bp.route('/options', methods=['POST'])
-def options_post() -> werkzeug.Response:
- action = flask.request.form['action']
-
- state = _app.get_haketilo_state()
-
- if action == 'use_enabled':
- state.update_settings(mapping_use_mode=st.MappingUseMode.WHEN_ENABLED)
- elif action == 'use_auto':
- state.update_settings(mapping_use_mode=st.MappingUseMode.AUTO)
- elif action == 'use_question':
- state.update_settings(mapping_use_mode=st.MappingUseMode.QUESTION)
- elif action == 'allow_scripts':
- state.update_settings(default_allow_scripts=True)
- elif action == 'block_scripts':
- state.update_settings(default_allow_scripts=False)
- elif action == 'user_make_advanced':
- state.update_settings(advanced_user=True)
- elif action == 'user_make_simple':
- state.update_settings(advanced_user=False)
- else:
- raise ValueError()
-
- return flask.redirect(flask.url_for('.options'), 303)
diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py
index 21c491b..a28fde8 100644
--- a/src/hydrilla/proxy/web_ui/root.py
+++ b/src/hydrilla/proxy/web_ui/root.py
@@ -45,7 +45,6 @@ from ...translations import translation as make_translation
from ... import item_infos
from .. import state as st
from .. import http_messages
-from . import options
from . import rules
from . import repos
from . import items
@@ -100,7 +99,7 @@ class WebUIAppImpl(_app.WebUIApp):
self.before_request(authenticate_by_referrer)
- for blueprint in [rules.bp, repos.bp, items.bp, prompts.bp, options.bp]:
+ for blueprint in [rules.bp, repos.bp, items.bp, prompts.bp]:
self.register_blueprint(blueprint)
# Flask app is not thread-safe and has to be accompanied by an ugly lock. This
@@ -110,10 +109,35 @@ app = WebUIAppImpl()
app_lock = Lock()
-@app.route('/')
-def home() -> str:
- return flask.render_template('index.html.jinja')
-
+@app.route('/', methods=['GET'])
+def home(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response:
+ html = flask.render_template('index.html.jinja', **errors)
+ return flask.make_response(html, 200)
+
+@app.route('/', methods=['POST'])
+def home_post() -> werkzeug.Response:
+ action = flask.request.form['action']
+
+ state = _app.get_haketilo_state()
+
+ if action == 'use_enabled':
+ state.update_settings(mapping_use_mode=st.MappingUseMode.WHEN_ENABLED)
+ elif action == 'use_auto':
+ state.update_settings(mapping_use_mode=st.MappingUseMode.AUTO)
+ elif action == 'use_question':
+ state.update_settings(mapping_use_mode=st.MappingUseMode.QUESTION)
+ elif action == 'allow_scripts':
+ state.update_settings(default_allow_scripts=True)
+ elif action == 'block_scripts':
+ state.update_settings(default_allow_scripts=False)
+ elif action == 'user_make_advanced':
+ state.update_settings(advanced_user=True)
+ elif action == 'user_make_simple':
+ state.update_settings(advanced_user=False)
+ else:
+ raise ValueError()
+
+ return flask.redirect(flask.url_for('.home'), 303)
def process_request(
request_info: http_messages.RequestInfo,
diff --git a/src/hydrilla/proxy/web_ui/templates/base.html.jinja b/src/hydrilla/proxy/web_ui/templates/base.html.jinja
index 37930e2..c0eecce 100644
--- a/src/hydrilla/proxy/web_ui/templates/base.html.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/base.html.jinja
@@ -239,7 +239,6 @@ code in a proprietary work, I am not going to enforce this in court.
{%
set navigation_bar = [
('home', _('web_ui.base.nav.home'), false),
- ('options.options', _('web_ui.base.nav.options'), false),
('rules.rules', _('web_ui.base.nav.rules'), false),
('items.packages', _('web_ui.base.nav.packages'), false),
('items.libraries', _('web_ui.base.nav.libraries'), true),
diff --git a/src/hydrilla/proxy/web_ui/templates/index.html.jinja b/src/hydrilla/proxy/web_ui/templates/index.html.jinja
index b0c0b36..d95937a 100644
--- a/src/hydrilla/proxy/web_ui/templates/index.html.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/index.html.jinja
@@ -40,4 +40,93 @@ code in a proprietary work, I am not going to enforce this in court.
<p>
{{ _('web_ui.home.haketilo_is_blah_blah') }}
</p>
+
+ <div class="horizontal-separator"></div>
+
+ <h4>
+ {{ _('web_ui.home.heading.options') }}
+ </h4>
+
+ {% set use_enabled_but_classes = ['green-button'] %}
+ {% set use_auto_but_classes = ['green-button'] %}
+ {% set use_question_but_classes = ['green-button'] %}
+
+ <p>
+ {% if settings.mapping_use_mode == MappingUseMode.WHEN_ENABLED %}
+ {% do use_enabled_but_classes.append('disabled-button') %}
+ {{ _('web_ui.home.packages_are_used_when_enabled') }}
+ {% elif settings.mapping_use_mode == MappingUseMode.QUESTION %}
+ {% do use_question_but_classes.append('disabled-button') %}
+ {{ _('web_ui.home.user_gets_asked_whether_to_enable_package') }}
+ {% else %}
+ {# settings.mapping_use_mode == MappingUseMode.AUTO #}
+ {% do use_auto_but_classes.append('disabled-button') %}
+ {{ _('web_ui.home.packages_are_used_automatically') }}
+ {% endif %}
+ </p>
+
+ {{
+ button_row([
+ (use_enabled_but_classes,
+ _('web_ui.home.use_enabled_button'),
+ {'action': 'use_enabled'}),
+ (use_question_but_classes,
+ _('web_ui.home.use_question_button'),
+ {'action': 'use_question'}),
+ (use_auto_but_classes,
+ _('web_ui.home.use_auto_button'),
+ {'action': 'use_auto'})
+ ])
+ }}
+
+ <div class="horizontal-separator"></div>
+
+ {% set allow_but_classes = ['red-button'] %}
+ {% set block_but_classes = ['blue-button'] %}
+
+ <p>
+ {% if settings.default_allow_scripts %}
+ {% do allow_but_classes.append('disabled-button') %}
+ {{ _('web_ui.home.scripts_are_allowed_by_default') }}
+ {% else %}
+ {% do block_but_classes.append('disabled-button') %}
+ {{ _('web_ui.home.scripts_are_blocked_by_default') }}
+ {% endif %}
+ </p>
+
+ {% set allow_but_text = _('web_ui.home.allow_scripts_button') %}
+ {% set block_but_text = _('web_ui.home.block_scripts_button') %}
+
+ {{
+ button_row([
+ (allow_but_classes, allow_but_text, {'action': 'allow_scripts'}),
+ (block_but_classes, block_but_text, {'action': 'block_scripts'})
+ ])
+ }}
+
+ <div class="horizontal-separator"></div>
+
+ {% set advanced_user_but_classes = ['red-button'] %}
+ {% set simple_user_but_classes = ['blue-button'] %}
+
+ <p>
+ {% if settings.advanced_user %}
+ {% do advanced_user_but_classes.append('disabled-button') %}
+ {{ _('web_ui.home.user_is_advanced_user') }}
+ {% else %}
+ {% do simple_user_but_classes.append('disabled-button') %}
+ {{ _('web_ui.home.user_is_simple_user') }}
+ {% endif %}
+ </p>
+
+ {{
+ button_row([
+ (advanced_user_but_classes,
+ _('web_ui.home.user_make_advanced_button'),
+ {'action': 'user_make_advanced'}),
+ (simple_user_but_classes,
+ _('web_ui.home.user_make_simple_button'),
+ {'action': 'user_make_simple'})
+ ])
+ }}
{% endblock %}
diff --git a/src/hydrilla/proxy/web_ui/templates/options.html.jinja b/src/hydrilla/proxy/web_ui/templates/options.html.jinja
deleted file mode 100644
index 26519c4..0000000
--- a/src/hydrilla/proxy/web_ui/templates/options.html.jinja
+++ /dev/null
@@ -1,112 +0,0 @@
-{#
-SPDX-License-Identifier: GPL-3.0-or-later OR CC-BY-SA-4.0
-
-Proxy web UI settings page.
-
-This file is part of Hydrilla&Haketilo.
-
-Copyright (C) 2022 Wojtek Kosior
-
-Dual licensed under
-* GNU General Public License v3.0 or later and
-* Creative Commons Attribution Share Alike 4.0 International.
-
-You can choose to use either of these licenses or both.
-
-
-I, Wojtek Kosior, thereby promise not to sue for violation of this
-file's licenses. Although I request that you do not make use of this
-code in a proprietary work, I am not going to enforce this in court.
-#}
-{% extends "base.html.jinja" %}
-
-{% block title %} {{ _('web_ui.options.title') }} {% endblock %}
-
-{% block main %}
- <h3>
- {{ _('web_ui.options.heading') }}
- </h3>
-
- {% set use_enabled_but_classes = ['green-button'] %}
- {% set use_auto_but_classes = ['green-button'] %}
- {% set use_question_but_classes = ['green-button'] %}
-
- <p>
- {% if settings.mapping_use_mode == MappingUseMode.WHEN_ENABLED %}
- {% do use_enabled_but_classes.append('disabled-button') %}
- {{ _('web_ui.options.packages_are_used_when_enabled') }}
- {% elif settings.mapping_use_mode == MappingUseMode.QUESTION %}
- {% do use_question_but_classes.append('disabled-button') %}
- {{ _('web_ui.options.user_gets_asked_whether_to_enable_package') }}
- {% else %}
- {# settings.mapping_use_mode == MappingUseMode.AUTO #}
- {% do use_auto_but_classes.append('disabled-button') %}
- {{ _('web_ui.options.packages_are_used_automatically') }}
- {% endif %}
- </p>
-
- {{
- button_row([
- (use_enabled_but_classes,
- _('web_ui.options.use_enabled_button'),
- {'action': 'use_enabled'}),
- (use_question_but_classes,
- _('web_ui.options.use_question_button'),
- {'action': 'use_question'}),
- (use_auto_but_classes,
- _('web_ui.options.use_auto_button'),
- {'action': 'use_auto'})
- ])
- }}
-
- <div class="horizontal-separator"></div>
-
- {% set allow_but_classes = ['red-button'] %}
- {% set block_but_classes = ['green-button'] %}
-
- <p>
- {% if settings.default_allow_scripts %}
- {% do allow_but_classes.append('disabled-button') %}
- {{ _('web_ui.options.scripts_are_allowed_by_default') }}
- {% else %}
- {% do block_but_classes.append('disabled-button') %}
- {{ _('web_ui.options.scripts_are_blocked_by_default') }}
- {% endif %}
- </p>
-
- {% set allow_but_text = _('web_ui.options.allow_scripts_button') %}
- {% set block_but_text = _('web_ui.options.block_scripts_button') %}
-
- {{
- button_row([
- (allow_but_classes, allow_but_text, {'action': 'allow_scripts'}),
- (block_but_classes, block_but_text, {'action': 'block_scripts'})
- ])
- }}
-
- <div class="horizontal-separator"></div>
-
- {% set advanced_user_but_classes = ['red-button'] %}
- {% set simple_user_but_classes = ['green-button'] %}
-
- <p>
- {% if settings.advanced_user %}
- {% do advanced_user_but_classes.append('disabled-button') %}
- {{ _('web_ui.options.user_is_advanced_user') }}
- {% else %}
- {% do simple_user_but_classes.append('disabled-button') %}
- {{ _('web_ui.options.user_is_simple_user') }}
- {% endif %}
- </p>
-
- {{
- button_row([
- (advanced_user_but_classes,
- _('web_ui.options.user_make_advanced_button'),
- {'action': 'user_make_advanced'}),
- (simple_user_but_classes,
- _('web_ui.options.user_make_simple_button'),
- {'action': 'user_make_simple'})
- ])
- }}
-{% endblock %}