Make gui version of content server able to show both abbreviated and full lists of tags.

This commit is contained in:
Charles Haley 2010-09-05 12:35:35 +01:00
parent 38c6199c7b
commit 06b266840c
4 changed files with 47 additions and 9 deletions

View File

@ -59,14 +59,44 @@ function render_book(book) {
title = title.slice(0, title.length-2); title = title.slice(0, title.length-2);
title += ' ({0} MB) '.format(size); title += ' ({0} MB) '.format(size);
} }
title += '<span class="tagdata_short" style="display:all">'
if (tags) {
t = tags.split(':&:', 2);
m = parseInt(t[0]);
t = t[1].split(',', m);
if (t.length == m) t[m] = '...'
title += 'Tags=[{0}] '.format(t.join(','));
}
custcols = book.attr("custcols").split(',')
for ( i = 0; i < custcols.length; i++) {
if (custcols[i].length > 0) {
vals = book.attr(custcols[i]).split(':#:', 2);
if (vals[0].indexOf('#T#') == 0) { //startswith
vals[0] = vals[0].substr(3, vals[0].length)
t = vals[1].split(':&:', 2);
m = parseInt(t[0]);
t = t[1].split(',', m);
if (t.length == m) t[m] = '...';
vals[1] = t.join(',');
}
title += '{0}=[{1}] '.format(vals[0], vals[1]);
}
}
title += '</span>'
title += '<span class="tagdata_long" style="display:none">'
if (tags) title += 'Tags=[{0}] '.format(tags); if (tags) title += 'Tags=[{0}] '.format(tags);
custcols = book.attr("custcols").split(',') custcols = book.attr("custcols").split(',')
for ( i = 0; i < custcols.length; i++) { for ( i = 0; i < custcols.length; i++) {
if (custcols[i].length > 0) { if (custcols[i].length > 0) {
vals = book.attr(custcols[i]).split(':#:', 2); vals = book.attr(custcols[i]).split(':#:', 2);
if (vals[0].indexOf('#T#') == 0) { //startswith
vals[0] = vals[0].substr(3, vals[0].length)
vals[1] = (vals[1].split(':&:', 2))[1];
}
title += '{0}=[{1}] '.format(vals[0], vals[1]); title += '{0}=[{1}] '.format(vals[0], vals[1]);
} }
} }
title += '</span>'
title += '<img style="display:none" alt="" src="get/cover/{0}" /></span>'.format(id); title += '<img style="display:none" alt="" src="get/cover/{0}" /></span>'.format(id);
title += '<div class="comments">{0}</div>'.format(comments) title += '<div class="comments">{0}</div>'.format(comments)
// Render authors cell // Render authors cell
@ -170,11 +200,15 @@ function fetch_library_books(start, num, timeout, sort, order, search) {
var cover = row.find('img').attr('src'); var cover = row.find('img').attr('src');
var collapsed = row.find('.comments').css('display') == 'none'; var collapsed = row.find('.comments').css('display') == 'none';
$("#book_list tbody tr * .comments").css('display', 'none'); $("#book_list tbody tr * .comments").css('display', 'none');
$("#book_list tbody tr * .tagdata_short").css('display', 'inherit');
$("#book_list tbody tr * .tagdata_long").css('display', 'none');
$('#cover_pane').css('visibility', 'hidden'); $('#cover_pane').css('visibility', 'hidden');
if (collapsed) { if (collapsed) {
row.find('.comments').css('display', 'inherit'); row.find('.comments').css('display', 'inherit');
$('#cover_pane img').attr('src', cover); $('#cover_pane img').attr('src', cover);
$('#cover_pane').css('visibility', 'visible'); $('#cover_pane').css('visibility', 'visible');
row.find(".tagdata_short").css('display', 'none');
row.find(".tagdata_long").css('display', 'inherit');
} }
}); });

View File

@ -262,10 +262,11 @@ class Metadata(object):
if other_lang and other_lang.lower() != 'und': if other_lang and other_lang.lower() != 'und':
self.language = other_lang self.language = other_lang
def format_series_index(self): def format_series_index(self, val=None):
from calibre.ebooks.metadata import fmt_sidx from calibre.ebooks.metadata import fmt_sidx
v = self.series_index if val is None else val
try: try:
x = float(self.series_index) x = float(v)
except ValueError: except ValueError:
x = 1 x = 1
return fmt_sidx(x) return fmt_sidx(x)
@ -296,7 +297,7 @@ class Metadata(object):
if datatype == 'text' and cmeta['is_multiple']: if datatype == 'text' and cmeta['is_multiple']:
res = u', '.join(res) res = u', '.join(res)
elif datatype == 'series': elif datatype == 'series':
res = res + ' [%s]'%self.format_series_index(self.get_extra(key)) res = res + ' [%s]'%self.format_series_index(val=self.get_extra(key))
elif datatype == 'datetime': elif datatype == 'datetime':
res = format_date(res, cmeta['display'].get('date_format','dd MMM yyyy')) res = format_date(res, cmeta['display'].get('date_format','dd MMM yyyy'))
elif datatype == 'bool': elif datatype == 'bool':

View File

@ -5,7 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import time import time, sys
import cherrypy import cherrypy
@ -44,8 +44,8 @@ def strftime(fmt='%Y/%m/%d %H:%M:%S', dt=None):
except: except:
return _strftime(fmt, nowf().timetuple()) return _strftime(fmt, nowf().timetuple())
def format_tag_string(tags, sep): def format_tag_string(tags, sep, ignore_max=False):
MAX = tweaks['max_content_server_tags_shown'] MAX = sys.maxint if ignore_max else tweaks['max_content_server_tags_shown']
if tags: if tags:
tlist = [t.strip() for t in tags.split(sep)] tlist = [t.strip() for t in tags.split(sep)]
else: else:
@ -53,5 +53,6 @@ def format_tag_string(tags, sep):
tlist.sort(cmp=lambda x,y:cmp(x.lower(), y.lower())) tlist.sort(cmp=lambda x,y:cmp(x.lower(), y.lower()))
if len(tlist) > MAX: if len(tlist) > MAX:
tlist = tlist[:MAX]+['...'] tlist = tlist[:MAX]+['...']
return u'%s'%(', '.join(tlist)) if tlist else '' return u'%s:&:%s'%(tweaks['max_content_server_tags_shown'],
', '.join(tlist)) if tlist else ''

View File

@ -89,7 +89,7 @@ class XMLServer(object):
'comments'): 'comments'):
y = record[FM[x]] y = record[FM[x]]
if x == 'tags': if x == 'tags':
y = format_tag_string(y, ',') y = format_tag_string(y, ',', ignore_max=True)
kwargs[x] = serialize(y) if y else '' kwargs[x] = serialize(y) if y else ''
c = kwargs.pop('comments') c = kwargs.pop('comments')
@ -111,7 +111,9 @@ class XMLServer(object):
name = CFM[key]['name'] name = CFM[key]['name']
custcols.append(k) custcols.append(k)
if datatype == 'text' and CFM[key]['is_multiple']: if datatype == 'text' and CFM[key]['is_multiple']:
kwargs[k] = concat(name, format_tag_string(val,'|')) kwargs[k] = concat('#T#'+name,
format_tag_string(val,'|',
ignore_max=True))
elif datatype == 'series': elif datatype == 'series':
kwargs[k] = concat(name, '%s [%s]'%(val, kwargs[k] = concat(name, '%s [%s]'%(val,
fmt_sidx(record[CFM.cc_series_index_column_for(key)]))) fmt_sidx(record[CFM.cc_series_index_column_for(key)])))