Skip to content

Commit

Permalink
Merge pull request #80 from juliushaag/create-web-interface-for-simul…
Browse files Browse the repository at this point in the history
…ation-view-app

Finalized web page
  • Loading branch information
juliushaag authored Jul 26, 2024
2 parents a306c53 + bb613ab commit 2fc8808
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 102 deletions.
2 changes: 1 addition & 1 deletion quafelweb/hardware_controller/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ class HardwareProfile(models.Model):
needs_totp = models.BooleanField(default=False)

def __str__(self):
return self.name + " " + self.description + " " + self.protocol + " " + self.ip_addr + " " + str(self.port_addr) + " " + str(self.archived)
return self.name + " " + self.description + " " + self.protocol + " " + self.ip_addr + " " + str(self.port_addr) + " " + str(self.archived)

18 changes: 11 additions & 7 deletions quafelweb/hardware_controller/static/hardware.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@
}


#add_hardware_name,
#add_hardware_description,
#add_hardware_connection {
#hardware_name,
#hardware_description,
#hardware_connection {
margin-bottom: 2em;
}

#add_hardware_description div input,
#add_hardware_description div textarea {
#hardware_description div input,
#hardware_description div textarea {
width: 100%;
height: 4em;
}


#add_hardware_description textarea{
#hardware_description textarea{
height: 15em;
resize: none;
overflow: auto;
}

#add_hardware_button {
#hardware_button {
width: 100%;
}

Expand All @@ -74,4 +74,8 @@
#button_array button,
#button_array a {
width: 10em;
}

#hardware_totp {
margin: 2em 0;
}
38 changes: 10 additions & 28 deletions quafelweb/hardware_controller/templates/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,28 @@
{% block content %}
<form method="post" class="page_panel" action="submit/">
{% csrf_token %}
<input required name="hardware_id" type="hidden" value="{{ hardware.uuid }}"></input>
<div>
<input required name="hardware_name" value="{{ hardware.name }}">
<input name="hardware_id" type="hidden" value="{{ hardware.uuid }}"></input>
<div id="hardware_name">
<input required name="hardware_name" value="{{ hardware.name }}">
<span>Name</span>
</div>
<div>
<div id="hardware_description">
<textarea required name="hardware_description">{{ hardware.description }}</textarea>
<span>Description</span>
</div>
<div>
<input required name="connection" value="{{ hardware.ip_addr }}">
<div id="hardware_connection">
<input required name="hardware_connection" value="{{ hardware.protocol }}://{{ hardware.ip_addr }}:{{hardware.port_addr}}">
<span>Connection</span>
</div>

<div id="button_array">
<a href="{% url "hardware" %}" class="link_button">Back</a>
<button type="submit" name="hardware_id" value={{hardware.uuid}}>Save</button>
<button type="submit" name="hardware_id" id="delete_button" value={{hardware.uuid}}>Delete</button>
</div>
</form>
<form method="post" class="page_panel" action="submit/">
{% csrf_token %}
<input required name="hardware_id" type="hidden" value="{{ hardware.uuid }}"></input>
<div>
<input required name="hardware_name" value="{{ hardware.name }}">
<span>Name</span>
</div>
<div>
<textarea required name="hardware_description">{{ hardware.description }}</textarea>
<span>Description</span>
</div>
<div>
<input required name="connection" value="{{ hardware.ip_addr }}">
<span>Connection</span>
<div id="hardware_totp">
<label for="hardware_totp"><b>Requires TOTP</b></label>
<input type="checkbox" name="hardware_totp" {% if hardware.needs_totp %}checked{%endif%}>
</div>

<div id="button_array">
<a href="{% url "hardware" %}" class="link_button">Back</a>
<button type="submit" name="hardware_id" value={{hardware.uuid}}>Save</button>
<button type="submit" name="hardware_id" id="delete_button" value={{hardware.uuid}}>Delete</button>
<button type="submit" name="hardware_id" id="delete_button" value={{hardware.uuid}} formaction="{% url "delete_hardware" %}" formmethod="post">Delete</button>
</div>

