Skip to content

Commit

Permalink
Updated App Submission Modal (#14)
Browse files Browse the repository at this point in the history
*Updated the home controller and used Django templating to remove a lot of the JS ran on ready. This removed duplicate calls to controllers in general

*Removed passing decrypted tokens through JS

*Added new validation for git credentials

*Instead of tracking and using active stores through JS global variables, the modal inputs are read directly and then used in JS.

*When the modal is closed, the modal will reset to the original object so that users can submit a new application

*Added GUI validations for user input
  • Loading branch information
ckrew authored Jan 29, 2024
1 parent c7b1f21 commit d5ef024
Show file tree
Hide file tree
Showing 17 changed files with 783 additions and 605 deletions.
27 changes: 23 additions & 4 deletions tethysapp/app_store/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
from tethys_sdk.routing import controller

from .resource_helpers import get_stores_reformatted
from .helpers import get_conda_stores
from .helpers import get_conda_stores, html_label_styles, get_color_label_dict
ALL_RESOURCES = []
CACHE_KEY = "warehouse_app_resources"


@controller(
name='home',
url='app-store',
permissions_required='use_app_store'
permissions_required='use_app_store',
app_workspace=True
)
def home(request):
def home(request, app_workspace):
"""Created the context for the home page of the app store
Args:
Expand All @@ -25,10 +26,28 @@ def home(request):
object: Rendered html Django object
"""
available_stores = get_conda_stores()
labels_style_dict, available_stores = get_color_label_dict(available_stores)

object_stores_formatted_by_label_and_channel = get_stores_reformatted(app_workspace, refresh=False,
conda_channels="all")

tethys_version_regex = re.search(r'([\d.]+[\d])', tethys_version).group(1)
object_stores_formatted_by_label_and_channel['tethysVersion'] = tethys_version_regex

availableApps = object_stores_formatted_by_label_and_channel['availableApps']
installedApps = object_stores_formatted_by_label_and_channel['installedApps']
incompatibleApps = object_stores_formatted_by_label_and_channel['incompatibleApps']
tethysVersion = object_stores_formatted_by_label_and_channel['tethysVersion']

context = {
'storesData': available_stores,
'show_stores': True if len(available_stores) > 0 else False
'show_stores': True if len(available_stores) > 0 else False,
'list_styles': html_label_styles,
'labels_style_dict': labels_style_dict,
'availableApps': availableApps,
'installedApps': installedApps,
'incompatibleApps': incompatibleApps,
'tethysVersion': tethysVersion
}

return render(request, 'app_store/home.html', context)
Expand Down
48 changes: 46 additions & 2 deletions tethysapp/app_store/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

CACHE_KEY = "warehouse_github_app_resources"

html_label_styles = ["blue", "indigo", "pink", "red", "teal", "cyan", "white", "gray", "gray-dark", "purple"]


def get_override_key():
"""Returns a github override value if set
Expand Down Expand Up @@ -176,7 +178,7 @@ def get_github_install_metadata(app_workspace):
return github_installed_apps_list


def get_conda_stores(active_only=False, conda_channels="all"):
def get_conda_stores(active_only=False, conda_channels="all", sensitive_info=False):
"""Get the conda stores from the custom settings and decrypt tokens as well
Args:
Expand All @@ -199,6 +201,48 @@ def get_conda_stores(active_only=False, conda_channels="all"):
available_stores = [store for store in available_stores if store['conda_channel'] in conda_channels]

for store in available_stores:
store['github_token'] = decrypt(store['github_token'], encryption_key)
if not sensitive_info:
del store['github_token']
del store['github_organization']
else:
store['github_token'] = decrypt(store['github_token'], encryption_key)

return available_stores


def get_color_label_dict(stores):
"""Creates a new dictionary and updates the store metadata with a unique color styling for each conda channel and
each conda label
Args:
stores (list): Dictionary of conda store metadata
Returns:
Dict: Color styling information for the conda channel and conda label. Used in JS
Dict: Updated store information with the color styling. Used in Django templating
"""
color_store_dict = {}
index_style = 0
for store in stores:
store['conda_labels'] = sorted(list(set(store['conda_labels']))) # remove duplicates
conda_channel = store['conda_channel']
store['conda_labels'] = [{"label_name": label} for label in store['conda_labels']]
conda_labels = store['conda_labels']
color_store_dict[conda_channel] = {'channel_style': '', 'label_styles': {}}

color_store_dict[conda_channel]['channel_style'] = html_label_styles[index_style]
store['channel_style'] = html_label_styles[index_style]
index_style += 1

for label in conda_labels:
label_name = label['label_name']
color_store_dict[conda_channel]['label_styles'][label_name] = html_label_styles[index_style]
label['label_style'] = html_label_styles[index_style]
if label_name in ['main', 'master']:
label['active'] = True
else:
label['active'] = False

index_style += 1

return color_store_dict, stores
2 changes: 1 addition & 1 deletion tethysapp/app_store/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def receive(self, text_data):
module_name = sys.modules[__name__]
args = [text_data_json['data'], self.channel_layer]

app_workspace_functions = ['begin_install', 'restart_server', 'get_log_file',
app_workspace_functions = ['begin_install', 'restart_server', 'get_log_file', 'process_branch'
'initialize_local_repo_for_active_stores', 'update_app', 'uninstall_app']
if function_name in app_workspace_functions:
app_workspace = await sync_to_async(get_app_workspace, thread_sensitive=True)(app)
Expand Down
Loading

0 comments on commit d5ef024

Please sign in to comment.