aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/web_ui
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-09-29 12:52:54 +0200
committerWojtek Kosior <koszko@koszko.org>2022-10-04 21:45:11 +0200
commit48f80ae480e2fc0eabbdb5041e841b80c0f788f4 (patch)
treecda20c09831038d4b0c3ae78679b43dc127950be /src/hydrilla/proxy/web_ui
parentb0fcc865599cfdc87e2ca8a637df8f5b336bb459 (diff)
downloadhaketilo-hydrilla-48f80ae480e2fc0eabbdb5041e841b80c0f788f4.tar.gz
haketilo-hydrilla-48f80ae480e2fc0eabbdb5041e841b80c0f788f4.zip
[proxy] display some more details in mapping/resource version view in the web UI
Diffstat (limited to 'src/hydrilla/proxy/web_ui')
-rw-r--r--src/hydrilla/proxy/web_ui/items.py129
-rw-r--r--src/hydrilla/proxy/web_ui/templates/include/item_list_style.css.jinja18
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/item_view.html.jinja6
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/item_viewversion.html.jinja108
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/libraries.html.jinja4
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/library_viewversion.html.jinja32
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/package_viewversion.html.jinja54
-rw-r--r--src/hydrilla/proxy/web_ui/templates/items/packages.html.jinja4
-rw-r--r--src/hydrilla/proxy/web_ui/templates/repos/index.html.jinja2
-rw-r--r--src/hydrilla/proxy/web_ui/templates/rules/index.html.jinja2
10 files changed, 326 insertions, 33 deletions
diff --git a/src/hydrilla/proxy/web_ui/items.py b/src/hydrilla/proxy/web_ui/items.py
index f34b89b..467be2f 100644
--- a/src/hydrilla/proxy/web_ui/items.py
+++ b/src/hydrilla/proxy/web_ui/items.py
@@ -34,6 +34,8 @@ from __future__ import annotations
import typing as t
+from urllib.parse import unquote
+
import flask
import werkzeug
@@ -231,3 +233,130 @@ def alter_library_version(item_version_id: str) -> werkzeug.Response:
@bp.route('/packages/viewversion/<string:item_version_id>', methods=['POST'])
def alter_package_version(item_version_id: str) -> werkzeug.Response:
return alter_item_version(item_version_id, item_infos.ItemType.MAPPING)
+
+def show_file(
+ item_version_id: str,
+ item_type: item_infos.ItemType,
+ file_type: str,
+ name: str,
+) -> werkzeug.Response:
+ if file_type not in ('license', 'web_resource'):
+ flask.abort(404)
+
+ try:
+ store = item_version_store(_app.get_haketilo_state(), item_type)
+ item_version_ref = store.get(item_version_id)
+
+ try:
+ if file_type == 'license':
+ file_data = item_version_ref.get_license_file(name)
+ else:
+ assert isinstance(item_version_ref, st.ResourceVersionRef)
+ file_data = item_version_ref.get_resource_file(name)
+
+ return werkzeug.Response(
+ file_data.contents,
+ mimetype = file_data.mime_type
+ )
+ except st.MissingItemError:
+ if file_type == 'license':
+ url = item_version_ref.get_upstream_license_file_url(name)
+ else:
+ assert isinstance(item_version_ref, st.ResourceVersionRef)
+ url = item_version_ref.get_upstream_resource_file_url(name)
+
+ return flask.redirect(url)
+
+ except st.MissingItemError:
+ flask.abort(404)
+
+@bp.route('/packages/viewversion/<string:item_version_id>/<string:file_type>/<path:name>')
+def show_mapping_file(item_version_id: str, file_type: str, name: str) \
+ -> werkzeug.Response:
+ item_type = item_infos.ItemType.MAPPING
+ return show_file(item_version_id, item_type, file_type, name)
+
+@bp.route('/libraries/viewversion/<string:item_version_id>/<string:file_type>/<path:name>')
+def show_resource_file(item_version_id: str, file_type: str, name: str) \
+ -> werkzeug.Response:
+ item_type = item_infos.ItemType.RESOURCE
+ return show_file(item_version_id, item_type, file_type, name)
+
+@bp.route('/libraries/viewdep/<string:item_version_id>/<string:dep_identifier>')
+def show_library_dep(item_version_id: str, dep_identifier: str) \
+ -> werkzeug.Response:
+ state = _app.get_haketilo_state()
+
+ try:
+ store = state.resource_version_store()
+ dep_id = store.get(item_version_id).get_dependency(dep_identifier).id
+ url = flask.url_for('.show_library_version', item_version_id=dep_id)
+ except st.MissingItemError:
+ try:
+ versionless_store = state.resource_store()
+ item_ref = versionless_store.get_by_identifier(dep_identifier)
+ url = flask.url_for('.show_library', item_id=item_ref.id)
+ except st.MissingItemError:
+ flask.abort(404)
+
+ return flask.redirect(url)
+
+@bp.route('/<string:item_type>/viewrequired/<string:item_version_id>/<string:required_identifier>')
+def show_required_mapping(
+ item_type: str,
+ item_version_id: str,
+ required_identifier: str
+) -> werkzeug.Response:
+ state = _app.get_haketilo_state()
+
+ if item_type not in ('package', 'library'):
+ flask.abort(404)
+
+ found = False
+
+ if item_type == 'package':
+ try:
+ ref = state.mapping_version_store().get(item_version_id)
+ mapping_ver_id = ref.get_required_mapping(required_identifier).id
+ url = flask.url_for(
+ '.show_package_version',
+ item_version_id = mapping_ver_id
+ )
+ found = True
+ except st.MissingItemError:
+ pass
+
+ if not found:
+ try:
+ versionless_store = state.mapping_store()
+ mapping_ref = versionless_store\
+ .get_by_identifier(required_identifier)
+ url = flask.url_for('.show_package', item_id=mapping_ref.id)
+ except st.MissingItemError:
+ flask.abort(404)
+
+ return flask.redirect(url)
+
+@bp.route('/package/viewpayload/<string:item_version_id>/<string:pattern>/<string:lib_identifier>')
+def show_payload(item_version_id: str, pattern: str, lib_identifier: str) \
+ -> werkzeug.Response:
+ state = _app.get_haketilo_state()
+
+ try:
+ ref = state.mapping_version_store().get(item_version_id)
+
+ try:
+ resource_ver_ref = \
+ ref.get_payload_resource(unquote(pattern), lib_identifier)
+ url = flask.url_for(
+ '.show_library_version',
+ item_version_id = resource_ver_ref.id
+ )
+ except st.MissingItemError:
+ resource_ref = \
+ state.resource_store().get_by_identifier(lib_identifier)
+ url = flask.url_for('.show_library', item_id=resource_ref.id)
+ except st.MissingItemError:
+ flask.abort(404)
+
+ return flask.redirect(url)
diff --git a/src/hydrilla/proxy/web_ui/templates/include/item_list_style.css.jinja b/src/hydrilla/proxy/web_ui/templates/include/item_list_style.css.jinja
index cbdf225..063cd01 100644
--- a/src/hydrilla/proxy/web_ui/templates/include/item_list_style.css.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/include/item_list_style.css.jinja
@@ -18,36 +18,40 @@ 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.
#}
-ul#item_list {
+ul.item-list {
padding: 0;
}
-ul#item_list > li {
+ul.item-list > li {
list-style-type: none;
max-width: 100%;
white-space: nowrap;
margin: 0;
}
-ul#item_list > li > :only-child {
+ul.item-list > li > :only-child {
display: block;
padding: 5px;
overflow-x: scroll;
border-bottom: 2px solid #999;
}
-ul#item_list > li.entry-line-dashed > :only-child {
+ul.item-list > li.entry-line-dashed > :only-child {
border-bottom-style: dashed
}
-ul#item_list > li.entry-line-green > :only-child {
+ul.item-list > li.entry-line-green > :only-child {
border-color: #4caf50;
}
-ul#item_list > li.entry-line-blue > :only-child {
+ul.item-list > li.entry-line-blue > :only-child {
border-color: #504caf;
}
-ul#item_list > li.entry-line-red > :only-child {
+ul.item-list > li.entry-line-red > :only-child {
border-color: #af504c;
}
+
+ul.item-list > li.invisible-entry-line > :only-child {
+ border-color: #fff;
+}
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 f048f14..5f8b102 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
@@ -20,7 +20,7 @@ code in a proprietary work, I am not going to enforce this in court.
#}
{% extends "base.html.jinja" %}
-{% macro versioned_identifier_with_repo(info) -%}
+{% macro version_with_repo(info) -%}
{{ info.info.version_string }}
{%- if not info.is_local %}
@
@@ -56,7 +56,7 @@ code in a proprietary work, I am not going to enforce this in court.
{% endblock %}
</h4>
- <ul id="item_list">
+ <ul class="item-list">
{% for info in display_info.all_versions %}
{%
if version_display_info is not defined or
@@ -88,7 +88,7 @@ code in a proprietary work, I am not going to enforce this in court.
)
%}
<a href="{{ href }}">
- <div> {{ versioned_identifier_with_repo(info) }} </div>
+ <div> {{ version_with_repo(info) }} </div>
</a>
</li>
{% endif %}
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 c7574f1..bb32be4 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
@@ -20,6 +20,50 @@ code in a proprietary work, I am not going to enforce this in court.
#}
{% extends "items/item_view.html.jinja" %}
+{% macro item_file_list(file_specs, file_type) %}
+ <ul class="item-list has-colored-links">
+ {% for spec in file_specs %}
+ <li class="invisible-entry-line">
+ {%
+ set url = url_for(
+ '.show_{}_file'.format(version_display_info.type.value),
+ item_version_id = version_display_info.ref.id,
+ file_type = file_type,
+ name = spec.name
+ )
+ %}
+ <div>
+ <a href="{{ url }}">
+ {{ spec.name }}
+ </a>
+ </div>
+ </li>
+ {% endfor %}
+ </ul>
+{% endmacro %}
+
+{% macro item_link_list(item_specs, make_url) %}
+ <ul class="item-list has-colored-links">
+ {% for spec in item_specs %}
+ <li class="invisible-entry-line">
+ <div>
+ <a href="{{ make_url(spec) }}">
+ {{ spec.identifier }}
+ </a>
+ </div>
+ </li>
+ {% endfor %}
+ </ul>
+{% endmacro %}
+
+{% block style %}
+ {{ super() }}
+
+ .has-colored-links a {
+ color: #557b8e;
+ }
+{% endblock %}
+
{% block main_info %}
{% if file_installation_error is defined %}
{{ error_note(_('web_ui.err.file_installation_error')) }}
@@ -35,19 +79,75 @@ code in a proprietary work, I am not going to enforce this in court.
{{ super() }}
+ {{ label(_('web_ui.items.single_version.identifier_label')) }}
+
+ <p>
+ {{ version_display_info.info.identifier }}
+ </p>
+
+ <div class="horizontal-separator"></div>
+
{{ label(_('web_ui.items.single_version.version_label')) }}
<p>
- {{ versioned_identifier_with_repo(version_display_info) }}
+ {{ version_with_repo(version_display_info) }}
</p>
<div class="horizontal-separator"></div>
- {% block main_info_bulk %}
+ {% if version_display_info.info.uuid is not none %}
+ {{ label(_('web_ui.items.single_version.uuid_label')) }}
+
+ <p>
+ {{ version_display_info.info.uuid }}
+ </p>
+
+ <div class="horizontal-separator"></div>
+ {% endif %}
+
+ {% if version_display_info.info.description %}
+ {{ label(_('web_ui.items.single_version.description_label')) }}
+
<p>
- TODO: add more info...
+ {{ version_display_info.info.description }}
</p>
- {% endblock %}
+
+ <div class="horizontal-separator"></div>
+ {% endif %}
+
+ {{ label(_('web_ui.items.single_version.licenses_label')) }}
+
+ {% if version_display_info.info.source_copyright %}
+ {{ item_file_list(version_display_info.info.source_copyright, 'license') }}
+ {% else %}
+ <p>
+ {{ _('web_ui.items.single_version.no_license_files') }}
+ </p>
+ {% endif %}
+
+ <div class="horizontal-separator"></div>
+
+ {% if version_display_info.info.required_mappings %}
+ {{ label(_('web_ui.items.single_version.reqired_mappings_label')) }}
+
+ {% macro make_mapping_url(spec) -%}
+ {{
+ url_for(
+ '.show_required_mapping',
+ item_type = version_display_info.type.alt_name,
+ item_version_id = version_display_info.ref.id,
+ required_identifier = spec.identifier
+ )
+ }}
+ {%- endmacro %}
+
+ {% set required_specs = version_display_info.info.required_mappings %}
+ {{ item_link_list(required_specs, make_mapping_url) }}
+
+ <div class="horizontal-separator"></div>
+ {% endif %}
+
+ {% block main_info_rest required %}{% endblock %}
{%
if settings.advanced_user and
diff --git a/src/hydrilla/proxy/web_ui/templates/items/libraries.html.jinja b/src/hydrilla/proxy/web_ui/templates/items/libraries.html.jinja
index 2d5ec29..0a72b64 100644
--- a/src/hydrilla/proxy/web_ui/templates/items/libraries.html.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/items/libraries.html.jinja
@@ -27,7 +27,7 @@ code in a proprietary work, I am not going to enforce this in court.
{% include 'include/item_list_style.css.jinja' %}
- ul#item_list > li > a {
+ ul.item-list > li > a {
display: flex !important;
flex-direction: column;
justify-content: center;
@@ -38,7 +38,7 @@ code in a proprietary work, I am not going to enforce this in court.
{% block main %}
<h3>{{ _('web_ui.libraries.heading') }}</h3>
- <ul id="item_list">
+ <ul class="item-list">
{% for info in display_infos %}
<li>
<a href="{{ url_for('.show_library', item_id=info.ref.id) }}">
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 0454391..eb77fe6 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
@@ -54,13 +54,35 @@ code in a proprietary work, I am not going to enforce this in court.
{{ _('web_ui.items.single_version.library.version_list_heading') }}
{% endblock %}
-{% block main_info_bulk %}
- <p>
- TODO: add more info...
- </p>
+{% block main_info_rest %}
+ {{ label(_('web_ui.items.single_version.library.scripts_label')) }}
+
+ {% if version_display_info.info.scripts %}
+ {{ item_file_list(version_display_info.info.scripts, 'web_resource') }}
+ {% else %}
+ <p>
+ {{ _('web_ui.items.single_version.library.no_script_files') }}
+ </p>
+ {% endif %}
<div class="horizontal-separator"></div>
+ {% if version_display_info.info.dependencies %}
+ {{ label(_('web_ui.items.single_version.library.deps_label')) }}
+
+ {% macro make_dep_url(spec) -%}
+ {{
+ url_for(
+ '.show_library_dep',
+ item_version_id = version_display_info.ref.id,
+ dep_identifier = spec.identifier
+ )
+ }}
+ {%- endmacro %}
+
+ {{ item_link_list(version_display_info.info.dependencies, make_dep_url) }}
+ {% endif %}
+
{{ label(_('web_ui.items.single_version.library.enabled_label')) }}
<p>
@@ -78,4 +100,4 @@ code in a proprietary work, I am not going to enforce this in court.
{{ _('web_ui.items.single_version.library.item_auto_activated') }}
{% endif %}
</p>
-{% endblock %}
+{% endblock main_info_rest %}
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 699469e..bc33c42 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
@@ -54,10 +54,50 @@ code in a proprietary work, I am not going to enforce this in court.
{{ _('web_ui.items.single_version.package.version_list_heading') }}
{% endblock %}
-{% block main_info_bulk %}
- <p>
- TODO: add more info...
- </p>
+{% block main_info_rest %}
+ {{ label(_('web_ui.items.single_version.package.payloads_label')) }}
+
+ {% if version_display_info.info.payloads|length > 0 %}
+ <ul class="item-list has-colored-links">
+ {% set by_lib = {} %}
+ {%
+ for pattern_struct, spec in version_display_info.info.payloads.items()
+ if pattern_struct.orig_url not in processed_patterns
+ %}
+ {% set pattern = pattern_struct.orig_url %}
+ {% do by_lib.setdefault(spec.identifier, []).append(pattern) %}
+ {% endfor %}
+ {% for lib_identifier, patterns in by_lib|dictsort %}
+ <li class="invisible-entry-line">
+ <div>
+ {% set encoded = patterns[0]|urlencode|replace('/', '%2F') %}
+ {%
+ set url = url_for(
+ '.show_payload',
+ item_version_id = version_display_info.ref.id,
+ pattern = encoded,
+ lib_identifier = lib_identifier
+ )
+ %}
+ <div>
+ <a href="{{ url }}">
+ {{ lib_identifier }}
+ </a>
+ </div>
+ {% for pattern in patterns|unique|sort(attribute='identifier') %}
+ <div class="small-print">
+ {{ pattern }}
+ </div>
+ {% endfor %}
+ </div>
+ </li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ <p>
+ {{ _('web_ui.items.single_version.package.no_payloads') }}
+ </p>
+ {% endif %}
<div class="horizontal-separator"></div>
@@ -183,9 +223,7 @@ code in a proprietary work, I am not going to enforce this in court.
{% else %}
{{
_('web_ui.items.single_version.active_ver_is_{}')
- .format(
- versioned_identifier_with_repo(display_info.active_version)
- )
+ .format(version_with_repo(display_info.active_version))
}}
{% endif %}
</p>
@@ -198,4 +236,4 @@ code in a proprietary work, I am not going to enforce this in court.
])
}}
{% endif %}{# display_info.enabled == EnabledStatus.ENABLED #}
-{% endblock main_info_bulk %}
+{% endblock main_info_rest %}
diff --git a/src/hydrilla/proxy/web_ui/templates/items/packages.html.jinja b/src/hydrilla/proxy/web_ui/templates/items/packages.html.jinja
index 29228a2..bc6b5bb 100644
--- a/src/hydrilla/proxy/web_ui/templates/items/packages.html.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/items/packages.html.jinja
@@ -27,7 +27,7 @@ code in a proprietary work, I am not going to enforce this in court.
{% include 'include/item_list_style.css.jinja' %}
- ul#item_list > li > a {
+ ul.item-list > li > a {
display: flex !important;
flex-direction: column;
justify-content: center;
@@ -38,7 +38,7 @@ code in a proprietary work, I am not going to enforce this in court.
{% block main %}
<h3>{{ _('web_ui.packages.heading') }}</h3>
- <ul id="item_list">
+ <ul class="item-list">
{% for info in display_infos %}
{% set entry_classes = [] %}
diff --git a/src/hydrilla/proxy/web_ui/templates/repos/index.html.jinja b/src/hydrilla/proxy/web_ui/templates/repos/index.html.jinja
index 15f821b..e670b59 100644
--- a/src/hydrilla/proxy/web_ui/templates/repos/index.html.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/repos/index.html.jinja
@@ -40,7 +40,7 @@ code in a proprietary work, I am not going to enforce this in court.
<h4>{{ _('web_ui.repos.repo_list_heading') }}</h4>
- <ul id="item_list">
+ <ul class="item-list">
{% for info in display_infos %}
{% set entry_classes = [] %}
diff --git a/src/hydrilla/proxy/web_ui/templates/rules/index.html.jinja b/src/hydrilla/proxy/web_ui/templates/rules/index.html.jinja
index 71712fe..799eaba 100644
--- a/src/hydrilla/proxy/web_ui/templates/rules/index.html.jinja
+++ b/src/hydrilla/proxy/web_ui/templates/rules/index.html.jinja
@@ -40,7 +40,7 @@ code in a proprietary work, I am not going to enforce this in court.
<h4>{{ _('web_ui.rules.rule_list_heading') }}</h4>
- <ul id="item_list">
+ <ul class="item-list">
{% for info in display_infos %}
{% if info.allow_scripts %}