</form>
Expand Down
7 changes: 3 additions & 4 deletions quafelweb/hardware_controller/templates/hardware.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
{%for hardware in hardware_profiles %}
<form class='hardware_entry' action="configure/" method="get">
<p>{{ hardware.name }}</p>
<p>{{ hardware.uuid }}</p>
<button class="icon_button" name="hardware_id" value={{hardware.uuid}}><span class="material-symbols-outlined">edit</span></button>
</form>
{% empty %}
Expand All @@ -26,15 +25,15 @@
</div>
<div class='page_panel'>
{% csrf_token %}
<div id="add_hardware_name">
<div id="hardware_name">
<input name="name">
<span>Name</span>
</div>
<div id="add_hardware_description">
<div id="hardware_description">
<textarea name="description"></textarea>
<span>Description</span>
</div>
<div id="add_hardware_connection">
<div id="hardware_connection">
<input name="connection">
<span>Connection</span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions quafelweb/hardware_controller/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
urlpatterns = [
path('', views.HardwareView.manage_profiles, name='hardware'),
path('add/', views.HardwareView.add_profile),
path('delete/', views.HardwareView.delete_profile),
path('delete/', views.HardwareView.delete_profile, name="delete_hardware"),
path('configure/', views.HardwareView.configure_profile),
path('configure/submit/', views.HardwareView.change_profile),
path('configure/submit/', views.HardwareView.submit_change),
]
62 changes: 38 additions & 24 deletions quafelweb/hardware_controller/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from account_controller.views import AccountView
from hardware_controller.models import HardwareProfile
from simulation_data.models import SimulationRun


# Create your views here.
import re as regex

class HardwareView:

Expand All @@ -26,15 +26,17 @@ def manage_profiles(request):

@AccountView.require_login
def add_profile(request):

if request.method == "POST":
name = request.POST["name"]
description = request.POST["description"]
connection = request.POST["connection"] # slurm://192.168.0.34:82
id = request.POST.get("hardware_id")
name = request.POST.get("hardware_name")
description = request.POST.get("hardware_description")
connection = request.POST.get("hardware_connection")

protocol, ip, port = connection.replace("//", "").split(":", 2)
addr_match = r"^([a-zA-Z]+)://(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})$"

HardwareProfile(name=name, description=description, protocol=protocol, ip_addr=ip, port_addr=port).save()
if id and name and description and regex.match(addr_match, connection):

protocol, ip_addr, port_addr = connection.replace("//", "").split(":", 2)
HardwareProfile(name=name, description=description, protocol=protocol, ip_addr=ip_addr, port_addr=port_addr).save()

return redirect("hardware")

Expand All @@ -43,8 +45,9 @@ def add_profile(request):
@AccountView.require_login
def delete_profile(request):

if request.method == "POST":
id = request.POST["hardware_id"]
if id := request.POST.get("hardware_id"):

SimulationRun.objects.filter(hardware=id).delete()
HardwareProfile.objects.filter(uuid=id).delete()

return redirect("hardware")
Expand All @@ -53,37 +56,48 @@ def delete_profile(request):
def configure_profile(request):


if request.method == "POST":
id = request.POST["hardware_id"]
if id := request.GET.get("hardware_id"):

profile = HardwareProfile.objects.filter(uuid=id)

if not profile.exists():
raise RuntimeError("Invalid hardware profile requested") # TODO

redirect("hardware")

context = { 'hardware' : profile.get() }

return render(request, 'configuration.html', context=context)
return render(request, 'configuration.html', context=context)

return redirect("hardware")

@AccountView.require_login
def change_profile(request):

if request.method == "GET":
id = request.GET["hardware_id"]
name = request.GET["hardware_name"]
description = request.GET["hardware_description"]

def submit_change(request):
id = request.POST.get("hardware_id")
name = request.POST.get("hardware_name")
description = request.POST.get("hardware_description")
connection = request.POST.get("hardware_connection")

addr_match = r"^([a-zA-Z]+)://(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})$"

if id and name and description and regex.match(addr_match, connection):

protocol, ip_addr, port_addr = connection.replace("//", "").split(":", 2)


profile = HardwareProfile.objects.filter(uuid=id)

needs_totp = request.POST.get("hardware_totp") == "on"

if not profile.exists():
raise RuntimeError("Invalid hardware profile requested") # TODO

profile.update(
name = name,
description = description
description = description,
protocol = protocol,
ip_addr=ip_addr,
port_addr=port_addr,
needs_totp = needs_totp
)
print(needs_totp)

return redirect("hardware")
2 changes: 1 addition & 1 deletion quafelweb/simulation_controller/static/simulation.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#filter_menu,
.env_entry {
display: grid;
grid-template-columns: 20% 30% 30% 20%;
grid-template-columns: 20% 40% 40%;
align-items: center;
}

Expand Down
24 changes: 13 additions & 11 deletions quafelweb/simulation_controller/templates/simulation.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,46 +96,45 @@ <h4>Shots</h4>
</div>
</div>
</div>
<button id="query_button">Update</button>
</div>
<div class="page_panel">
<div id="filter_menu">
<button id="simulation_conf_submit" type="submit" method="get" name="check_all">All</button>
<button id="simulation_conf_submit" type="submit" name="check_all">All</button>
<div class="dropdown">
<div class="dropbtn">{{ request.GET.hardware_filter|default:"Hardware"}}</div>
<div class="dropdown-content">
<input name="hardware_filter" type="hidden" value="{{request.GET.hardware_filter}}">
{% if request.GET.hardware_filter %}
<button name="hardware_filter" type="submit" value="">All</button>
<button name="hardware_filter" type="submit" value="">All</button>
{% endif %}
{% for hardware in hardware_profiles %}
{% if request.GET.hardware_filter != hardware.name%}
<button name="hardware_filter" type="submit" value="{{hardware.name}}">{{hardware.name}}</button>
{% endif %}
{% if request.GET.hardware_filter != hardware.name%}
<button name="hardware_filter" type="submit" value="{{hardware.name}}">{{hardware.name}}</button>
{% endif %}
{% endfor %}
</div>
</div>
<div class="dropdown">
<div class="dropbtn">{{ request.GET.simulator_filter|default:"Simulator"}}</div>
<div class="dropdown-content">
<input name="simulator_filter" type="hidden" value="{{request.GET.simulator_filter}}">
{% if request.GET.simulator_filter %}
<button name="simulator_filter" type="submit" value="">All</button>
<button name="simulator_filter" type="submit" value="">All</button>
{% endif %}
{% for simulator in simulator_profiles %}
{% if request.GET.simulator_filter != simulator.name%}
<button name="simulator_filter" type="submit" value="{{simulator.name}}">{{simulator.name}}</button>
<button name="simulator_filter" type="submit" value="{{simulator.name}}">{{simulator.name}}</button>
{% endif %}
{% endfor %}
</div>
</div>
<div class="link_button">Finished</div>
</div>
<div id="env_container">
{% for env in envs %}
<div class="env_entry">
<input type="checkbox" name={{ env.3 }} {% if env.4 %}checked{% endif %}></button>
<p>{{env.0.name}}</p>
<p>{{env.1.name}}</p>
<p >{{env.2}}/{{max_amount}}</p>
</div>
{% endfor %}
</div>
Expand Down Expand Up @@ -215,7 +214,10 @@ <h3>Hardware authentication</h3>
<span>Password</span>
</div>
{% if hardware.needs_totp %}
<input name="TOTP::{{hardware.name}}">
<div>
<input name="TOTP::{{hardware.uuid}}">
<span>TOTP</span>
</div>
{% endif %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion quafelweb/simulation_controller/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import simulation_controller.views as views

urlpatterns = [
path('', views.SimulationRequestView.default, name='simulation_configuration'),
path('', views.SimulationRequestView.selection, name='simulation_configuration'),
path('submit/', views.SimulationRequestView.submit_request, name="submit"),
path('submit_request/', views.SimulationRequestView.submit_request, name='submit_request'),

Expand Down
Loading

0 comments on commit 2fc8808

Please sign in to comment.