mirror of https://github.com/logos-co/open-law.git
delete section UI, fix create section/subcollection
This commit is contained in:
parent
00dc7dca7e
commit
dc23dcfeca
|
@ -19,9 +19,7 @@ class CreateSectionForm(BaseSectionForm):
|
|||
collection_id = field.data
|
||||
collection: m.Collection = db.session.get(m.Collection, collection_id)
|
||||
|
||||
if not collection or [
|
||||
child for child in collection.children if not child.is_deleted
|
||||
]:
|
||||
if not collection or collection.sub_collections:
|
||||
log(log.WARNING, "Collection [%s] it not leaf", collection)
|
||||
|
||||
raise ValidationError("You can't create section for this collection")
|
||||
|
|
|
@ -25,3 +25,15 @@ class Collection(BaseModel):
|
|||
|
||||
def __repr__(self):
|
||||
return f"<{self.id}: {self.label}>"
|
||||
|
||||
@property
|
||||
def active_sections(self):
|
||||
return [section for section in self.sections if not section.is_deleted]
|
||||
|
||||
@property
|
||||
def sub_collections(self):
|
||||
return [
|
||||
sub_collection
|
||||
for sub_collection in self.children
|
||||
if not sub_collection.is_deleted
|
||||
]
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<!-- prettier-ignore-->
|
||||
<div id="delete-collection-modal" tabindex="-1" aria-hidden="true" class="fixed top-0 left-0 right-0 z-50 hidden w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
||||
<div class="relative w-full max-w-2xl max-h-full">
|
||||
<!-- Modal content -->
|
||||
<form
|
||||
{% if sub_collection %}
|
||||
action="{{ url_for('book.section_delete', book_id=book.id, collection_id=collection.id, sub_collection_id=sub_collection.id, section_id=section.id) }}"
|
||||
{% else %}
|
||||
action="{{ url_for('book.section_delete', book_id=book.id, collection_id=collection.id, section_id=section.id) }}"
|
||||
{% endif %}
|
||||
method="post" class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
||||
{{ form_hidden_tag() }}
|
||||
<!-- Modal header -->
|
||||
<div class="flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600">
|
||||
<h3 class="text-xl font-semibold text-gray-900 dark:text-white"> Delete Section </h3>
|
||||
<button id="modalAddCloseButton" data-modal-hide="delete-collection-modal" type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center dark:hover:bg-gray-600 dark:hover:text-white"> <svg aria-hidden="true" class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg> </button>
|
||||
</div>
|
||||
<!-- Modal body -->
|
||||
|
||||
<!-- Modal footer -->
|
||||
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
|
||||
<button name="submit" type="submit" class="text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-800">Confirm Deletion</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
|
@ -1,5 +1,16 @@
|
|||
<!-- prettier-ignore -->
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% include 'book/delete_section_modal.html' %}
|
||||
|
||||
<!-- show delete section btn on rightside bar -->
|
||||
{% set show_delete_section = True %}
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
{% block right_sidebar %}
|
||||
{% include 'book/right_sidebar.html' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="relative overflow-x-auto shadow-md sm:rounded-lg mt-5 md:mr-64">
|
||||
{% include 'book/breadcrumbs_navigation.html'%}
|
||||
|
|
|
@ -52,6 +52,16 @@
|
|||
</button>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if show_delete_section %}
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<button type="button" data-modal-target="collection-collection-modal" data-modal-toggle="delete-collection-modal" class="space-x-3 text-white ml-2 w-11/12 bg-red-700 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 font-medium rounded-lg text-sm px-4 py-2.5 text-center inline-flex items-center dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-800">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" /> </svg>
|
||||
<p>Delete Section</p>
|
||||
</button>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
<!-- prettier-ignore -->
|
||||
{% extends 'base.html' %}
|
||||
{% if book.owner.id == current_user.id %}
|
||||
<!-- show edit collection btn on rightside bar -->
|
||||
{% set show_edit_collection = True %}
|
||||
<!-- show delete collection btn on rightside bar -->
|
||||
{% set show_delete_collection = True %}
|
||||
<!-- show create section btn on rightside bar -->
|
||||
{% set show_create_section = True %}
|
||||
{% set show_create_collection = not collection.sub_collections and not collection.is_leaf %}
|
||||
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
{% include 'book/edit_collection_modal.html' %}
|
||||
{% include 'book/delete_collection_modal.html' %}
|
||||
{% include 'book/add_section_modal.html' %}
|
||||
{% include 'book/add_collection_modal.html' %}
|
||||
{% endif %}
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
|
|
|
@ -2,14 +2,10 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% if book.owner.id == current_user.id %}
|
||||
<!-- show edit collection btn on rightside bar -->
|
||||
{% set show_edit_collection = True %}
|
||||
<!-- show delete collection btn on rightside bar -->
|
||||
{% set show_delete_collection = True %}
|
||||
<!-- show create collection btn on rightside bar -->
|
||||
{% set show_create_collection = True %}
|
||||
<!-- show create section btn on rightside bar -->
|
||||
{% set show_create_section = collection.is_leaf or not collection.children %}
|
||||
{% set show_create_section = not collection.sub_collections or collection.is_leaf or not collection.children %}
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
{% include 'book/edit_collection_modal.html' %}
|
||||
|
@ -56,7 +52,7 @@
|
|||
<!-- prettier-ignore -->
|
||||
<dl class="w-md md:w-full text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700">
|
||||
<!-- prettier-ignore -->
|
||||
{% for sub_collection in collection.children %}
|
||||
{% for sub_collection in collection.sub_collections %}
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{url_for('book.section_view',book_id=book.id,collection_id=collection.id,sub_collection_id=sub_collection.id)}}">
|
||||
<dl class="bg-white dark:bg-gray-900 max-w-full p-3 text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700 m-3 border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
|
||||
|
|
|
@ -173,9 +173,9 @@ def section_view(
|
|||
)
|
||||
|
||||
if sub_collection:
|
||||
sections = sub_collection.sections
|
||||
sections = sub_collection.active_sections
|
||||
else:
|
||||
sections = collection.sections
|
||||
sections = collection.active_sections
|
||||
|
||||
breadcrumbs = create_breadcrumbs(
|
||||
book_id=book_id,
|
||||
|
@ -823,6 +823,8 @@ def section_delete(
|
|||
log(log.WARNING, "Collection with id [%s] not found", collection_id)
|
||||
flash("Collection not found", "danger")
|
||||
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||
|
||||
collection_to_edit = collection
|
||||
if sub_collection_id:
|
||||
sub_collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
|
||||
if not sub_collection or sub_collection.is_deleted:
|
||||
|
@ -835,6 +837,7 @@ def section_delete(
|
|||
collection_id=collection_id,
|
||||
)
|
||||
)
|
||||
collection_to_edit = sub_collection
|
||||
|
||||
redirect_url = url_for(
|
||||
"book.section_view",
|
||||
|
@ -849,6 +852,13 @@ def section_delete(
|
|||
return redirect(redirect_url)
|
||||
|
||||
section.is_deleted = True
|
||||
if not collection_to_edit.active_sections:
|
||||
log(
|
||||
log.INFO,
|
||||
"Section [%s] has no active section. Set is_leaf = False",
|
||||
section.id,
|
||||
)
|
||||
collection_to_edit.is_leaf = False
|
||||
|
||||
log(log.INFO, "Delete section [%s]", section.id)
|
||||
section.save()
|
||||
|
|
Loading…
Reference in New Issue