2021-11-01 14:46:36 +08:00

118 lines
5.1 KiB
HTML
Executable File

<script type="text/javascript">//<![CDATA[
XHR.poll(5,'<%=url("admin/services/wxedge/status")%>', null,
function (x, st) {
var tb = document.getElementById('wxedge_status');
if (st && tb) {
if (st.docker_install){
if (st.docker_start){
if (st.container_install) {
if (st.container_running) {
const htmlString = '<br/><em><%:The wxedge service is running.%></em>'
+ "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:open wxedge%> \" onclick=\"open_container('" + st.container_port + "')\" />"
+ "<input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:stop wxedge%> \" onclick=\"stop_container('" + st.container_id + "')\" /><br/><br/>";
tb.innerHTML = htmlString;
}
else {
tb.innerHTML = '<br/><em><%:The wxedge service is not running.%></em>'
+ "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:run wxedge%> \" onclick=\"start_container('" + st.container_id + "')\" />"
+ "<input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:uninstall wxedge%> \" onclick=\"uninstall_container('" + st.container_id + "')\" /><br/><br/>";
}
}
else {
let cache = document.getElementById('cache')
if(!cache){
var configs = [
{id: "cache", label: "<%:storage path%><sup>*</sup>:", value: st.cache_path},
];
tb.innerHTML = '<br/><em><%:The wxedge service is not installed.%></em>';
configs.forEach(function(c){
tb.innerHTML += ("<div class=\"cbi-value\"><label class=\"cbi-value-title\" for=\"" + c.id + "\">" + c.label + "</label>"
+ "<div class=\"cbi-value-field\"><input type=\"text\" class=\"cbi-input-text\" id=\"" + c.id + "\" value=\"" + c.value + "\"/></div></div>");
});
tb.innerHTML += ("<div class=\"cbi-value\"><label class=\"cbi-value-title\"></label>"
+ "<div class=\"cbi-value-field\"><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:install wxedge%> \" onclick=\"install_container()\" /></div></div><br>");
}
}
}
else{
tb.innerHTML = '<br/><em><%:Docker service is not start.%></em>'
}
}
else{
tb.innerHTML = '<br/><em><%:Docker is not installed.%></em>'
}
}
}
);
var xhr_post = function(url, data, cb) {
data = data || {};
data.token = '<%=token%>';
cb || docker_status_message('notice', '<img src="/luci-static/resources/icons/loading.gif" alt="" style="vertical-align:middle" />');
new XHR().post(url, data, (x, d) => {
cb || docker_status_message();
cb && cb(x, d);
});
};
function open_container(x) {
Url = "http://" + window.location.hostname + ":" + x
// alert(Url)
window.open(Url)
return false
}
const STOP_URL = '<%=luci.dispatcher.build_url("admin", "services", "wxedge","stop")%>';
function stop_container(x) {
xhr_post(STOP_URL, { container_id: x });
return false
}
const START_URL = '<%=luci.dispatcher.build_url("admin", "services", "wxedge","start")%>';
function start_container(x) {
xhr_post(START_URL, { container_id: x });
return false
}
const UNINSTALL_URL = '<%=luci.dispatcher.build_url("admin", "services", "wxedge","uninstall")%>';
function uninstall_container(x) {
xhr_post(UNINSTALL_URL, { container_id: x });
return false
}
const INSTALL_URL = '<%=luci.dispatcher.build_url("admin", "services", "wxedge","install")%>';
function install_container(x) {
let cache = document.getElementById('cache')
let cache_path = cache.value
if (cache_path == "") {
alert("<%:Storage path could not be empty!%>");
return false;
}
xhr_post(INSTALL_URL, {cache: cache_path}, (x, d) => {
// alert(" 删除容器'" + d.image_name + "' ");
location.reload()
});
uci_confirm_docker();
return false
}
//]]></script>
<fieldset class="cbi-section">
<fieldset class="cbi-section-node" id="wxedge_status">
<em>
<%:Collecting data...%>
</em>
</fieldset>
</fieldset>