Commit a3b9c301 authored by Jan Čermák's avatar Jan Čermák

project renamed from KRUci to Foris, with all consequences

parent 827713a6
*.pyc
static/.sass-cache/*
\ No newline at end of file
KRUci
Foris
======
KRUci is Remote Uci - it is a web GUI for configuration of system via Nuci,
Foris is Remote Uci - it is a web GUI for configuration of system via Nuci,
i.e. using Netconf.
Nowadays, KRuci is in early stage of development and almost everything in it
Nowadays, Foris is in early stage of development and almost everything in it
is a possible subject to change, thus there's no guaranteed API stability
and all the parts should be used externally only with extreme caution, if ever...
Oh, and the name is a DEFINITE subject to change ;)
......@@ -7,10 +7,10 @@ from utils import Lazy
import validators as validators_module
logger = logging.getLogger("kapi")
logger = logging.getLogger("fapi")
class KruciFormElement(object):
class ForisFormElement(object):
def __init__(self):
self.children = []
self.parent = None
......@@ -26,7 +26,7 @@ class KruciFormElement(object):
child.parent = None
class KruciForm(KruciFormElement):
class ForisForm(ForisFormElement):
def __init__(self, name, data=None, filter=None):
"""
......@@ -36,7 +36,7 @@ class KruciForm(KruciFormElement):
:type filter: Element
:return:
"""
super(KruciForm, self).__init__()
super(ForisForm, self).__init__()
self.name = name
self._request_data = data or {} # values from request
self._nuci_data = {} # values fetched from nuci
......@@ -184,7 +184,7 @@ class KruciForm(KruciFormElement):
raise NotImplementedError("Unsupported callback operation: %s" % operation)
class Section(KruciFormElement):
class Section(ForisFormElement):
def __init__(self, main_form, name, title, description=None):
super(Section, self).__init__()
self._main_form = main_form
......@@ -219,13 +219,13 @@ class Section(KruciFormElement):
% dict(title=self.title, description=self.description, content=content)
class Field(KruciFormElement):
class Field(ForisFormElement):
def __init__(self, main_form, type, name, label=None, required=False, callback=None, nuci_path=None,
nuci_preproc=lambda val: val.value, validators=None, **kwargs):
"""
:param main_form: parent form of this field
:type main_form: KruciForm
:type main_form: ForisForm
:param type: type of field
:param name: field name (rendered also as HTML name attribute)
:param label: display name of field
......
#!/usr/bin/env python
import bottle
import logging
from nuci import client
......@@ -7,7 +9,7 @@ import uci
import wizard
logger = logging.getLogger("kruci")
logger = logging.getLogger("foris")
#def set_template_defaults(template):
# template.defaults.update({
......
"""
HTML forms, based on part of web.py with some customizations.
Currently, it is used in KRUci for rendering and validating forms.
Currently, it is used in Foris for rendering and validating forms.
It might be replaced by our own solution in future, or get changed
heavily to suit our needs...
......@@ -13,7 +13,7 @@ Current major changes:
- field is validated only if it's non-empty and Field.required is True (Field.required is
also a new attribute)
- Form.render() and Form.render_css() is not used anymore and throws NotImplementedError,
Form fields should be rendered by KAPI
Form fields should be rendered by FAPI
- TODO: change signature of Field constructors, make it consistent (see Input vs. Dropdown)
web.py is originally licensed under public domain
......
var KruciWizard = {};
var ForisWizard = {};
KruciWizard.validators = {
ForisWizard.validators = {
ipv4: function(value) {
var re_ipv4 = /^(\d{1,3}\.){3}\d{1,3}$/;
return value.search(re_ipv4) != -1;
......@@ -24,7 +24,7 @@ KruciWizard.validators = {
}
};
KruciWizard.runValidator = function(validator, value, mangledArgs) {
ForisWizard.runValidator = function(validator, value, mangledArgs) {
if (!mangledArgs)
return this.validators[validator](value);
var argsArray = mangledArgs.split("|");
......@@ -38,7 +38,7 @@ KruciWizard.runValidator = function(validator, value, mangledArgs) {
return this.validators[validator](value, argsArray[0], argsArray[1], argsArray[2]);
};
KruciWizard.validateField = function(field) {
ForisWizard.validateField = function(field) {
field = $(field);
var markInvalid = function() {
......@@ -58,9 +58,9 @@ KruciWizard.validateField = function(field) {
var validators = field.data("validators").split(" ");
for (var i in validators) {
console.log("checking for validator " + validators[i]);
if (validators.hasOwnProperty(i) && KruciWizard.validators.hasOwnProperty(validators[i])) {
if (validators.hasOwnProperty(i) && ForisWizard.validators.hasOwnProperty(validators[i])) {
var args = field.data("validator-" + validators[i]);
var result = KruciWizard.runValidator(validators[i], field.val(), args);
var result = ForisWizard.runValidator(validators[i], field.val(), args);
if (result) {
markOk();
}
......@@ -74,18 +74,18 @@ KruciWizard.validateField = function(field) {
};
KruciWizard.validateForm = function(form) {
ForisWizard.validateForm = function(form) {
var inputs = $("input.validate", form);
console.log(inputs);
for (var i in inputs) {
if (inputs.hasOwnProperty(i) && !KruciWizard.validateField(inputs[i]))
if (inputs.hasOwnProperty(i) && !ForisWizard.validateField(inputs[i]))
return false;
}
return true;
};
KruciWizard.updateForm = function() {
ForisWizard.updateForm = function() {
var form = $("#wizard-form");
form.css("background-color", "red");
$.post(form.attr("action"), form.serialize())
......@@ -95,35 +95,35 @@ KruciWizard.updateForm = function() {
});
};
KruciWizard.callAjaxAction = function(wizardStep, action) {
ForisWizard.callAjaxAction = function(wizardStep, action) {
return $.get("/wizard/step/" + wizardStep + "/ajax", {action: action});
};
KruciWizard.ntpUpdate = function() {
KruciWizard.callAjaxAction("3", "ntp_update")
ForisWizard.ntpUpdate = function() {
ForisWizard.callAjaxAction("3", "ntp_update")
.done(function(data) {
if (data.success) {
$("#wizard-time").empty().append("<p>Bazinga! Jdeme dál.</p>")
}
else {
KruciWizard.showTimeForm();
ForisWizard.showTimeForm();
}
});
};
KruciWizard.runUpdater = function () {
KruciWizard.callAjaxAction("4", "run_updater")
ForisWizard.runUpdater = function () {
ForisWizard.callAjaxAction("4", "run_updater")
.done(function(data) {
console.log(data);
if (data.success)
KruciWizard.checkUpdaterStatus();
ForisWizard.checkUpdaterStatus();
else
console.log("TODO: SHIT HAPPENED");
});
};
KruciWizard.checkUpdaterStatus = function() {
KruciWizard.callAjaxAction("4", "updater_status")
ForisWizard.checkUpdaterStatus = function() {
ForisWizard.callAjaxAction("4", "updater_status")
.done(function(data) {
var updaterStatus = $("#wizard-updater-status");
updaterStatus.empty().append(data.status);
......@@ -134,13 +134,13 @@ KruciWizard.checkUpdaterStatus = function() {
else if (data.status == "running") {
// timeout is better, because we won't get multiple requests stuck processing
// real delay between status updates is then delay + request_processing_time
window.setTimeout(KruciWizard.checkUpdaterStatus, 1000);
window.setTimeout(ForisWizard.checkUpdaterStatus, 1000);
}
});
};
KruciWizard.showTimeForm = function() {
KruciWizard.callAjaxAction("3", "time_form")
ForisWizard.showTimeForm = function() {
ForisWizard.callAjaxAction("3", "time_form")
.done(function(data) {
$("#wizard-time").empty().append(data.form);
});
......@@ -151,15 +151,15 @@ KruciWizard.showTimeForm = function() {
// TODO: also, most of these "hooks" are not production-ready
$(document).ready(function(){
$(document).on("change", ".has-requirements", function(){
KruciWizard.updateForm();
ForisWizard.updateForm();
});
$(document).on("keyup", ".validate", function() {
KruciWizard.validateField(this);
ForisWizard.validateField(this);
});
$(document).on("submit", "form", function(e) {
if (KruciWizard.validateForm(this)) {
if (ForisWizard.validateForm(this)) {
console.log("submitting!");
}
else {
......
......@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>KRUci is Remote Uci </title>
<title>Foris administration interface</title>
<link href="/static/css/gumby.css" rel="stylesheet">
<link href="/static/css/font-awesome.css" rel="stylesheet">
<link href="/static/css/screen.css" rel="stylesheet">
......
%rebase _layout **locals()
<h1>KRUci!</h1>
<h1>Foris</h1>
<h2>roscesňýk</h2>
<ul>
......
......@@ -37,7 +37,7 @@
%end
%############################## PAGE ITSELF STARTS HERE ############################################
<h1>KRUci</h1>
<h1>Foris</h1>
<h2>about:config</h2>
%if tree:
......
......@@ -15,7 +15,7 @@
<script>
$(document).ready(function(){
KruciWizard.ntpUpdate();
ForisWizard.ntpUpdate();
});
</script>
%end
\ No newline at end of file
......@@ -9,6 +9,6 @@
<script>
$(document).ready(function() {
KruciWizard.runUpdater();
ForisWizard.runUpdater();
});
</script>
\ No newline at end of file
......@@ -10,7 +10,7 @@ from utils import print_model
from validators import NotEmpty, RegExp
logger = logging.getLogger("kruci.uci")
logger = logging.getLogger("foris.uci")
class UciRawForm(Form):
......
......@@ -2,7 +2,7 @@ import logging
from xml.etree import cElementTree as ET
logger = logging.getLogger("kruci.utils")
logger = logging.getLogger("foris.utils")
class Lazy(object):
......
......@@ -2,7 +2,7 @@ from bottle import Bottle, template, request
import bottle
import logging
from form import Password, Textbox, Dropdown, Checkbox, Hidden
import kapi
import fapi
from nuci import client
from nuci.modules import time, uci_raw, updater
from nuci.modules.uci_raw import Uci, Config, Section, Option
......@@ -43,7 +43,7 @@ class BaseWizardStep(object):
"""
:return:
:rtype: kapi.KruciForm
:rtype: fapi.ForisForm
"""
raise NotImplementedError()
......@@ -68,7 +68,7 @@ class WizardStep1(BaseWizardStep):
"""
def get_form(self):
# form definitions
pw_form = kapi.KruciForm("password", self.data)
pw_form = fapi.ForisForm("password", self.data)
pw_main = pw_form.add_section(name="set_password", title="Password",
description="Set your password.")
pw_main.add_field(Password, name="password", label="Password", required=True,
......@@ -84,9 +84,9 @@ class WizardStep1(BaseWizardStep):
uci = Uci()
cznic = Config("cznic")
uci.add(cznic)
kruci = Section("kruci", "config")
cznic.add(kruci)
kruci.add(Option("password", password))
foris = Section("foris", "config")
cznic.add(foris)
foris.add(Option("password", password))
return "edit_config", uci
......@@ -100,7 +100,7 @@ class WizardStep2(BaseWizardStep):
"""
def get_form(self):
# WAN
wan_form = kapi.KruciForm("wan", self.data, filter=uci_filter)
wan_form = fapi.ForisForm("wan", self.data, filter=uci_filter)
wan_main = wan_form.add_section(name="set_wan", title="WAN")
WAN_DHCP = "dhcp"
......@@ -176,7 +176,7 @@ class WizardStep3(BaseWizardStep):
raise ValueError("Unknown Wizard action.")
def get_form(self):
time_form = kapi.KruciForm("time", self.data, filter=ET.Element(time.Time.qual_tag("time")))
time_form = fapi.ForisForm("time", self.data, filter=ET.Element(time.Time.qual_tag("time")))
time_main = time_form.add_section(name="set_time", title="Time")
time_main.add_field(Textbox, name="time", label="Time", nuci_path="time",
......@@ -235,7 +235,7 @@ class WizardStep5(BaseWizardStep):
"""
def get_form(self):
# WAN
lan_form = kapi.KruciForm("lan", self.data, filter=uci_filter)
lan_form = fapi.ForisForm("lan", self.data, filter=uci_filter)
lan_main = lan_form.add_section(name="set_lan", title="LAN")
lan_main.add_field(Checkbox, name="dhcp_enabled", label="Enable DHCP", nuci_path="uci.dhcp.lan.ignore",
......@@ -278,7 +278,7 @@ class WizardStep6(BaseWizardStep):
WiFi settings.
"""
def get_form(self):
wifi_form = kapi.KruciForm("lan", self.data, filter=uci_filter)
wifi_form = fapi.ForisForm("lan", self.data, filter=uci_filter)
wifi_main = wifi_form.add_section(name="set_wifi", title="WiFi")
wifi_main.add_field(Hidden, name="iface_section", nuci_path="uci.wireless.@wifi-iface[1]", nuci_preproc=lambda val: val.name)
wifi_main.add_field(Checkbox, name="wifi_enabled", label="Enable WiFi", default=True,
......
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