luci-app-diskman: bump to 0.2.8

This commit is contained in:
CN_SZTL 2020-04-10 01:07:32 +08:00
parent 364079b1fa
commit 5edfe8f276
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
7 changed files with 188 additions and 58 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-diskman
PKG_VERSION:=v0.2.7
PKG_VERSION:=v0.2.8
PKG_RELEASE:=beta
PKG_MAINTAINER:=lisaac <https://github.com/lisaac/luci-app-diskman>
PKG_LICENSE:=AGPL-3.0

View File

@ -25,12 +25,35 @@ function index()
entry({"admin", "system", "diskman", "disks"}, form("diskman/disks"), nil).leaf = true
entry({"admin", "system", "diskman", "partition"}, form("diskman/partition"), nil).leaf = true
entry({"admin", "system", "diskman", "btrfs"}, form("diskman/btrfs"), nil).leaf = true
entry({"admin", "system", "diskman", "format_partition"}, call("format_partition"), nil).leaf = true
entry({"admin", "system", "diskman", "get_disk_info"}, call("get_disk_info"), nil).leaf = true
entry({"admin", "system", "diskman", "mk_p_table"}, call("mk_p_table"), nil).leaf = true
entry({"admin", "system", "diskman", "smartdetail"}, call("smart_detail"), nil).leaf = true
entry({"admin", "system", "diskman", "smartattr"}, call("smart_attr"), nil).leaf = true
end
function format_partition()
local partation_name = luci.http.formvalue("partation_name")
local fs = luci.http.formvalue("file_system")
if not partation_name then
luci.http.status(500, "Partition NOT found!")
luci.http.write_json("Partition NOT found!")
return
elseif not nixio.fs.access("/dev/"..partation_name) then
luci.http.status(500, "Partition NOT found!")
luci.http.write_json("Partition NOT found!")
return
elseif not fs then
luci.http.status(500, "no file system")
luci.http.write_json("no file system")
return
end
local dm = require "luci.model.diskman"
code, msg = dm.format_partition(partation_name, fs)
luci.http.status(code, msg)
luci.http.write_json({msg})
end
function get_disk_info(dev)
if not dev then
luci.http.status(500, "no device")

View File

