diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index ba4404ed..213ddb9e 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -87,7 +87,6 @@ function index() entry({"admin", "services", appname, "delete_select_nodes"}, call("delete_select_nodes")).leaf = true entry({"admin", "services", appname, "reassign_group"}, call("reassign_group")).leaf = true entry({"admin", "services", appname, "get_node"}, call("get_node")).leaf = true - entry({"admin", "services", appname, "save_node_order"}, call("save_node_order")).leaf = true entry({"admin", "services", appname, "save_node_list_opt"}, call("save_node_list_opt")).leaf = true entry({"admin", "services", appname, "update_rules"}, call("update_rules")).leaf = true entry({"admin", "services", appname, "rollback_rules"}, call("rollback_rules")).leaf = true @@ -99,7 +98,6 @@ function index() entry({"admin", "services", appname, "get_shunt_rules"}, call("get_shunt_rules")).leaf = true entry({"admin", "services", appname, "add_shunt_rule"}, call("add_shunt_rule")).leaf = true entry({"admin", "services", appname, "delete_select_shunt_rules"}, call("delete_select_shunt_rules")).leaf = true - entry({"admin", "services", appname, "save_shunt_rule_order"}, call("save_shunt_rule_order")).leaf = true --[[rule_list]] entry({"admin", "services", appname, "read_rulelist"}, call("read_rulelist")).leaf = true @@ -720,19 +718,6 @@ function get_node() http_write_json(result) end -function save_node_order() - local ids = http.formvalue("ids") or "" - local new_order = {} - for id in ids:gmatch("([^,]+)") do - new_order[#new_order + 1] = id - end - for idx, name in ipairs(new_order) do - luci.sys.call(string.format("uci -q reorder %s.%s=%d", appname, name, idx - 1)) - end - api.sh_uci_commit(appname) - http_write_json({ status = "ok" }) -end - function reassign_group() local ids = http.formvalue("ids") or "" local group = http.formvalue("group") or "default" @@ -1209,16 +1194,3 @@ function delete_select_shunt_rules() api.uci_save(uci, appname, true, true) end end - -function save_shunt_rule_order() - local ids = http.formvalue("ids") or "" - local new_order = {} - for id in ids:gmatch("([^,]+)") do - new_order[#new_order + 1] = id - end - for idx, name in ipairs(new_order) do - luci.sys.call(string.format("uci -q reorder %s.%s=%d", appname, name, idx - 1)) - end - api.sh_uci_commit(appname) - http_write_json({ status = "ok" }) -end diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua index fdbf0c29..4195cbfa 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua @@ -1,7 +1,5 @@ local api = require "luci.passwall.api" local appname = "passwall" -local sys = api.sys -local datatypes = api.datatypes api.set_default_cbi() @@ -30,6 +28,29 @@ o:value("https://connectivitycheck.platform.hicloud.com/generate_204", "HiCloud o:value("https://wifi.vivo.com.cn/generate_204", "VIVO (CN)") o.default = o.keylist[3] -m:append(Template(appname .. "/node_list/node_list")) +if true then + local o = Template(appname .. "/node_list/node_list") + o.map = m + o.api = api + m:append(o) + + if luci.http.formvalue("cbi.submit") == "1" then + local group_order = {} + group_order = luci.http.formvaluetable("group.order") + if group_order then + for k, v in pairs(group_order) do + if v and v~= "" then + local new_order = {} + string.gsub(v, "[^" .. " " .. "]+", function(w) + new_order[#new_order + 1] = w + end) + for idx, name in ipairs(new_order) do + m.uci:reorder(appname, name, idx - 1) + end + end + end + end + end +end return api.return_map(m) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua index adad962d..e081be37 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule.lua @@ -146,7 +146,26 @@ end s:append(Template(appname .. "/rule/rule_version")) if has_xray or has_singbox then - m:append(Template(appname .. "/rule/shunt_rule_list")) + local o = Template(appname .. "/rule/shunt_rule_list") + o.api = api + m:append(o) + + if luci.http.formvalue("cbi.submit") == "1" then + local group_order = luci.http.formvaluetable("group.order") + if group_order then + for k, v in pairs(group_order) do + if v and v~= "" then + local new_order = {} + string.gsub(v, "[^" .. " " .. "]+", function(w) + new_order[#new_order + 1] = w + end) + for idx, name in ipairs(new_order) do + m.uci:reorder(appname, name, idx - 1) + end + end + end + end + end end return api.return_map(m) diff --git a/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm b/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm index 98d77bdd..39aca0b2 100644 --- a/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm +++ b/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm @@ -1,6 +1,7 @@ <% -local api = require "luci.passwall.api" +local api = self.api local appname = api.appname +local map = self.map local is_js_luci = api.is_js_luci() local section_tag = is_js_luci and "div" or "fieldset" -%> @@ -500,15 +501,7 @@ table td, .table .td { let firstDataRow = parent.querySelector("tr:not(.cbi-section-table-titles)"); if (firstDataRow && firstDataRow !== row) { parent.insertBefore(row, firstDataRow); - let save_order_btn = document.getElementById("save_order_btn_" + group); - if (save_order_btn) { - const new_order = get_node_order(group); - if (!arraysEqual(new_order, origin_group_node_order[group])) { - save_order_btn.style.display = null; - } else { - save_order_btn.style.display = "none"; - } - } + set_order(group); } break; case "del_all": @@ -652,48 +645,24 @@ table td, .table .td { return ids; } - function save_current_page_order(group) { - var table = document.getElementById("cbi-<%=appname%>-nodes-" + group + "-table"); + function set_order(group) { + let table = document.getElementById("cbi-<%=appname%>-nodes-" + group + "-table"); if (!table) { alert("<%:No table!%>"); return; } - var rows = table.querySelectorAll("tr.cbi-section-table-row"); + let rows = table.querySelectorAll("tr.cbi-section-table-row"); if (!rows || rows.length === 0) { alert("<%:No nodes!%>"); return; } - var btn = document.getElementById("save_order_btn_" + group); - if (btn) { - btn.style.display = "none"; - btn.disabled = true; - } - var ids = []; + let ids = []; rows.forEach(function(row) { - var id = row.id.replace("cbi-<%=appname%>-", ""); + let id = row.id.replace("cbi-<%=appname%>-", ""); ids.push(id); }); - ajax.abortAll(); - XHR.get('<%=api.url("save_node_order")%>', { - group: group, - ids: ids.join(",") - }, - function(x, result) { - if (btn) { - btn.style.display = null; - btn.disabled = false; - } - if (x && x.status === 200) { - origin_group_node_order[group] = get_node_order(group); - alert("<%:Saved current page order successfully.%>"); - if (btn) { - btn.style.display = "none"; - } - } else { - alert("<%:Save failed!%>"); - } - } - ); + const input_order = document.getElementsByName(`group.order.${group}`)[0]; + input_order.value = ids.join(" "); } //获取当前使用的节点 @@ -947,16 +916,7 @@ table td, .table .td { forceFallback: false, swapThreshold: 0.65, onEnd: function (evt) { - //save_current_page_order(group); // 自动提交保存 - let save_order_btn = document.getElementById("save_order_btn_" + group); - if (save_order_btn) { - const new_order = get_node_order(group); - if (!arraysEqual(new_order, origin_group_node_order[group])) { - save_order_btn.style.display = null; - } else { - save_order_btn.style.display = "none"; - } - } + set_order(group); } }; try { @@ -1302,9 +1262,9 @@ table td, .table .td { {{node-tr}} +
-
> diff --git a/luci-app-passwall/luasrc/view/passwall/rule/shunt_rule_list.htm b/luci-app-passwall/luasrc/view/passwall/rule/shunt_rule_list.htm index a0ee9570..c2e6b448 100644 --- a/luci-app-passwall/luasrc/view/passwall/rule/shunt_rule_list.htm +++ b/luci-app-passwall/luasrc/view/passwall/rule/shunt_rule_list.htm @@ -1,7 +1,6 @@ <% -local api = require "luci.passwall.api" +local api = self.api local appname = api.appname -local uci = api.uci local is_js_luci = api.is_js_luci() local section_tag = is_js_luci and "div" or "fieldset" local title_tag = is_js_luci and "h3" or "legend" @@ -185,15 +184,7 @@ table td, .table .td { let firstDataRow = parent.querySelector("tr:not(.cbi-section-table-titles)"); if (firstDataRow && firstDataRow !== row) { parent.insertBefore(row, firstDataRow); - let save_order_btn = document.getElementById("save_order_btn_" + group); - if (save_order_btn) { - const new_order = get_shunt_rule_order(group); - if (!arraysEqual(new_order, origin_group_shunt_rule_order[group])) { - save_order_btn.style.display = null; - } else { - save_order_btn.style.display = "none"; - } - } + set_order(group); } } @@ -214,48 +205,24 @@ table td, .table .td { return ids; } - function save_current_page_order(group) { - var table = document.getElementById("cbi-<%=appname%>-shunt_rules-" + group + "-table"); + function set_order(group) { + let table = document.getElementById("cbi-<%=appname%>-shunt_rules-" + group + "-table"); if (!table) { alert("<%:No table!%>"); return; } - var rows = table.querySelectorAll("tr.cbi-section-table-row"); + let rows = table.querySelectorAll("tr.cbi-section-table-row"); if (!rows || rows.length === 0) { alert("<%:No shunt_rules!%>"); return; } - var btn = document.getElementById("save_order_btn_" + group); - if (btn) { - btn.style.display = "none"; - btn.disabled = true; - } - var ids = []; + let ids = []; rows.forEach(function(row) { - var id = row.id.replace("cbi-<%=appname%>-", ""); + let id = row.id.replace("cbi-<%=appname%>-", ""); ids.push(id); }); - XHR.get('<%=api.url("save_shunt_rule_order")%>', { - group: group, - ids: ids.join(",") - }, - function(x, result) { - if (btn) { - btn.style.display = null; - btn.disabled = false; - } - if (x && x.status === 200) { -// origin_group_shunt_rule_order[group] = get_shunt_rule_order(group); - alert("<%:Saved current page order successfully.%>"); -// if (btn) { -// btn.style.display = "none"; -// } - window.location.reload(); - } else { - alert("<%:Save failed!%>"); - } - } - ); + const input_order = document.getElementsByName(`group.order.${group}`)[0]; + input_order.value = ids.join(" "); } // List drag and rearrange @@ -274,16 +241,7 @@ table td, .table .td { forceFallback: false, swapThreshold: 0.65, onEnd: function (evt) { - //save_current_page_order(group); // Auto save - let save_order_btn = document.getElementById("save_order_btn_" + group); - if (save_order_btn) { - const new_order = get_shunt_rule_order(group); - if (!arraysEqual(new_order, origin_group_shunt_rule_order[group])) { - save_order_btn.style.display = null; - } else { - save_order_btn.style.display = "none"; - } - } + set_order(group); } }; try { @@ -339,10 +297,10 @@ table td, .table .td { {{shunt_rule-tr}} +
-
> diff --git a/luci-app-passwall/po/zh-cn/passwall.po b/luci-app-passwall/po/zh-cn/passwall.po index f8fe18f3..85d6092b 100644 --- a/luci-app-passwall/po/zh-cn/passwall.po +++ b/luci-app-passwall/po/zh-cn/passwall.po @@ -448,12 +448,6 @@ msgstr "节点备注" msgid "Add Mode" msgstr "添加方式" -msgid "Save Order" -msgstr "保存当前顺序" - -msgid "Saved current page order successfully." -msgstr "保存当前页面顺序成功。" - msgid "Drag to reorder" msgstr "拖动以重排"