Added Btrfs class and fixed configurator select html element issues
This commit is contained in:
parent
990813aa59
commit
bbd03b14be
4 changed files with 146 additions and 17 deletions
|
|
@ -58,7 +58,7 @@ public class OpenAPIHttpPage implements HttpPage {
|
|||
out.setHeader(HttpHeader.HEADER_CONTENT_TYPE, "application/json");
|
||||
wsdl.write(out);
|
||||
} else {
|
||||
// Output human readable interface
|
||||
// Output human-readable interface
|
||||
|
||||
out.println("<!DOCTYPE html>");
|
||||
out.println("<html>");
|
||||
|
|
|
|||
78
src/zutil/osal/linux/app/Btrfs.java
Normal file
78
src/zutil/osal/linux/app/Btrfs.java
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package zutil.osal.linux.app;
|
||||
|
||||
import zutil.osal.MultiCommandExecutor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Wrapper for the linux Btrfs command to query and modify btrfs based filesystems.
|
||||
*/
|
||||
public class Btrfs {
|
||||
private static String BTRFS_CMD = "btrfs";
|
||||
private static SimpleDateFormat DATE_PARSER = new SimpleDateFormat("dow mon dd hh:mm:ss zzz yyyy");
|
||||
|
||||
// The disk used as an id to btrfs
|
||||
private String path;
|
||||
// Terminal where all commands will be executed.
|
||||
private MultiCommandExecutor terminal;
|
||||
|
||||
|
||||
public Btrfs(String path) {
|
||||
this(path, new MultiCommandExecutor());
|
||||
}
|
||||
public Btrfs(String path, MultiCommandExecutor terminal) {
|
||||
this.path = path;
|
||||
this.terminal = terminal;
|
||||
}
|
||||
|
||||
|
||||
// ****************************************************
|
||||
// Balance functions
|
||||
// ****************************************************
|
||||
|
||||
public void startBalance() throws IOException {
|
||||
execBtrfsCommand("balance start", path);
|
||||
}
|
||||
|
||||
public void cancelBalance() throws IOException {
|
||||
execBtrfsCommand("balance cancel", path);
|
||||
}
|
||||
|
||||
public void getBalanceProgress() throws IOException {
|
||||
execBtrfsCommand("balance status", path);
|
||||
}
|
||||
|
||||
// ****************************************************
|
||||
// Scrub functions
|
||||
// ****************************************************
|
||||
|
||||
public void startScrub() throws IOException {
|
||||
execBtrfsCommand("scrub start", path);
|
||||
}
|
||||
|
||||
public void cancelScrub() throws IOException {
|
||||
execBtrfsCommand("scrub cancel", path);
|
||||
}
|
||||
|
||||
public void getScrubProgress() throws IOException {
|
||||
execBtrfsCommand("scrub status", path);
|
||||
}
|
||||
|
||||
public Date getLastScrubDate() throws IOException {
|
||||
String log = execBtrfsCommand("scrub status", path);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ****************************************************
|
||||
// Utility functions
|
||||
// ****************************************************
|
||||
|
||||
public String execBtrfsCommand(String params, String path) throws IOException {
|
||||
terminal.exec(BTRFS_CMD + " " + params + " " + path);
|
||||
|
||||
return terminal.readAll();
|
||||
}
|
||||
}
|
||||
|
|
@ -28,26 +28,36 @@
|
|||
if (formTemplateId != null)
|
||||
modal.find("#" + formTemplateId).empty(); // clear form div
|
||||
|
||||
// select dynamic form
|
||||
var selector = modal.find("select[name=type]");
|
||||
selector.val(button.data("type"));
|
||||
selector.change(); // Update dynamic inputs
|
||||
// set dynamic form data
|
||||
$.each(button.attr(), function(fieldName, value) {
|
||||
if (fieldName.startsWith("data-")) {
|
||||
fieldName = fieldName.substring(5);
|
||||
if(fieldName.startsWith("data-")) {
|
||||
fieldName = fieldName.substring(5); // remove prefix data-
|
||||
|
||||
// case insensitive search
|
||||
input = modal.find("input").filter(function() {
|
||||
return this.name.toLowerCase() == fieldName;
|
||||
var input = modal.find("input, select").filter(function() {
|
||||
if (this.name.toLowerCase() == fieldName) {
|
||||
if (this.type == "hidden" && modal.find("input[type=checkbox][name=" + fieldName + "]") != null)
|
||||
return false; // Workaround for the default(false) boolean input
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (input.attr("type") == "checkbox") { // special handling for checkboxes
|
||||
input.attr("value", "true");
|
||||
if (value=="true") input.attr("checked", "true");
|
||||
else input.removeAttr("checked");
|
||||
// Add default false value as a unchecked checkbox is not included in the post
|
||||
input.parent().prepend("<input type='hidden' name='" + input.attr("name") + "' value='false' />");
|
||||
} else {
|
||||
input.val(value);
|
||||
|
||||
if (input != null) {
|
||||
if (input.prop("type") == "checkbox") { // special handling for checkboxes
|
||||
input.prop("value", "true");
|
||||
input.prop("checked", value == "true");
|
||||
|
||||
if (modal.find("input[type=hidden][name=" + fieldName + "]") == null) {
|
||||
// Add default false value as a unchecked checkbox is not included in the post
|
||||
input.parent().prepend("<input type='hidden' name='" + input.prop("name") + "' value='false' />");
|
||||
}
|
||||
} else {
|
||||
input.val(value);
|
||||
|
||||
if (input.prop("tagName") == "SELECT")
|
||||
input.change(); // required for select elements to update properly
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue