From 5cdb4c29ea9e736ea5a52483c2e62009c4c7d27e Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 2 Sep 2022 13:51:25 +0200 Subject: [proxy] allow packages to be frozen and unfrozen in the web UI This commit also makes some minor changes and fixes in other parts of the web UI. --- src/hydrilla/proxy/web_ui/items.py | 62 +++++------ src/hydrilla/proxy/web_ui/root.py | 1 + .../web_ui/templates/items/item_view.html.jinja | 60 ++++++----- .../templates/items/item_viewversion.html.jinja | 18 ++-- .../templates/items/library_viewversion.html.jinja | 15 ++- .../templates/items/package_viewversion.html.jinja | 119 +++++++++++++++++---- .../web_ui/templates/repos/show_single.html.jinja | 2 +- 7 files changed, 177 insertions(+), 100 deletions(-) (limited to 'src/hydrilla/proxy/web_ui') diff --git a/src/hydrilla/proxy/web_ui/items.py b/src/hydrilla/proxy/web_ui/items.py index 01ae406..a781856 100644 --- a/src/hydrilla/proxy/web_ui/items.py +++ b/src/hydrilla/proxy/web_ui/items.py @@ -124,40 +124,11 @@ def show_item(item_id: str, item_type: item_infos.ItemType) \ -> werkzeug.Response: try: store = item_store(_app.get_haketilo_state(), item_type) - item_ref = store.get(str(item_id)) - version_display_infos = item_ref.get_version_display_infos() - - display_info: t.Union[st.MappingDisplayInfo, st.ResourceDisplayInfo] - - if isinstance(item_ref, st.ResourceRef): - display_info = st.ResourceDisplayInfo( - ref = item_ref, - identifier = version_display_infos[0].info.identifier - ) - else: - version_display_infos = t.cast( - t.Sequence[st.MappingVersionDisplayInfo], - version_display_infos - ) - - active_version: t.Optional[st.MappingVersionDisplayInfo] = None - - for info in version_display_infos: - if info.active != st.ActiveStatus.NOT_ACTIVE: - active_version = info - - display_info = st.MappingDisplayInfo( - ref = item_ref, - identifier = version_display_infos[0].info.identifier, - enabled = version_display_infos[0].mapping_enabled, - frozen = version_display_infos[0].mapping_frozen, - active_version = active_version - ) + display_info = store.get(str(item_id)).get_display_info() html = flask.render_template( f'items/{item_type.alt_name}_view.html.jinja', - display_info = display_info, - version_display_infos = version_display_infos + display_info = display_info ) return flask.make_response(html, 200) except st.MissingItemError: @@ -194,23 +165,20 @@ def show_item_version( try: store = item_version_store(_app.get_haketilo_state(), item_type) version_ref = store.get(item_version_id) - display_infos = version_ref.get_all_version_display_infos() + display_info = version_ref.get_item_display_info() - other_infos: list[ItemVersionDisplayInfo] = [] this_info: t.Optional[ItemVersionDisplayInfo] = None - for info in display_infos: + for info in display_info.all_versions: if info.ref == version_ref: this_info = info - else: - other_infos.append(info) assert this_info is not None html = flask.render_template( f'items/{item_type.alt_name}_viewversion.html.jinja', - display_info = this_info, - version_display_infos = other_infos, + display_info = display_info, + version_display_info = this_info, **errors ) return flask.make_response(html, 200) @@ -246,6 +214,24 @@ def alter_item_version(item_version_id: str, item_type: item_infos.ItemType) \ enabled = st.EnabledStatus.ENABLED, frozen = st.FrozenStatus.EXACT_VERSION, ) + elif action == 'unfreeze_item': + assert isinstance(item_version_ref, st.MappingVersionRef) + item_version_ref.update_mapping_status( + enabled = st.EnabledStatus.ENABLED, + frozen = st.FrozenStatus.NOT_FROZEN, + ) + elif action == 'freeze_to_repo': + assert isinstance(item_version_ref, st.MappingVersionRef) + item_version_ref.update_mapping_status( + enabled = st.EnabledStatus.ENABLED, + frozen = st.FrozenStatus.REPOSITORY, + ) + elif action == 'freeze_to_version': + assert isinstance(item_version_ref, st.MappingVersionRef) + item_version_ref.update_mapping_status( + enabled = st.EnabledStatus.ENABLED, + frozen = st.FrozenStatus.EXACT_VERSION, + ) elif action == 'install_item_version': item_version_ref.install() elif action == 'uninstall_item_version': diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py index b199506..eac3be7 100644 --- a/src/hydrilla/proxy/web_ui/root.py +++ b/src/hydrilla/proxy/web_ui/root.py @@ -84,6 +84,7 @@ class WebUIAppImpl(_app.WebUIApp): self.jinja_env.globals['get_current_endpoint'] = get_current_endpoint self.jinja_env.globals['EnabledStatus'] = st.EnabledStatus + self.jinja_env.globals['FrozenStatus'] = st.FrozenStatus self.jinja_env.globals['InstalledStatus'] = st.InstalledStatus self.jinja_env.globals['ActiveStatus'] = st.ActiveStatus self.jinja_env.globals['ItemType'] = item_infos.ItemType diff --git a/src/hydrilla/proxy/web_ui/templates/items/item_view.html.jinja b/src/hydrilla/proxy/web_ui/templates/items/item_view.html.jinja index 861d5ef..1ad8df3 100644 --- a/src/hydrilla/proxy/web_ui/templates/items/item_view.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/items/item_view.html.jinja @@ -19,6 +19,15 @@ file's licenses. Although I request that you do not make use this code in a proprietary work, I am not going to enforce this in court. #} {% extends "base.html.jinja" %} + +{% macro versioned_identifier_with_repo(info) %} + {{ info.info.versioned_identifier }} + {% if not info.is_local %} + @ + {{ info.info.repo }} + {% endif %} +{% endmacro %} + {% block style %} {{ super() }} @@ -28,38 +37,37 @@ in a proprietary work, I am not going to enforce this in court. {% block main_info %}

