luci-app-qbittorrent: convert to JS
Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
parent
01b55365e8
commit
f2a7ca027f
@ -6,7 +6,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=luci-app-qbittorrent
|
PKG_NAME:=luci-app-qbittorrent
|
||||||
PKG_VERSION:=1.0.0
|
PKG_VERSION:=1.0.1
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
LUCI_TITLE:=LuCI support for qBittorrent
|
LUCI_TITLE:=LuCI support for qBittorrent
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
'use strict';
|
||||||
|
'require form';
|
||||||
|
'require poll';
|
||||||
|
'require rpc';
|
||||||
|
'require uci';
|
||||||
|
'require view';
|
||||||
|
|
||||||
|
var callServiceList = rpc.declare({
|
||||||
|
object: 'service',
|
||||||
|
method: 'list',
|
||||||
|
params: ['name'],
|
||||||
|
expect: { '': {} }
|
||||||
|
});
|
||||||
|
|
||||||
|
function getServiceStatus() {
|
||||||
|
return L.resolveDefault(callServiceList('qbittorrent'), {}).then(function (res) {
|
||||||
|
var isRunning = false;
|
||||||
|
try {
|
||||||
|
isRunning = res['qbittorrent']['instances']['instance1']['running'];
|
||||||
|
} catch (e) { }
|
||||||
|
return isRunning;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderStatus(isRunning, webport) {
|
||||||
|
var spanTemp = '<em><span style="color:%s"><strong>%s %s</strong></span></em>';
|
||||||
|
var renderHTML;
|
||||||
|
if (isRunning) {
|
||||||
|
var button = String.format('<input class="cbi-button-reload" type="button" style="margin-left: 50px" value="%s" onclick="window.open(\'//%s:%s/\')">',
|
||||||
|
_('Open Web Interface'), window.location.hostname, webport);
|
||||||
|
renderHTML = spanTemp.format('green', _('qBittorrent'), _('RUNNING')) + button;
|
||||||
|
} else {
|
||||||
|
renderHTML = spanTemp.format('red', _('qBittorrent'), _('NOT RUNNING'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
return view.extend({
|
||||||
|
load: function() {
|
||||||
|
return Promise.all([
|
||||||
|
uci.load('qbittorrent')
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
|
render: function(data) {
|
||||||
|
var m, s, o;
|
||||||
|
var webport = uci.get(data[0], 'config', 'port') || '8080';
|
||||||
|
|
||||||
|
m = new form.Map('qbittorrent', _('qBittorrent'),
|
||||||
|
_('qBittorrent is a cross-platform free and open-source BitTorrent client. Default username & password: admin / adminadmin'));
|
||||||
|
|
||||||
|
s = m.section(form.TypedSection);
|
||||||
|
s.anonymous = true;
|
||||||
|
s.render = function () {
|
||||||
|
poll.add(function () {
|
||||||
|
return L.resolveDefault(getServiceStatus()).then(function (res) {
|
||||||
|
var view = document.getElementById('service_status');
|
||||||
|
view.innerHTML = renderStatus(res, webport);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return E('div', { class: 'cbi-section', id: 'status_bar' }, [
|
||||||
|
E('p', { id: 'service_status' }, _('Collecting data...'))
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
s = m.section(form.NamedSection, 'config', 'qbittorrent');
|
||||||
|
|
||||||
|
o = s.option(form.Flag, 'enabled', _('Enable'));
|
||||||
|
o.default = o.disabled;
|
||||||
|
o.rmempty = false;
|
||||||
|
|
||||||
|
o = s.option(form.Value, 'port', _('WebUI Listen port'));
|
||||||
|
o.datatype = 'port';
|
||||||
|
o.default = '8080';
|
||||||
|
o.rmempty = false;
|
||||||
|
|
||||||
|
o = s.option(form.Value, 'profile_dir', _('Configuration files Path'));
|
||||||
|
o.default = '/etc/qbittorrent';
|
||||||
|
o.rmempty = false;
|
||||||
|
|
||||||
|
return m.render();
|
||||||
|
}
|
||||||
|
});
|
@ -1,24 +0,0 @@
|
|||||||
module("luci.controller.qbittorrent", package.seeall)
|
|
||||||
|
|
||||||
function index()
|
|
||||||
if not nixio.fs.access("/etc/config/qbittorrent") then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
entry({"admin", "services", "qbittorrent"}, cbi("qbittorrent"), _("qBittorrent"), 20).dependent = true
|
|
||||||
entry({"admin", "services", "qbittorrent_status"}, call("qbittorrent_status"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function qbittorrent_status()
|
|
||||||
local sys = require "luci.sys"
|
|
||||||
local uci = require "luci.model.uci".cursor()
|
|
||||||
local port = tonumber(uci:get_first("qbittorrent", "qbittorrent", "port"))
|
|
||||||
|
|
||||||
local status = {
|
|
||||||
running = (sys.call("pidof qbittorrent-nox >/dev/null") == 0),
|
|
||||||
port = (port or 8080)
|
|
||||||
}
|
|
||||||
|
|
||||||
luci.http.prepare_content("application/json")
|
|
||||||
luci.http.write_json(status)
|
|
||||||
end
|
|
@ -1,15 +0,0 @@
|
|||||||
local m, s
|
|
||||||
|
|
||||||
m = Map("qbittorrent", translate("qBittorrent"), translate("qBittorrent is a cross-platform free and open-source BitTorrent client. Default username & password: admin / adminadmin"))
|
|
||||||
|
|
||||||
m:section(SimpleSection).template = "qbittorrent_status"
|
|
||||||
|
|
||||||
s=m:section(TypedSection, "qbittorrent", translate("Global settings"))
|
|
||||||
s.addremove=false
|
|
||||||
s.anonymous=true
|
|
||||||
|
|
||||||
s:option(Flag, "enabled", translate("Enable")).rmempty=false
|
|
||||||
s:option(Value, "port", translate("WebUI Port")).rmempty=false
|
|
||||||
s:option(Value, "profile_dir", translate("Configuration files Path")).rmempty=false
|
|
||||||
|
|
||||||
return m
|
|
@ -1,26 +0,0 @@
|
|||||||
<script type="text/javascript">//<![CDATA[
|
|
||||||
XHR.poll(5, '<%=url("admin/services/qbittorrent_status")%>', null,
|
|
||||||
function(x, st)
|
|
||||||
{
|
|
||||||
var tb = document.getElementById('qbittorrent_status');
|
|
||||||
if (st && tb)
|
|
||||||
{
|
|
||||||
if (st.running)
|
|
||||||
{
|
|
||||||
tb.innerHTML = '<em style=\"color:green\"><b>qBittorrent <%:RUNNING%></b></em>' + "<input class=\"cbi-button-reload mar-10\" type=\"button\" value=\" <%:Open Web Interface%> \" onclick=\"window.open('http://" + window.location.hostname + ":" + st.port + "/')\"/>";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tb.innerHTML = '<em style=\"color:red\"><b>qBittorrent <%:NOT RUNNING%></b></em>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//]]></script>
|
|
||||||
|
|
||||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
|
||||||
<fieldset class="cbi-section">
|
|
||||||
<p id="qbittorrent_status">
|
|
||||||
<em><b><%:Collecting data...%></b></em>
|
|
||||||
</p>
|
|
||||||
</fieldset>
|
|
@ -10,10 +10,7 @@ msgstr "打开 Web 界面"
|
|||||||
msgid "qBittorrent is a cross-platform free and open-source BitTorrent client. Default username & password: admin / adminadmin"
|
msgid "qBittorrent is a cross-platform free and open-source BitTorrent client. Default username & password: admin / adminadmin"
|
||||||
msgstr "qBittorrent 是一个基于 QT 的跨平台的开源 BitTorrent 客户端。默认用户名 & 密码:admin / adminadmin"
|
msgstr "qBittorrent 是一个基于 QT 的跨平台的开源 BitTorrent 客户端。默认用户名 & 密码:admin / adminadmin"
|
||||||
|
|
||||||
msgid "Global settings"
|
msgid "WebUI Listen port"
|
||||||
msgstr "全局设置"
|
|
||||||
|
|
||||||
msgid "WebUI Port"
|
|
||||||
msgstr "WebUI 监听端口"
|
msgstr "WebUI 监听端口"
|
||||||
|
|
||||||
msgid "Configuration files Path"
|
msgid "Configuration files Path"
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
rm -f /tmp/luci-indexcache*
|
|
||||||
exit 0
|
|
11
luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent
Executable file
11
luci-app-qbittorrent/root/etc/uci-defaults/qbittorrent
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
uci -q batch <<-EOF >/dev/null
|
||||||
|
delete ucitrack.@qbittorrent[-1]
|
||||||
|
add ucitrack qbittorrent
|
||||||
|
set ucitrack.@qbittorrent[-1].init=qbittorrent
|
||||||
|
commit ucitrack
|
||||||
|
EOF
|
||||||
|
|
||||||
|
rm -f /tmp/luci-indexcache*
|
||||||
|
exit 0
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"admin/services/qbittorrent": {
|
||||||
|
"title": "qBittorrent",
|
||||||
|
"order": 20,
|
||||||
|
"action": {
|
||||||
|
"type": "view",
|
||||||
|
"path": "qbittorrent"
|
||||||
|
},
|
||||||
|
"depends": {
|
||||||
|
"acl": [ "luci-app-qbittorrent" ],
|
||||||
|
"uci": { "qbittorrent": true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,9 @@
|
|||||||
"luci-app-qbittorrent": {
|
"luci-app-qbittorrent": {
|
||||||
"description": "Grant UCI access for luci-app-qbittorrent",
|
"description": "Grant UCI access for luci-app-qbittorrent",
|
||||||
"read": {
|
"read": {
|
||||||
|
"ubus": {
|
||||||
|
"service": [ "list" ]
|
||||||
|
},
|
||||||
"uci": [ "qbittorrent" ]
|
"uci": [ "qbittorrent" ]
|
||||||
},
|
},
|
||||||
"write": {
|
"write": {
|
||||||
|
Loading…
Reference in New Issue
Block a user