mirror of https://github.com/logos-co/open-law.git
done
This commit is contained in:
parent
3be075c135
commit
58037e1065
|
@ -11,7 +11,7 @@
|
|||
<button type="button" id="connectWalletBtn" class="w-full h-full text-black dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-100 font-medium rounded-lg text-sm px-4 py-2.5 justify-center text-center inline-flex items-center border border-gray-200 dark:border-gray-700"><div class="my-auto"></div> Connect you wallet to see your favorite books! </div></button></div>
|
||||
<!-- prettier-ignore -->
|
||||
{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.stars|length== 0%}
|
||||
{% if current_user.is_authenticated and not books %}
|
||||
<!-- prettier-ignore -->
|
||||
<div class="mx-auto my-auto h-full w-full p-2">
|
||||
<button type="button" data-modal-target="add-book-modal" data-modal-toggle="add-book-modal" class="w-full h-full text-black dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-100 font-medium rounded-lg text-sm px-4 py-2.5 justify-center text-center inline-flex items-center border border-gray-200 dark:border-gray-700"><div class="my-auto"></div><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="M12 4.5v15m7.5-7.5h-15" /> </svg> You don't have favorite books start to create your own! </div></button></div>
|
||||
|
@ -20,7 +20,7 @@
|
|||
<!-- prettier-ignore -->
|
||||
<div class="flex flex-col w-4/5">
|
||||
<h1 class=" text-lg font-extrabold dark:text-white ml-4">Fav books</h1>
|
||||
{% for book in current_user.stars %}
|
||||
{% for book in books %}
|
||||
<!-- prettier-ignore -->
|
||||
<dl class="bg-white dark:bg-gray-900 h-max w-full p-5 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">
|
||||
<dt class="mb-2"><a class="flex flex-col pb-4" href="{{url_for('book.collection_view',book_id=book.id)}}">{{book.label}}</a></dt>
|
||||
|
@ -47,6 +47,59 @@
|
|||
</dd>
|
||||
</dl>
|
||||
{% endfor %}
|
||||
{% if current_user.is_authenticated and page.pages > 1 %}
|
||||
<div class="container content-center mt-3 flex bg-white dark:bg-gray-800">
|
||||
<nav aria-label="Page navigation example" class="mx-auto">
|
||||
<ul class="inline-flex items-center -space-x-px">
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.favorite_books') }}?page=1&q={{page.query}}" class="block px-3 py-2 ml-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-l-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
|
||||
<span class="sr-only">First</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"> <path fill-rule="evenodd" d="M15.79 14.77a.75.75 0 01-1.06.02l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 111.04 1.08L11.832 10l3.938 3.71a.75.75 0 01.02 1.06zm-6 0a.75.75 0 01-1.06.02l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 111.04 1.08L5.832 10l3.938 3.71a.75.75 0 01.02 1.06z" clip-rule="evenodd" /> </svg>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.favorite_books') }}?page={{page.page-1 if page.page > 1 else 1}}&q={{page.query}}" class="block px-3 py-2 ml-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-l-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
|
||||
<span class="sr-only">Previous</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"> <path fill-rule="evenodd" d="M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z" clip-rule="evenodd" /> </svg>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
{% for p in page.pages_for_links %}
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
{% if p == page.page %}
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.favorite_books') }}?page={{p}}&q={{page.query}}" aria-current="page" class="z-10 px-3 py-2 leading-tight text-blue-600 border border-blue-300 bg-blue-50 hover:bg-blue-100 hover:text-blue-700 dark:border-gray-700 dark:bg-gray-700 dark:text-white">{{p}}</a>
|
||||
{% else %}
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.favorite_books') }}?page={{p}}&q={{page.query}}" class="px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">{{p}}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.favorite_books') }}?page={{page.page+1 if page.page < page.pages else page.pages}}&q={{page.query}}" class="block px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 rounded-r-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
|
||||
<!-- prettier-ignore -->
|
||||
<span class="sr-only">Next</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"> <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" /> </svg>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.favorite_books') }}?page={{page.pages}}&q={{page.query}}" class="block px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 rounded-r-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
|
||||
<!-- prettier-ignore -->
|
||||
<span class="sr-only">Last</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"> <path fill-rule="evenodd" d="M10.21 14.77a.75.75 0 01.02-1.06L14.168 10 10.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" /> <path fill-rule="evenodd" d="M4.21 14.77a.75.75 0 01.02-1.06L8.168 10 4.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" /> </svg>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<!-- prettier-ignore -->
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<!-- prettier-ignore -->
|
||||
<div class="flex flex-col w-4/5">
|
||||
<h1 class=" text-lg font-extrabold dark:text-white ml-4">My contributions</h1>
|
||||
{% for interpretation in current_user.contributions %}
|
||||
{% for interpretation in interpretations %}
|
||||
<!-- prettier-ignore -->
|
||||
<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">
|
||||
<div class="flex flex-row pb-3 p-3 w-2/3 md:w-10/12">
|
||||
|
@ -89,6 +89,59 @@
|
|||
</div>
|
||||
</dl>
|
||||
{% endfor %}
|
||||
{% if current_user.is_authenticated and page.pages > 1 %}
|
||||
<div class="container content-center mt-3 flex bg-white dark:bg-gray-800">
|
||||
<nav aria-label="Page navigation example" class="mx-auto">
|
||||
<ul class="inline-flex items-center -space-x-px">
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.my_contributions') }}?page=1&q={{page.query}}" class="block px-3 py-2 ml-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-l-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
|
||||
<span class="sr-only">First</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"> <path fill-rule="evenodd" d="M15.79 14.77a.75.75 0 01-1.06.02l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 111.04 1.08L11.832 10l3.938 3.71a.75.75 0 01.02 1.06zm-6 0a.75.75 0 01-1.06.02l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 111.04 1.08L5.832 10l3.938 3.71a.75.75 0 01.02 1.06z" clip-rule="evenodd" /> </svg>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.my_contributions') }}?page={{page.page-1 if page.page > 1 else 1}}&q={{page.query}}" class="block px-3 py-2 ml-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-l-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
|
||||
<span class="sr-only">Previous</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"> <path fill-rule="evenodd" d="M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z" clip-rule="evenodd" /> </svg>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
{% for p in page.pages_for_links %}
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
{% if p == page.page %}
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.my_contributions') }}?page={{p}}&q={{page.query}}" aria-current="page" class="z-10 px-3 py-2 leading-tight text-blue-600 border border-blue-300 bg-blue-50 hover:bg-blue-100 hover:text-blue-700 dark:border-gray-700 dark:bg-gray-700 dark:text-white">{{p}}</a>
|
||||
{% else %}
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.my_contributions') }}?page={{p}}&q={{page.query}}" class="px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">{{p}}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.my_contributions') }}?page={{page.page+1 if page.page < page.pages else page.pages}}&q={{page.query}}" class="block px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 rounded-r-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
|
||||
<!-- prettier-ignore -->
|
||||
<span class="sr-only">Next</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"> <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" /> </svg>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<!-- prettier-ignore -->
|
||||
<a href="{{ url_for('book.my_contributions') }}?page={{page.pages}}&q={{page.query}}" class="block px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 rounded-r-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
|
||||
<!-- prettier-ignore -->
|
||||
<span class="sr-only">Last</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5"> <path fill-rule="evenodd" d="M10.21 14.77a.75.75 0 01.02-1.06L14.168 10 10.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" /> <path fill-rule="evenodd" d="M4.21 14.77a.75.75 0 01.02-1.06L8.168 10 4.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" /> </svg>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<!-- prettier-ignore -->
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
</dd>
|
||||
</dl>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
{% if current_user.is_authenticated and page.pages > 1 %}
|
||||
<div class="container content-center mt-3 flex bg-white dark:bg-gray-800">
|
||||
|
@ -102,6 +102,7 @@
|
|||
</nav>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<!-- prettier-ignore -->
|
||||
{% endblock %}
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<dl class="w-md md:w-full text-gray-900 divide-y divide-gray-200 dark:text-white dark:divide-gray-700">
|
||||
<!-- prettier-ignore -->
|
||||
<div class="text-sm dark:text-white p-3">Comments:</div>
|
||||
{% for comment in interpretation.comments if not comment.is_deleted %}
|
||||
{% for comment in interpretation.comments if not comment.is_deleted and not comment.parent_id%}
|
||||
<!-- prettier-ignore -->
|
||||
<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">
|
||||
<div class="flex flex-row pb-3 p-3 w-2/3 md:w-full">
|
||||
|
|
|
@ -6,6 +6,7 @@ from flask import (
|
|||
request,
|
||||
)
|
||||
from flask_login import login_required, current_user
|
||||
from sqlalchemy import and_, or_
|
||||
|
||||
from app.controllers import (
|
||||
create_pagination,
|
||||
|
@ -40,19 +41,14 @@ def get_all():
|
|||
@bp.route("/my_library", methods=["GET"])
|
||||
def my_library():
|
||||
if current_user.is_authenticated:
|
||||
q = request.args.get("q", type=str, default=None)
|
||||
books: m.Book = m.Book.query.order_by(m.Book.id)
|
||||
books = books.filter_by(user_id=current_user.id, is_deleted=False)
|
||||
if q:
|
||||
books = books.filter(m.Book.label.like(f"{q}"))
|
||||
|
||||
pagination = create_pagination(total=books.count())
|
||||
|
||||
return render_template(
|
||||
"book/my_library.html",
|
||||
books=books.paginate(page=pagination.page, per_page=pagination.per_page),
|
||||
page=pagination,
|
||||
search_query=q,
|
||||
)
|
||||
return render_template(
|
||||
"book/my_library.html",
|
||||
|
@ -141,13 +137,62 @@ def statistic_view(book_id: int):
|
|||
|
||||
@bp.route("/favorite_books", methods=["GET"])
|
||||
def favorite_books():
|
||||
if current_user.is_authenticated:
|
||||
books = (
|
||||
db.session.query(
|
||||
m.Book,
|
||||
)
|
||||
.filter(
|
||||
and_(
|
||||
m.Book.id == m.BookStar.book_id,
|
||||
m.BookStar.user_id == current_user.id,
|
||||
m.Book.is_deleted.is_(False),
|
||||
)
|
||||
)
|
||||
.order_by(m.Book.created_at.desc())
|
||||
)
|
||||
|
||||
books = books.filter_by(is_deleted=False)
|
||||
pagination = create_pagination(total=books.count())
|
||||
|
||||
return render_template(
|
||||
"book/favorite_books.html",
|
||||
books=books.paginate(page=pagination.page, per_page=pagination.per_page),
|
||||
page=pagination,
|
||||
)
|
||||
return render_template("book/favorite_books.html", books=[])
|
||||
|
||||
|
||||
@bp.route("/my_contributions", methods=["GET"])
|
||||
def my_contributions():
|
||||
interpretations = (
|
||||
db.session.query(
|
||||
m.Interpretation,
|
||||
)
|
||||
.filter(
|
||||
or_(
|
||||
and_(
|
||||
m.Interpretation.id == m.Comment.interpretation_id,
|
||||
m.Comment.user_id == current_user.id,
|
||||
m.Comment.is_deleted.is_(False),
|
||||
m.Interpretation.is_deleted.is_(False),
|
||||
),
|
||||
and_(
|
||||
m.Interpretation.user_id == current_user.id,
|
||||
m.Interpretation.is_deleted.is_(False),
|
||||
),
|
||||
)
|
||||
)
|
||||
.group_by(m.Interpretation.id)
|
||||
.order_by(m.Interpretation.created_at.desc())
|
||||
)
|
||||
|
||||
pagination = create_pagination(total=interpretations.count())
|
||||
|
||||
return render_template(
|
||||
"book/my_contributions.html",
|
||||
interpretations=interpretations.paginate(
|
||||
page=pagination.page, per_page=pagination.per_page
|
||||
),
|
||||
page=pagination,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue