diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-08-24 10:47:33 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-09-28 12:54:53 +0200 |
commit | d516b9decad07b940b3cd117fc4e353dd8bbe7d2 (patch) | |
tree | 2ab6f78e067d88a9dce1043e496b1d5af283464b /src/hydrilla/proxy/web_ui | |
parent | 964bd44649aaf03c9afea06eadad0443032d8b77 (diff) | |
download | haketilo-hydrilla-d516b9decad07b940b3cd117fc4e353dd8bbe7d2.tar.gz haketilo-hydrilla-d516b9decad07b940b3cd117fc4e353dd8bbe7d2.zip |
make repo packages (mappings) load as uninstalled; make them installable through the web UI
Diffstat (limited to 'src/hydrilla/proxy/web_ui')
7 files changed, 109 insertions, 11 deletions
diff --git a/src/hydrilla/proxy/web_ui/packages.py b/src/hydrilla/proxy/web_ui/packages.py index 85e5d00..ac8b480 100644 --- a/src/hydrilla/proxy/web_ui/packages.py +++ b/src/hydrilla/proxy/web_ui/packages.py @@ -132,15 +132,50 @@ def show_package(mapping_id: str) -> werkzeug.Response: flask.abort(404) @bp.route('/packages/viewversion/<string:mapping_version_id>') -def show_package_version(mapping_version_id: str) -> werkzeug.Response: +def show_package_version( + mapping_version_id: str, + errors: t.Mapping[str, bool] = {} +) -> werkzeug.Response: try: store = _app.get_haketilo_state().mapping_version_store() display_info = store.get(mapping_version_id).get_display_info() html = flask.render_template( 'packages/show_single_version.html.jinja', - display_info = display_info + display_info = display_info, + **errors ) return flask.make_response(html, 200) except st.MissingItemError: flask.abort(404) + +@bp.route('/packages/viewversion/<string:mapping_version_id>', methods=['POST']) +def alter_package_version(mapping_version_id: str) -> werkzeug.Response: + form_data = flask.request.form + action = form_data['action'] + + try: + store = _app.get_haketilo_state().mapping_version_store() + mapping_version_ref = store.get(mapping_version_id) + + if action == 'install_package': + mapping_version_ref.install() + elif action == 'uninstall_package': + mapping_version_ref.uninstall() + return flask.redirect(flask.url_for('.packages')) + else: + raise ValueError() + except st.ImpossibleSituation: + return show_package_version( + mapping_version_id, + {'uninstall_disallowed': True} + ) + except st.MissingItemError: + flask.abort(404) + + return flask.redirect( + flask.url_for( + '.show_package_version', + mapping_version_id = mapping_version_id + ) + ) diff --git a/src/hydrilla/proxy/web_ui/repos.py b/src/hydrilla/proxy/web_ui/repos.py index ae4741f..5aa5a21 100644 --- a/src/hydrilla/proxy/web_ui/repos.py +++ b/src/hydrilla/proxy/web_ui/repos.py @@ -129,6 +129,10 @@ def alter_repo(repo_id: str) -> werkzeug.Response: return show_repo(repo_id, {'repo_url_invalid': True}) except st.RepoCommunicationError: return show_repo(repo_id, {'repo_communication_error': True}) + except st.FileInstallationError: + # We'll add the ability to present more meaningful errors later. For now + # let's treat file errors the same as repo communication errors. + return show_repo(repo_id, {'repo_communication_error': True}) except st.RepoApiVersionUnsupported: return show_repo(repo_id, {'repo_api_version_unsupported': True}) except st.MissingItemError: diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py index b2c1a43..c3e0c80 100644 --- a/src/hydrilla/proxy/web_ui/root.py +++ b/src/hydrilla/proxy/web_ui/root.py @@ -82,6 +82,8 @@ class WebUIAppImpl(_app.WebUIApp): self.jinja_env.globals['versions'] = versions self.jinja_env.globals['get_current_endpoint'] = get_current_endpoint + self.jinja_env.globals['InstalledStatus'] = st.InstalledStatus + self.jinja_env.globals['EnabledStatus'] = st.EnabledStatus self.before_request(authenticate_by_referrer) diff --git a/src/hydrilla/proxy/web_ui/templates/base.html.jinja b/src/hydrilla/proxy/web_ui/templates/base.html.jinja index b41a106..a34d538 100644 --- a/src/hydrilla/proxy/web_ui/templates/base.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/base.html.jinja @@ -45,6 +45,12 @@ in a proprietary work, I am not going to enforce this in court. color: inherit; } + .inline-form { + display: inline-block; + padding: 0; + margin: 0; + } + .small-print { font-size: 80%; color: #555; diff --git a/src/hydrilla/proxy/web_ui/templates/packages/show_single_version.html.jinja b/src/hydrilla/proxy/web_ui/templates/packages/show_single_version.html.jinja index beedd43..1b46da7 100644 --- a/src/hydrilla/proxy/web_ui/templates/packages/show_single_version.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/packages/show_single_version.html.jinja @@ -25,6 +25,16 @@ in a proprietary work, I am not going to enforce this in court. {{ super() }} {% endblock %} {% block main %} + {%- if uninstall_disallowed is defined %} + <aside class="error-note"> + {{ _('web_ui.err.uninstall_disallowed') }} + </aside> + {%- endif %} + {%- if repo_communication_error is defined %} + <aside class="error-note"> + {{ _('web_ui.err.repo_communication_error') }} + </aside> + {%- endif %} <h3> {{ _('web_ui.packages.single_version.heading.name_{}') @@ -35,4 +45,45 @@ in a proprietary work, I am not going to enforce this in court. {{ display_info.info.versioned_identifier }} </div> TODO: add more info... -{% endblock %} + {%- if display_info.installed == InstalledStatus.INSTALLED %} + <div> + {{ _('web_ui.packages.single_version.package_is_installed') }} + </div> + {%- if uninstall_disallowed is not defined %} + <form method="POST"> + <input name="action" value="uninstall_package" type="hidden"> + <button class="green-button"> + {{ _('web_ui.packages.single_version.uninstall_button') }} + </button> + </form> + {%- endif %} + {%- elif display_info.installed == InstalledStatus.NOT_INSTALLED %} + <div> + {{ _('web_ui.packages.single_version.package_is_not_installed') }} + </div> + <form method="POST"> + <input name="action" value="install_package" type="hidden"> + <button class="green-button"> + {{ _('web_ui.packages.single_version.install_button') }} + </button> + </form> + {%- else %} + <div> + {{ _('web_ui.packages.single_version.package_install_failed') }} + </div> + <div> + <form method="POST" class="inline-form"> + <input name="action" value="install_package" type="hidden"> + <button class="green-button"> + {{ _('web_ui.packages.single_version.retry_install_button') }} + </button> + </form> + <form method="POST" class="inline-form"> + <input name="action" value="uninstall_package" type="hidden"> + <button class="green-button"> + {{ _('web_ui.packages.single_version.leave_uninstalled_button') }} + </button> + </form> + </div> + {%- endif %} +{%- endblock %} diff --git a/src/hydrilla/proxy/web_ui/templates/repos/add.html.jinja b/src/hydrilla/proxy/web_ui/templates/repos/add.html.jinja index 3fdcbd3..1b618cf 100644 --- a/src/hydrilla/proxy/web_ui/templates/repos/add.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/repos/add.html.jinja @@ -31,12 +31,12 @@ in a proprietary work, I am not going to enforce this in court. </div> {% if repo_name_invalid is defined -%} <aside class="error-note"> - {{ _('web_ui.repos.add.repo_name_invalid') }} + {{ _('web_ui.err.repo_name_invalid') }} </aside> {%- endif %} {% if repo_name_taken is defined -%} <aside class="error-note"> - {{ _('web_ui.repos.add.repo_name_taken') }} + {{ _('web_ui.err.repo_name_taken') }} </aside> {%- endif %} <div> @@ -49,7 +49,7 @@ in a proprietary work, I am not going to enforce this in court. </div> {% if repo_url_invalid is defined -%} <aside class="error-note"> - {{ _('web_ui.repos.add.repo_url_invalid') }} + {{ _('web_ui.err.repo_url_invalid') }} </aside> {%- endif %} <div> 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 b3a4f32..a5998b8 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 @@ -29,12 +29,12 @@ in a proprietary work, I am not going to enforce this in court. {% block main %} {%- if repo_communication_error is defined %} <aside class="error-note"> - {{ _('web_ui.repos.add.repo_communication_error') }} + {{ _('web_ui.err.repo_communication_error') }} </aside> {%- endif %} {%- if repo_api_version_unsupported is defined %} <aside class="error-note"> - {{ _('web_ui.repos.add.repo_api_version_unsupported') }} + {{ _('web_ui.err.repo_api_version_unsupported') }} </aside> {%- endif %} {%- set repo_id = display_info.ref.id %} @@ -61,12 +61,12 @@ in a proprietary work, I am not going to enforce this in court. <input type="hidden" name="action" value="update_repo_data"> {%- if repo_name_invalid is defined %} <aside class="error-note"> - {{ _('web_ui.repos.add.repo_name_invalid') }} + {{ _('web_ui.err.repo_name_invalid') }} </aside> {%- endif %} {%- if repo_name_taken is defined %} <aside class="error-note"> - {{ _('web_ui.repos.add.repo_name_taken') }} + {{ _('web_ui.err.repo_name_taken') }} </aside> {%- endif %} <div> @@ -109,7 +109,7 @@ in a proprietary work, I am not going to enforce this in court. <input type="hidden" name="action" value="update_repo_data"> {%- if repo_url_invalid is defined %} <aside class="error-note"> - {{ _('web_ui.repos.add.repo_url_invalid') }} + {{ _('web_ui.err.repo_url_invalid') }} </aside> {%- endif %} <div> |