diff options
Diffstat (limited to 'src/hydrilla/proxy/web_ui')
9 files changed, 135 insertions, 111 deletions
diff --git a/src/hydrilla/proxy/web_ui/items.py b/src/hydrilla/proxy/web_ui/items.py index ec394ee..6195107 100644 --- a/src/hydrilla/proxy/web_ui/items.py +++ b/src/hydrilla/proxy/web_ui/items.py @@ -177,7 +177,6 @@ def show_item_version( f'items/{item_type.alt_name}_viewversion.html.jinja', display_info = display_info, version_display_info = this_info, - settings = state.get_settings(), **errors ) return flask.make_response(html, 200) diff --git a/src/hydrilla/proxy/web_ui/options.py b/src/hydrilla/proxy/web_ui/options.py index 9be1ae0..7d59375 100644 --- a/src/hydrilla/proxy/web_ui/options.py +++ b/src/hydrilla/proxy/web_ui/options.py @@ -41,11 +41,7 @@ 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', - settings = _app.get_haketilo_state().get_settings(), - **errors - ) + html = flask.render_template('options.html.jinja', **errors) return flask.make_response(html, 200) @bp.route('/options', methods=['POST']) @@ -64,6 +60,10 @@ def options_post() -> werkzeug.Response: 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() diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py index ed030d2..21c491b 100644 --- a/src/hydrilla/proxy/web_ui/root.py +++ b/src/hydrilla/proxy/web_ui/root.py @@ -64,11 +64,14 @@ def authenticate_by_referrer() -> t.Optional[werkzeug.Response]: flask.abort(403) -def get_current_endpoint() -> t.Optional[str]: +def get_current_endpoint() -> str: endpoint = flask.request.endpoint assert endpoint is not None return endpoint +def get_settings() -> st.HaketiloGlobalSettings: + return _app.get_haketilo_state().get_settings() + class WebUIAppImpl(_app.WebUIApp): def __init__(self): @@ -87,6 +90,7 @@ class WebUIAppImpl(_app.WebUIApp): } self.jinja_env.globals['get_current_endpoint'] = get_current_endpoint + self.jinja_env.globals['get_settings'] = get_settings self.jinja_env.globals['EnabledStatus'] = st.EnabledStatus self.jinja_env.globals['FrozenStatus'] = st.FrozenStatus self.jinja_env.globals['InstalledStatus'] = st.InstalledStatus diff --git a/src/hydrilla/proxy/web_ui/templates/base.html.jinja b/src/hydrilla/proxy/web_ui/templates/base.html.jinja index ff9fd71..493398a 100644 --- a/src/hydrilla/proxy/web_ui/templates/base.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/base.html.jinja @@ -20,6 +20,8 @@ code in a proprietary work, I am not going to enforce this in court. -#} <!DOCTYPE html> +{% set settings = get_settings() %} + {% macro button_row(buttons_data, common_fields={}) %} <div class="flex-row"> {% for classes, text, extra_fields in buttons_data %} @@ -236,17 +238,20 @@ code in a proprietary work, I am not going to enforce this in court. {% set active_endpoint = get_current_endpoint() %} {% set navigation_bar = [ - ('home', _('web_ui.base.nav.home')), - ('options.options', _('web_ui.base.nav.options')), - ('rules.rules', _('web_ui.base.nav.rules')), - ('items.packages', _('web_ui.base.nav.packages')), - ('items.libraries', _('web_ui.base.nav.libraries')), - ('repos.repos', _('web_ui.base.nav.repos')), - ('items.load_from_disk', _('web_ui.base.nav.load')) + ('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), + ('repos.repos', _('web_ui.base.nav.repos'), false), + ('items.load_from_disk', _('web_ui.base.nav.load'), false) ] %} <ul id="nav"> - {% for endpoint, label in navigation_bar %} + {% + for endpoint, label, advanced_user_only in navigation_bar + if not advanced_user_only or settings.advanced_user + %} {% if not loop.first %} {% set sep_classes = ['nav-separator'] %} {% if loop.last %} diff --git a/src/hydrilla/proxy/web_ui/templates/items/item_viewversion.html.jinja b/src/hydrilla/proxy/web_ui/templates/items/item_viewversion.html.jinja index 952c6b7..a1056b1 100644 --- a/src/hydrilla/proxy/web_ui/templates/items/item_viewversion.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/items/item_viewversion.html.jinja @@ -48,62 +48,53 @@ code in a proprietary work, I am not going to enforce this in court. <p> TODO: add more info... </p> + {% endblock %} + {% + if settings.advanced_user and + version_display_info.active != ActiveStatus.REQUIRED + %} <div class="horizontal-separator"></div> - {% endblock %} - <p> - {% if version_display_info.active == ActiveStatus.REQUIRED %} - {% block item_required_msg required %}{% endblock %} - {% - elif version_display_info.active == ActiveStatus.NOT_ACTIVE or - settings.mapping_use_mode == MappingUseMode.WHEN_ENABLED - %} - {% block item_not_activated_msg required %}{% endblock %} - {% elif settings.mapping_use_mode == MappingUseMode.QUESTION %} - {% block item_will_be_asked_about_msg required %}{% endblock %} + {% set install_but_classes = ['green-button'] %} + {% set uninstall_but_classes = ['green-button'] %} + {% if version_display_info.installed == InstalledStatus.FAILED_TO_INSTALL %} + {% + set install_text = + _('web_ui.items.single_version.retry_install_button') + %} + {% + set uninstall_text = + _('web_ui.items.single_version.leave_uninstalled_button') + %} + <div>{% block item_install_failed_msg required %}{% endblock %}</div> {% else %} - {# settings.mapping_use_mode == MappingUseMode.AUTO #} - {% block item_auto_activated_msg required %}{% endblock %} - {% endif %} - </p> - - {% set install_but_classes = ['green-button'] %} - {% set uninstall_but_classes = ['green-button'] %} - {% if version_display_info.installed == InstalledStatus.FAILED_TO_INSTALL %} - {% - set install_text = - _('web_ui.items.single_version.retry_install_button') - %} - {% - set uninstall_text = - _('web_ui.items.single_version.leave_uninstalled_button') - %} - <div>{% block item_install_failed_msg required %}{% endblock %}</div> - {% else %} - {% set install_text = _('web_ui.items.single_version.install_button') %} - {% set uninstall_text = _('web_ui.items.single_version.uninstall_button') %} - {% if version_display_info.installed == InstalledStatus.INSTALLED %} - {% do install_but_classes.append('disabled-button') %} + {% set install_text = _('web_ui.items.single_version.install_button') %} {% - if uninstall_disallowed is defined or - version_display_info.active == ActiveStatus.REQUIRED + set uninstall_text = _('web_ui.items.single_version.uninstall_button') %} + {% if version_display_info.installed == InstalledStatus.INSTALLED %} + {% do install_but_classes.append('disabled-button') %} + {% + if uninstall_disallowed is defined or + version_display_info.active == ActiveStatus.REQUIRED + %} + {% do uninstall_but_classes.append('disabled-button') %} + {% endif %} + {% else %} + {# version_display_info.installed == InstalledStatus.NOT_INSTALLED #} {% do uninstall_but_classes.append('disabled-button') %} {% endif %} - {% else %} - {# version_display_info.installed == InstalledStatus.NOT_INSTALLED #} - {% do uninstall_but_classes.append('disabled-button') %} - {% endif %} - {% endif %}{# else/ version_display_info.installed == InstalledStatus.FA... #} - - {% set uninstall_fields = {'action': 'uninstall_item_version'} %} - {% set install_fields = {'action': 'install_item_version'} %} - - {{ - button_row([ - (uninstall_but_classes, uninstall_text, uninstall_fields), - (install_but_classes, install_text, install_fields) - ]) - }} + {% endif %}{# else/ version_display_info.installed == InstalledStatus.... #} + + {% set uninstall_fields = {'action': 'uninstall_item_version'} %} + {% set install_fields = {'action': 'install_item_version'} %} + + {{ + button_row([ + (uninstall_but_classes, uninstall_text, uninstall_fields), + (install_but_classes, install_text, install_fields) + ]) + }} + {% endif %}{# settings.advanced_user #} {% endblock main_info %} diff --git a/src/hydrilla/proxy/web_ui/templates/items/library_viewversion.html.jinja b/src/hydrilla/proxy/web_ui/templates/items/library_viewversion.html.jinja index f1d1b74..13ee41a 100644 --- a/src/hydrilla/proxy/web_ui/templates/items/library_viewversion.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/items/library_viewversion.html.jinja @@ -38,22 +38,6 @@ code in a proprietary work, I am not going to enforce this in court. {% endif %} {% endblock %} -{% block item_required_msg %} - {{ _('web_ui.items.single_version.library.item_required') }} -{% endblock %} - -{% block item_auto_activated_msg %} - {{ _('web_ui.items.single_version.library.item_auto_activated') }} -{% endblock %} - -{% block item_not_activated_msg %} - {{ _('web_ui.items.single_version.library.item_not_activated') }} -{% endblock %} - -{% block item_will_be_asked_about_msg %} - {{ _('web_ui.items.single_version.library.item_will_be_asked_about') }} -{% endblock %} - {% block item_install_failed_msg %} {{ _('web_ui.items.single_version.library.install_failed') }} {% endblock %} @@ -68,4 +52,20 @@ code in a proprietary work, I am not going to enforce this in court. </p> <div class="horizontal-separator"></div> + + <p> + {% if version_display_info.active == ActiveStatus.REQUIRED %} + {{ _('web_ui.items.single_version.library.item_required') }} + {% + elif version_display_info.active == ActiveStatus.NOT_ACTIVE or + settings.mapping_use_mode == MappingUseMode.WHEN_ENABLED + %} + {{ _('web_ui.items.single_version.library.item_not_activated') }} + {% elif settings.mapping_use_mode == MappingUseMode.QUESTION %} + {{ _('web_ui.items.single_version.library.item_will_be_asked_about') }} + {% else %} + {# settings.mapping_use_mode == MappingUseMode.AUTO #} + {{ _('web_ui.items.single_version.library.item_auto_activated') }} + {% endif %} + </p> {% endblock %} diff --git a/src/hydrilla/proxy/web_ui/templates/items/package_viewversion.html.jinja b/src/hydrilla/proxy/web_ui/templates/items/package_viewversion.html.jinja index 04caf8c..31f5e2e 100644 --- a/src/hydrilla/proxy/web_ui/templates/items/package_viewversion.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/items/package_viewversion.html.jinja @@ -38,22 +38,6 @@ code in a proprietary work, I am not going to enforce this in court. {% endif %} {% endblock %} -{% block item_required_msg %} - {{ _('web_ui.items.single_version.package.item_required') }} -{% endblock %} - -{% block item_auto_activated_msg %} - {{ _('web_ui.items.single_version.package.item_auto_activated') }} -{% endblock %} - -{% block item_not_activated_msg %} - {{ _('web_ui.items.single_version.package.item_not_activated') }} -{% endblock %} - -{% block item_will_be_asked_about_msg %} - {{ _('web_ui.items.single_version.package.item_will_be_asked_about') }} -{% endblock %} - {% block item_install_failed_msg %} {{ _('web_ui.items.single_version.package.install_failed') }} {% endblock %} @@ -80,14 +64,24 @@ code in a proprietary work, I am not going to enforce this in court. <p> {% if display_info.enabled == EnabledStatus.NO_MARK %} {% do unenable_but_classes.append('disabled-button') %} - {{ _('web_ui.items.single_version.item_not_marked') }} + {% + if version_display_info.active == ActiveStatus.NOT_ACTIVE or + settings.mapping_use_mode == MappingUseMode.WHEN_ENABLED + %} + {{ _('web_ui.items.single_version.package.item_not_activated') }} + {% elif settings.mapping_use_mode == MappingUseMode.QUESTION %} + {{ _('web_ui.items.single_version.package.item_will_be_asked_about') }} + {% else %} + {# settings.mapping_use_mode == MappingUseMode.AUTO #} + {{ _('web_ui.items.single_version.package.item_auto_activated') }} + {% endif %} {% elif display_info.enabled == EnabledStatus.DISABLED %} {% do disable_but_classes.append('disabled-button') %} - {{ _('web_ui.items.single_version.item_disabled') }} + {{ _('web_ui.items.single_version.package.item_disabled') }} {% else %} {# display_info.enabled == EnabledStatus.ENABLED #} {% do enable_but_classes.append('disabled-button') %} - {{ _('web_ui.items.single_version.item_enabled') }} + {{ _('web_ui.items.single_version.package.item_enabled') }} {% endif %} </p> @@ -99,9 +93,9 @@ code in a proprietary work, I am not going to enforce this in court. ]) }} - <div class="horizontal-separator"></div> - {% if display_info.enabled == EnabledStatus.ENABLED %} + <div class="horizontal-separator"></div> + {% set unpin_but_classes = ['green-button'] %} {% set pin_repo_but_classes = ['green-button'] %} {% set pin_ver_but_classes = ['green-button'] %} @@ -191,7 +185,5 @@ code in a proprietary work, I am not going to enforce this in court. (pin_ver_but_classes, pin_ver_text, {'action': 'freeze_to_version'}) ]) }} - - <div class="horizontal-separator"></div> {% endif %}{# display_info.enabled == EnabledStatus.ENABLED #} {% endblock main_info_bulk %} diff --git a/src/hydrilla/proxy/web_ui/templates/options.html.jinja b/src/hydrilla/proxy/web_ui/templates/options.html.jinja index a7e6d7d..26519c4 100644 --- a/src/hydrilla/proxy/web_ui/templates/options.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/options.html.jinja @@ -83,4 +83,30 @@ code in a proprietary work, I am not going to enforce this in court. (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 %} diff --git a/src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja b/src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja index 25015ae..d2c85df 100644 --- a/src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/repos/show_single.html.jinja @@ -159,13 +159,20 @@ code in a proprietary work, I am not going to enforce this in court. <div class="horizontal-separator"></div> {% endif %}{# not display_info.deleted (elif) #} <p> - {{ - _('web_ui.repos.item_count_{mappings}_{resources}') - .format( - mappings = display_info.mapping_count, - resources = display_info.resource_count - ) - }} + {% if settings.advanced_user %} + {{ + _('web_ui.repos.item_count_{mappings}_{resources}') + .format( + mappings = display_info.mapping_count, + resources = display_info.resource_count + ) + }} + {% else %} + {{ + _('web_ui.repos.item_count_{mappings}') + .format(mappings = display_info.mapping_count) + }} + {% endif %} </p> {% if not display_info.is_local_semirepo and not display_info.deleted %} |