HEAD + some attempts at bug fixing.

This commit is contained in:
Raoul Snyman 2011-03-15 22:33:26 +02:00
commit edc4f4d626
3 changed files with 101 additions and 9 deletions

View File

@ -227,6 +227,10 @@ class BGExtract(object):
cleanup = [(re.compile('\s+'), lambda match: ' ')]
verses = BeautifulSoup(str(soup), markupMassage=cleanup)
verse_list = {}
# Cater for inconsistent mark up in the first verse of a chapter.
first_verse = verses.find(u'versenum')
if first_verse:
verse_list[1] = unicode(first_verse.contents[0])
for verse in verses(u'sup', u'versenum'):
raw_verse_num = verse.next
clean_verse_num = 0

View File

@ -46,7 +46,7 @@ window.OpenLP = {
ul.html("");
for (idx in data.results) {
var li = $("<li data-icon=\"false\">").append(
$("<a href=\"#\">").attr("value", idx + 1).text(data.results[idx]["title"]));
$("<a href=\"#\">").attr("value", parseInt(idx, 10)).text(data.results[idx]["title"]));
li.children("a").click(OpenLP.setItem);
ul.append(li);
}
@ -62,7 +62,7 @@ window.OpenLP = {
ul.html("");
for (idx in data.results.slides) {
var li = $("<li data-icon=\"false\">").append(
$("<a href=\"#\">").attr("value", idx + 1).html(data.results.slides[idx]["text"]));
$("<a href=\"#\">").attr("value", parseInt(idx, 10)).html(data.results.slides[idx]["text"]));
if (data.results.slides[idx]["selected"]) {
li.attr("data-theme", "e");
}
@ -92,6 +92,7 @@ window.OpenLP = {
},
setSlide: function (event) {
var slide = OpenLP.getElement(event);
console.log(slide);
var id = slide.attr("value");
var text = JSON.stringify({"request": {"id": id}});
$.getJSON(
@ -114,18 +115,34 @@ window.OpenLP = {
OpenLP.currentSlide = data.results.slide;
OpenLP.currentItem = data.results.item;
if ($("#service-manager").is(":visible")) {
$("#service-manager > div[data-role=content] ul[data-role=listview] li a").each(function () {
$("#service-manager div[data-role=content] ul[data-role=listview] li").attr("data-theme", "c").removeClass("ui-btn-up-e").addClass("ui-btn-up-c");
$("#service-manager div[data-role=content] ul[data-role=listview] li a").each(function () {
var item = $(this);
if (item.text() == OpenLP.currentItem) {
$("#service-manager > div[data-role=content] ul[data-role=listview] li").attr("data-theme", "c").removeClass("ui-btn-up-e").addClass("ui-btn-up-c");
while (item[0].tagName != "LI") {
item = item.parent();
}
item.attr("data-theme", "e").removeClass("ui-btn-up-c").addClass("ui-btn-up-e");
$("#slide-controller div[data-role=content] ul[data-role=listview]").listview("refresh");
return false;
}
});
$("#service-manager div[data-role=content] ul[data-role=listview]").listview("refresh");
}
if ($("#slide-controller").is(":visible")) {
var idx = 0;
$("#slide-controller div[data-role=content] ul[data-role=listview] li").attr("data-theme", "c").removeClass("ui-btn-up-e").addClass("ui-btn-up-c");
$("#slide-controller div[data-role=content] ul[data-role=listview] li a").each(function () {
var item = $(this);
if (idx == OpenLP.currentSlide) {
while (item[0].tagName != "LI") {
item = item.parent();
}
item.attr("data-theme", "e").removeClass("ui-btn-up-c").addClass("ui-btn-up-e");
return false;
}
idx++;
});
$("#slide-controller div[data-role=content] ul[data-role=listview]").listview("refresh");
}
}
);
@ -136,3 +153,4 @@ $("#service-manager").live("pagebeforeshow", OpenLP.loadService);
$("#slide-controller").live("pagebeforeshow", OpenLP.loadController);
// Poll the server twice a second to get any updates.
setInterval("OpenLP.pollServer();", 500);
OpenLP.pollServer();

View File

@ -24,6 +24,74 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`http` module contains the API web server. This is a lightweight web
server used by remotes to interact with OpenLP. It uses JSON to communicate with
the remotes.
*Routes:*
``/``
Go to the web interface.
``/files/{filename}``
Serve a static file.
``/api/poll``
Poll to see if there are any changes. Returns a JSON-encoded dict of
any changes that occurred::
{"results": {"type": "controller"}}
Or, if there were no results, False::
{"results": False}
``/api/controller/{live|preview}/{action}``
Perform ``{action}`` on the live or preview controller. Valid actions
are:
``next``
Load the next slide.
``previous``
Load the previous slide.
``jump``
Jump to a specific slide. Requires an id return in a JSON-encoded
dict like so::
{"request": {"id": 1}}
``first``
Load the first slide.
``last``
Load the last slide.
``text``
Request the text of the current slide.
``/api/service/{action}``
Perform ``{action}`` on the service manager (e.g. go live). Data is
passed as a json-encoded ``data`` parameter. Valid actions are:
``next``
Load the next item in the service.
``previous``
Load the previews item in the service.
``jump``
Jump to a specific item in the service. Requires an id returned in
a JSON-encoded dict like so::
{"request": {"id": 1}}
``list``
Request a list of items in the service.
"""
import logging
import os
import urlparse
@ -143,7 +211,8 @@ class HttpServer(object):
The connection has been closed. Clean up
"""
log.debug(u'close http connection')
self.connections.remove(connection)
if connection in self.connections:
self.connections.remove(connection)
def close(self):
"""
@ -168,8 +237,6 @@ class HttpConnection(object):
self.routes = [
(u'^/$', self.serve_file),
(r'^/files/(.*)$', self.serve_file),
#(r'^/send/(.*)$', self.process_event),
#(r'^/request/(.*)$', self.process_request),
(r'^/api/poll$', self.poll),
(r'^/api/controller/(live|preview)/(.*)$', self.controller),
(r'^/api/service/(.*)$', self.service)
@ -321,7 +388,10 @@ class HttpConnection(object):
else:
if self.url_params and self.url_params.get(u'data'):
data = json.loads(self.url_params[u'data'][0])
Receiver.send_message(event, data[u'request'][u'id'])
log.info(data)
# This slot expects an int within a list.
id = data[u'request'][u'id']
Receiver.send_message(event, [id])
else:
Receiver.send_message(event)
json_data = {u'results': {u'success': True}}