mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-24 10:37:23 +00:00
Sorting of users in table according to selection possible
This commit is contained in:
parent
ae97e87506
commit
b6177b27f4
36
cps/admin.py
36
cps/admin.py
@ -38,6 +38,7 @@ from sqlalchemy import and_
|
|||||||
from sqlalchemy.orm.attributes import flag_modified
|
from sqlalchemy.orm.attributes import flag_modified
|
||||||
from sqlalchemy.exc import IntegrityError, OperationalError, InvalidRequestError
|
from sqlalchemy.exc import IntegrityError, OperationalError, InvalidRequestError
|
||||||
from sqlalchemy.sql.expression import func, or_, text
|
from sqlalchemy.sql.expression import func, or_, text
|
||||||
|
# from sqlalchemy.func import field
|
||||||
|
|
||||||
from . import constants, logger, helper, services
|
from . import constants, logger, helper, services
|
||||||
from .cli import filepicker
|
from .cli import filepicker
|
||||||
@ -241,29 +242,44 @@ def edit_user_table():
|
|||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def list_users():
|
def list_users():
|
||||||
off = request.args.get("offset") or 0
|
off = int(request.args.get("offset") or 0)
|
||||||
limit = request.args.get("limit") or 10
|
limit = int(request.args.get("limit") or 10)
|
||||||
search = request.args.get("search")
|
search = request.args.get("search")
|
||||||
sort = request.args.get("sort")
|
sort = request.args.get("sort", "state")
|
||||||
order = request.args.get("order")
|
order = request.args.get("order")
|
||||||
if sort and order:
|
state = None
|
||||||
|
if sort != "state" and order:
|
||||||
order = text(sort + " " + order)
|
order = text(sort + " " + order)
|
||||||
else:
|
else:
|
||||||
order = ub.User.name.desc()
|
order = ub.User.name.desc()
|
||||||
|
if sort == "state":
|
||||||
|
state = json.loads(request.args.get("state"))
|
||||||
|
|
||||||
all_user = ub.session.query(ub.User)
|
all_user = ub.session.query(ub.User)
|
||||||
if not config.config_anonbrowse:
|
if not config.config_anonbrowse:
|
||||||
all_user = all_user.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS)
|
all_user = all_user.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS)
|
||||||
total_count = all_user.count()
|
|
||||||
|
total_count = filtered_count = all_user.count()
|
||||||
|
|
||||||
if search:
|
if search:
|
||||||
users = all_user.filter(or_(func.lower(ub.User.name).ilike("%" + search + "%"),
|
all_user = all_user.filter(or_(func.lower(ub.User.name).ilike("%" + search + "%"),
|
||||||
func.lower(ub.User.kindle_mail).ilike("%" + search + "%"),
|
func.lower(ub.User.kindle_mail).ilike("%" + search + "%"),
|
||||||
func.lower(ub.User.email).ilike("%" + search + "%")))\
|
func.lower(ub.User.email).ilike("%" + search + "%")))
|
||||||
.order_by(order).offset(off).limit(limit).all()
|
if state:
|
||||||
filtered_count = len(users)
|
outcome = list()
|
||||||
|
userlist = {user.id:user for user in all_user.all()}
|
||||||
|
for entry in state:
|
||||||
|
outcome.append(userlist[entry])
|
||||||
|
del userlist[entry]
|
||||||
|
for entry in userlist:
|
||||||
|
outcome.append(userlist[entry])
|
||||||
|
if request.args.get("order", "").lower() == "asc":
|
||||||
|
outcome.reverse()
|
||||||
|
users = outcome[off:off + limit]
|
||||||
else:
|
else:
|
||||||
users = all_user.order_by(order).offset(off).limit(limit).all()
|
users = all_user.order_by(order).offset(off).limit(limit).all()
|
||||||
filtered_count = total_count
|
if search:
|
||||||
|
filtered_count = len(users)
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
if user.default_language == "all":
|
if user.default_language == "all":
|
||||||
|
15
cps/db.py
15
cps/db.py
@ -689,23 +689,26 @@ class CalibreDB():
|
|||||||
return self.session.query(Books) \
|
return self.session.query(Books) \
|
||||||
.filter(and_(Books.authors.any(and_(*q)), func.lower(Books.title).ilike("%" + title + "%"))).first()
|
.filter(and_(Books.authors.any(and_(*q)), func.lower(Books.title).ilike("%" + title + "%"))).first()
|
||||||
|
|
||||||
# read search results from calibre-database and return it (function is used for feed and simple search
|
def search_query(self, term):
|
||||||
def get_search_results(self, term, offset=None, order=None, limit=None):
|
|
||||||
order = order or [Books.sort]
|
|
||||||
pagination = None
|
|
||||||
term.strip().lower()
|
term.strip().lower()
|
||||||
self.session.connection().connection.connection.create_function("lower", 1, lcase)
|
self.session.connection().connection.connection.create_function("lower", 1, lcase)
|
||||||
q = list()
|
q = list()
|
||||||
authorterms = re.split("[, ]+", term)
|
authorterms = re.split("[, ]+", term)
|
||||||
for authorterm in authorterms:
|
for authorterm in authorterms:
|
||||||
q.append(Books.authors.any(func.lower(Authors.name).ilike("%" + authorterm + "%")))
|
q.append(Books.authors.any(func.lower(Authors.name).ilike("%" + authorterm + "%")))
|
||||||
result = self.session.query(Books).filter(self.common_filters(True)).filter(
|
return self.session.query(Books).filter(self.common_filters(True)).filter(
|
||||||
or_(Books.tags.any(func.lower(Tags.name).ilike("%" + term + "%")),
|
or_(Books.tags.any(func.lower(Tags.name).ilike("%" + term + "%")),
|
||||||
Books.series.any(func.lower(Series.name).ilike("%" + term + "%")),
|
Books.series.any(func.lower(Series.name).ilike("%" + term + "%")),
|
||||||
Books.authors.any(and_(*q)),
|
Books.authors.any(and_(*q)),
|
||||||
Books.publishers.any(func.lower(Publishers.name).ilike("%" + term + "%")),
|
Books.publishers.any(func.lower(Publishers.name).ilike("%" + term + "%")),
|
||||||
func.lower(Books.title).ilike("%" + term + "%")
|
func.lower(Books.title).ilike("%" + term + "%")
|
||||||
)).order_by(*order).all()
|
))
|
||||||
|
|
||||||
|
# read search results from calibre-database and return it (function is used for feed and simple search
|
||||||
|
def get_search_results(self, term, offset=None, order=None, limit=None):
|
||||||
|
order = order or [Books.sort]
|
||||||
|
pagination = None
|
||||||
|
result = self.search_query(term).order_by(*order).all()
|
||||||
result_count = len(result)
|
result_count = len(result)
|
||||||
if offset != None and limit != None:
|
if offset != None and limit != None:
|
||||||
offset = int(offset)
|
offset = int(offset)
|
||||||
|
@ -422,6 +422,7 @@ $(function() {
|
|||||||
|
|
||||||
$("#user-table").bootstrapTable({
|
$("#user-table").bootstrapTable({
|
||||||
sidePagination: "server",
|
sidePagination: "server",
|
||||||
|
queryParams: queryParams,
|
||||||
pagination: true,
|
pagination: true,
|
||||||
paginationLoop: false,
|
paginationLoop: false,
|
||||||
paginationDetailHAlign: " hidden",
|
paginationDetailHAlign: " hidden",
|
||||||
@ -462,28 +463,10 @@ $(function() {
|
|||||||
$("input[data-name='sidebar_read_and_unread'][data-pk='"+guest.data("pk")+"']").prop("disabled", true);
|
$("input[data-name='sidebar_read_and_unread'][data-pk='"+guest.data("pk")+"']").prop("disabled", true);
|
||||||
$(".user-remove[data-pk='"+guest.data("pk")+"']").prop("disabled", true);
|
$(".user-remove[data-pk='"+guest.data("pk")+"']").prop("disabled", true);
|
||||||
},
|
},
|
||||||
|
onSort: function(a, b) {
|
||||||
// eslint-disable-next-line no-unused-vars
|
console.log("huh");
|
||||||
/*onEditableSave: function (field, row, oldvalue, $el) {
|
},
|
||||||
if (field === "title" || field === "authors") {
|
onColumnSwitch: function () {
|
||||||
$.ajax({
|
|
||||||
method:"get",
|
|
||||||
dataType: "json",
|
|
||||||
url: window.location.pathname + "/../../ajax/sort_value/" + field + "/" + row.id,
|
|
||||||
success: function success(data) {
|
|
||||||
var key = Object.keys(data)[0];
|
|
||||||
$("#books-table").bootstrapTable("updateCellByUniqueId", {
|
|
||||||
id: row.id,
|
|
||||||
field: key,
|
|
||||||
value: data[key]
|
|
||||||
});
|
|
||||||
// console.log(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},*/
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
|
||||||
onColumnSwitch: function (field, checked) {
|
|
||||||
var visible = $("#user-table").bootstrapTable("getVisibleColumns");
|
var visible = $("#user-table").bootstrapTable("getVisibleColumns");
|
||||||
var hidden = $("#user-table").bootstrapTable("getHiddenColumns");
|
var hidden = $("#user-table").bootstrapTable("getHiddenColumns");
|
||||||
var st = "";
|
var st = "";
|
||||||
@ -746,6 +729,11 @@ function deleteUser(a,b){
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function queryParams(params)
|
||||||
|
{
|
||||||
|
params.state = JSON.stringify(selections);
|
||||||
|
return params;
|
||||||
|
}
|
||||||
function user_handle (userId) {
|
function user_handle (userId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@
|
|||||||
{{ restrict_modal() }}
|
{{ restrict_modal() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block js %}
|
{% block js %}
|
||||||
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table-editable.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-table-editable.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-editable.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/bootstrap-table/bootstrap-editable.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/table.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/table.js') }}"></script>
|
||||||
|
35
cps/web.py
35
cps/web.py
@ -753,21 +753,42 @@ def books_table():
|
|||||||
@web.route("/ajax/listbooks")
|
@web.route("/ajax/listbooks")
|
||||||
@login_required
|
@login_required
|
||||||
def list_books():
|
def list_books():
|
||||||
off = request.args.get("offset") or 0
|
off = int(request.args.get("offset") or 0)
|
||||||
limit = request.args.get("limit") or config.config_books_per_page
|
limit = int(request.args.get("limit") or config.config_books_per_page)
|
||||||
sort = request.args.get("sort")
|
search = request.args.get("search")
|
||||||
|
sort = request.args.get("sort", "state")
|
||||||
order = request.args.get("order")
|
order = request.args.get("order")
|
||||||
if sort and order:
|
state = None
|
||||||
|
if sort != "state" and order:
|
||||||
order = [text(sort + " " + order)]
|
order = [text(sort + " " + order)]
|
||||||
else:
|
else:
|
||||||
order = [db.Books.timestamp.desc()]
|
order = [db.Books.timestamp.desc()]
|
||||||
search = request.args.get("search")
|
if sort == "state":
|
||||||
total_count = calibre_db.session.query(db.Books).count()
|
state = json.loads(request.args.get("state"))
|
||||||
|
|
||||||
|
total_count = filtered_count = calibre_db.session.query(db.Books).count()
|
||||||
|
|
||||||
|
if state:
|
||||||
|
outcome = list()
|
||||||
if search:
|
if search:
|
||||||
|
books = calibre_db.search_query(search)
|
||||||
|
filtered_count = len(books)
|
||||||
|
else:
|
||||||
|
books = calibre_db.session.query(db.Books).filter(calibre_db.common_filters()).all()
|
||||||
|
booklist = {book.id: book for book in books}
|
||||||
|
for entry in state:
|
||||||
|
outcome.append(booklist[entry])
|
||||||
|
del booklist[entry]
|
||||||
|
for entry in booklist:
|
||||||
|
outcome.append(booklist[entry])
|
||||||
|
if request.args.get("order", "").lower() == "asc":
|
||||||
|
outcome.reverse()
|
||||||
|
entries = outcome[off:off + limit]
|
||||||
|
elif search:
|
||||||
entries, filtered_count, __ = calibre_db.get_search_results(search, off, order, limit)
|
entries, filtered_count, __ = calibre_db.get_search_results(search, off, order, limit)
|
||||||
else:
|
else:
|
||||||
entries, __, __ = calibre_db.fill_indexpage((int(off) / (int(limit)) + 1), limit, db.Books, True, order)
|
entries, __, __ = calibre_db.fill_indexpage((int(off) / (int(limit)) + 1), limit, db.Books, True, order)
|
||||||
filtered_count = total_count
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
for index in range(0, len(entry.languages)):
|
for index in range(0, len(entry.languages)):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user