aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/web_ui
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-10-08 19:07:12 +0200
committerWojtek Kosior <koszko@koszko.org>2022-10-08 19:08:39 +0200
commitb2055032cb914fd160270971dd1da46f8c7c838d (patch)
treebd1a67b9a708af1eae704e208bd50849e4b7f1f7 /src/hydrilla/proxy/web_ui
parent4f016d740e3c15e72b944aa0d6f82ca863d1ae67 (diff)
downloadhaketilo-hydrilla-b2055032cb914fd160270971dd1da46f8c7c838d.tar.gz
haketilo-hydrilla-b2055032cb914fd160270971dd1da46f8c7c838d.zip
[proxy] remove TODOs from library and package pages and make package page display enable/disable/forget buttons
Diffstat (limited to 'src/hydrilla/proxy/web_ui')
-rw-r--r--src/hydrilla/proxy/web_ui/items.py78
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/item_view.html.jinja14
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/item_viewversion.html.jinja16
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/library_view.html.jinja4
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/package_view.html.jinja87
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/package_viewversion.html.jinja6
6 files changed, 173 insertions, 32 deletions
diff --git a/src/hydrilla/proxy/web_ui/items.py b/src/hydrilla/proxy/web_ui/items.py
index 467be2f..01b201d 100644
--- a/src/hydrilla/proxy/web_ui/items.py
+++ b/src/hydrilla/proxy/web_ui/items.py
@@ -73,15 +73,19 @@ def item_store(state: st.HaketiloState, item_type: item_infos.ItemType) \
else:
return state.mapping_store()
-def show_item(item_id: str, item_type: item_infos.ItemType) \
- -> werkzeug.Response:
+def show_item(
+ item_id: str,
+ item_type: item_infos.ItemType,
+ errors: t.Mapping[str, bool] = {}
+) -> werkzeug.Response:
try:
store = item_store(_app.get_haketilo_state(), item_type)
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
+ display_info = display_info,
+ **errors
)
return flask.make_response(html, 200)
except st.MissingItemError:
@@ -96,6 +100,64 @@ def show_library(item_id: str) -> werkzeug.Response:
def show_package(item_id: str) -> werkzeug.Response:
return show_item(item_id, item_infos.ItemType.MAPPING)
+def alter_item(item_id: str, item_type: item_infos.ItemType) \
+ -> werkzeug.Response:
+ form_data = flask.request.form
+ action = form_data['action']
+
+ try:
+ store = item_store(_app.get_haketilo_state(), item_type)
+ item_ref = store.get(item_id)
+
+ if action == 'disable_item':
+ assert isinstance(item_ref, st.MappingRef)
+ item_ref.update_status(st.EnabledStatus.DISABLED)
+ elif action == 'unenable_item':
+ assert isinstance(item_ref, st.MappingRef)
+ item_ref.update_status(st.EnabledStatus.NO_MARK)
+ elif action in ('enable_item', 'unfreeze_item'):
+ assert isinstance(item_ref, st.MappingRef)
+ item_ref.update_status(
+ enabled = st.EnabledStatus.ENABLED,
+ frozen = st.FrozenStatus.NOT_FROZEN,
+ )
+ elif action == 'freeze_to_repo':
+ assert isinstance(item_ref, st.MappingRef)
+ item_ref.update_status(
+ enabled = st.EnabledStatus.ENABLED,
+ frozen = st.FrozenStatus.REPOSITORY,
+ )
+ elif action == 'freeze_to_version':
+ assert isinstance(item_ref, st.MappingRef)
+ item_ref.update_status(
+ enabled = st.EnabledStatus.ENABLED,
+ frozen = st.FrozenStatus.EXACT_VERSION,
+ )
+ else:
+ raise ValueError()
+ except st.RepoCommunicationError:
+ return show_item(item_id, item_type, {'repo_communication_error': True})
+ except st.FileInstallationError:
+ return show_item(item_id, item_type, {'file_installation_error': True})
+ except st.ImpossibleSituation:
+ errors = {'impossible_situation_error': True}
+ return show_item(item_id, item_type, errors)
+ except st.MissingItemError:
+ flask.abort(404)
+
+ return flask.redirect(
+ flask.url_for(f'.show_{item_type.alt_name}', item_id=item_id)
+ )
+
+@bp.route('/libraries/view/<string:item_id>', methods=['POST'])
+def alter_library(item_id: str) -> werkzeug.Response:
+ return alter_item(item_id, item_infos.ItemType.RESOURCE)
+
+@bp.route('/packages/view/<string:item_id>', methods=['POST'])
+def alter_package(item_id: str) -> werkzeug.Response:
+ return alter_item(item_id, item_infos.ItemType.MAPPING)
+
+
ItemVersionDisplayInfo = t.Union[
st.MappingVersionDisplayInfo,
st.ResourceVersionDisplayInfo
@@ -163,7 +225,7 @@ def alter_item_version(item_version_id: str, item_type: item_infos.ItemType) \
elif action == 'unenable_item':
assert isinstance(item_version_ref, st.MappingVersionRef)
item_version_ref.update_mapping_status(st.EnabledStatus.NO_MARK)
- elif action == 'enable_item_version':
+ elif action in ('enable_item_version', 'freeze_to_version'):
assert isinstance(item_version_ref, st.MappingVersionRef)
item_version_ref.update_mapping_status(
enabled = st.EnabledStatus.ENABLED,
@@ -181,12 +243,6 @@ def alter_item_version(item_version_id: str, item_type: item_infos.ItemType) \
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':
@@ -214,7 +270,7 @@ def alter_item_version(item_version_id: str, item_type: item_infos.ItemType) \
return show_item_version(
item_version_id = item_version_id,
item_type = item_type,
- errors = {'uninstall_disallowed': True}
+ errors = {'impossible_situation_error': True}
)
except st.MissingItemError:
flask.abort(404)
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 5f8b102..e517f3b 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
@@ -39,6 +39,20 @@ code in a proprietary work, I am not going to enforce this in court.
{% endblock %}
{% block main %}
+ {% block top_errors %}
+ {% if file_installation_error is defined %}
+ {{ error_note(_('web_ui.err.file_installation_error')) }}
+ {% endif %}
+
+ {% if impossible_situation_error is defined %}
+ {{ error_note(_('web_ui.err.impossible_situation_error')) }}
+ {% endif %}
+
+ {% if repo_communication_error is defined %}
+ {{ error_note(_('web_ui.err.repo_communication_error')) }}
+ {% endif %}
+ {% endblock top_errors %}
+
{% block main_info %}
<h3>{% block heading required %}{% endblock %}</h3>
{% endblock %}
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 0d2ed57..3d1a2cb 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
@@ -64,23 +64,13 @@ code in a proprietary work, I am not going to enforce this in court.
}
{% endblock %}
-{% block main_info %}
- {% if file_installation_error is defined %}
- {{ error_note(_('web_ui.err.file_installation_error')) }}
- {% endif %}
-
- {% if uninstall_disallowed is defined %}
- {{ error_note(_('web_ui.err.uninstall_disallowed')) }}
- {% endif %}
-
- {% if repo_communication_error is defined %}
- {{ error_note(_('web_ui.err.repo_communication_error')) }}
- {% endif %}
-
+{% block top_errors %}
{% if not version_display_info.info.compatible %}
{{ error_note(_('web_ui.err.item_not_compatible')) }}
{% endif %}
+{% endblock %}
+{% block main_info %}
{{ super() }}
{{ label(_('web_ui.items.single_version.identifier_label')) }}
diff --git a/src/hydrilla/proxy/web_ui/templates/items/library_view.html.jinja b/src/hydrilla/proxy/web_ui/templates/items/library_view.html.jinja
index 76f63f3..f33b5b7 100644
--- a/src/hydrilla/proxy/web_ui/templates/items/library_view.html.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/items/library_view.html.jinja
@@ -31,10 +31,6 @@ code in a proprietary work, I am not going to enforce this in court.
{% block main_info %}
{{ super() }}
-
- <p>
- TODO: add more info...
- </p>
{% endblock %}
{% block version_list_heading %}
diff --git a/src/hydrilla/proxy/web_ui/templates/items/package_view.html.jinja b/src/hydrilla/proxy/web_ui/templates/items/package_view.html.jinja
index d0bc1c8..d5ba2a0 100644
--- a/src/hydrilla/proxy/web_ui/templates/items/package_view.html.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/items/package_view.html.jinja
@@ -32,9 +32,94 @@ code in a proprietary work, I am not going to enforce this in court.
{% block main_info %}
{{ super() }}
+ {#
+ The labels and buttons below are similar to those in single package versions
+ view but not similar enough for us to be able to refactor common code.
+ #}
+
+ {{ label(_('web_ui.items.single.package.enabled_label')) }}
+
+ {% set enable_but_classes = ['blue-button'] %}
+ {% set unenable_but_classes = ['green-button'] %}
+ {% set disable_but_classes = ['red-button'] %}
+
+ {% set unenable_text = _('web_ui.items.unenable_button') %}
+ {% set disable_text = _('web_ui.items.disable_button') %}
+ {% set enable_text = _('web_ui.items.enable_button') %}
+
<p>
- TODO: add more info...
+ {% if display_info.enabled == EnabledStatus.NO_MARK %}
+ {% do unenable_but_classes.append('disabled-button') %}
+ {{ _('web_ui.items.single.package.item_not_enabled') }}
+ {% elif display_info.enabled == EnabledStatus.DISABLED %}
+ {% do disable_but_classes.append('disabled-button') %}
+ {{ _('web_ui.items.single.package.item_disabled') }}
+ {% else %}
+ {# display_info.enabled == EnabledStatus.ENABLED #}
+ {% do enable_but_classes.append('disabled-button') %}
+ {{ _('web_ui.items.single.package.item_enabled') }}
+ {% endif %}
</p>
+
+ {{
+ button_row([
+ (disable_but_classes, disable_text, {'action': 'disable_item'}),
+ (unenable_but_classes, unenable_text, {'action': 'unenable_item'}),
+ (enable_but_classes, enable_text, {'action': 'enable_item'})
+ ])
+ }}
+
+ {% if display_info.enabled == EnabledStatus.ENABLED %}
+ <div class="horizontal-separator"></div>
+
+ {{ label(_('web_ui.items.single.package.pinning_label')) }}
+
+ {% set unpin_but_classes = ['green-button'] %}
+ {% set pin_repo_but_classes = ['green-button'] %}
+ {% set pin_ver_but_classes = ['green-button'] %}
+
+ {% set unpin_text = _('web_ui.items.single.package.unpin_button') %}
+
+ {% if display_info.active_version.is_local %}
+ {%
+ set pin_repo_text =
+ _('web_ui.items.single.package.pin_local_repo_button')
+ %}
+ {% else %}
+ {% set pin_repo_text = _('web_ui.items.single.package.pin_repo_button') %}
+ {% endif %}
+
+ {% set pin_ver_text = _('web_ui.items.single.package.pin_ver_button') %}
+
+ <p>
+ {% if display_info.frozen == FrozenStatus.NOT_FROZEN %}
+ {% do unpin_but_classes.append('disabled-button') %}
+ {{ _('web_ui.items.single.package.not_pinned') }}
+ {% elif display_info.frozen == FrozenStatus.REPOSITORY %}
+ {% do pin_repo_but_classes.append('disabled-button') %}
+ {% if display_info.active_version.is_local %}
+ {{ _('web_ui.items.single.package.pinned_repo_local') }}
+ {% else %}
+ {{
+ _('web_ui.items.single.package.pinned_repo_{}')
+ .format(display_info.active_version.info.repo)
+ }}
+ {% endif %}
+ {% else %}
+ {# display_info.frozen == FrozenStatus.EXACT_VERSION #}
+ {% do pin_ver_but_classes.append('disabled-button') %}
+ {{ _('web_ui.items.single.package.pinned_ver') }}
+ {% endif %}
+ </p>
+
+ {{
+ button_row([
+ (unpin_but_classes, unpin_text, {'action': 'unfreeze_item'}),
+ (pin_repo_but_classes, pin_repo_text, {'action': 'freeze_to_repo'}),
+ (pin_ver_but_classes, pin_ver_text, {'action': 'freeze_to_version'})
+ ])
+ }}
+ {% endif %}{# display_info.enabled == EnabledStatus.ENABLED #}
{% endblock %}
{% block version_list_heading %}
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 fa7c954..fe816ab 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
@@ -114,9 +114,9 @@ code in a proprietary work, I am not going to enforce this in court.
{% do enable_but_classes.append('disabled-button') %}
{% endif %}
- {% set unenable_text = _('web_ui.items.single_version.unenable_button') %}
- {% set disable_text = _('web_ui.items.single_version.disable_button') %}
- {% set enable_text = _('web_ui.items.single_version.enable_button') %}
+ {% set unenable_text = _('web_ui.items.unenable_button') %}
+ {% set disable_text = _('web_ui.items.disable_button') %}
+ {% set enable_text = _('web_ui.items.enable_button') %}
<p>
{% if display_info.enabled == EnabledStatus.NO_MARK %}