Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
enolfc committed Aug 26, 2024
1 parent 5d7c695 commit b5fd7a8
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 100 deletions.
10 changes: 1 addition & 9 deletions egi_notebooks_hub/b2drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@

import base64

from jinja2 import (
BaseLoader,
ChoiceLoader,
Environment,
FileSystemLoader,
PackageLoader,
)

from egi_notebooks_hub.onedata import OnedataSpawner

from jinja2 import ChoiceLoader, Environment, FileSystemLoader, PackageLoader
from kubernetes_asyncio.client.rest import ApiException


Expand Down
184 changes: 95 additions & 89 deletions egi_notebooks_hub/templates/b2drop-form.html
Original file line number Diff line number Diff line change
@@ -1,115 +1,122 @@
<style>{% include 'b2drop-style.css' %}</style>
<!-- htmlhint id-class-value:false,doctype-first:false,spec-char-escape:false -->
<style>
{% include 'b2drop-style.css' %}
</style>
<div class="form-group" id="kubespawner-profiles-list">
{%- for profile in profile_list %}
{#- Wrap everything in a label tag so clicking anywhere selects the option #}
<label for="profile-item-{{ profile.slug }}"
class="profile js-profile-label">
<div class="radio">
<input type="radio"
name="profile"
id="profile-item-{{ profile.slug }}"
value="{{ profile.slug }}"
{% if profile.default %}checked{% endif %} />
</div>
{#- Wrap everything in a label tag so clicking anywhere selects the option #}
<label for="profile-item-{{ profile.slug }}" class="profile js-profile-label">
<div class="radio">
<input type="radio" name="profile" id="profile-item-{{ profile.slug }}"
value="{{ profile.slug }}" {% if profile.default %}checked{% endif %} />
</div>
<div>
<h3>{{ profile.display_name }}</h3>
{%- if profile.description %}<p>{{ profile.description }}</p>{%- endif %}
{%- if profile.profile_options %}
<div>
<h3>{{ profile.display_name }}</h3>
{%- if profile.description %}<p>{{ profile.description }}</p>{%- endif %}
{%- if profile.profile_options %}
<div>
{%- for k, option in profile.profile_options.items() %}
<div class="js-options-container">
<div class="option">
<label for="profile-option-{{ profile.slug }}--{{ k }}"
class="js-profile-option-label">{{ option.display_name }}</label>
<select name="profile-option-{{ profile.slug }}--{{ k }}"
class="form-control js-profile-option-select">
{%- for k, choice in option['choices'].items() %}
<option value="{{ k }}" {% if choice.default %}selected{% endif %}>{{ choice.display_name }}</option>
{%- endfor %}
{%- if option['unlisted_choice']['enabled'] %}
<option value="unlisted-choice">{{ option['unlisted_choice']['display_name_in_choices'] }}</option>
{%- endif %}
</select>
</div>
{%- if option['unlisted_choice']['enabled'] %}
<div class="option hidden js-other-input-container">
<label for="profile-option-{{ profile.slug }}--{{ k }}--unlisted-choice">
{{ option['unlisted_choice']['display_name'] }}
</label>
<input data-name="profile-option-{{ profile.slug }}--{{ k }}--unlisted-choice"
{%- if option['unlisted_choice']['validation_regex'] %}
pattern="{{ option['unlisted_choice']['validation_regex'] }}"
{%- endif %}
title="{{ option['unlisted_choice']['validation_message'] }}"
class="form-control js-other-input" />
</div>
{%- endif %}
</div>
{%- endfor %}
{%- for k, option in profile.profile_options.items() %}
<div class="js-options-container">
<div class="option">
<label for="profile-option-{{ profile.slug }}--{{ k }}"
class="js-profile-option-label">{{ option.display_name }}</label>
<select name="profile-option-{{ profile.slug }}--{{ k }}"
class="form-control js-profile-option-select">
{%- for k, choice in option['choices'].items() %}
<option value="{{ k }}" {% if choice.default %}selected{% endif %}>
{{ choice.display_name }}
</option>
{%- endfor %}
{%- if option['unlisted_choice']['enabled'] %}
<option value="unlisted-choice">
{{ option['unlisted_choice']['display_name_in_choices'] }}
</option>
{%- endif %}
</select>
</div>
{%- endif %}
{%- if option['unlisted_choice']['enabled'] %}
<div class="option hidden js-other-input-container">
<label for="profile-option-{{ profile.slug }}--{{ k }}--unlisted-choice">
{{ option['unlisted_choice']['display_name'] }}
</label>
<input
data-name="profile-option-{{ profile.slug }}--{{ k }}--unlisted-choice"
{%- if option['unlisted_choice']['validation_regex'] %}
pattern="{{ option['unlisted_choice']['validation_regex'] }}"
{%- endif %}
title="{{ option['unlisted_choice']['validation_message'] }}"
class="form-control js-other-input"
/>
</div>
{%- endif %}
</div>
{%- endfor %}
</div>
</label>
{%- endif %}
</div>
</label>
{%- endfor %}
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a class="collabpsed" role="button" data-toggle="collapse"
data-parent="#accordion" href="#collapseOne" aria-expanded="false"
aria-controls="collapseOne">
<a class="collabpsed" role="button" data-toggle="collapse" data-parent="#accordion"
href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
B2DROP connection
</a>
{%if b2drop_ready %}<span class="label label-success">Already configured!</span>{% endif %}
{%if b2drop_ready %}
<span class="label label-success">Already configured!</span>
{% endif %}
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel"
aria-labelledby="headingOne">
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<div class='form-group'>
<div class="form-group">
<label for="b2drop-user" class="form-label">B2DROP app Username</label>
<input type="text" class="form-control" name="b2drop-user"
id="b2drop-user" aria-describedby="b2drop-user-help"
value="{{ b2drop_user }}">
<input type="text" class="form-control" name="b2drop-user" id="b2drop-user"
aria-describedby="b2drop-user-help" value="{{ b2drop_user }}"/>
<div id="b2drop-user-help" class="form-text">
Create new app password at
<a href="https://b2drop.eudat.eu/settings/user/security">
B2DROP security configuration
</a>
</div>
<a href="https://b2drop.eudat.eu/settings/user/security">
B2DROP security configuration</a>
</div>
</div>
<div class='form-group'>
<label for="b2drop-pwd" class="form-label">B2DROP app Password</label>
<input type="password" class="form-control" name="b2drop-pwd"
id="b2drop-pwd" value="{{ b2drop_pwd }}">
<div class="form-group">
<label for="b2drop-pwd" class="form-label">B2DROP app Password</label>
<input type="password" class="form-control" name="b2drop-pwd" id="b2drop-pwd"
value="{{ b2drop_pwd }}"/>
</div>
<div class='form-group'>
<input type="checkbox" id="b2drop-remember"
name="b2drop-remember" {%if b2drop_ready %}checked{% endif %}>
<label class="form-check-label" for="from-check-input">
Remember B2DROP credentials
</label>
<div class="form-group">
<input type="checkbox" id="b2drop-remember" name="b2drop-remember"
{%if b2drop_ready %}checked{% endif %}/>
<label class="form-check-label" for="from-check-input">
Remember B2DROP credentials
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$('.js-profile-option-select, .js-profile-option-label').click(function() {
$(".js-profile-option-select, .js-profile-option-label").click(function () {
// we need this bit of JS to select the profile when a <select> inside is clicked.
$(this).parents('.js-profile-label')
.find('input[type=radio]')
.prop('checked', true);
$(this)
.parents(".js-profile-label")
.find("input[type=radio]")
.prop("checked", true);
});

// If the user selects "Other" in the dropdown, show the free text field
$('.js-profile-option-select').change(function() {
$(".js-profile-option-select").change(function () {
const selectionValue = $(this).val();
const $otherInputContainer = $(this).parents('.js-options-container').find('.js-other-input-container');
const $otherInput = $(this).parents('.js-options-container').find('.js-other-input');
if (selectionValue === 'unlisted-choice') {

const $otherInputContainer = $(this)
.parents(".js-options-container")
.find(".js-other-input-container");
const $otherInput = $(this)
.parents(".js-options-container")
.find(".js-other-input");
if (selectionValue === "unlisted-choice") {
// if the Select box is selected with a value that is not 'unlisted-choice',
// we remove the "name" attribute for the unlisted-choice input
// and vice-versa, so that we only submit valid form values
Expand All @@ -118,14 +125,14 @@ <h4 class="panel-title">

// This can probably be done cleaner by completely refactoring
// how we send values from the frontend.
$(this).data('name', $(this).attr('name'));
$(this).removeAttr('name');
$otherInput.attr('name', $otherInput.data('name'));
$otherInputContainer.removeClass('hidden');
$(this).data("name", $(this).attr("name"));
$(this).removeAttr("name");
$otherInput.attr("name", $otherInput.data("name"));
$otherInputContainer.removeClass("hidden");
} else {
$otherInput.removeAttr('name');
$(this).attr('name', $(this).data('name'));
$otherInputContainer.addClass('hidden');
$otherInput.removeAttr("name");
$(this).attr("name", $(this).data("name"));
$otherInputContainer.addClass("hidden");
}
});

Expand All @@ -135,7 +142,6 @@ <h4 class="panel-title">
// trigger the `change` event on the select inputs,
// so that if "Other" is selected on page load, the corresponding
// free-text input shows
$('.js-profile-option-select').trigger('change');
$(".js-profile-option-select").trigger("change");
});

</script>
11 changes: 10 additions & 1 deletion static/css/egi.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/* Footer */
/*
* Some style for the footer
*/

html {
position: relative;
min-height: 100%;
}

body {
margin-bottom: 60px; /* Margin bottom by footer height */
font-family: 'DM Sans', sans-serif;
}

.footer {
z-index: 10;
position: fixed;
Expand All @@ -17,15 +22,19 @@ body {
opacity: 0.80;
font-size: 0.85rem;
}

.footer img {
height: 30px;
margin-right: 20px;
}

#jupyterhub-logo .jpy-logo {
height: 60px;
margin-top: 5px;
margin-right: 20px;
}

/* this is mainly for the policy pages */
address {
white-space: pre-line;
}
2 changes: 1 addition & 1 deletion templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
alt="CESNET logo"
src="{{ static_url('images/cesnet.png') }}"
/></a>
{{ service_name }} is an <a href="https://www.egi.eu">EGI</a> service provided by
{{ service_name }} is an <a href="https://www.egi.eu">EGI</a> service provided by
<a href="https://www.cesnet.cz/?lang=en">CESNET</a>
</div>
<div class="col-md-6 text-end">
Expand Down

0 comments on commit b5fd7a8

Please sign in to comment.