Skip to content

Commit

Permalink
Merge pull request #64 from acdh-oeaw/limit-col-width
Browse files Browse the repository at this point in the history
Limit col width
  • Loading branch information
gythaogg authored Jun 10, 2024
2 parents b829efd + ad5c326 commit 5e4c247
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 139 deletions.
26 changes: 26 additions & 0 deletions apis_ontology/static/styles/tibschol.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.show-more:checked + .content .more-content {
display: inline;
}
.show-more:checked + .content .preview {
display: none;
}
.show-more:checked + .content .more-link {
display: none;
}
.show-more:checked + .content .less-link {
display: inline;
}
.show-more, .less-link, .more-content {
display: none;
}

.linkish {
color: #007BFF;
cursor: pointer;
text-decoration: none;
}

.linkish:hover {
color: #0056b3;
text-decoration: underline;
}
31 changes: 27 additions & 4 deletions apis_ontology/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from apis_core.apis_entities.tables import AbstractEntityTable
from apis_core.generic.tables import GenericTable
from django_tables2.utils import A
from django.template.loader import render_to_string

from .models import Excerpts, Instance, Person, Place, TibScholRelationMixin, Work
from .templatetags.filter_utils import (
preview_text,
render_coordinate,
render_links,
render_list_field,
Expand Down Expand Up @@ -146,11 +148,32 @@ def render_name(self, record):
else:
return ""

def render_support_notes(self, value):
return mark_safe(parse_comment(value))
def render_support_notes(self, record):
notes = parse_comment(render_list_field(record.support_notes))
preview = parse_comment(
render_list_field(preview_text(record.support_notes, 50))
)
context = {
"record": record,
"preview_value": mark_safe(preview),
"field_value": mark_safe(notes),
"field_name": "support_notes",
}

def render_zotero_refs(self, value):
return mark_safe(parse_comment(render_list_field(value)))
return mark_safe(render_to_string("apis_ontology/preview_column.html", context))

def render_zotero_refs(self, record):
zotero_refs = mark_safe(parse_comment(render_list_field(record.zotero_refs)))
preview = mark_safe(
parse_comment(render_list_field(preview_text(record.zotero_refs, 50)))
)
context = {
"record": record,
"preview_value": preview,
"field_value": zotero_refs,
"field_name": "zotero_refs",
}
return mark_safe(render_to_string("apis_ontology/preview_column.html", context))

def render_obj(self, record):
# return str(record) + str(self.context["object"].pk)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "apis_core/apis_entities/abstractentity.html" %}

{% block scriptHeader %}
{{ block.super }}
<link rel="stylesheet" href="/static/styles/tibschol.css">
{% endblock %}

This file was deleted.

19 changes: 19 additions & 0 deletions apis_ontology/templates/apis_ontology/preview_column.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% if preview_value != field_value %}
<input type="checkbox" id="show-more-{{ record.id }}-{{ field_name }}" class="show-more">
{% endif %}
<div class="content" id="content-{{ record.id }}-{{ field_name }}">
<span class="preview">
{{preview_value }}
</span>
<span class="more-content">
{{ field_value }}
</span>
{% if preview_value != field_value %}
<label for="show-more-{{ record.id }}-{{ field_name }}" class="more-link linkish">
more
</label>
<label for="show-more-{{ record.id }}-{{ field_name }}" class="less-link linkish">
less
</label>
{% endif %}
</div>
8 changes: 8 additions & 0 deletions apis_ontology/templatetags/filter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ def render_zotero_links(value):

rendered_links = "<br>".join(links)
return mark_safe(rendered_links)


@register.filter
def preview_text(text, n=50):
if len(text) <= n:
return text
truncated_text = text[:n].rsplit(" ", 1)[0]
return truncated_text + "…"
Loading

0 comments on commit 5e4c247

Please sign in to comment.