@ -183,69 +183,79 @@ if not disk_info.p_table:match("Raid") then
end
local val_fs = s_partition_table:option(Value, "fs", translate("File System"))
val_fs.forcewrite = true
val_fs.partitions = disk_info.partitions
for k, v in pairs(format_cmd) do
val_fs.format_cmd = val_fs.format_cmd and (val_fs.format_cmd .. "," .. k) or k
end
val_fs.write = function(self, section, value)
disk_info.partitions[section]._fs = value
end
val_fs.render = function(self, section, scope)
-- use listvalue when partition not mounted
if disk_info.partitions[section].mount_point == "-" and disk_info.partitions[section].number ~= -1 and disk_info.partitions[section].type ~= "extended" then
self.template = "cbi/value"
self:reset_values()
self.keylist = {}
self.vallist = {}
for k, v in pairs(format_cmd) do
self:value(k,k)
end
self.template = "diskman/cbi/format_button"
self.inputstyle = "reset"
self.inputtitle = disk_info.partitions[section].fs:match("^%s+$") and "Format" or disk_info.partitions[section].fs
Button.render(self, section, scope)
-- self:reset_values()
-- self.keylist = {}
-- self.vallist = {}
-- for k, v in pairs(format_cmd) do
-- self:value(k,k)
-- end
-- self.default = disk_info.partitions[section].fs
else
self:reset_values()
self.keylist = {}
self.vallist = {}
-- self:reset_values()
-- self.keylist = {}
-- self.vallist = {}
self.template = "cbi/dvalue"
end
DummyValue.render(self, section, scope)
end
btn_format = s_partition_table:option(Button, "_format")
btn_format.render = function(self, section, scope)
if disk_info.partitions[section].mount_point == "-" and disk_info.partitions[section].number ~= -1 and disk_info.partitions[section].type ~= "extended" then
self.inputtitle = translate("Format")
self.template = "diskman/cbi/disabled_button"
self.view_disabled = false
self.inputstyle = "reset"
for k, v in pairs(format_cmd) do
self:depends("val_fs", "k")
end
-- elseif disk_info.partitions[section].mount_point ~= "-" and disk_info.partitions[section].number ~= -1 then
-- self.inputtitle = "Format"
-- self.template = "diskman/cbi/disabled_button"
-- self.view_disabled = true
-- self.inputstyle = "reset"
else
self.inputtitle = ""
self.template = "cbi/dvalue"
end
Button.render(self, section, scope)
end
btn_format.forcewrite = true
btn_format.write = function(self, section, value)
local partition_name = "/dev/".. disk_info.partitions[section].name
if not nixio.fs.access(partition_name) then
m.errmessage = translate("Partition NOT found!")
return
end
local fs = disk_info.partitions[section]._fs
if not format_cmd[fs] then
m.errmessage = translate("Filesystem NOT support!")
return
end
local cmd = format_cmd[fs].cmd .. " " .. format_cmd[fs].option .. " " .. partition_name
local res = luci.util.exec(cmd .. " 2>&1")
if res and res:lower():match("error+") then
m.errmessage = luci.util.pcdata(res)
else
luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/partition/" .. dev))
DummyValue.render(self, section, scope)
end
end
-- btn_format = s_partition_table:option(Button, "_format")
-- btn_format.template = "diskman/cbi/format_button"
-- btn_format.partitions = disk_info.partitions
-- btn_format.render = function(self, section, scope)
-- if disk_info.partitions[section].mount_point == "-" and disk_info.partitions[section].number ~= -1 and disk_info.partitions[section].type ~= "extended" then
-- self.inputtitle = translate("Format")
-- self.template = "diskman/cbi/disabled_button"
-- self.view_disabled = false
-- self.inputstyle = "reset"
-- for k, v in pairs(format_cmd) do
-- self:depends("val_fs", "k")
-- end
-- -- elseif disk_info.partitions[section].mount_point ~= "-" and disk_info.partitions[section].number ~= -1 then
-- -- self.inputtitle = "Format"
-- -- self.template = "diskman/cbi/disabled_button"
-- -- self.view_disabled = true
-- -- self.inputstyle = "reset"
-- else
-- self.inputtitle = ""
-- self.template = "cbi/dvalue"
-- end
-- Button.render(self, section, scope)
-- end
-- btn_format.forcewrite = true
-- btn_format.write = function(self, section, value)
-- local partition_name = "/dev/".. disk_info.partitions[section].name
-- if not nixio.fs.access(partition_name) then
-- m.errmessage = translate("Partition NOT found!")
-- return
-- end
-- local fs = disk_info.partitions[section]._fs
-- if not format_cmd[fs] then
-- m.errmessage = translate("Filesystem NOT support!")
-- return
-- end
-- local cmd = format_cmd[fs].cmd .. " " .. format_cmd[fs].option .. " " .. partition_name
-- local res = luci.util.exec(cmd .. " 2>&1")
-- if res and res:lower():match("error+") then
-- m.errmessage = luci.util.pcdata(res)
-- else
-- luci.http.redirect(luci.dispatcher.build_url("admin/system/diskman/partition/" .. dev))
-- end
-- end
local btn_action = s_partition_table:option(Button, "_action")
btn_action.forcewrite = true

View File

@ -714,4 +714,23 @@ end
return subvolume
end
d.format_partition = function(partition, fs)
local partition_name = "/dev/".. partition
if not nixio.fs.access(partition_name) then
return 500, translate("Partition NOT found!")
end
local format_cmd = d.get_format_cmd()
if not format_cmd[fs] then
return 500, translate("Filesystem NOT support!")
end
local cmd = format_cmd[fs].cmd .. " " .. format_cmd[fs].option .. " " .. partition_name
local res = luci.util.exec(cmd .. " 2>&1")
if res and res:lower():match("error+") then
return 500, res
else
return 200, "OK"
end
end
return d

View File

