Verified Commit ebb71412 authored by Štěpán Henek's avatar Štěpán Henek 🌩

netboot plugin logic integrated

parent 7e2f1e34
This diff is collapsed.
......@@ -18,10 +18,10 @@ import base64
import bottle
import typing
from foris import fapi
from foris import fapi, validators
from foris.form import File, Hidden, Textbox
from foris.state import current_state
from foris.utils.translators import gettext as _
from foris.utils.translators import gettext as _, gettext_dummy as gettext
from foris.config_handlers.base import BaseConfigHandler
from foris.config_handlers.wifi import WifiEditForm
......@@ -195,3 +195,33 @@ class SubordinatesWifiHandler(BaseConfigHandler):
def get_form(self):
ajax_form = WifiEditForm(self.data)
return ajax_form.foris_form
class NetbootConfigHandler(BaseConfigHandler):
STATE_ACCEPTED = gettext("accepted")
STATE_INCOMMING = gettext("incomming")
userfriendly_title = gettext("Netboot")
def get_form(self):
form = fapi.ForisForm("netboot", {})
form.add_section(
name="main_section",
title=self.userfriendly_title,
)
def form_cb(data):
return "save_result", {}
form.add_callback(form_cb)
return form
def get_serial_form(self, data=None):
generate_serial_form = fapi.ForisForm("serial_form", data)
serial_section = generate_serial_form.add_section("serial_section", title=None)
serial_section.add_field(
Textbox, name="serial", label=" ", required=True,
validators=[validators.MacAddress()],
)
return generate_serial_form
// TODO separete reasonable part for dynamic js
Foris.initNetbootRecordsForms = () => {
$(".record-form").submit((e) => {
e.preventDefault();
let form = $(e.currentTarget);
let action = $(e.originalEvent.explicitOriginalTarget).val();
switch (action) {
case "revoke":
$.ajax({
type: "POST",
url: form.attr('action'),
data: `${form.serialize()}&action=${action}`,
success: (data) => {
if (data.result) {
Foris.loadNetbootList();
// TODO success message
} else {
// TODO error message
}
},
});
break;
case "accept":
$.ajax({
type: "POST",
url: form.attr('action'),
data: `${form.serialize()}&action=${action}`,
success: (data) => {
if (data.result) {
Foris.loadNetbootList();
// TODO success message
} else {
// TODO error message
}
},
});
form.find("button").prop('disabled', true);
break;
}
});
}
Foris.addWsHanlder("netboot", (msg) => {
switch(msg.action) {
case "revoke":
case "accept":
Foris.loadNetbootList();
break;
}
});
// Update chart after page is rendred
$(document).ready(function() {
Foris.initNetbootRecordsForms();
Foris.loadNetbootList();
});
Foris.messages.subordinatesSubordinatesFailed = (controller_id) => {
return `{% trans controller_id="${controller_id}" %}Connection to '{{ controller_id }}' was interrupted.{% endtrans %}`;
};
Foris.netbootMessages = {
}
Foris.loadNetbootList = () => {
$.get('{{ url("config_ajax", page_name="subordinates-netboot") }}', {action: "list"})
.done((response) => {
$("#records-table").replaceWith(response);
Foris.initNetbootRecordsForms();
})
}
{% if records %}
<table id="records-table">
<thead><th>{% trans %}Serial{% endtrans %}</th><th>{% trans %}Paired{% endtrans %}</th><th></th></thead>
<tbody>
{% for record in records %}
<tr>
<td>{{ record.serial }}</td>
{% if record.state == "accepted" %}
<td title="{% trans %}Paired{% endtrans %}">
<i class="fas fa-check"></i>
</td>
{% else %}
<td title="{% trans %}Unpaired{% endtrans %}">
<i class="fas fa-times"></i>
</td>
{% endif %}
<td>
<form action="{{ url("config_ajax", page_name="subordinates-netboot") }}" method="post" class="record-form">
<input type="hidden" name="serial" value="{{ record.serial }}">
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
{% if record.state == "accepted" %}
<button name="action" value="revoke" type="submit">{% trans %}Revoke{% endtrans %}</button>
{% else %}
<button name="action" value="accept" type="submit">{% trans %}Accept{% endtrans %}</button>
{% endif %}
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p id="records-table">{% trans %}No suitable devices found.{% endtrans %}</p>
{% endif %}
{% macro sub_buttons(controller_id, enabled, form_class) -%}
<form action="{{ url("config_ajax", page_name="subordinates") }}" method="post" class="subordinate-buttons {{ form_class }}">
<form action="{{ url("config_ajax", page_name="subordinates-setup") }}" method="post" class="subordinate-buttons {{ form_class }}">
<input type="hidden" name="controller_id" value="{{ controller_id }}">
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
{% if enabled %}
......
{% extends 'config/base.html.j2' %}
{% block config_base %}
{% if is_xhr is not defined %}
<div id="page-subordinates-netboot" class="config-page">
{% endif %}
{% include '_messages.html.j2' %}
<p>{% trans %}Manage devices which can be booted from this device through network.{% endtrans %}</p>
</form>
<h3>{% trans %}Devices suitable for netboot{% endtrans %}</h3>
<div id="records-table">
{% trans %}Loading devices...{% endtrans %}
</div>
<br />
<div class="message info">
{%- trans setup_url=url("config_page", page_name="subordinates-setup") %}
Note that if everything goes well the accepted devices should <strong>eventually appear</strong> on <a href="{{ setup_url }}">Set up</a> page.
{% endtrans -%}
</div>
{% if is_xhr is not defined %}
</div>
{% endif %}
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment