Skip to content

Commit

Permalink
Uninstall button, refs #12
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 11, 2021
1 parent fa03310 commit 359bf9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions datasette_app_support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async def inner():
plugin["name"]: plugin["version"]
for plugin in (await datasette.client.get("/-/plugins.json")).json()
}
default_plugins = (os.environ.get("DATASETTE_DEFAULT_PLUGINS") or "").split()
for plugin in plugins:
is_installed = plugin["name"] in installed_plugins
installed_version = installed_plugins.get(plugin["name"])
Expand All @@ -42,6 +43,7 @@ async def inner():
)
else None
)
plugin["is_default"] = plugin["name"] in default_plugins

datasette.remove_database("_memory")
datasette.add_memory_database("temporary")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ <h2>{{ row.name }}</h2>
<p><strong>Downloads this week:</strong> {{ row.downloads_this_week }} &nbsp; <strong>Stars:</strong> {{ row.stargazers_count }}</p>
<p><strong>Latest release:</strong> {{ row.tag_name }} on {{ prettydate(row.latest_release_at) }}</p>
{% if row.installed == "installed" %}
<p><strong>{{ row.installed_version }} currently installed</strong></p>
<p><strong>{{ row.installed_version }} currently installed</strong>{% if row.is_default %} (default plugin){% endif %}</p>
{% if actor.id == "root" and row.upgrade == "upgrade available" %}
<p><a class="plugin-button upgrade-plugin-button" data-plugin="{{ row.name }}" data-pluginversion="{{ row.tag_name }}" href="#">Upgrade to {{ row.tag_name }}</a></p>
{% endif %}
{% if actor.id == "root" and not row.is_default %}
<p><a class="plugin-button uninstall-plugin-button" data-plugin="{{ row.name }}" data-pluginversion="{{ row.tag_name }}" href="#">Uninstall {{ row.tag_name }}</a></p>
{% endif %}
{% else %}
{% if actor.id == "root" %}
<p><a class="plugin-button install-plugin-button" data-plugin="{{ row.name }}" data-pluginversion="{{ row.tag_name }}" href="#">Install plugin: {{ row.name }}</a></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@
);
});
});
Array.from(document.querySelectorAll(".uninstall-plugin-button")).forEach(button => {
button.addEventListener("click", (ev) => {
ev.preventDefault();
ev.target.style.pointerEvents = 'none';
datasetteApp.uninstallPlugin(
ev.target.dataset.plugin,
ev.target
);
});
});
});
</script>
{% endblock %}

0 comments on commit 359bf9e

Please sign in to comment.