diff --git a/.gitignore b/.gitignore index ecee1b5..73e77ca 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ certs rebuild.sh +vendor diff --git a/.gxignore b/.gxignore index ecee1b5..d6ae8c3 100644 --- a/.gxignore +++ b/.gxignore @@ -1,5 +1,5 @@ # -# .gitignore for nntpchan repo +# .gxignore for nntpchan repo # # emacs temp files @@ -27,5 +27,6 @@ srndv2 # certificates certs - rebuild.sh + +.git diff --git a/contrib/static/feed.js b/contrib/static/feed.js new file mode 100644 index 0000000..7744176 --- /dev/null +++ b/contrib/static/feed.js @@ -0,0 +1,107 @@ + +function createConnectionElement(j) { + var e = document.createElement("div"); + e.setAttribute("class", "connection"); + var auth = document.createElement("div"); + auth.appendChild(document.createTextNode("Connection: "+j.name)); + // authentication state + if (j.authed) { + auth.setAttribute("class", "authed"); + auth.appendChild(document.createTextNode("(authenticated)")); + } else { + auth.appendChild(document.createTextNode("(not authenticated)")); + } + e.appendChild(auth); + + // connection mode + var mode = document.createElement("div"); + mode.setAttribute("class", "mode"); + mode.appendChild(document.createTextNode("mode: "+j.mode)); + e.appendChild(mode); + + var pending = document.createElement("div"); + pending.setAttribute("class", "pending"); + // pending articles + var articles = Object.keys(j.pending); + pending.appendChild(document.createTextNode("pending articles: "+articles.length)); + for ( var idx = 0 ; idx < articles.length; idx ++ ) { + var msgid = articles[idx]; + var state = j.pending[msgid]; + var elem = document.createElement("div"); + elem.appendChild(document.createTextNode(msgid + ": " + state)); + elem.setAttribute("class", "pending_item "+state); + pending.appendChild(elem); + } + e.appendChild(pending); + // e.appendChild(document.createTextNode(JSON.stringify(j))); + return e; +} + +function inject_nntp_feed_element(feed, elem) { + elem.appendChild(document.createElement("hr")); + var name = document.createElement("div"); + name.setAttribute("class", "feeds_name"); + name_elem = document.createTextNode("Name: "+feed.State.Config.Name); + name.appendChild(name_elem); + elem.appendChild(name); + var conns = document.createElement("div"); + conns.setAttribute("class", "connections"); + for ( var idx = 0 ; idx < feed.Conns.length; idx ++ ) { + conns.appendChild(createConnectionElement(feed.Conns[idx])); + } + elem.appendChild(conns); +} + +function update_nntpchan_feed_ticker(elem, result_elem) { + nntpchan_admin("feed.list", null, function(j) { + if (j) { + if (j.error) { + console.log("nntpchan_feed_ticker: error, "+j.error); + } else { + // remove all children + while(elem.children.length) { + elem.children[0].remove(); + } + var result = j.result; + for (var idx = 0; idx < result.length; idx++) { + var item = result[idx]; + var entry = document.createElement("div"); + inject_nntp_feed_element(item, entry); + elem.appendChild(entry); + } + } + } + }, result_elem); +} + + +function nntp_feed_add() { + var param = {}; + + var e = document.getElementById("add_feed_name"); + param.name = e.value; + e = document.getElementById("add_feed_host"); + param.host = e.value; + e = document.getElementById("add_feed_port"); + param.port = parseInt(e.value); + + e = document.getElementById("nntpchan_feed_result"); + nntpchan_admin("feed.add", param, null, e); +} + +function nntp_feed_del() { + var e = document.getElementById("del_feed_name"); + var name = e.value; + e = document.getElementById("nntpchan_feed_result"); + nntpchan_admin("feed.del", {name: name}, null, e); +} + +function nntp_feed_update() { + var e = document.getElementById("nntpchan_feeds"); + if (e) { + setInterval(function(){ + var e1 = document.getElementById("nntpchan_feed_result"); + update_nntpchan_feed_ticker(e, e1); + }, 1000); + } +} diff --git a/contrib/static/mod.js b/contrib/static/mod.js index 42485fc..a4db20b 100644 --- a/contrib/static/mod.js +++ b/contrib/static/mod.js @@ -87,7 +87,7 @@ function nntpchan_admin_board(method) { }) } -function nntpchan_admin(method, param, handler_cb) { +function nntpchan_admin(method, param, handler_cb, result_elem) { if (handler_cb) { // we got a handler already set } else { @@ -108,7 +108,7 @@ function nntpchan_admin(method, param, handler_cb) { handle: handler_cb, method: ( param && "POST" ) || "GET", data: param - }) + }, result_elem) } @@ -142,83 +142,7 @@ function nntpchan_delete() { }); } -function createConnectionElement(j) { - var e = document.createElement("div"); - e.setAttribute("class", "connection"); - var auth = document.createElement("div"); - auth.appendChild(document.createTextNode("Connection: "+j.name)); - // authentication state - if (j.authed) { - auth.setAttribute("class", "authed"); - auth.appendChild(document.createTextNode("(authenticated)")); - } else { - auth.appendChild(document.createTextNode("(not authenticated)")); - } - e.appendChild(auth); - - // connection mode - var mode = document.createElement("div"); - mode.setAttribute("class", "mode"); - mode.appendChild(document.createTextNode("mode: "+j.mode)); - e.appendChild(mode); - - var pending = document.createElement("div"); - pending.setAttribute("class", "pending"); - // pending articles - var articles = Object.keys(j.pending); - pending.appendChild(document.createTextNode("pending articles: "+articles.length)); - for ( var idx = 0 ; idx < articles.length; idx ++ ) { - var msgid = articles[idx]; - var state = j.pending[msgid]; - var elem = document.createElement("div"); - elem.appendChild(document.createTextNode(msgid + ": " + state)); - elem.setAttribute("class", "pending_item "+state); - pending.appendChild(elem); - } - e.appendChild(pending); - // e.appendChild(document.createTextNode(JSON.stringify(j))); - return e; -} - -function inject_nntp_feed_element(feed, elem) { - elem.appendChild(document.createElement("hr")); - var name = document.createElement("div"); - name.setAttribute("class", "feeds_name"); - name_elem = document.createTextNode("Name: "+feed.State.Config.Name); - name.appendChild(name_elem); - elem.appendChild(name); - var conns = document.createElement("div"); - conns.setAttribute("class", "connections"); - for ( var idx = 0 ; idx < feed.Conns.length; idx ++ ) { - conns.appendChild(createConnectionElement(feed.Conns[idx])); - } - elem.appendChild(conns); -} - -function update_nntpchan_feed_ticker(elem) { - nntpchan_admin("feed.list", null, function(j) { - if (j) { - if (j.error) { - console.log("nntpchan_feed_ticker: error, "+j.error); - } else { - // remove all children - while(elem.children.length) { - elem.children[0].remove(); - } - - var result = j.result; - for (var idx = 0; idx < result.length; idx++) { - var item = result[idx]; - var entry = document.createElement("div"); - inject_nntp_feed_element(item, entry); - elem.appendChild(entry); - } - } - } - }); -} - -function nntpchan_mod(mod_action) { +function nntpchan_mod(mod_action, result_elem) { // get the element var input = document.getElementById("nntpchan_mod_target"); @@ -226,8 +150,13 @@ function nntpchan_mod(mod_action) { if (mod_action.parser) { target = mod_action.parser(target); } - - var elem = document.getElementById("nntpchan_mod_result"); + var elem; + if (result_elem) { + elem = result_elem; + } else { + elem = document.getElementById("nntpchan_mod_result"); + } + // clear old results while( elem.firstChild ) { elem.removeChild(elem.firstChild); diff --git a/contrib/templates/default/modfeed.mustache b/contrib/templates/default/modfeed.mustache new file mode 100644 index 0000000..b82dc14 --- /dev/null +++ b/contrib/templates/default/modfeed.mustache @@ -0,0 +1,41 @@ +{{! + modpage.mustache -- the moderator panel when logged in + template parameters: + - prefix ( the site's prefix ) + +}} + +
+ + + + + + +Add Feed+ + + + + + + +
Remove Feed+ + + +