@ -6,7 +6,7 @@
lines.forEach((item) => {
let dev = item.id.match(/cbi-disk-(.*)/)[1]
if (dev == "table") { return }
XHR.get('/cgi-bin/luci/admin/system/diskman/get_disk_info/' + dev, null, (x, disk_info) => {
XHR.get('<%=luci.dispatcher.build_url("admin/system/diskman/get_disk_info")%>/' + dev, null, (x, disk_info) => {
// handle disk info
item.childNodes.forEach((cell) => {
if (cell && cell.attributes) {
@ -71,7 +71,7 @@
let dev = item.id.match(/cbi-_raid-(.*)/)[1]
if (dev == "table") { return }
console.log(dev)
XHR.get('/cgi-bin/luci/admin/system/diskman/get_disk_info/' + dev, null, (x, disk_info) => {
XHR.get('<%=luci.dispatcher.build_url("admin/system/diskman/get_disk_info")%>/' + dev, null, (x, disk_info) => {
// handle raid info
item.childNodes.forEach((cell) => {
if (cell && cell.attributes) {

View File

@ -1,7 +1,59 @@
<style type="text/css">
#dialog_format {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
display: none;
z-index: 20000;
}
#dialog_format .dialog_box {
position: relative;
background: rgba(255, 255, 255);
top: 35%;
width: 40%;
min-width: 20em;
margin: auto;
display: flex;
flex-wrap: wrap;
height:auto;
align-items: center;
}
#dialog_format .dialog_line {
margin-top: .5em;
margin-bottom: .5em;
margin-left: 2em;
margin-right: 2em;
}
#dialog_format .dialog_box>h4,
#dialog_format .dialog_box>p,
#dialog_format .dialog_box>div {
flex-basis: 100%;
}
#dialog_format .dialog_box>img {
margin-right: 1em;
flex-basis: 32px;
}
body.dialog-format-active {
overflow: hidden;
height: 100vh;
}
body.dialog-format-active #dialog_format {
display: block;
}
</style>
<script type="text/javascript">//<![CDATA[
function show_detail(dev, e) {
e.preventDefault()
window.open('<%=luci.dispatcher.build_url("admin", "system", "diskman", "smartdetail")%>/' + dev,
window.open('<%=luci.dispatcher.build_url("admin/system/diskman/smartdetail")%>/' + dev,
'newwindow', 'height=480,width=800,top=100,left=200,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no')
}
window.onload = function () {
@ -14,7 +66,7 @@
if (btn_p_table_index != btn_p_table_raw_index) {
if (confirm("Warnning !! \nTHIS WILL OVERWRITE EXISTING PARTITIONS!! \nModify the partition table?")) {
let p_table = btn_p_table.options[btn_p_table_index].value
XHR.get('<%=luci.dispatcher.build_url("admin", "system", "diskman", "mk_p_table")%>', { dev: val_name, p_table: p_table }, (x, res) => {
XHR.get('<%=luci.dispatcher.build_url("admin/system/diskman/mk_p_table")%>', { dev: val_name, p_table: p_table }, (x, res) => {
if (res.code == 0) {
location.reload();
}
@ -31,4 +83,31 @@
const btn_smart_detail = document.getElementById("cbi-table-1-health")
btn_smart_detail.children[0].onclick = show_detail.bind(this, dev)
}
function close_dialog() {
document.body.classList.remove('dialog-format-active')
document.documentElement.style.overflowY = 'scroll'
}
function do_format(partation_name){
let fs = document.getElementById("filesystem_list").value
let xhr = new XHR()
xhr.post('<%=luci.dispatcher.build_url("admin/system/diskman/format_partition")%>', { partation_name: partation_name, file_system: fs }, (x, res) => {
if (x.status == 200) {
location.reload();
}
})
}
function partition_format(partition_name, format_cmd, current_fs){
console.log(format_cmd)
let list = ''
format_cmd.split(",").forEach(e => {
list = list + '<option value="'+e+'">'+e+'</option>'
});
console.log(partition_name)
document.getElementById('dialog_format') || document.body.insertAdjacentHTML("beforeend", '<div id="dialog_format"><div class="dialog_box"><div class="dialog_line"></div><div class="dialog_line"><span><%:Format partation:%> <b>'+partition_name+'</b></span><br><spanid="cmd-line-status"></span></div><div class="dialog_line"><select id="filesystem_list" class="cbi-input-select">'+list+'</select></div><div class="dialog_line" style="text-align: right;"><input type="button" class="cbi-button cbi-button-apply"type="submit" value="<%:Format%>" onclick="do_format(`'+partition_name+'`)" /> <input type="button"class="cbi-button cbi-button-reset" type="reset" value="<%:Cancel%>" onclick="close_dialog()" /></div><div class="dialog_line"></div></div></div>>')
document.body.classList.add('dialog-format-active')
document.documentElement.style.overflowY = 'hidden'
let fs_list = document.getElementById("filesystem_list")
fs_list.value = current_fs
}
</script>

View File

@ -9,7 +9,6 @@
xhr.onload = function () {
let st = JSON.parse(xhr.responseText)
let tb = document.getElementById('smart_attr_table');
console.log(st)
if (st && tb) {
/* clear all rows */
while (tb.rows.length > 1)