Skip to content

Commit

Permalink
Merge pull request #2035 from digitalfabrik/feature/hide_files_in_glo…
Browse files Browse the repository at this point in the history
…bal_media_library

Add option to hide files in global media library
  • Loading branch information
JoeyStk authored Feb 18, 2023
2 parents 35ab8e8 + 7300c9f commit 3d18cdc
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion integreat_cms/cms/forms/media/directory_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions integreat_cms/cms/forms/media/media_file_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ class Meta:
fields = (
"name",
"alt_text",
"is_hidden",
)
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
9 changes: 8 additions & 1 deletion integreat_cms/cms/models/media/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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
Expand All @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion integreat_cms/cms/models/media/media_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand Down
9 changes: 6 additions & 3 deletions integreat_cms/cms/views/media/media_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
4 changes: 3 additions & 1 deletion integreat_cms/cms/views/media/media_context_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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."),
Expand Down
35 changes: 29 additions & 6 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:"
Expand Down Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="grid grid-cols-gallery max-h-full gap-1">
{mediaLibraryContent.map((entry: MediaLibraryEntry, index: number) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ const EditDirectorySidebar = ({
setDirectoryNameEditable(false);
}, [directory]);

const onIsHiddenCheckboxClick = () => {
setChangedDirectory({
...changedDirectory,
isHidden: !changedDirectory.isHidden,
});
};

return (
<div className="absolute w-full h-full flex flex-col rounded border border-blue-500 bg-white border-solid shadow-2xl">
<div class="rounded w-full p-4 bg-water-500 font-bold">
Expand Down Expand Up @@ -105,17 +112,34 @@ const EditDirectorySidebar = ({
<label class="secondary my-0">{mediaTranslations.label_directory_created}</label>
<p>{directory.CreatedDate}</p>
</div>
{directory.isGlobal && globalEdit && (
<div class="flex flex-wrap justify-between gap-2 p-4 border-b">
<label class="secondary my-0" for="directory-hide-input">
{mediaTranslations.label_directory_is_hidden}
</label>
<input
id="directory-hide-input"
name="is_hidden"
type="checkbox"
value={String(changedDirectory.isHidden)}
checked={changedDirectory.isHidden}
onClick={() => {
onIsHiddenCheckboxClick();
}}
/>
</div>
)}
<div class="p-4">
{isEditingAllowed ? (
<div class="flex flex-col gap-4">
{isDirectoryNameEditable && (
{(isDirectoryNameEditable || changedDirectory.isHidden !== directory.isHidden) && (
<button
title={mediaTranslations.btn_rename_directory}
title={mediaTranslations.btn_change_directory}
class="btn"
type="submit"
disabled={isLoading}>
<Save class="mr-1 inline-block h-5" />
{mediaTranslations.btn_rename_directory}
{mediaTranslations.btn_change_directory}
</button>
)}
{canDeleteDirectory && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ const EditSidebar = ({
};
}, [file]);

const onIsHiddenCheckboxClick = () => {
setChangedFile({
...changedFile,
isHidden: !changedFile.isHidden,
});
console.log(changedFile);
};

return (
<div className="absolute w-full h-full flex flex-col rounded border border-blue-500 shadow-2xl bg-white">
<div class="rounded w-full p-4 bg-water-500 font-bold">
Expand Down Expand Up @@ -221,6 +229,23 @@ const EditSidebar = ({
<label className="secondary my-0">{mediaTranslations.label_file_modified}</label>
<p>{file.lastModified}</p>
</div>
{file.isGlobal && globalEdit && (
<div className="flex flex-wrap justify-between gap-2 hover:bg-gray-50 p-4 border-b">
<label className="secondary my-0" for="file-hide-input">
{mediaTranslations.label_file_is_hidden}
</label>
<input
id="file-hide-input"
name="is_hidden"
type="checkbox"
value={String(changedFile.isHidden)}
checked={changedFile.isHidden}
onClick={() => {
onIsHiddenCheckboxClick();
}}
/>
</div>
)}
{expertMode && (
<div class="flex flex-wrap justify-between gap-2 hover:bg-gray-50 p-4 border-b">
<label class="secondary my-0">{mediaTranslations.label_url}</label>
Expand All @@ -238,7 +263,9 @@ const EditSidebar = ({
<div className="flex flex-col p-4 gap-4">
{isEditingAllowed ? (
<>
{(isFileNameEditable || isAltTextEditable) && (
{(isFileNameEditable ||
isAltTextEditable ||
changedFile.isHidden !== file.isHidden) && (
<button title={mediaTranslations.btn_save_file} class="btn" disabled={isLoading}>
<Save class="inline-block" />
{mediaTranslations.btn_save_file}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const DirectoryContentLibrary = (props: LibraryProps) => {
}
// Load the new directory content
ajaxRequest(getDirectoryContent, urlParams, setMediaLibraryContent);

// Close the file sidebar
setFileIndex(null);
/* eslint-disable-next-line react-hooks/exhaustive-deps */
Expand Down
2 changes: 2 additions & 0 deletions integreat_cms/static/src/js/media-management/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type File = {
uploadedDate: Date;
lastModified: Date;
isGlobal: boolean;
isHidden: boolean;
};

export type Directory = {
Expand All @@ -53,6 +54,7 @@ export type Directory = {
numberOfEntries: number;
CreatedDate: Date;
isGlobal: boolean;
isHidden: boolean;
type: "directory";
};

Expand Down

0 comments on commit 3d18cdc

Please sign in to comment.