Merge branch 'develop' into kostia/fix/user_profile_ui

This commit is contained in:
Kostiantyn Stoliarskyi 2023-05-12 11:45:17 +03:00
commit 4faf54e652
28 changed files with 887 additions and 146527 deletions

View File

@ -1,3 +1,4 @@
# flake8: noqa F401
from .pagination import create_pagination
from .breadcrumbs import create_breadcrumbs
from .book_verify import register_book_verify_route, book_validator

View File

@ -0,0 +1,119 @@
from flask_login import current_user
from flask import Response, flash, redirect, url_for, request
from app import models as m, db
from app.logger import log
class BookRouteVerifier:
_routes = []
@classmethod
def add_route(cls, route_name: str):
cls._routes.append(route_name)
@classmethod
def remove_route(cls, route_name: str):
cls._routes.remove(route_name)
@classmethod
def is_present(cls, route_name: str) -> bool:
return route_name in cls._routes
def register_book_verify_route(blueprint_name: str):
def decorator(func: callable):
BookRouteVerifier.add_route(f"{blueprint_name}.{func.__name__}")
return func
return decorator
def book_validator() -> Response | None:
if not BookRouteVerifier.is_present(request.endpoint):
return None
request_args = (
{**request.view_args, **request.args} if request.view_args else {**request.args}
)
book_id = request_args.get("book_id")
if book_id:
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted or book.owner != current_user:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_library"))
collection_id = request_args.get("collection_id")
if collection_id:
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
sub_collection_id = request_args.get("sub_collection_id")
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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("Subcollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
section_id = request_args.get("section_id")
if section_id:
section: m.Section = db.session.get(m.Section, section_id)
if not section or collection.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section)
flash("Section not found", "danger")
return redirect(
url_for(
"book.section_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
)
)
interpretation_id = request_args.get("interpretation_id")
if interpretation_id:
interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id
)
if not interpretation or interpretation.is_deleted:
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
flash("Interpretation not found", "danger")
return redirect(
url_for(
"book.qa_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
section_id=section_id,
interpretation_id=interpretation_id,
)
)
comment_id = request_args.get("comment_id")
if comment_id:
comment: m.Comment = db.session.get(m.Comment, comment_id)
if not comment or comment.is_deleted:
log(log.WARNING, "Comment with id [%s] not found", comment_id)
flash("Comment not found", "danger")
return redirect(
url_for(
"book.qa_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
section_id=section_id,
interpretation_id=interpretation_id,
)
)

View File

