Skip to content

Commit

Permalink
Add "Include prereleases" check box to app manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
csadorf committed Jul 14, 2021
1 parent 846b1d5 commit 2e27a3f
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions home/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import traitlets
from aiidalab.app import AppVersion
from jinja2 import Template
from packaging.version import parse

from home.utils import load_logo
from home.widgets import Spinner, StatusHTML
Expand All @@ -24,6 +25,7 @@ class VersionSelectorWidget(ipw.VBox):
"""Class to choose app's version."""

disabled = traitlets.Bool()
prereleases = traitlets.Bool()

def __init__(self, *args, **kwargs):
style = {"description_width": "100px"}
Expand Down Expand Up @@ -171,6 +173,17 @@ def __init__(self, app, with_version_selector=False):
)
children.insert(2, self.version_selector)

# Prereleases opt-in
self.include_prereleases = ipw.Checkbox(description="Include prereleases")
ipw.dlink(
(self.include_prereleases, "value"), (self.app, "include_prereleases")
)
self.app.observe(
self._refresh_prereleases, names=["has_prereleases", "installed_version"]
)
self._refresh_prereleases(change=dict(owner=self.app)) # initialize
children.insert(3, self.include_prereleases)

super().__init__(children=children)

self.app.observe(self._refresh_widget_state)
Expand All @@ -190,6 +203,28 @@ def _formatted_version(version):

return version

def _refresh_prereleases(self, change):
app = change["owner"]
installed_version = app.installed_version

has_prereleases = app.has_prereleases
prerelease_installed = (
parse(installed_version).is_prerelease
if isinstance(installed_version, str)
else False
)

with self.hold_trait_notifications():
# The checkbox can only be enabled when the app has prereleases,
# and cannot be disabled when a prerelease is currently installed.
self.include_prereleases.disabled = (
prerelease_installed or not has_prereleases
)
# The checkbox is checked if it was already checked or a prerelease is installed:
self.include_prereleases.value = (
self.include_prereleases.value or prerelease_installed
)

def _refresh_widget_state(self, _=None):
"""Refresh the widget to reflect the current state of the app."""
with self.hold_trait_notifications():
Expand Down Expand Up @@ -223,9 +258,7 @@ def _refresh_widget_state(self, _=None):
)
else:
tooltip_danger = "Operation blocked due to local modifications."
tooltip_incompatible = (
"The app is not supported for this version of the environment."
)
tooltip_incompatible = "The app is not supported for this environment."

# Determine whether we can install, updated, and uninstall.
can_switch = (
Expand Down Expand Up @@ -327,7 +360,7 @@ def _refresh_widget_state(self, _=None):
"is not on the specified release line."
)
elif not compatible:
self.issue_indicator.value = f'<i class="fa fa-{warn_or_ban_icon}"></i> The app is not supported for this version of the environment.'
self.issue_indicator.value = f'<i class="fa fa-{warn_or_ban_icon}"></i> The app is not supported for this environment.'
else:
self.issue_indicator.value = ""
self.blocked_ignore.layout.visibility = (
Expand Down

0 comments on commit 2e27a3f

Please sign in to comment.