{% block heading required %}{% endblock %}

{% endblock %} - {% if version_display_infos|length > 0 %} + {% if display_info.all_versions|length > 0 %}

{% block version_list_heading required %} {% endblock %}

- {% endif %}{# version_display_infos|length > 0 #} + {% endif %}{# display_info.all_versions|length > 0 #} {% endblock main %} 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 54cb3cf..de62330 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 @@ -39,25 +39,25 @@ in a proprietary work, I am not going to enforce this in court. {{ super() }}
- {{ display_info.info.versioned_identifier }} + {{ versioned_identifier_with_repo(version_display_info) }}
{% block main_info_bulk %} TODO: add more info... {% endblock %} - {% if display_info.active == ActiveStatus.REQUIRED %} + {% if version_display_info.active == ActiveStatus.REQUIRED %}
{% block item_required_msg required %}{% endblock %}
- {% elif display_info.active == ActiveStatus.AUTO %} + {% elif version_display_info.active == ActiveStatus.AUTO %}
{% block item_auto_activated_msg required %}{% endblock %}
{% else %} - {# display_info.active == ActiveStatus.NOT_ACTIVE #} + {# version_display_info.active == ActiveStatus.NOT_ACTIVE #}
{% block item_not_activated_msg required %}{% endblock %}
{% endif %} {% set install_but_classes = ['green-button', 'button-bordering-left'] %} {% set uninstall_but_classes = ['green-button', 'button-bordering-right'] %} - {% if display_info.installed == InstalledStatus.FAILED_TO_INSTALL %} + {% if version_display_info.installed == InstalledStatus.FAILED_TO_INSTALL %} {% set install_text = _('web_ui.items.single_version.retry_install_button') @@ -70,19 +70,19 @@ in a proprietary work, I am not going to enforce this in court. {% else %} {% set install_text = _('web_ui.items.single_version.install_button') %} {% set uninstall_text = _('web_ui.items.single_version.uninstall_button') %} - {% if display_info.installed == InstalledStatus.INSTALLED %} + {% if version_display_info.installed == InstalledStatus.INSTALLED %} {% do install_but_classes.append('disabled-button') %} {% if uninstall_disallowed is defined or - display_info.active == ActiveStatus.REQUIRED + version_display_info.active == ActiveStatus.REQUIRED %} {% do uninstall_but_classes.append('disabled-button') %} {% endif %} {% else %} - {# display_info.installed == InstalledStatus.NOT_INSTALLED #} + {# version_display_info.installed == InstalledStatus.NOT_INSTALLED #} {% do uninstall_but_classes.append('disabled-button') %} {% endif %} - {% endif %}{# else/ display_info.installed == InstalledStatus.FAILED_TO_I...#} + {% endif %}{# else/ version_display_info.installed == InstalledStatus.FA... #} {{ button_row([ (uninstall_but_classes, uninstall_text, 'uninstall_item_version'), 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 30e084d..9e0a32e 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 @@ -25,10 +25,17 @@ in a proprietary work, I am not going to enforce this in court. {% endblock %} {% block heading %} - {{ - _('web_ui.items.single_version.library.heading.name_{}') - .format(display_info.info.long_name) - }} + {% if version_display_info.is_local %} + {{ + _('web_ui.items.single_version.library_local.heading.name_{}') + .format(version_display_info.info.long_name) + }} + {% else %} + {{ + _('web_ui.items.single_version.library.heading.name_{}') + .format(version_display_info.info.long_name) + }} + {% endif %} {% endblock %} {% block item_required_msg %} 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 a532b5f..ea8b7d3 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 @@ -25,10 +25,17 @@ in a proprietary work, I am not going to enforce this in court. {% endblock %} {% block heading %} - {{ - _('web_ui.items.single_version.package.heading.name_{}') - .format(display_info.info.long_name) - }} + {% if version_display_info.is_local %} + {{ + _('web_ui.items.single_version.package_local.heading.name_{}') + .format(version_display_info.info.long_name) + }} + {% else %} + {{ + _('web_ui.items.single_version.package.heading.name_{}') + .format(version_display_info.info.long_name) + }} + {% endif %} {% endblock %} {% block item_required_msg %} @@ -66,28 +73,18 @@ in a proprietary work, I am not going to enforce this in court. {% set unenable_text = _('web_ui.items.single_version.unenable_button') %} {% set disable_text = _('web_ui.items.single_version.disable_button') %} - {% - if display_info.mapping_enabled == EnabledStatus.ENABLED and - display_info.active == ActiveStatus.NOT_ACTIVE - %} - {% - set enable_text = - _('web_ui.items.single_version.freeze_to_this_button') - %} - {% else %} - {% set enable_text = _('web_ui.items.single_version.enable_button') %} - {% endif %} + {% set enable_text = _('web_ui.items.single_version.enable_button') %} - {% if display_info.mapping_enabled == EnabledStatus.NO_MARK %} + {% if display_info.enabled == EnabledStatus.NO_MARK %} {% do unenable_but_classes.append('disabled-button') %} - {% elif display_info.mapping_enabled == EnabledStatus.DISABLED %} +
{{ _('web_ui.items.single_version.item_not_marked') }}
+ {% elif display_info.enabled == EnabledStatus.DISABLED %} {% do disable_but_classes.append('disabled-button') %} +
{{ _('web_ui.items.single_version.item_disabled') }}
{% else %} - {% if display_info.active == ActiveStatus.REQUIRED %} - {% do enable_but_classes.append('disabled-button') %} - {% else %} -
{{ _('web_ui.items.single_version.other_version_enabled') }}
- {% endif %} + {# display_info.enabled == EnabledStatus.ENABLED #} + {% do enable_but_classes.append('disabled-button') %} +
{{ _('web_ui.items.single_version.item_enabled') }}
{% endif %} {{ @@ -97,4 +94,82 @@ in a proprietary work, I am not going to enforce this in court. (enable_but_classes, enable_text, 'enable_item_version') ]) }} + + {% if display_info.enabled == EnabledStatus.ENABLED %} + {% set unpin_but_classes = ['green-button', 'button-bordering-right'] %} + {% + set pin_repo_but_classes = [ + 'green-button', + 'button-bordering-right', + 'button-bordering-left' + ] + %} + {% set pin_ver_but_classes = ['green-button', 'button-bordering-left'] %} + + {% set unpin_text = _('web_ui.items.single_version.unpin_button') %} + + {% if display_info.frozen == FrozenStatus.NOT_FROZEN %} + {% do unpin_but_classes.append('disabled-button') %} +
{{ _('web_ui.items.single_version.not_pinned') }}
+ {% endif %} + + {% if display_info.frozen == FrozenStatus.REPOSITORY %} + {% if display_info.active_version.is_local %} +
{{ _('web_ui.items.single_version.pinned_repo_local') }}
+ {% else %} +
+ {{ + _('web_ui.items.single_version.pinned_repo_{}') + .format(display_info.active_version.info.repo) + }} +
+ {% endif %} + {% + if display_info.active_version.info.repo == + version_display_info.info.repo + %} + {% if version_display_info.is_local %} + {% + set pin_repo_text = + _('web_ui.items.single_version.pin_local_repo_button') + %} + {% else %} + {% + set pin_repo_text = _('web_ui.items.single_version.pin_repo_button') + %} + {% endif %} + {% do pin_repo_but_classes.append('disabled-button') %} + {% else %} + {% + set pin_repo_text = + _('web_ui.items.single_version.repin_repo_button') + %} + {% endif %} + {% else %}{# display_info.frozen == FrozenStatus.REPOSITORY #} + {% set pin_repo_text = _('web_ui.items.single_version.pin_repo_button') %} + {% endif %}{# else/ display_info.frozen == FrozenStatus.REPOSITORY #} + + {% if display_info.frozen == FrozenStatus.EXACT_VERSION %} + {% if display_info.active_version.ref == version_display_info.ref %} + {% set pin_ver_text = _('web_ui.items.single_version.pin_ver_button') %} + {% do pin_ver_but_classes.append('disabled-button') %} +
{{ _('web_ui.items.single_version.pinned_ver') }}
+ {% else %} + {% + set pin_ver_text = _('web_ui.items.single_version.repin_ver_button') + %} +
{{ _('web_ui.items.single_version.pinned_other_ver') }}
+ {% endif %} + {% else %} + {% set pin_ver_text = _('web_ui.items.single_version.pin_ver_button') %} + {% endif %}{# else/ display_info.frozen == FrozenStatus.EXACT_VERSION #} + + {{ + button_row([ + (unpin_but_classes, unpin_text, 'unfreeze_item'), + (pin_repo_but_classes, pin_repo_text, 'freeze_to_repo'), + (pin_ver_but_classes, pin_ver_text, 'freeze_to_version') + ]) + }} + {% endif %}{# display_info.enabled == EnabledStatus.ENABLED #} {% endblock main_info_bulk %} 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 ce1cef2..604b38c 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 @@ -80,7 +80,7 @@ in a proprietary work, I am not going to enforce this in court. -