@ -30,7 +30,7 @@ def create_breadcrumbs(
crumples += [
s.BreadCrumb(
type=s.BreadCrumbType.MyBookList,
url=url_for("book.my_books"),
url=url_for("book.my_library"),
label="My Books",
)
]

View File

@ -2,12 +2,13 @@ from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, ValidationError
from wtforms.validators import DataRequired, Length
from app import models as m, db
from app import models as m
from app.logger import log
class BaseBookForm(FlaskForm):
label = StringField("Label", [DataRequired(), Length(6, 256)])
about = StringField("About")
class CreateBookForm(BaseBookForm):
@ -18,21 +19,18 @@ class EditBookForm(BaseBookForm):
book_id = StringField("User ID", [DataRequired()])
submit = SubmitField("Edit book")
def validate_book_id(self, field):
book_id = field.data
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.WARNING, "Book with id [%s] not found", book_id)
raise ValidationError("Book not found")
def validate_label(self, field):
label = field.data
book_id = self.book_id.data
existing_book: m.Book = m.Book.query.filter_by(
is_deleted=False,
label=label,
).first()
existing_book: m.Book = (
m.Book.query.filter_by(
is_deleted=False,
label=label,
)
.filter(m.Book.id != book_id)
.first()
)
if existing_book:
log(
log.WARNING, "Book with label [%s] already exists: [%s]", label, book_id

View File

@ -1,5 +1,6 @@
from app import db
from app.models.utils import BaseModel
from app.controllers import create_breadcrumbs
class Section(BaseModel):
@ -32,6 +33,20 @@ class Section(BaseModel):
path += self.label
return path
@property
def breadcrumbs_path(self):
parent = self.collection
grand_parent = parent.parent
if grand_parent.is_root:
collection_path = (parent.id,)
else:
collection_path = (
grand_parent.id,
parent.id,
)
breadcrumbs_path = create_breadcrumbs(self.book_id, collection_path)
return breadcrumbs_path
@property
def book_id(self):
_book_id = self.version.book_id

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,11 +9,10 @@
<h1 class="text-2xl font-extrabold dark:text-white ml-4">Books</h1>
</div>
{% for book in books %}
{% for book in books if not book.is_deleted %}
<!-- prettier-ignore -->
<dl class="bg-white dark:bg-gray-900 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">
<a class="flex flex-col pb-2" href="{{url_for('book.collection_view',book_id=book.id)}}">
<dt class="mb-2"> {{book.owner.username}}/{{book.label}} </dt>
<dt class="mb-2"> <a class="flex flex-col pb-4" href="{{url_for('book.collection_view',book_id=book.id)}}">{{book.owner.username}}/{{book.label}}</a> </dt>
<dd class="flex flex-col md:flex-row text-lg font-semibold text-gray-500 md:text-lg dark:text-gray-400">
{% if book.versions %}
<p> Last updated on {{book.versions[-1].updated_at.strftime('%B %d, %Y')}}</p>
@ -34,7 +33,6 @@
</span>
</div>
</dd>
</a>
</dl>
{% endfor %}
<!-- prettier-ignore -->

View File

@ -1,13 +1,17 @@
<!-- prettier-ignore -->
<nav class="fixed flex top-32 p-4 pl-1 mt-1.5 z-40 w-full md:w-4/5 bg-white border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700" aria-label="Breadcrumb">
<nav class="fixed flex top-32 p-4 pl-1 mt-1.5 z-40 w-full bg-white border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700" aria-label="Breadcrumb">
<ol class="inline-flex items-center space-x-1 md:space-x-3 ml-5 overflow-x-scroll md:overflow-auto p-0">
{% for breadcrumb in breadcrumbs %}
<li class="inline-flex items-center">
{% if not loop.index==breadcrumbs|length %}
<a href="{{ breadcrumb.url }}" class="inline-flex items-center text-sm truncate w-30 font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white">
<a href="{{ breadcrumb.url }}" class="inline-flex items-center text-sm truncate w-24 font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white" data-tooltip-target="breadcrumb-{{loop.index}}-tooltip" data-tooltip-placement="bottom">
{% else %}
<span class="inline-flex items-center text-sm truncate w-40 font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white">
<span class="inline-flex items-center text-sm truncate w-40 font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white" data-tooltip-target="breadcrumb-{{loop.index}}-tooltip" data-tooltip-placement="bottom">
{% endif %}
<div id="breadcrumb-{{loop.index}}-tooltip" role="tooltip" class="delay-100 absolute z-[100] invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-700 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
{{ breadcrumb.label }}
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
<!-- prettier-ignore -->
<!--svg for all types of breadcrumb-->
{% if breadcrumb.type == "MyBookList" or breadcrumb.type == "AuthorBookList" %}

View File

@ -19,9 +19,9 @@
{% block content %}
<div class="overflow-x-auto shadow-md sm:rounded-lg md:mr-64">
<!-- prettier-ignore -->
<div class="fixed z-40 w-full md:w-4/5 bg-white border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700">
<div class="fixed z-40 w-full bg-white border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700">
<!-- prettier-ignore -->
<h1 class="font-extrabold text-lg dark:text-white ml-4 mt-5"> {{book.label}} </h1>
<h1 class="font-extrabold text-lg dark:text-white ml-4"> {{book.label}} </h1>
<!-- prettier-ignore -->
<div class="mb-1">
<ul class="flex flex-wrap -mb-px text-sm font-medium text-center" id="myTab" data-tabs-toggle="#myTabContent" role="tablist">

View File

@ -0,0 +1,20 @@
<!-- prettier-ignore-->
<div id="delete_book_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 action="{{ url_for('book.delete',book_id=book.id) }}" 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 book</h3>
<button id="modalAddCloseButton" data-modal-hide="delete_book_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>

View File

@ -1,23 +1,27 @@
<!-- prettier-ignore -->
{% extends 'base.html' %}
{% set selected_tab='my_library' %}
{% block content %}
<div class="md:mr-64 relative overflow-x-auto shadow-md sm:rounded-lg mt-1">
<div
class="md:mr-64 relative overflow-x-auto shadow-md sm:rounded-lg mt-1 h-box w-box flex">
{% if not current_user.is_authenticated %}
<!-- prettier-ignore -->
<div class="p-5 flex border-b-2 border-gray-200 border-solid dark:border-gray-700 text-gray-900 dark:text-white dark:divide-gray-700">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-8 h-8"> <path stroke-linecap="round" stroke-linejoin="round" d="M16.5 3.75V16.5L12 14.25 7.5 16.5V3.75m9 0H18A2.25 2.25 0 0120.25 6v12A2.25 2.25 0 0118 20.25H6A2.25 2.25 0 013.75 18V6A2.25 2.25 0 016 3.75h1.5m9 0h-9" /> </svg>
{% if all_books %}
<h1 class="text-2xl font-extrabold dark:text-white ml-4">Books</h1>
{% else %}
<h1 class="text-2xl font-extrabold dark:text-white ml-4">My books</h1>
{% endif %}
</div>
{% for book in books %}
<div class="mx-auto my-auto h-full w-full p-2">
<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 library! </div></button></div>
<!-- prettier-ignore -->
<dl class=" bg-white dark:bg-gray-900 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">
<a class="flex flex-col pb-2" href="{{url_for('book.collection_view',book_id=book.id)}}">
<dt class="mb-2">{{book.owner.username}}/{{book.label}}</dt>
{% endif %}
{% if current_user.is_authenticated and books.total<1 %}
<!-- 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> New book </div></button></div>
<!-- prettier-ignore -->
{% endif %}
<!-- prettier-ignore -->
{% for book in books if not book.is_deleted%}
<!-- 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.owner.username}}/{{book.label}}</a></dt>
<dd class="flex flex-col md:flex-row text-lg font-semibold text-gray-500 md:text-lg dark:text-gray-400">
{% if book.versions %}
<p>
@ -39,24 +43,23 @@
</span>
</div>
</dd>
</a>
</dl>
{% endfor %}
<!-- prettier-ignore -->
{% if page.pages > 1 %}
{% 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_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">
<a href="{{ url_for('book.my_library') }}?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_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">
<a href="{{ url_for('book.my_library') }}?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>
@ -68,17 +71,17 @@
<!-- prettier-ignore -->
{% if p == page.page %}
<!-- prettier-ignore -->
<a href="{{ url_for('book.my_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>
<a href="{{ url_for('book.my_library') }}?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_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>
<a href="{{ url_for('book.my_library') }}?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_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">
<a href="{{ url_for('book.my_library') }}?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>
@ -86,7 +89,7 @@
</li>
<li>
<!-- prettier-ignore -->
<a href="{{ url_for('book.my_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">
<a href="{{ url_for('book.my_library') }}?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>

View File

@ -16,7 +16,7 @@
{% include 'book/breadcrumbs_navigation.html'%}
<div class="overflow-x-auto shadow-md sm:rounded-lg md:mr-64">
<!-- prettier-ignore -->
<div class="fixed z-30 w-full md:w-4/5 top-44 pt-6 bg-white border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700">
<div class="fixed z-30 w-full top-44 pt-6 bg-white border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700">
<!-- prettier-ignore -->
<h1 class="text-l font-extrabold dark:text-white ml-4"> Interpretations page </h1>
<!-- prettier-ignore -->
@ -57,6 +57,17 @@
<!-- prettier-ignore -->
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="interpretation" role="tabpanel" aria-labelledby="interpretation-tab">
{% if not current_user.is_authenticated %}
<div class="bg-white dark:bg-gray-900 max-w-full p-6 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="grid gap-6">
<div class="col-span-6 sm:col-span-3 truncate">
<h3 class="text-xl font-semibold text-gray-900 dark:text-white ">Connect you wallet to start contributing!</h3>
</div>
</div>
</div>
<!-- prettier-ignore -->
{% endif %}
{% if current_user.is_authenticated %}
<!-- prettier-ignore -->
<form
{% if sub_collection %}
@ -90,6 +101,8 @@
<button name="submit" type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 ml-auto">Submit</button>
</div>
</form>
<!-- prettier-ignore -->
{% endif %}
<!-- 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 -->

View File

@ -0,0 +1,26 @@
<!-- prettier-ignore -->
<ol class="inline-flex items-center overflow-x-scroll md:overflow-auto p-0">
{% for breadcrumb in local_breadcrumbs if breadcrumb.type != "MyBookList" and breadcrumb.type != "AuthorBookList" %}
<li class="inline-flex items-center align-middle justify-center">
{% if not loop.index==local_breadcrumbs|length %}
<a href="{{ breadcrumb.url }}" class="inline-flex text-xs font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white" data-tooltip-target="breadcrumb-{{loop.index}}-tooltip" data-tooltip-placement="bottom">
{% else %}
<span class="inline-flex items-center text-sm font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white" data-tooltip-target="breadcrumb-{{loop.index}}-tooltip" data-tooltip-placement="bottom">
{% endif %}
<div id="breadcrumb-{{loop.index}}-tooltip" role="tooltip" class="delay-100 absolute z-[100] invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-700 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
{{ breadcrumb.label }}
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
<!-- prettier-ignore -->
<span class="select-none">{{ breadcrumb.label }}</span>
{% if not loop.index==local_breadcrumbs|length %}
</a>
{% else %}
</span>
{% endif %}
{% if not loop.index==local_breadcrumbs|length %}
<svg aria-hidden="true" class="w-4 h-4 text-gray-400" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd"></path> </svg>
{% endif %}
</li>
{% endfor %}
</ol>

View File

@ -1,5 +1,5 @@
<!-- prettier-ignore -->
<aside id="logo-right-sidebar" class="fixed top-0 right-0 left-auto z-50 w-64 h-screen pt-28 transition-transform translate-x-96 bg-white border-r border-gray-200 md:translate-x-0 dark:bg-gray-800 dark:border-gray-700" aria-label="Right-sidebar">
<aside id="logo-right-sidebar" class="fixed top-10 right-0 left-auto z-50 w-64 h-screen pt-28 transition-transform translate-x-96 bg-white border-r border-gray-200 md:translate-x-0 dark:bg-gray-800 dark:border-gray-700" aria-label="Right-sidebar">
<div class="h-full pb-4 overflow-y-auto bg-white dark:bg-gray-800">
<ul class="space-y-4 mt-1 font-medium">
{% if book.owner.id == current_user.id %}

View File

@ -1,91 +1,107 @@
<!-- prettier-ignore -->
{% extends 'base.html' %}
{% include 'book/add_contributor_modal.html' %}
{% include 'book/delete_book_modal.html' %}
{% block content %}
<!-- Hide right_sidebar -->
<!-- prettier-ignore -->
{% block right_sidebar %} {% endblock %}
<div class="p-5">
<div class="p-3 pl-4">
<div class="flex justify-between ml-4 mb-3">
<h1 class="text-2xl font-extrabold dark:text-white">Settings</h1>
<h1 class="text-2xl font-extrabold dark:text-white">{{book.label}}</h1>
</div>
<form action="{{ url_for('book.edit', book_id=book.id) }}" method="post" class="mb-0 flex flex-col space-y-2 w-1/2">
{{ form_hidden_tag() }}
<input value="{{book.id}}" type="text" name="book_id" id="book_id" class="hidden" placeholder="Book id" required>
<div>
<label for="label" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Label</label>
<input value="{{book.label}}" type="text" name="label" id="label" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="My Book" required>
</div>
<div>
<button type="submit" class="text-center text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Save</button>
</div>
</form>
</div>
<div class="p-5">
<div class="flex justify-between ml-4 mb-2">
<h1 class="text-2xl font-extrabold dark:text-white">Contributors</h1>
<div class="mb-1">
<!-- prettier-ignore -->
<button
type="button" data-modal-target="add-contributor-modal" data-modal-toggle="add-contributor-modal"
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-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 mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v6m3-3H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z" /> </svg>
Add
</button>
<ul class="flex flex-wrap -mb-px text-sm font-medium text-center" id="myTab" data-tabs-toggle="#myTabContent" role="tablist">
<li class="mr-2" role="presentation">
<!-- prettier-ignore -->
<button class="flex items-center space-x-2 p-4 border-b-2 rounded-t-lg" id="settings-tab" data-tabs-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">
<!-- prettier-ignore -->
<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="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /> </svg>
<span>Book settings</span>
</button>
</li>
<li class="mr-2" role="presentation">
<!-- prettier-ignore -->
<button class="flex items-center space-x-2 p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300" id="permissions-tab" data-tabs-target="#permissions" type="button" role="tab" aria-controls="permissions" aria-selected="false">
<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="M6 13.5V3.75m0 9.75a1.5 1.5 0 010 3m0-3a1.5 1.5 0 000 3m0 3.75V16.5m12-3V3.75m0 9.75a1.5 1.5 0 010 3m0-3a1.5 1.5 0 000 3m0 3.75V16.5m-6-9V3.75m0 3.75a1.5 1.5 0 010 3m0-3a1.5 1.5 0 000 3m0 9.75V10.5" /> </svg>
<span>User permissions</span>
</button>
</li>
</ul>
</div>
</div>
<div id="myTabContent">
<!-- prettier-ignore -->
<div class="hidden pl-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="settings" role="tabpanel" aria-labelledby="settings-tab">
<form action="{{ url_for('book.edit', book_id=book.id) }}" method="post" class="mb-0 flex flex-col space-y-2 w-1/2">
{{ form_hidden_tag() }}
<input value="{{book.id}}" type="text" name="book_id" id="book_id" class="hidden" placeholder="Book id" required>
<div>
<label for="label" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Label</label>
<input value="{{book.label}}" type="text" name="label" id="label" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="My Book" required>
</div>
<div>
<label for="about" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Book about</label>
<textarea type="text" name="about" id="about" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="About my Book">{{book.about if not book.about==None}}</textarea>
</div>
<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
<thead
class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-3">Username</th>
<th scope="col" class="px-6 py-3">Role</th>
<th scope="col" class="px-6 py-3">Action</th>
</tr>
</thead>
<tbody>
{% for contributor in book.contributors %}
<tr class="bg-white border-b dark:bg-gray-900 dark:border-gray-700">
<td class="px-6 py-4">{{ contributor.user.username }}</td>
<td class="px-6 py-4">
<form action="{{ url_for('book.edit_contributor_role', book_id=book.id) }}" method="post" class="mb-0 flex space-x-2">
{{ form_hidden_tag() }}
<input type="hidden" name="user_id" id="user_id" value="{{ contributor.user_id }}" />
<select
id="role"
name="role"
data-user-id="{{ contributor.user.id }}"
class="contributor-role-select block w-1/2 py-1.5 px-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
>
{% for role in roles if role.value %}
<option
{% if contributor.role == role %} selected {% endif %}
value="{{ role.value }}">
{{ role.name.title() }}
</option>
{% endfor %}
</select>
<button type="submit" class="text-gray-900 bg-white border border-gray-300 focus:outline-none hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 font-medium rounded-lg text-sm px-5 py-1 dark:bg-gray-800 dark:text-white dark:border-gray-600 dark:hover:bg-gray-700 dark:hover:border-gray-600 dark:focus:ring-gray-700">Save</button>
</form>
</td>
<td class="px-6 py-4">
<!-- prettier-ignore -->
<form action="{{ url_for('book.delete_contributor', book_id=book.id) }}" method="post" class="mb-0">
{{ form_hidden_tag() }}
<input type="hidden" name="user_id" id="user_id" value="{{ contributor.user_id }}" />
<button type="submit" class="text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-sm rounded-lg text-sm px-5 py-1.5 dark:bg-red-600 dark:hover:bg-red-700 focus:outline-none dark:focus:ring-red-800">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div>
<button type="submit" class="text-center text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Submit</button>
</div>
</form>
<button type="button" data-modal-target="delete_book_modal" data-modal-toggle="delete_book_modal" class="mt-3 text-red-700 hover:text-white border border-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 mr-2 mb-2 dark:border-red-500 dark:text-red-500 dark:hover:text-white dark:hover:bg-red-600 dark:focus:ring-red-900">Delete Book</button>
</div>
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="permissions" role="tabpanel" aria-labelledby="permissions-tab">
<div class="p-5">
<div class="flex justify-between ml-4 mb-2">
<h1 class="text-2xl font-extrabold dark:text-white">Contributors</h1>
<!-- prettier-ignore -->
<button type="button" data-modal-target="add-contributor-modal" data-modal-toggle="add-contributor-modal" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-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 mr-1"> <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v6m3-3H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z" /> </svg>
Add
</button>
</div>
<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr> <th scope="col" class="px-6 py-3">Username</th> <th scope="col" class="px-6 py-3">Role</th> <th scope="col" class="px-6 py-3">Action</th> </tr>
</thead>
<tbody>
{% for contributor in book.contributors %}
<tr class="bg-white border-b dark:bg-gray-900 dark:border-gray-700">
<td class="px-6 py-4">{{ contributor.user.username }}</td>
<td class="px-6 py-4">
<form action="{{ url_for('book.edit_contributor_role', book_id=book.id) }}" method="post" class="mb-0 flex space-x-2">
{{ form_hidden_tag() }}
<input type="hidden" name="user_id" id="user_id" value="{{ contributor.user_id }}" />
<select id="role" name="role" data-user-id="{{ contributor.user.id }}" class="contributor-role-select block w-1/2 py-1.5 px-2 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" >
{% for role in roles if role.value %}
<option
{% if contributor.role == role %} selected {% endif %}
value="{{ role.value }}">
{{ role.name.title() }}
</option>
{% endfor %}
</select>
<button type="submit" class="text-gray-900 bg-white border border-gray-300 focus:outline-none hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 font-medium rounded-lg text-sm px-5 py-1 dark:bg-gray-800 dark:text-white dark:border-gray-600 dark:hover:bg-gray-700 dark:hover:border-gray-600 dark:focus:ring-gray-700">Save</button>
</form>
</td>
<td class="px-6 py-4">
<!-- prettier-ignore -->
<form action="{{ url_for('book.delete_contributor', book_id=book.id) }}" method="post" class="mb-0">
{{ form_hidden_tag() }}
<input type="hidden" name="user_id" id="user_id" value="{{ contributor.user_id }}" />
<button type="submit" class="text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-sm rounded-lg text-sm px-5 py-1.5 dark:bg-red-600 dark:hover:bg-red-700 focus:outline-none dark:focus:ring-red-800">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,66 @@
<!-- prettier-ignore -->
{% extends 'base.html' %}
{% block content %}
<div class="border-b border-gray-200 dark:border-gray-700 md:mr-64">
<!-- prettier-ignore -->
<h1 class="hidden md:inline font-extrabold text-lg dark:text-white ml-4 mt-5">{{book.label}}</h1>
<!-- prettier-ignore -->
<p class="hidden md:block text-sm ml-4 w-1/2 text-gray-500 text-center md:text-left dark:text-gray-400">
An open-source law hosting platform that allows online communities to easily
create, collaborate, and publish their own body of law.
</p>
<!-- prettier-ignore -->
<ul class="flex md:flex-wrap -mb-px text-xs md:text-sm font-medium text-center" id="myTab" data-tabs-toggle="#myTabContent" role="tablist">
<li class="mr-2 w-full md:w-auto" role="presentation">
<!-- prettier-ignore -->
<button class="inline-flex p-4 border-b-2 rounded-t-lg" id="favorited-tab" data-tabs-target="#favorited" type="button" role="tab" aria-controls="favorited" aria-selected="false"><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 mr-3"> <path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 011.04 0l2.125 5.111a.563.563 0 00.475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 00-.182.557l1.285 5.385a.562.562 0 01-.84.61l-4.725-2.885a.563.563 0 00-.586 0L6.982 20.54a.562.562 0 01-.84-.61l1.285-5.386a.562.562 0 00-.182-.557l-4.204-3.602a.563.563 0 01.321-.988l5.518-.442a.563.563 0 00.475-.345L11.48 3.5z" /> </svg>
Favorited by
</button>
</li>
<li class="mr-2 w-full md:w-auto" role="presentation">
<!-- prettier-ignore -->
<button class="inline-flex p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300" id="contributors-tab" data-tabs-target="#contributors" type="button" role="tab" aria-controls="contributors" aria-selected="false"><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 mr-3"> <path stroke-linecap="round" stroke-linejoin="round" d="M15 19.128a9.38 9.38 0 002.625.372 9.337 9.337 0 004.121-.952 4.125 4.125 0 00-7.533-2.493M15 19.128v-.003c0-1.113-.285-2.16-.786-3.07M15 19.128v.106A12.318 12.318 0 018.624 21c-2.331 0-4.512-.645-6.374-1.766l-.001-.109a6.375 6.375 0 0111.964-3.07M12 6.375a3.375 3.375 0 11-6.75 0 3.375 3.375 0 016.75 0zm8.25 2.25a2.625 2.625 0 11-5.25 0 2.625 2.625 0 015.25 0z" /> </svg>
Contributors
</button>
</li>
<li class="mr-2 w-full md:w-auto" role="presentation">
<!-- prettier-ignore -->
<button class="inline-flex p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300" id="fork-tab" data-tabs-target="#fork" type="button" role="tab" aria-controls="fork" aria-selected="false"><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 mr-3"> <path stroke-linecap="round" stroke-linejoin="round" d="M7.217 10.907a2.25 2.25 0 100 2.186m0-2.186c.18.324.283.696.283 1.093s-.103.77-.283 1.093m0-2.186l9.566-5.314m-9.566 7.5l9.566 5.314m0 0a2.25 2.25 0 103.935 2.186 2.25 2.25 0 00-3.935-2.186zm0-12.814a2.25 2.25 0 103.933-2.185 2.25 2.25 0 00-3.933 2.185z" /> </svg>
Forks
</button>
</li>
</ul>
</div>
<div id="myTabContent" class="md:mr-64">
<!-- prettier-ignore -->
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="favorited" role="tabpanel" aria-labelledby="favorited-tab">
<div class="relative w-full overflow-x-auto border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400"> <tr> <th scope="col" class="px-6 py-3"> Username </th> <th scope="col" class="px-6 py-3"> Address </th> </tr> </thead>
<tbody>
{% for star in book.stars %}
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700"> <th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"> {{star.user.username}} </th> <td class="px-6 py-4"> {{star.user.wallet_id}} </td> </tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!-- prettier-ignore -->
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="contributors" role="tabpanel" aria-labelledby="contributors-tab">
<div class="relative w-full overflow-x-auto border-2 border-gray-200 border-solid rounded-lg dark:border-gray-700">
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400"> <tr> <th scope="col" class="px-6 py-3"> Username </th> <th scope="col" class="px-6 py-3"> Address </th> <th scope="col" class="px-6 py-3"> Role </th></tr> </thead>
<tbody>
{% for contributor in book.contributors %}
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700"> <th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"> {{contributor.user.username}} </th> <td class="px-6 py-4"> {{contributor.user.wallet_id}} </td> <td class="px-6 py-4"> {{contributor.role}} </td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!-- prettier-ignore -->
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="fork" role="tabpanel" aria-labelledby="fork-tab">
<p class="text-sm text-gray-500 dark:text-gray-400">Fork sections</p>
</div>
</div>
{% endblock %}

View File

@ -120,25 +120,25 @@
<div class="flex items-center justify-between">
<div class="flex w-full items-center justify-between">
<ul class="flex font-medium items-center">
<li class="mx-2">
<li class="mx-2 {% if selected_tab == 'my_library' %} bg-slate-300 dark:bg-slate-700 rounded-lg {% endif %}">
<a
href="#"
href="{{ url_for('book.my_library') }}"
class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700">
<span>My Library</span>
<span class="text-center md:text-left">My Library</span>
</a>
</li>
<li class="my-auto">
<a
href="#"
class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700">
<span>My Contributions</span>
<span class="text-center md:text-left">My Contributions</span>
</a>
</li>
<li>
<a
href="#"
class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700">
<span>Favorite Books</span>
<span class="text-center md:text-left">Favorite Books</span>
</a>
</li>
</ul>

View File

@ -2,12 +2,19 @@
{% extends 'base.html' %}
{% block content %}
<div class="border-b border-gray-200 dark:border-gray-700 md:mr-64">
<!-- prettier-ignore -->
<h1 class="hidden md:inline font-extrabold text-lg dark:text-white ml-4 mt-5">Open Common Law</h1>
<p
class="hidden md:block text-sm ml-4 w-1/2 text-gray-500 text-center md:text-left dark:text-gray-400">
An open-source law hosting platform that allows online communities to easily
create, collaborate, and publish their own body of law.
</p>
<!-- prettier-ignore -->
<ul class="flex md:flex-wrap -mb-px text-xs md:text-sm font-medium text-center" id="myTab" data-tabs-toggle="#myTabContent" role="tablist">
<li class="mr-2 w-full md:w-auto" role="presentation">
<!-- prettier-ignore -->
<button class="inline-flex p-4 border-b-2 rounded-t-lg" id="last-sections-tab" data-tabs-target="#last-sections" type="button" role="tab" aria-controls="last-sections" aria-selected="false"> <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 mr-3"> <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z" /> </svg>
Last Sections
LAtest Interpretations
</button>
</li>
<li class="mr-2 w-full md:w-auto" role="presentation">
@ -16,28 +23,86 @@
Explore Books
</button>
</li>
<li class="mr-2 w-full md:w-auto" role="presentation">
<!-- prettier-ignore -->
<button class="inline-flex p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300" id="all-sections-tab" data-tabs-target="#all-sections" type="button" role="tab" aria-controls="all-sections" aria-selected="false"> <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 mr-3"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m5.231 13.481L15 17.25m-4.5-15H5.625c-.621 0-1.125.504-1.125 1.125v16.5c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9zm3.75 11.625a2.625 2.625 0 11-5.25 0 2.625 2.625 0 015.25 0z" /> </svg>
All Sections
</button>
</li>
</ul>
</div>
<div id="myTabContent" class="md:mr-64">
<!-- prettier-ignore -->
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="last-sections" role="tabpanel" aria-labelledby="last-sections-tab">
<p class="text-sm text-gray-500 dark:text-gray-400">Last sections</p>
{% 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">
<div class="vote-block flex flex-col m-5 justify-center items-center">
{% if interpretation.user_id != current_user.id %}
<div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="true">
<svg class="w-6 h-6 select-none
{% if interpretation.current_user_vote %}
stroke-green-500
{% endif %}
" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" > <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 10.5L12 3m0 0l7.5 7.5M12 3v18" /> </svg>
</div>
{% endif %}
<span
class="vote-count text-3xl select-none
{% if interpretation.vote_count < 0 %}
text-red-500
{% elif interpretation.vote_count > 0 %}
text-green-500
{% endif %}
"
>
{{ interpretation.vote_count }}
</span>
{% if interpretation.user_id != current_user.id %}
<div class="vote-button cursor-pointer" data-vote-for="interpretation" data-entity-id="{{ interpretation.id }}" data-positive="false">
<svg class="w-6 h-6 select-none
{% if interpretation.current_user_vote == False %}
stroke-red-500
{% endif %}
" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5L12 21m0 0l-7.5-7.5M12 21V3" /> </svg>
</div>
{% endif %}
</div>
<!-- prettier-ignore -->
<dt class="flex w-full mb-1 text-gray-500 md:text-lg dark:text-gray-400 flex-col">
<div class="ql-snow truncate md:max-w-xl">
{% set local_breadcrumbs = interpretation.section.breadcrumbs_path %}
{% include 'book/local_breadcrumbs_navigation.html'%}
<p>{{ interpretation.section.label }}</p>
</a>
<div class="dark:text-white h-30 ql-editor">
<p>{{ interpretation.text|safe }}</p>
</div>
</div>
<div class="flex mt-auto align-center justify-between md:w-full">
<div>
<span class="hidden md:inline-block">Interpretation by</span>
{{interpretation.user.username}} on {{interpretation.created_at.strftime('%B %d, %Y')}}
</div>
<div class="flex ml-auto justify-between w-24">
<span class="space-x-0.5 flex items-center">
<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="M9 8.25H7.5a2.25 2.25 0 00-2.25 2.25v9a2.25 2.25 0 002.25 2.25h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25H15m0-3l-3-3m0 0l-3 3m3-3V15" /> </svg>
</span>
<div class="space-x-0.5 flex items-center">
<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="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 01-.825-.242m9.345-8.334a2.126 2.126 0 00-.476-.095 48.64 48.64 0 00-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0011.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" /> </svg>
<p>{{interpretation.active_comments | length}}</p>
</div>
</div>
</div>
</dt>
</div>
</dl>
{% endfor %}
</div>
<!-- prettier-ignore -->
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="explore-books" role="tabpanel" aria-labelledby="explore-books-tab">
{% for book in books %}
{% for book in books if not book.is_deleted %}
<!-- prettier-ignore -->
<dl class=" bg-white dark:bg-gray-900 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">
<a
class="flex flex-col pb-2"
href="{{url_for('book.collection_view',book_id=book.id)}}">
<dt class="mb-2">{{book.owner.username}}/{{book.label}}</dt>
<dt class="mb-2"><a class="flex flex-col pb-4" href="{{url_for('book.collection_view',book_id=book.id)}}">{{book.owner.username}}/{{book.label}}</a></dt>
<dd class="flex flex-col md:flex-row text-lg font-semibold text-gray-500 md:text-lg dark:text-gray-400">
{% if book.versions %}
<p> Last updated on {{book.versions[-1].updated_at.strftime('%B %d, %Y')}} </p>
@ -57,18 +122,9 @@
</span>
</div>
</dd>
</a>
</dl>
{% endfor %}
<a type="button" href="{{ url_for('book.get_all') }}" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"> Explore all books... <svg aria-hidden="true" class="w-5 h-5 ml-2 -mr-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg> </a>
</div>
<!-- prettier-ignore -->
<div class="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800" id="all-sections" role="tabpanel" aria-labelledby="all-sections-tab">
{% for section in sections %}
<!-- prettier-ignore -->
<h1 class="text-l font-extrabold dark:text-white my-2">{{section.path}}</h1>
{% endfor %}
<a type="button" href="{{ url_for('section.get_all') }}" class="mt-4 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"> Explore all sections... <svg aria-hidden="true" class="w-5 h-5 ml-2 -mr-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg> </a>
</div>
</div>
{% endblock %}

View File

@ -1,6 +1,6 @@
<aside
id="logo-right-sidebar"
class="fixed top-0 right-0 left-auto z-40 w-64 h-screen pt-28 transition-transform translate-x-96 bg-white border-r border-gray-200 md:translate-x-0 dark:bg-gray-800 dark:border-gray-700"
class="fixed top-10 right-0 left-auto z-40 w-64 h-screen pt-28 transition-transform translate-x-96 bg-white border-r border-gray-200 md:translate-x-0 dark:bg-gray-800 dark:border-gray-700"
aria-label="Right-sidebar">
<div class="h-full pb-4 overflow-y-auto bg-white dark:bg-gray-800">
<ul class="space-y-4 font-medium">

View File

@ -45,7 +45,7 @@
</li>
{% if current_user.is_authenticated %}
<li>
<a href="{{ url_for('book.my_books') }}" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700">
<a href="{{ url_for('book.my_library') }}" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700">
<!-- prettier-ignore -->
<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="M16.5 3.75V16.5L12 14.25 7.5 16.5V3.75m9 0H18A2.25 2.25 0 0120.25 6v12A2.25 2.25 0 0118 20.25H6A2.25 2.25 0 013.75 18V6A2.25 2.25 0 016 3.75h1.5m9 0h-9" /> </svg>
<span class="ml-3">My Books</span>

View File

@ -8,13 +8,24 @@ from flask import (
)
from flask_login import login_required, current_user
from app.controllers import create_pagination, create_breadcrumbs
from app.controllers import (
create_pagination,
create_breadcrumbs,
register_book_verify_route,
book_validator,
)
from app import models as m, db, forms as f
from app.logger import log
bp = Blueprint("book", __name__, url_prefix="/book")
@bp.before_request
def before_request():
if response := book_validator():
return response
@bp.route("/all", methods=["GET"])
def get_all():
q = request.args.get("q", type=str, default=None)
@ -34,21 +45,25 @@ def get_all():
@bp.route("/", methods=["GET"])
@login_required
def my_books():
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)
if q:
books = books.filter(m.Book.label.like(f"{q}"))
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())
pagination = create_pagination(total=books.count())
return render_template(
"book/index.html",
books=books.paginate(page=pagination.page, per_page=pagination.per_page),
page=pagination,
search_query=q,
)
return render_template(
"book/index.html",
books=books.paginate(page=pagination.page, per_page=pagination.per_page),
page=pagination,
search_query=q,
books=[],
)
@ -66,25 +81,28 @@ def create():
).save()
flash("Book added!", "success")
return redirect(url_for("book.my_books"))
return redirect(url_for("book.my_library"))
else:
log(log.ERROR, "Book create errors: [%s]", form.errors)
for field, errors in form.errors.items():
field_label = form._fields[field].label.text
for error in errors:
flash(error.replace("Field", field_label), "danger")
return redirect(url_for("book.my_books"))
return redirect(url_for("book.my_library"))
@bp.route("/<int:book_id>/edit", methods=["POST"])
@register_book_verify_route(bp.name)
@login_required
def edit(book_id: int):
form = f.EditBookForm()
if form.validate_on_submit():
book: m.Book = db.session.get(m.Book, book_id)
label = form.label.data
about = form.about.data
book.label = label
book.about = about
log(log.INFO, "Update Book: [%s]", book)
book.save()
flash("Success!", "success")
@ -98,6 +116,23 @@ def edit(book_id: int):
return redirect(url_for("book.settings", book_id=book_id))
@bp.route("/<int:book_id>/delete", methods=["POST"])
@login_required
def delete(book_id: int):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_library"))
book.is_deleted = True
log(log.INFO, "Book deleted: [%s]", book)
book.save()
flash("Success!", "success")
return redirect(url_for("book.my_library"))
@bp.route("/<int:book_id>/collections", methods=["GET"])
def collection_view(book_id: int):
book = db.session.get(m.Book, book_id)
@ -105,20 +140,31 @@ def collection_view(book_id: int):
if not book or book.is_deleted:
log(log.WARNING, "Book with id [%s] not found", book_id)
flash("Book not found", "danger")
return redirect(url_for("book.my_books"))
return redirect(url_for("book.my_library"))
else:
return render_template(
"book/collection_view.html", book=book, breadcrumbs=breadcrumbs
)
@bp.route("/<int:book_id>/statistics", methods=["GET"])
def statistic_view(book_id: int):
book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.WARNING, "Book with id [%s] not found", book_id)
flash("Book not found", "danger")
return redirect(url_for("book.my_library"))
else:
return render_template("book/stat.html", book=book)
@bp.route("/<int:book_id>/<int:collection_id>/subcollections", methods=["GET"])
def sub_collection_view(book_id: int, collection_id: int):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.WARNING, "Book with id [%s] not found", book_id)
flash("Book not found", "danger")
return redirect(url_for("book.my_books"))
return redirect(url_for("book.my_library"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
log(log.WARNING, "Collection with id [%s] not found", collection_id)
@ -150,7 +196,7 @@ def section_view(
if not book or book.is_deleted:
log(log.WARNING, "Book with id [%s] not found", book_id)
flash("Book not found", "danger")
return redirect(url_for("book.my_books"))
return redirect(url_for("book.my_library"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
@ -213,7 +259,7 @@ def interpretation_view(
if not book or book.is_deleted:
log(log.WARNING, "Book with id [%s] not found", book_id)
flash("Book not found", "danger")
return redirect(url_for("book.my_books"))
return redirect(url_for("book.my_library"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
@ -266,13 +312,10 @@ def interpretation_view(
@bp.route("/<int:book_id>/settings", methods=["GET"])
@register_book_verify_route(bp.name)
@login_required
def settings(book_id: int):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted or book.owner != current_user:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
return render_template(
"book/settings.html", book=book, roles=m.BookContributor.Roles
@ -280,14 +323,9 @@ def settings(book_id: int):
@bp.route("/<int:book_id>/add_contributor", methods=["POST"])
@register_book_verify_route(bp.name)
@login_required
def add_contributor(book_id: int):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted or book.owner != current_user:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
form = f.AddContributorForm()
if form.validate_on_submit():
@ -318,26 +356,21 @@ def add_contributor(book_id: int):
@bp.route("/<int:book_id>/delete_contributor", methods=["POST"])
@register_book_verify_route(bp.name)
@login_required
def delete_contributor(book_id: int):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted or book.owner != current_user:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
form = f.DeleteContributorForm()
if form.validate_on_submit():
book_contributor = m.BookContributor.query.filter_by(
user_id=int(form.user_id.data), book_id=book.id
user_id=int(form.user_id.data), book_id=book_id
).first()
if not book_contributor:
log(
log.INFO,
"BookContributor does not exists user: [%s], book: [%s]",
form.user_id.data,
book.id,
book_id,
)
flash("Does not exists!", "success")
return redirect(url_for("book.settings", book_id=book_id))
@ -358,26 +391,21 @@ def delete_contributor(book_id: int):
@bp.route("/<int:book_id>/edit_contributor_role", methods=["POST"])
@register_book_verify_route(bp.name)
@login_required
def edit_contributor_role(book_id: int):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted or book.owner != current_user:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
form = f.EditContributorRoleForm()
if form.validate_on_submit():
book_contributor = m.BookContributor.query.filter_by(
user_id=int(form.user_id.data), book_id=book.id
user_id=int(form.user_id.data), book_id=book_id
).first()
if not book_contributor:
log(
log.INFO,
"BookContributor does not exists user: [%s], book: [%s]",
form.user_id.data,
book.id,
book_id,
)
flash("Does not exists!", "success")
return redirect(url_for("book.settings", book_id=book_id))
@ -411,20 +439,15 @@ def edit_contributor_role(book_id: int):
@bp.route("/<int:book_id>/create_collection", methods=["POST"])
@bp.route("/<int:book_id>/<int:collection_id>/create_sub_collection", methods=["POST"])
@register_book_verify_route(bp.name)
@login_required
def collection_create(book_id: int, collection_id: int | None = None):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.owner != current_user or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
redirect_url = url_for("book.collection_view", book_id=book_id)
if collection_id:
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
elif collection.is_leaf:
if collection.is_leaf:
log(log.WARNING, "Collection with id [%s] is leaf", collection_id)
flash("You can't create subcollection for this collection", "danger")
return redirect(
@ -435,8 +458,6 @@ def collection_create(book_id: int, collection_id: int | None = None):
)
)
redirect_url = url_for("book.collection_view", book_id=book_id)
if collection_id:
redirect_url = url_for(
"book.sub_collection_view", book_id=book_id, collection_id=collection_id
)
@ -499,35 +520,15 @@ def collection_create(book_id: int, collection_id: int | None = None):
@bp.route(
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/edit", methods=["POST"]
)
@register_book_verify_route(bp.name)
@login_required
def collection_edit(
book_id: int, collection_id: int, sub_collection_id: int | None = None
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.owner != current_user or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
collection_to_edit = sub_collection
collection = db.session.get(m.Collection, sub_collection_id)
form = f.EditCollectionForm()
redirect_url = url_for(
@ -541,13 +542,13 @@ def collection_edit(
collection_query: m.Collection = m.Collection.query.filter_by(
is_deleted=False,
label=label,
).filter(m.Collection.id != collection_to_edit.id)
).filter(m.Collection.id != collection.id)
if sub_collection_id:
collection_query = collection_query.filter_by(parent_id=collection_id)
else:
collection_query = collection_query.filter_by(
parent_id=collection_to_edit.parent.id
parent_id=collection.parent.id
)
if collection_query.first():
@ -555,21 +556,21 @@ def collection_edit(
log.INFO,
"Collection with similar label already exists. Book: [%s], Collection: [%s], Label: [%s]",
book.id,
collection.id,
collection_id,
label,
)
flash("Collection label must be unique!", "danger")
return redirect(redirect_url)
if label:
collection_to_edit.label = label
collection.label = label
about = form.about.data
if about:
collection_to_edit.about = about
collection.about = about
log(log.INFO, "Edit collection [%s]", collection_to_edit.id)
collection_to_edit.save()
log(log.INFO, "Edit collection [%s]", collection.id)
collection.save()
flash("Success!", "success")
if sub_collection_id:
@ -594,40 +595,19 @@ def collection_edit(
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/delete",
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def collection_delete(
book_id: int, collection_id: int, sub_collection_id: int | None = None
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.owner != current_user:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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_delete = 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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
collection_to_delete = sub_collection
collection: m.Collection = db.session.get(m.Collection, sub_collection_id)
collection_to_delete.is_deleted = True
collection.is_deleted = True
log(log.INFO, "Delete collection [%s]", collection_to_delete.id)
collection_to_delete.save()
log(log.INFO, "Delete collection [%s]", collection.id)
collection.save()
flash("Success!", "success")
return redirect(
@ -648,35 +628,16 @@ def collection_delete(
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/create_section",
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def section_create(
book_id: int, collection_id: int, sub_collection_id: int | None = None
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.WARNING, "Book with id [%s] not found", book_id)
flash("Book not found", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
sub_collection = None
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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("Subcollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
redirect_url = url_for("book.collection_view", book_id=book_id)
if collection_id:
@ -721,6 +682,7 @@ def section_create(
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/<int:section_id>/edit_section",
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def section_edit(
book_id: int,
@ -728,31 +690,6 @@ def section_edit(
section_id: int,
sub_collection_id: int | None = None,
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.owner != current_user or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
redirect_url = url_for(
"book.interpretation_view",
book_id=book_id,
@ -761,10 +698,6 @@ def section_edit(
section_id=section_id,
)
section: m.Section = db.session.get(m.Section, section_id)
if not section or section.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section_id)
flash("Section not found", "danger")
return redirect(redirect_url)
form = f.EditSectionForm()
@ -799,6 +732,7 @@ def section_edit(
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/<int:section_id>/delete_section",
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def section_delete(
book_id: int,
@ -806,53 +740,19 @@ def section_delete(
section_id: int,
sub_collection_id: int | None = None,
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.owner != current_user:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
collection_to_edit = sub_collection
redirect_url = url_for(
"book.section_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
collection: m.Collection = db.session.get(
m.Collection, sub_collection_id or collection_id
)
section: m.Section = db.session.get(m.Section, section_id)
if not section or section.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section_id)
flash("Section not found", "danger")
return redirect(redirect_url)
section.is_deleted = True
if not collection_to_edit.active_sections:
if not collection.active_sections:
log(
log.INFO,
"Section [%s] has no active section. Set is_leaf = False",
section.id,
)
collection_to_edit.is_leaf = False
collection.is_leaf = False
log(log.INFO, "Delete section [%s]", section.id)
section.save()
@ -879,6 +779,7 @@ def section_delete(
"/<int:book_id>/<int:collection_id>/<int:sub_collection_id>/<int:section_id>/create_interpretation",
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def interpretation_create(
book_id: int,
@ -886,44 +787,8 @@ def interpretation_create(
section_id: int,
sub_collection_id: int | None = None,
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.WARNING, "Book with id [%s] not found", book_id)
flash("Book not found", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
sub_collection = None
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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
section: m.Section = db.session.get(m.Section, section_id)
if not section or collection.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section)
flash("Section not found", "danger")
return redirect(
url_for(
"book.section_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
)
)
form = f.CreateInterpretationForm()
redirect_url = url_for(
"book.interpretation_view",
book_id=book_id,
@ -932,8 +797,6 @@ def interpretation_create(
section_id=section.id,
)
form = f.CreateInterpretationForm()
if form.validate_on_submit():
interpretation: m.Interpretation = m.Interpretation(
label=form.label.data,
@ -971,6 +834,7 @@ def interpretation_create(
),
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def interpretation_edit(
book_id: int,
@ -979,31 +843,10 @@ def interpretation_edit(
interpretation_id: int,
sub_collection_id: int | None = None,
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.owner != current_user or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id
)
form = f.EditInterpretationForm()
redirect_url = url_for(
"book.qa_view",
book_id=book_id,
@ -1012,21 +855,6 @@ def interpretation_edit(
section_id=section_id,
interpretation_id=interpretation_id,
)
section: m.Section = db.session.get(m.Section, section_id)
if not section or section.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section_id)
flash("Section not found", "danger")
return redirect(redirect_url)
interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id
)
if not interpretation or interpretation.is_deleted:
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
flash("Interpretation not found", "danger")
return redirect(redirect_url)
form = f.EditInterpretationForm()
if form.validate_on_submit():
label = form.label.data
@ -1060,6 +888,7 @@ def interpretation_edit(
),
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def interpretation_delete(
book_id: int,
@ -1068,51 +897,9 @@ def interpretation_delete(
interpretation_id: int,
sub_collection_id: int | None = None,
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.owner != current_user or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
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:
log(log.WARNING, "Sub_collection with id [%s] not found", sub_collection_id)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
redirect_url = url_for(
"book.interpretation_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
section_id=section_id,
)
section: m.Section = db.session.get(m.Section, section_id)
if not section or section.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section_id)
flash("Section not found", "danger")
return redirect(redirect_url)
interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id
)
if not interpretation or interpretation.is_deleted:
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
flash("Interpretation not found", "danger")
return redirect(redirect_url)
interpretation.is_deleted = True
log(log.INFO, "Delete interpretation [%s]", interpretation)
@ -1150,7 +937,7 @@ def qa_view(
if not book or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
return redirect(url_for("book.my_library"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
@ -1235,7 +1022,7 @@ def create_comment(
if not book or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
return redirect(url_for("book.my_library"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
@ -1333,6 +1120,7 @@ def create_comment(
),
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def comment_delete(
book_id: int,
@ -1341,65 +1129,9 @@ def comment_delete(
interpretation_id: int,
sub_collection_id: int | None = None,
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
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:
log(
log.WARNING,
"Sub_collection with id [%s] not found",
sub_collection_id,
)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
redirect_url = url_for(
"book.qa_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
section_id=section_id,
interpretation_id=interpretation_id,
)
section: m.Section = db.session.get(m.Section, section_id)
if not section or section.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section_id)
flash("Section not found", "danger")
return redirect(redirect_url)
interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id
)
if not interpretation or interpretation.is_deleted:
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
flash("Interpretation not found", "danger")
return redirect(redirect_url)
form = f.DeleteCommentForm()
comment_id = form.comment_id.data
comment: m.Comment = db.session.get(m.Comment, comment_id)
if not comment or comment.is_deleted:
log(log.WARNING, "Comment with id [%s] not found", comment_id)
flash("Comment not found", "danger")
return redirect(redirect_url)
if form.validate_on_submit():
comment.is_deleted = True
@ -1407,7 +1139,16 @@ def comment_delete(
comment.save()
flash("Success!", "success")
return redirect(redirect_url)
return redirect(
url_for(
"book.qa_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
section_id=section_id,
interpretation_id=interpretation_id,
)
)
return redirect(
url_for(
"book.sub_collection_view",
@ -1428,6 +1169,7 @@ def comment_delete(
),
methods=["POST"],
)
@register_book_verify_route(bp.name)
@login_required
def comment_edit(
book_id: int,
@ -1436,65 +1178,9 @@ def comment_edit(
interpretation_id: int,
sub_collection_id: int | None = None,
):
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
flash("You are not owner of this book!", "danger")
return redirect(url_for("book.my_books"))
collection: m.Collection = db.session.get(m.Collection, collection_id)
if not collection or collection.is_deleted:
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))
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:
log(
log.WARNING,
"Sub_collection with id [%s] not found",
sub_collection_id,
)
flash("SubCollection not found", "danger")
return redirect(
url_for(
"book.sub_collection_view",
book_id=book_id,
collection_id=collection_id,
)
)
redirect_url = url_for(
"book.qa_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
section_id=section_id,
interpretation_id=interpretation_id,
)
section: m.Section = db.session.get(m.Section, section_id)
if not section or section.is_deleted:
log(log.WARNING, "Section with id [%s] not found", section_id)
flash("Section not found", "danger")
return redirect(redirect_url)
interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id
)
if not interpretation or interpretation.is_deleted:
log(log.WARNING, "Interpretation with id [%s] not found", interpretation_id)
flash("Interpretation not found", "danger")
return redirect(redirect_url)
form = f.EditCommentForm()
comment_id = form.comment_id.data
comment: m.Comment = db.session.get(m.Comment, comment_id)
if not comment or comment.is_deleted:
log(log.WARNING, "Comment with id [%s] not found", comment_id)
flash("Comment not found", "danger")
return redirect(redirect_url)
if form.validate_on_submit():
comment.text = form.text.data
@ -1503,7 +1189,16 @@ def comment_edit(
comment.save()
flash("Success!", "success")
return redirect(redirect_url)
return redirect(
url_for(
"book.qa_view",
book_id=book_id,
collection_id=collection_id,
sub_collection_id=sub_collection_id,
section_id=section_id,
interpretation_id=interpretation_id,
)
)
return redirect(
url_for(
"book.sub_collection_view",

View File

@ -2,9 +2,8 @@ from flask import (
Blueprint,
render_template,
)
from flask_login import current_user
from app import models as m
from sqlalchemy import and_
from app import models as m, db
bp = Blueprint("home", __name__, url_prefix="/home")
@ -12,16 +11,30 @@ bp = Blueprint("home", __name__, url_prefix="/home")
@bp.route("/", methods=["GET"])
def get_all():
books: m.Book = m.Book.query.order_by(m.Book.id).limit(5)
sections: m.Section = m.Section.query.order_by(m.Section.id).limit(5)
last_user_sections = []
if current_user.is_authenticated:
last_user_sections: m.Section = m.Section.query.order_by(
m.Section.created_at
).limit(5)
interpretations = (
db.session.query(
m.Interpretation,
)
.filter(
and_(
m.Section.id == m.Interpretation.section_id,
m.Collection.id == m.Section.collection_id,
m.BookVersion.id == m.Section.version_id,
m.Book.id == m.BookVersion.book_id,
m.Book.is_deleted.is_(False),
m.BookVersion.is_deleted.is_(False),
m.Interpretation.is_deleted.is_(False),
m.Section.is_deleted.is_(False),
m.Collection.is_deleted.is_(False),
)
)
.order_by(m.Interpretation.created_at.desc())
.limit(5)
.all()
)
return render_template(
"home/index.html",
books=books,
sections=sections,
last_user_sections=last_user_sections,
interpretations=interpretations,
)

2
build_static.sh Normal file
View File

@ -0,0 +1,2 @@
yarn js;
yarn css;

View File

@ -5,4 +5,10 @@
.text-danger {
color: red;
}
.h-box{
height: calc(100vh - 150px);
}
.w-box{
width: calc(100vw - 255px);
}

View File

@ -54,15 +54,16 @@ export function initWallet() {
credentials: 'include',
redirect: 'follow',
});
console.log('res2', res2);
window.location.href = res2.url;
window.location.reload();
}
const connectWalletBtn = document.querySelector('#connectWalletBtn');
const connectWalletBtns = document.querySelectorAll('#connectWalletBtn');
if (connectWalletBtn) {
connectWalletBtn.addEventListener('click', () => {
signInWithEthereum();
});
if (connectWalletBtns) {
connectWalletBtns.forEach(btn =>
btn.addEventListener('click', () => {
signInWithEthereum();
}),
);
}
}

View File

@ -1,13 +1,13 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: "class",
darkMode: 'class',
content: [
"./app/templates/**/*.html",
"./src/js/**/*.js",
"./node_modules/flowbite/**/*.js",
'./app/templates/**/*.html',
'./src/js/**/*.js',
'./node_modules/flowbite/**/*.js',
],
theme: {
extend: {},
},
plugins: [require("flowbite/plugin")],
plugins: [require('flowbite/plugin')],
};

View File

@ -3,10 +3,10 @@ from flask import current_app as Response
from flask.testing import FlaskClient, FlaskCliRunner
from app import models as m, db
from tests.utils import login
from tests.utils import login, logout
def test_create_edit_book(client: FlaskClient):
def test_create_edit_delete_book(client: FlaskClient):
login(client)
BOOK_NAME = "Test Book"
@ -72,19 +72,7 @@ def test_create_edit_book(client: FlaskClient):
)
assert response.status_code == 200
assert b"Book not found" in response.data
response: Response = client.post(
f"/book/{book.id}/edit",
data=dict(
book_id=book.id,
label=BOOK_NAME,
),
follow_redirects=True,
)
assert response.status_code == 200
assert b"Book label must be unique!" in response.data
assert b"You are not owner of this book!" in response.data
response: Response = client.post(
f"/book/{book.id}/edit",
@ -100,6 +88,19 @@ def test_create_edit_book(client: FlaskClient):
book = db.session.get(m.Book, book.id)
assert book.label != BOOK_NAME
response: Response = client.post(
f"/book/{book.id}/delete",
data=dict(
book_id=book.id,
),
follow_redirects=True,
)
assert response.status_code == 200
assert b"Success!" in response.data
book = db.session.get(m.Book, book.id)
assert book.is_deleted == True
def test_add_contributor(client: FlaskClient):
_, user = login(client)
@ -193,6 +194,15 @@ def test_delete_contributor(client: FlaskClient, runner: FlaskCliRunner):
assert response.status_code == 200
assert b"Does not exists!" in response.data
response: Response = client.post(
f"/book/{123}/add_contributor",
data=dict(user_id=1, role=m.BookContributor.Roles.MODERATOR),
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
def test_edit_contributor_role(client: FlaskClient, runner: FlaskCliRunner):
_, user = login(client)
@ -224,6 +234,27 @@ def test_edit_contributor_role(client: FlaskClient, runner: FlaskCliRunner):
assert response.status_code == 200
assert b"Success!" in response.data
moderator = m.User(username="Moderator", password="test").save()
moderators_book = m.Book(label="Test Book", user_id=moderator.id).save()
response: Response = client.post(
f"/book/{moderators_book.id}/add_contributor",
data=dict(user_id=moderator.id, role=m.BookContributor.Roles.MODERATOR),
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
response: Response = client.post(
f"/book/999/add_contributor",
data=dict(user_id=moderator.id, role=m.BookContributor.Roles.MODERATOR),
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
def test_crud_collection(client: FlaskClient, runner: FlaskCliRunner):
_, user = login(client)
@ -254,6 +285,14 @@ def test_crud_collection(client: FlaskClient, runner: FlaskCliRunner):
assert response.status_code == 200
assert b"Collection label must be unique!" in response.data
response: Response = client.post(
f"/book/999/create_collection",
data=dict(label="Test Collection #1 Label", about="Test Collection #1 About"),
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
collection: m.Collection = m.Collection.query.filter_by(
label="Test Collection #1 Label"
).first()
@ -289,6 +328,14 @@ def test_crud_collection(client: FlaskClient, runner: FlaskCliRunner):
assert response.status_code == 200
assert b"Success!" in response.data
response: Response = client.post(
f"/book/999/{collection.id}/edit",
data=dict(label="Test Collection #1 Label", about="Test Collection #1 About"),
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
edited_collection: m.Collection = m.Collection.query.filter_by(
label=new_label, about=new_about
).first()
@ -325,12 +372,20 @@ def test_crud_collection(client: FlaskClient, runner: FlaskCliRunner):
assert response.status_code == 200
assert b"Collection not found" in response.data
response: Response = client.post(
f"/book/999/{collection.id}/delete",
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
def test_crud_subcollection(client: FlaskClient, runner: FlaskCliRunner):
_, user = login(client)
user: m.User
# add dummmy data
# add dummy data
runner.invoke(args=["db-populate"])
book: m.Book = db.session.get(m.Book, 1)
@ -347,6 +402,16 @@ def test_crud_subcollection(client: FlaskClient, runner: FlaskCliRunner):
label="Test Collection #1 Label", version_id=book.last_version.id
).save()
response: Response = client.post(
f"/book/999/{leaf_collection.id}/create_sub_collection",
data=dict(
label="Test SubCollection #1 Label", about="Test SubCollection #1 About"
),
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
response: Response = client.post(
f"/book/{book.id}/{leaf_collection.id}/create_sub_collection",
data=dict(
@ -434,7 +499,7 @@ def test_crud_subcollection(client: FlaskClient, runner: FlaskCliRunner):
)
assert response.status_code == 200
assert b"SubCollection not found" in response.data
assert b"Subcollection not found" in response.data
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{sub_collection.id}/delete",
@ -453,7 +518,7 @@ def test_crud_subcollection(client: FlaskClient, runner: FlaskCliRunner):
)
assert response.status_code == 200
assert b"Collection not found" in response.data
assert b"Subcollection not found" in response.data
def test_crud_sections(client: FlaskClient, runner: FlaskCliRunner):
@ -1003,3 +1068,146 @@ def test_crud_comment(client: FlaskClient, runner: FlaskCliRunner):
assert response.status_code == 200
assert b"Success" in response.data
assert str.encode(comment_text) not in response.data
def test_access_to_settings_page(client: FlaskClient):
_, user = login(client)
book_1 = m.Book(label="test", about="test").save()
book_2 = m.Book(label="test", about="test", user_id=user.id).save()
response: Response = client.get(
f"/book/{book_1.id}/settings",
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
response: Response = client.get(
f"/book/{book_2.id}/settings",
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" not in response.data
logout(client)
response: Response = client.get(
f"/book/{book_2.id}/settings",
follow_redirects=True,
)
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
def test_interpretation_in_home_last_inter_section(
client: FlaskClient, runner: FlaskCliRunner
):
_, user = login(client)
user: m.User
# add dummmy data
runner.invoke(args=["db-populate"])
book: m.Book = db.session.get(m.Book, 1)
book.user_id = user.id
book.save()
leaf_collection: m.Collection = m.Collection(
label="Test Leaf Collection #1 Label",
version_id=book.last_version.id,
is_leaf=True,
parent_id=book.last_version.root_collection.id,
).save()
section_in_collection: m.Section = m.Section(
label="Test Section in Collection #1 Label",
about="Test Section in Collection #1 About",
collection_id=leaf_collection.id,
version_id=book.last_version.id,
).save()
collection: m.Collection = m.Collection(
label="Test Collection #1 Label", version_id=book.last_version.id
).save()
sub_collection: m.Collection = m.Collection(
label="Test SubCollection #1 Label",
version_id=book.last_version.id,
parent_id=collection.id,
is_leaf=True,
).save()
section_in_subcollection: m.Section = m.Section(
label="Test Section in Subcollection #1 Label",
about="Test Section in Subcollection #1 About",
collection_id=sub_collection.id,
version_id=book.last_version.id,
).save()
label_1 = "Test Interpretation #1 Label"
text_1 = "Test Interpretation #1 Text"
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/create_interpretation",
data=dict(section_id=section_in_subcollection.id, label=label_1, text=text_1),
follow_redirects=True,
)
assert response.status_code == 200
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=label_1, section_id=section_in_subcollection.id
).first()
assert interpretation
assert interpretation.section_id == section_in_subcollection.id
assert not interpretation.comments
response: Response = client.post(
f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/create_interpretation",
data=dict(section_id=section_in_collection.id, label=label_1, text=text_1),
follow_redirects=True,
)
assert response.status_code == 200
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
label=label_1, section_id=section_in_collection.id
).first()
assert interpretation
assert interpretation.section_id == section_in_collection.id
assert not interpretation.comments
response: Response = client.post(
f"/book/{book.id}/{collection.id}/999/create_section",
data=dict(collection_id=999, label=label_1, text=text_1),
follow_redirects=True,
)
assert response.status_code == 200
assert b"Subcollection not found" in response.data
response: Response = client.post(
f"/book/{book.id}/{leaf_collection.id}/999/create_interpretation",
data=dict(collection_id=999, label=label_1, text=text_1),
follow_redirects=True,
)
assert response.status_code == 200
assert b"Section not found" in response.data
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{sub_collection.id}/888/create_interpretation",
data=dict(collection_id=999, label=label_1, text=text_1),
follow_redirects=True,
)
assert response.status_code == 200
assert b"Section not found" in response.data
response: Response = client.get(
f"/home",
follow_redirects=True,
)
assert response
assert response.status_code == 200
assert str.encode(text_1) in response.data