Make heading-on-side for comments columns configurable

This commit is contained in:
Kovid Goyal 2016-07-24 09:42:28 +05:30
parent b49b1e81a9
commit 0b0f6e6b9d
3 changed files with 20 additions and 6 deletions

View File

@ -98,8 +98,14 @@ def mi_to_html(mi, field_list=None, default_author_link=None, use_roman_numbers=
val = markdown(val) val = markdown(val)
else: else:
val = comments_to_html(val) val = comments_to_html(val)
add_comment = True
if disp.get('show_heading'): if disp.get('show_heading'):
if disp.get('heading_on_side'):
ans.append((field, row % (name, val)))
add_comment = False
else:
val = '<h3 class="comments-heading">%s</h3>%s' % (p(name), val) val = '<h3 class="comments-heading">%s</h3>%s' % (p(name), val)
if add_comment:
comment_fields.append('<div id="%s" class="comments">%s</div>' % (field.replace('#', '_'), val)) comment_fields.append('<div id="%s" class="comments">%s</div>' % (field.replace('#', '_'), val))
elif metadata['datatype'] == 'rating': elif metadata['datatype'] == 'rating':
val = getattr(mi, field) val = getattr(mi, field)

View File

@ -165,6 +165,7 @@ class CreateCustomColumn(QDialog):
self.format_box.setText(c['display'].get('number_format', '')) self.format_box.setText(c['display'].get('number_format', ''))
elif ct == 'comments': elif ct == 'comments':
self.show_comments_heading.setChecked(c['display'].get('show_heading', False)) self.show_comments_heading.setChecked(c['display'].get('show_heading', False))
self.comments_heading_on_side.setChecked(c['display'].get('heading_on_side', False))
idx = max(0, self.comments_type.findData(c['display'].get('interpret_as', 'html'))) idx = max(0, self.comments_type.findData(c['display'].get('interpret_as', 'html')))
self.comments_type.setCurrentIndex(idx) self.comments_type.setCurrentIndex(idx)
self.datatype_changed() self.datatype_changed()
@ -207,6 +208,7 @@ class CreateCustomColumn(QDialog):
self.composite_sort_by.setCurrentIndex(0) self.composite_sort_by.setCurrentIndex(0)
if which == 'text': if which == 'text':
self.show_comments_heading.setChecked(True) self.show_comments_heading.setChecked(True)
self.comments_heading_on_side.setChecked(True)
self.comments_type.setCurrentIndex(self.comments_type.findData('short-text')) self.comments_type.setCurrentIndex(self.comments_type.findData('short-text'))
# }}} # }}}
@ -307,9 +309,13 @@ class CreateCustomColumn(QDialog):
self.composite_label = add_row(_("&Template"), h) self.composite_label = add_row(_("&Template"), h)
# Comments properties # Comments properties
self.show_comments_heading = sch = QCheckBox(_('Show heading in book details panel')) self.show_comments_heading = sch = QCheckBox(_('Show heading in the Book Details panel'))
sch.setToolTip(_( sch.setToolTip(_(
'Choose whether to show the heading for this column in the Book Details Panel')) 'Choose whether to show the heading for this column in the Book Details panel'))
add_row(None, sch)
self.comments_heading_on_side = sch = QCheckBox(_('Show column heading to the side of the text'))
sch.setToolTip(_(
'Choose whether to show the heading above or to the side of the text in the Book Details panel'))
add_row(None, sch) add_row(None, sch)
self.comments_type = ct = QComboBox(self) self.comments_type = ct = QComboBox(self)
for k, text in ( for k, text in (
@ -418,6 +424,7 @@ class CreateCustomColumn(QDialog):
self.show_comments_heading.setVisible(is_comments) self.show_comments_heading.setVisible(is_comments)
self.comments_type.setVisible(is_comments) self.comments_type.setVisible(is_comments)
self.comments_type_label.setVisible(is_comments) self.comments_type_label.setVisible(is_comments)
self.comments_heading_on_side.setVisible(is_comments)
def accept(self): def accept(self):
col = unicode(self.column_name_box.text()).strip() col = unicode(self.column_name_box.text()).strip()
@ -515,6 +522,7 @@ class CreateCustomColumn(QDialog):
elif col_type == 'comments': elif col_type == 'comments':
display_dict['show_heading'] = bool(self.show_comments_heading.isChecked()) display_dict['show_heading'] = bool(self.show_comments_heading.isChecked())
display_dict['interpret_as'] = type(u'')(self.comments_type.currentData()) display_dict['interpret_as'] = type(u'')(self.comments_type.currentData())
display_dict['heading_on_side'] = bool(self.comments_heading_on_side.isChecked())
if col_type in ['text', 'composite', 'enumeration'] and not is_multiple: if col_type in ['text', 'composite', 'enumeration'] and not is_multiple:
display_dict['use_decorations'] = self.use_decorations.checkState() display_dict['use_decorations'] = self.use_decorations.checkState()

View File

@ -201,8 +201,8 @@ def render_metadata(mi, interface_data, table, field_list=None):
datatype = fm.datatype datatype = fm.datatype
val = mi[field] val = mi[field]
if field is 'comments' or datatype is 'comments': if field is 'comments' or datatype is 'comments':
if fm.display?.interpret_as is 'short-text': if fm.display?.heading_on_side:
add_row(name, val) add_row(name, val, is_html=fm.display?.interpret_as is not 'short-text')
else: else:
comments[field] = val comments[field] = val
return return