From 7300c9f4d63bad0670badc00d0724632504eca12 Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 30 Jan 2023 13:48:28 +0100 Subject: [PATCH] Add option to hide fields in global media library --- CHANGELOG.md | 1 + .../cms/forms/media/directory_form.py | 2 +- .../cms/forms/media/media_file_form.py | 1 + ...is_hidden_field_to_global_media_library.py | 34 ++++++++++++++++++ integreat_cms/cms/models/media/directory.py | 9 ++++- integreat_cms/cms/models/media/media_file.py | 8 ++++- .../cms/views/media/media_actions.py | 9 +++-- .../cms/views/media/media_context_mixin.py | 4 ++- integreat_cms/locale/de/LC_MESSAGES/django.po | 35 +++++++++++++++---- .../component/directory-content.tsx | 1 - .../component/edit-directory-sidebar.tsx | 30 ++++++++++++++-- .../component/edit-sidebar.tsx | 29 ++++++++++++++- .../directory-content-library.tsx | 1 + .../static/src/js/media-management/index.tsx | 2 ++ 14 files changed, 148 insertions(+), 18 deletions(-) create mode 100644 integreat_cms/cms/migrations/0063_add_is_hidden_field_to_global_media_library.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b266db815..6826dfdaa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ UNRELEASED * [ [#2056](https://github.com/digitalfabrik/integreat-cms/issues/2056) ] Change restriction of event duration to 28 days * [ [#2032](https://github.com/digitalfabrik/integreat-cms/issues/2032) ] Remove gap between sidebar boxes in location form * [ [#1989](https://github.com/digitalfabrik/integreat-cms/issues/1989) ] Improve load time of locations endpoint +* [ [#1578](https://github.com/digitalfabrik/integreat-cms/issues/1578) ] Add option to hide files in global media library 2023.2.0 diff --git a/integreat_cms/cms/forms/media/directory_form.py b/integreat_cms/cms/forms/media/directory_form.py index 51ccb8a91b..10a917da3a 100644 --- a/integreat_cms/cms/forms/media/directory_form.py +++ b/integreat_cms/cms/forms/media/directory_form.py @@ -16,4 +16,4 @@ class Meta: #: The model of this :class:`django.forms.ModelForm` model = Directory #: The fields of the model which should be handled by this form - fields = ("name",) + fields = ("name", "is_hidden") diff --git a/integreat_cms/cms/forms/media/media_file_form.py b/integreat_cms/cms/forms/media/media_file_form.py index 48fba30f5a..c434811930 100644 --- a/integreat_cms/cms/forms/media/media_file_form.py +++ b/integreat_cms/cms/forms/media/media_file_form.py @@ -23,4 +23,5 @@ class Meta: fields = ( "name", "alt_text", + "is_hidden", ) diff --git a/integreat_cms/cms/migrations/0063_add_is_hidden_field_to_global_media_library.py b/integreat_cms/cms/migrations/0063_add_is_hidden_field_to_global_media_library.py new file mode 100644 index 0000000000..50e5ad9117 --- /dev/null +++ b/integreat_cms/cms/migrations/0063_add_is_hidden_field_to_global_media_library.py @@ -0,0 +1,34 @@ +# Generated by Django 3.2.16 on 2023-01-30 10:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + """ + Update fields for media files and media directories to add the option to make them hidden + """ + + dependencies = [ + ("cms", "0062_alter_languagetreenode"), + ] + + operations = [ + migrations.AddField( + model_name="directory", + name="is_hidden", + field=models.BooleanField( + default=False, + help_text="Whether the directory is hidden in the regional media library", + verbose_name="hidden", + ), + ), + migrations.AddField( + model_name="mediafile", + name="is_hidden", + field=models.BooleanField( + default=False, + help_text="Whether the media file is hidden in the regional media library", + verbose_name="hidden", + ), + ), + ] diff --git a/integreat_cms/cms/models/media/directory.py b/integreat_cms/cms/models/media/directory.py index ded865e6fc..1f5da9be46 100644 --- a/integreat_cms/cms/models/media/directory.py +++ b/integreat_cms/cms/models/media/directory.py @@ -36,6 +36,11 @@ class Directory(AbstractBaseModel): verbose_name=_("creation date"), help_text=_("The date and time when the directory was created"), ) + is_hidden = models.BooleanField( + default=False, + verbose_name=_("hidden"), + help_text=_("Whether the directory is hidden in the regional media library"), + ) def serialize(self): """ @@ -53,6 +58,7 @@ def serialize(self): "CreatedDate": localize(timezone.localtime(self.created_date)), "isGlobal": not self.region, "numberOfEntries": self.subdirectories.count() + self.files.count(), + "isHidden": self.is_hidden, } @classmethod @@ -70,7 +76,8 @@ def search(cls, region, query): :rtype: ~django.db.models.query.QuerySet [ ~integreat_cms.cms.models.media.directory.Directory ] """ return cls.objects.filter( - Q(region=region) | Q(region__isnull=True), Q(name__icontains=query) + Q(region=region) | Q(region__isnull=True, is_hidden=False), + Q(name__icontains=query), ) def __str__(self): diff --git a/integreat_cms/cms/models/media/media_file.py b/integreat_cms/cms/models/media/media_file.py index f9fed94cb3..fa8e07bd18 100644 --- a/integreat_cms/cms/models/media/media_file.py +++ b/integreat_cms/cms/models/media/media_file.py @@ -169,6 +169,11 @@ class MediaFile(AbstractBaseModel): verbose_name=_("last modified"), help_text=_("The date and time when the physical media file was last modified"), ) + is_hidden = models.BooleanField( + default=False, + verbose_name=_("hidden"), + help_text=_("Whether the media file is hidden in the regional media library"), + ) @property def url(self): @@ -217,6 +222,7 @@ def serialize(self): "uploadedDate": localize(timezone.localtime(self.uploaded_date)), "lastModified": localize(timezone.localtime(self.last_modified)), "isGlobal": not self.region, + "isHidden": self.is_hidden, } @classmethod @@ -234,7 +240,7 @@ def search(cls, region, query): :rtype: ~django.db.models.query.QuerySet [ ~integreat_cms.cms.models.media.media_file.MediaFile ] """ return cls.objects.filter( - Q(region=region) | Q(region__isnull=True), + Q(region=region) | Q(region__isnull=True, is_hidden=False), Q(name__icontains=query) | Q(alt_text__icontains=query) | Q(file__icontains=query), diff --git a/integreat_cms/cms/views/media/media_actions.py b/integreat_cms/cms/views/media/media_actions.py index c24450a3fb..aa5c273a5f 100644 --- a/integreat_cms/cms/views/media/media_actions.py +++ b/integreat_cms/cms/views/media/media_actions.py @@ -81,15 +81,18 @@ def get_directory_content_ajax(request, region_slug=None): directory = None if request.GET.get("directory"): directory = get_object_or_404( - Directory.objects.filter(Q(region=region) | Q(region__isnull=True)), + Directory.objects.filter( + Q(region=region) | Q(region__isnull=True, is_hidden=False), + ), id=request.GET.get("directory"), ) media_files = MediaFile.objects.filter( - Q(region=region) | Q(region__isnull=True), Q(parent_directory=directory) + Q(region=region) | Q(region__isnull=True, is_hidden=False), + Q(parent_directory=directory), ) directories = Directory.objects.filter( - Q(region=region) | Q(region__isnull=True), parent=directory + Q(region=region) | Q(region__isnull=True, is_hidden=False), parent=directory ) result = list(map(lambda d: d.serialize(), list(directories) + list(media_files))) diff --git a/integreat_cms/cms/views/media/media_context_mixin.py b/integreat_cms/cms/views/media/media_context_mixin.py index c40574659f..7da29bc3b4 100644 --- a/integreat_cms/cms/views/media/media_context_mixin.py +++ b/integreat_cms/cms/views/media/media_context_mixin.py @@ -43,7 +43,7 @@ def get_context_data(self, **kwargs): "btn_create": _("Create"), "btn_enter_directory": _("Enter directory"), "btn_create_directory": _("Create directory"), - "btn_rename_directory": _("Rename directory"), + "btn_change_directory": _("Save changes"), "btn_delete_directory": _("Delete directory"), "btn_delete_empty_directory": _( "You can only delete empty directories" @@ -63,6 +63,8 @@ def get_context_data(self, **kwargs): "label_file_uploaded": _("File uploaded on:"), "label_file_modified": _("File modified on:"), "label_directory_created": _("Directory created on:"), + "label_directory_is_hidden": _("Hide this directory:"), + "label_file_is_hidden": _("Hide this file:"), "label_alt_text": _("Alternative text:"), "text_enter_directory_name": _("Enter directory name here"), "text_file_readonly": _("This file is read-only and cannot be edited."), diff --git a/integreat_cms/locale/de/LC_MESSAGES/django.po b/integreat_cms/locale/de/LC_MESSAGES/django.po index 58a3963f67..f15c1f8b48 100644 --- a/integreat_cms/locale/de/LC_MESSAGES/django.po +++ b/integreat_cms/locale/de/LC_MESSAGES/django.po @@ -2771,6 +2771,15 @@ msgstr "Elternverzeichnis" msgid "The date and time when the directory was created" msgstr "Das Datum und die Uhrzeit, zu der das Verzeichnis erstellt wurde" +#: cms/models/media/directory.py cms/models/media/media_file.py +#: cms/views/language_tree/language_tree_bulk_actions.py +msgid "hidden" +msgstr "versteckt" + +#: cms/models/media/directory.py +msgid "Whether the directory is hidden in the regional media library" +msgstr "Ob das Verzeichnis in den regionalen Medienbibliotheken verborgen ist" + #: cms/models/media/directory.py msgid "media directory" msgstr "Medien-Verzeichnis" @@ -2817,6 +2826,10 @@ msgstr "" "Das Datum und die Uhrzeit, zu der die physische Medien-Datei zuletzt " "geändert wurde" +#: cms/models/media/media_file.py +msgid "Whether the media file is hidden in the regional media library" +msgstr "Ob die Mediendatei in den regionalen Medienbibliotheken verborgen ist" + #: cms/models/media/media_file.py msgid "media file" msgstr "Medien-Datei" @@ -7272,10 +7285,6 @@ msgstr "" msgid "made visible" msgstr "sichtbar gemacht" -#: cms/views/language_tree/language_tree_bulk_actions.py -msgid "hidden" -msgstr "versteckt" - #: cms/views/language_tree/language_tree_bulk_actions.py msgid "activated" msgstr "aktiviert" @@ -7405,8 +7414,8 @@ msgid "Create directory" msgstr "Verzeichnis erstellen" #: cms/views/media/media_context_mixin.py -msgid "Rename directory" -msgstr "Verzeichnis umbenennen" +msgid "Save changes" +msgstr "Änderungen speichern" #: cms/views/media/media_context_mixin.py msgid "Delete directory" @@ -7464,6 +7473,14 @@ msgstr "Datei zuletzt geändert am:" msgid "Directory created on:" msgstr "Verzeichnis erstellt am:" +#: cms/views/media/media_context_mixin.py +msgid "Hide this directory:" +msgstr "Dieses Verzeichnis verbergen:" + +#: cms/views/media/media_context_mixin.py +msgid "Hide this file:" +msgstr "Diese Datei verbergen:" + #: cms/views/media/media_context_mixin.py msgid "Alternative text:" msgstr "Alternativer Text:" @@ -8334,12 +8351,18 @@ msgstr "" #~ msgid "Add language" #~ msgstr "Sprache hinzufügen" +#~ msgid "File is hidden:" +#~ msgstr "Datei ist verborgen:" + #~ msgid "Barrier free" #~ msgstr "Barrierefrei" #~ msgid "Organization" #~ msgstr "Organisation" +#~ msgid "Rename directory" +#~ msgstr "Verzeichnis umbenennen" + #~ msgid "of" #~ msgstr "von" diff --git a/integreat_cms/static/src/js/media-management/component/directory-content.tsx b/integreat_cms/static/src/js/media-management/component/directory-content.tsx index 01d5d512b5..e38ad80236 100644 --- a/integreat_cms/static/src/js/media-management/component/directory-content.tsx +++ b/integreat_cms/static/src/js/media-management/component/directory-content.tsx @@ -34,7 +34,6 @@ const DirectoryContent = ({ }: Props) => { // The file index contains the index of the file which is currently opened in the sidebar const [fileIndex, setFileIndex] = fileIndexState; - return (
{mediaLibraryContent.map((entry: MediaLibraryEntry, index: number) => diff --git a/integreat_cms/static/src/js/media-management/component/edit-directory-sidebar.tsx b/integreat_cms/static/src/js/media-management/component/edit-directory-sidebar.tsx index dac30c90b6..5e055c6289 100644 --- a/integreat_cms/static/src/js/media-management/component/edit-directory-sidebar.tsx +++ b/integreat_cms/static/src/js/media-management/component/edit-directory-sidebar.tsx @@ -44,6 +44,13 @@ const EditDirectorySidebar = ({ setDirectoryNameEditable(false); }, [directory]); + const onIsHiddenCheckboxClick = () => { + setChangedDirectory({ + ...changedDirectory, + isHidden: !changedDirectory.isHidden, + }); + }; + return (
@@ -105,17 +112,34 @@ const EditDirectorySidebar = ({

{directory.CreatedDate}

+ {directory.isGlobal && globalEdit && ( +
+ + { + onIsHiddenCheckboxClick(); + }} + /> +
+ )}
{isEditingAllowed ? (
- {isDirectoryNameEditable && ( + {(isDirectoryNameEditable || changedDirectory.isHidden !== directory.isHidden) && ( )} {canDeleteDirectory && ( diff --git a/integreat_cms/static/src/js/media-management/component/edit-sidebar.tsx b/integreat_cms/static/src/js/media-management/component/edit-sidebar.tsx index 9e3e395d03..17d1259b3f 100644 --- a/integreat_cms/static/src/js/media-management/component/edit-sidebar.tsx +++ b/integreat_cms/static/src/js/media-management/component/edit-sidebar.tsx @@ -90,6 +90,14 @@ const EditSidebar = ({ }; }, [file]); + const onIsHiddenCheckboxClick = () => { + setChangedFile({ + ...changedFile, + isHidden: !changedFile.isHidden, + }); + console.log(changedFile); + }; + return (
@@ -221,6 +229,23 @@ const EditSidebar = ({

{file.lastModified}

+ {file.isGlobal && globalEdit && ( +
+ + { + onIsHiddenCheckboxClick(); + }} + /> +
+ )} {expertMode && (
@@ -238,7 +263,9 @@ const EditSidebar = ({
{isEditingAllowed ? ( <> - {(isFileNameEditable || isAltTextEditable) && ( + {(isFileNameEditable || + isAltTextEditable || + changedFile.isHidden !== file.isHidden) && (