Small cleanups

This commit is contained in:
andrew committed 2023-06-09 00:39:15 -04:00
1 parent 5ae64025aa
commit b5b95ec9cf
5 files changed
+64 -53

No files matched your search

+47 -40
View File
@@ -1,5 +1,8 @@
{% extends "OpenBench/base.html" %}
{% load static %}
{% load mytags %}
{% block content %}
<form method="POST" action="/profile/">
@@ -12,7 +15,7 @@
<div class="row">
<label>Email</label><input value="{{ profile.user.email }}" name="email">
</div>
<div class="row">
<label>New Password</label><input type="password" name="password1">
</div>
@@ -23,57 +26,61 @@
</div>
</div>
</form>
<hr>
<br>
<form method="POST" action="/profileConfig/">
{% csrf_token %}
<div class="col" id="engines-container">
{% for engine, repo in profile.repos.items %}
<div class="row" id="engine-row-{{ engine }}">
<label>{{ engine }}</label>
<input type="text" name="engine-repo-{{ engine }}" value="{{ repo }}">
<input id="radio-{{engine}}" type="radio" name="default-status" value="{{ engine }}" {% if profile.engine == engine %}checked{% endif %}>
<span onclick="deleteRow(event)">
<i class="fa-solid fa-trash-can" style="color: #ff0000;" data-engine="{{ engine }}"></i>
</span>
</div>
{% endfor %}
<div class="row">
<select name="new-engine-name">
<option value="None">None</option>
<option selected disabled hidden>Choose an engine</option>
{% for engine in config.engines.keys %}
{% if engine not in profile.repos %}
<option value="{{ engine }}">{{ engine }}</option>
{% endif %}
{% endfor %}
</select>
<input name="new-engine-repo">
</div>
<div class="form">
<div class="col" id="engines-container">
<input type="hidden" name="deleted-repos" id="deleted-repos" value="[]">
<input class="anchorbutton btn-blue w-100" type="submit" name="add-engine" value="Update Engine">
<!-- Display engines which have repos already defined -->
{% for engine, repo in profile.repos.items %}
<div class="row" id="engine-row-{{ engine }}">
<label>{{ engine }}</label>
<input type="text" name="engine-repo-{{ engine }}" value="{{ repo|removePrefix:'https://github.com/' }}">
<input id="radio-{{engine}}" type="radio" name="default-status" value="{{ engine }}" {% if profile.engine == engine %}checked{% endif %}>
<span onclick="deleteRow(event)">
<i class="fa-solid fa-trash-can" style="color: #ff0000;" data-engine="{{ engine }}" ></i>
</span>
</div>
{% endfor %}
<div class="row">
<label> <!-- CSS Hack -->
<select name="new-engine-name">
<option value="None">None</option>
<option selected disabled hidden>New Engine</option>
{% for engine in config.engines.keys %}
{% if engine not in profile.repos %}
<option value="{{ engine }}">{{ engine }}</option>
{% endif %}
{% endfor %}
</select>
</label>
<input name="new-engine-repo">
</div>
<input type="hidden" name="deleted-repos" id="deleted-repos" value="[]">
<input class="anchorbutton btn-blue w-100" type="submit" name="add-engine" value="Save Configuration">
</div>
</div>
</form>
<script>
function deleteRow(event) {
const button = event.currentTarget.querySelector('i');
const engine = button.getAttribute('data-engine');
const radioId = 'radio-' + engine;
const radio = document.getElementById(radioId);
if (engine && radio && radio.checked) {
// Don't delete default engine.
const radio = document.getElementById('radio-' + engine);
if (engine && radio && radio.checked)
return;
}
if (engine) {
// Perform the delete action here
console.log(`Deleting engine: ${engine}`);
// Remove the corresponding row from the DOM
const row = button.parentNode.parentNode;
row.parentNode.removeChild(row);
@@ -81,13 +88,13 @@
// Update the deleted-repos hidden input field with the deleted engine
const deletedReposInput = document.getElementById('deleted-repos');
let deletedRepos = JSON.parse(deletedReposInput.value);
deletedRepos.push(engine);
deletedReposInput.value = JSON.stringify(deletedRepos);
console.log(deletedRepos);
}
}
</script>
{% endblock %}