mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-28 19:10:31 +00:00
Update python metadata search
This commit is contained in:
parent
aa9fdd2ada
commit
a35c635987
@ -20,12 +20,6 @@ from scholarly import scholarly
|
||||
from flask import url_for
|
||||
|
||||
from cps.services.Metadata import Metadata
|
||||
#try:
|
||||
|
||||
#except ImportError:
|
||||
# have_scholar = False
|
||||
# pass
|
||||
|
||||
|
||||
|
||||
class scholar(Metadata):
|
||||
|
@ -38,7 +38,7 @@ log = logger.create()
|
||||
|
||||
new_list = list()
|
||||
meta_dir = os.path.join(constants.BASE_DIR, "cps", "metadata_provider")
|
||||
modules = os.listdir(os.path.join(constants.BASE_DIR, "cps", "metadata_provider")) #glob.glob(join(dirname(__file__), "*.py"))
|
||||
modules = os.listdir(os.path.join(constants.BASE_DIR, "cps", "metadata_provider"))
|
||||
for f in modules:
|
||||
if os.path.isfile(os.path.join(meta_dir, f)) and not f.endswith('__init__.py'):
|
||||
a = os.path.basename(f)[:-3]
|
||||
@ -65,12 +65,14 @@ def metadata_provider():
|
||||
active = current_user.view_settings.get('metadata', {})
|
||||
provider = list()
|
||||
for c in cl:
|
||||
provider.append({"name": c.__name__, "active": active.get(c.__id__, True), "id": c.__id__})
|
||||
ac = active.get(c.__id__, True)
|
||||
provider.append({"name": c.__name__, "active": ac, "initial": ac, "id": c.__id__})
|
||||
return Response(json.dumps(provider), mimetype='application/json')
|
||||
|
||||
@meta.route("/metadata/provider", methods=['POST'])
|
||||
@meta.route("/metadata/provider/<prov_name>", methods=['POST'])
|
||||
@login_required
|
||||
def metadata_change_active_provider():
|
||||
def metadata_change_active_provider(prov_name):
|
||||
new_state = request.get_json()
|
||||
active = current_user.view_settings.get('metadata', {})
|
||||
active[new_state['id']] = new_state['value']
|
||||
@ -84,10 +86,13 @@ def metadata_change_active_provider():
|
||||
except (InvalidRequestError, OperationalError):
|
||||
log.error("Invalid request received: {}".format(request))
|
||||
return "Invalid request", 400
|
||||
provider = list()
|
||||
for c in cl:
|
||||
provider.append({"name": c.__name__, "active": active.get(c.__id__, True), "id": c.__id__})
|
||||
return "" # Response(json.dumps(provider), mimetype='application/json')
|
||||
if "initial" in new_state and prov_name:
|
||||
for c in cl:
|
||||
if c.__id__ == prov_name:
|
||||
data = c.search(new_state.get('query', ""))
|
||||
break
|
||||
return Response(json.dumps(data), mimetype='application/json')
|
||||
return ""
|
||||
|
||||
@meta.route("/metadata/search", methods=['POST'])
|
||||
@login_required
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
$(function () {
|
||||
var msg = i18nMsg;
|
||||
var keyword = ""
|
||||
|
||||
var templates = {
|
||||
bookResult: _.template(
|
||||
@ -56,7 +57,6 @@ $(function () {
|
||||
data: {"query": keyword},
|
||||
dataType: "json",
|
||||
success: function success(data) {
|
||||
// console.log(data);
|
||||
$("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
||||
data.forEach(function(book) {
|
||||
var $book = $(templates.bookResult(book));
|
||||
@ -80,13 +80,12 @@ $(function () {
|
||||
type: "get",
|
||||
dataType: "json",
|
||||
success: function success(data) {
|
||||
// console.log(data);
|
||||
data.forEach(function(provider) {
|
||||
var checked = "";
|
||||
if (provider.active) {
|
||||
checked = "checked";
|
||||
}
|
||||
var $provider_button = '<input type="checkbox" id="show-' + provider.name + '" class="pill" data-control="' + provider.id + '" ' + checked + '><label for="show-' + provider.name + '">' + provider.name + ' <span class="glyphicon glyphicon-ok"></span></label>'
|
||||
var $provider_button = '<input type="checkbox" id="show-' + provider.name + '" class="pill" data-initial="' + provider.initial + '" data-control="' + provider.id + '" ' + checked + '><label for="show-' + provider.name + '">' + provider.name + ' <span class="glyphicon glyphicon-ok"></span></label>'
|
||||
$("#metadata_provider").append($provider_button);
|
||||
});
|
||||
},
|
||||
@ -94,20 +93,42 @@ $(function () {
|
||||
}
|
||||
|
||||
$(document).on("change", ".pill", function () {
|
||||
var id = $(this).data("control");
|
||||
var val = $(this).prop('checked');
|
||||
var element = $(this);
|
||||
var id = element.data("control");
|
||||
var initial = element.data("initial");
|
||||
var val = element.prop('checked');
|
||||
var params = {id : id, value: val};
|
||||
if (!initial) {
|
||||
params['initial'] = initial;
|
||||
params['query'] = keyword;
|
||||
}
|
||||
$.ajax({
|
||||
method:"post",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
url: getPath() + "/metadata/provider",
|
||||
data: JSON.stringify({id : id, value: val}),
|
||||
url: getPath() + "/metadata/provider/" + id,
|
||||
data: JSON.stringify(params),
|
||||
success: function success(data) {
|
||||
element.data("initial", "true");
|
||||
data.forEach(function(book) {
|
||||
var $book = $(templates.bookResult(book));
|
||||
$book.find("img").on("click", function () {
|
||||
populateForm(book);
|
||||
});
|
||||
$("#book-list").append($book);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#meta-search").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
var keyword = $("#keyword").val();
|
||||
keyword = $("#keyword").val();
|
||||
$('.pill').each(function(){
|
||||
// console.log($(this).data('control'));
|
||||
$(this).data("initial", $(this).prop('checked'));
|
||||
// console.log($(this).data('initial'));
|
||||
});
|
||||
doSearch(keyword);
|
||||
});
|
||||
|
||||
@ -115,6 +136,7 @@ $(function () {
|
||||
populate_provider();
|
||||
var bookTitle = $("#book_title").val();
|
||||
$("#keyword").val(bookTitle);
|
||||
keyword = bookTitle;
|
||||
doSearch(bookTitle);
|
||||
});
|
||||
$("#metaModal").on("show.bs.modal", function(e) {
|
||||
|
Loading…
Reference in New Issue
Block a user