diff --git a/bookmarks/e2e/e2e_test_settings_general.py b/bookmarks/e2e/e2e_test_settings_general.py index cdbf192..3b480c5 100644 --- a/bookmarks/e2e/e2e_test_settings_general.py +++ b/bookmarks/e2e/e2e_test_settings_general.py @@ -2,6 +2,7 @@ from django.urls import reverse from playwright.sync_api import sync_playwright, expect from bookmarks.e2e.helpers import LinkdingE2ETestCase +from bookmarks.models import UserProfile class SettingsGeneralE2ETestCase(LinkdingE2ETestCase): @@ -39,3 +40,49 @@ class SettingsGeneralE2ETestCase(LinkdingE2ETestCase): expect(enable_sharing).not_to_be_checked() expect(enable_public_sharing).not_to_be_checked() expect(enable_public_sharing).to_be_disabled() + + def test_should_not_show_bookmark_description_max_lines_when_display_inline(self): + profile = self.get_or_create_test_user().profile + profile.bookmark_description_display = ( + UserProfile.BOOKMARK_DESCRIPTION_DISPLAY_INLINE + ) + profile.save() + + with sync_playwright() as p: + browser = self.setup_browser(p) + page = browser.new_page() + page.goto(self.live_server_url + reverse("bookmarks:settings.general")) + + max_lines = page.get_by_label("Bookmark description max lines") + expect(max_lines).to_be_hidden() + + def test_should_show_bookmark_description_max_lines_when_display_separate(self): + profile = self.get_or_create_test_user().profile + profile.bookmark_description_display = ( + UserProfile.BOOKMARK_DESCRIPTION_DISPLAY_SEPARATE + ) + profile.save() + + with sync_playwright() as p: + browser = self.setup_browser(p) + page = browser.new_page() + page.goto(self.live_server_url + reverse("bookmarks:settings.general")) + + max_lines = page.get_by_label("Bookmark description max lines") + expect(max_lines).to_be_visible() + + def test_should_update_bookmark_description_max_lines_when_changing_display(self): + with sync_playwright() as p: + browser = self.setup_browser(p) + page = browser.new_page() + page.goto(self.live_server_url + reverse("bookmarks:settings.general")) + + max_lines = page.get_by_label("Bookmark description max lines") + expect(max_lines).to_be_hidden() + + display = page.get_by_label("Bookmark description", exact=True) + display.select_option("separate") + expect(max_lines).to_be_visible() + + display.select_option("inline") + expect(max_lines).to_be_hidden() diff --git a/bookmarks/migrations/0027_userprofile_bookmark_description_display_and_more.py b/bookmarks/migrations/0027_userprofile_bookmark_description_display_and_more.py new file mode 100644 index 0000000..917fbba --- /dev/null +++ b/bookmarks/migrations/0027_userprofile_bookmark_description_display_and_more.py @@ -0,0 +1,27 @@ +# Generated by Django 5.0.2 on 2024-03-23 21:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookmarks", "0026_userprofile_custom_css"), + ] + + operations = [ + migrations.AddField( + model_name="userprofile", + name="bookmark_description_display", + field=models.CharField( + choices=[("inline", "Inline"), ("separate", "Separate")], + default="inline", + max_length=10, + ), + ), + migrations.AddField( + model_name="userprofile", + name="bookmark_description_max_lines", + field=models.IntegerField(default=1), + ), + ] diff --git a/bookmarks/models.py b/bookmarks/models.py index 8714283..126353e 100644 --- a/bookmarks/models.py +++ b/bookmarks/models.py @@ -278,6 +278,12 @@ class UserProfile(models.Model): (BOOKMARK_DATE_DISPLAY_ABSOLUTE, "Absolute"), (BOOKMARK_DATE_DISPLAY_HIDDEN, "Hidden"), ] + BOOKMARK_DESCRIPTION_DISPLAY_INLINE = "inline" + BOOKMARK_DESCRIPTION_DISPLAY_SEPARATE = "separate" + BOOKMARK_DESCRIPTION_DISPLAY_CHOICES = [ + (BOOKMARK_DESCRIPTION_DISPLAY_INLINE, "Inline"), + (BOOKMARK_DESCRIPTION_DISPLAY_SEPARATE, "Separate"), + ] BOOKMARK_LINK_TARGET_BLANK = "_blank" BOOKMARK_LINK_TARGET_SELF = "_self" BOOKMARK_LINK_TARGET_CHOICES = [ @@ -308,6 +314,16 @@ class UserProfile(models.Model): blank=False, default=BOOKMARK_DATE_DISPLAY_RELATIVE, ) + bookmark_description_display = models.CharField( + max_length=10, + choices=BOOKMARK_DESCRIPTION_DISPLAY_CHOICES, + blank=False, + default=BOOKMARK_DESCRIPTION_DISPLAY_INLINE, + ) + bookmark_description_max_lines = models.IntegerField( + null=False, + default=1, + ) bookmark_link_target = models.CharField( max_length=10, choices=BOOKMARK_LINK_TARGET_CHOICES, @@ -341,6 +357,8 @@ class UserProfileForm(forms.ModelForm): fields = [ "theme", "bookmark_date_display", + "bookmark_description_display", + "bookmark_description_max_lines", "bookmark_link_target", "web_archive_integration", "tag_search", diff --git a/bookmarks/styles/bookmark-page.scss b/bookmarks/styles/bookmark-page.scss index c0909cf..2efd822 100644 --- a/bookmarks/styles/bookmark-page.scss +++ b/bookmarks/styles/bookmark-page.scss @@ -175,7 +175,16 @@ li[ld-bookmark-item] { .description { color: $gray-color-dark; + } + .description.separate { + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: var(--ld-bookmark-description-max-lines, 1); + overflow: hidden; + } + + .tags { a, a:visited:hover { color: $alternative-color; } diff --git a/bookmarks/templates/bookmarks/bookmark_list.html b/bookmarks/templates/bookmarks/bookmark_list.html index c5b6c0a..1abca54 100644 --- a/bookmarks/templates/bookmarks/bookmark_list.html +++ b/bookmarks/templates/bookmarks/bookmark_list.html @@ -6,6 +6,7 @@ {% include 'bookmarks/empty_bookmarks.html' %} {% else %}