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 flask import url_for
|
||||||
|
|
||||||
from cps.services.Metadata import Metadata
|
from cps.services.Metadata import Metadata
|
||||||
#try:
|
|
||||||
|
|
||||||
#except ImportError:
|
|
||||||
# have_scholar = False
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class scholar(Metadata):
|
class scholar(Metadata):
|
||||||
|
|
|
@ -38,7 +38,7 @@ log = logger.create()
|
||||||
|
|
||||||
new_list = list()
|
new_list = list()
|
||||||
meta_dir = os.path.join(constants.BASE_DIR, "cps", "metadata_provider")
|
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:
|
for f in modules:
|
||||||
if os.path.isfile(os.path.join(meta_dir, f)) and not f.endswith('__init__.py'):
|
if os.path.isfile(os.path.join(meta_dir, f)) and not f.endswith('__init__.py'):
|
||||||
a = os.path.basename(f)[:-3]
|
a = os.path.basename(f)[:-3]
|
||||||
|
@ -65,12 +65,14 @@ def metadata_provider():
|
||||||
active = current_user.view_settings.get('metadata', {})
|
active = current_user.view_settings.get('metadata', {})
|
||||||
provider = list()
|
provider = list()
|
||||||
for c in cl:
|
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')
|
return Response(json.dumps(provider), mimetype='application/json')
|
||||||
|
|
||||||
@meta.route("/metadata/provider", methods=['POST'])
|
@meta.route("/metadata/provider", methods=['POST'])
|
||||||
|
@meta.route("/metadata/provider/<prov_name>", methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def metadata_change_active_provider():
|
def metadata_change_active_provider(prov_name):
|
||||||
new_state = request.get_json()
|
new_state = request.get_json()
|
||||||
active = current_user.view_settings.get('metadata', {})
|
active = current_user.view_settings.get('metadata', {})
|
||||||
active[new_state['id']] = new_state['value']
|
active[new_state['id']] = new_state['value']
|
||||||
|
@ -84,10 +86,13 @@ def metadata_change_active_provider():
|
||||||
except (InvalidRequestError, OperationalError):
|
except (InvalidRequestError, OperationalError):
|
||||||
log.error("Invalid request received: {}".format(request))
|
log.error("Invalid request received: {}".format(request))
|
||||||
return "Invalid request", 400
|
return "Invalid request", 400
|
||||||
provider = list()
|
if "initial" in new_state and prov_name:
|
||||||
for c in cl:
|
for c in cl:
|
||||||
provider.append({"name": c.__name__, "active": active.get(c.__id__, True), "id": c.__id__})
|
if c.__id__ == prov_name:
|
||||||
return "" # Response(json.dumps(provider), mimetype='application/json')
|
data = c.search(new_state.get('query', ""))
|
||||||
|
break
|
||||||
|
return Response(json.dumps(data), mimetype='application/json')
|
||||||
|
return ""
|
||||||
|
|
||||||
@meta.route("/metadata/search", methods=['POST'])
|
@meta.route("/metadata/search", methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var msg = i18nMsg;
|
var msg = i18nMsg;
|
||||||
|
var keyword = ""
|
||||||
|
|
||||||
var templates = {
|
var templates = {
|
||||||
bookResult: _.template(
|
bookResult: _.template(
|
||||||
|
@ -56,7 +57,6 @@ $(function () {
|
||||||
data: {"query": keyword},
|
data: {"query": keyword},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function success(data) {
|
success: function success(data) {
|
||||||
// console.log(data);
|
|
||||||
$("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
$("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
||||||
data.forEach(function(book) {
|
data.forEach(function(book) {
|
||||||
var $book = $(templates.bookResult(book));
|
var $book = $(templates.bookResult(book));
|
||||||
|
@ -80,13 +80,12 @@ $(function () {
|
||||||
type: "get",
|
type: "get",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function success(data) {
|
success: function success(data) {
|
||||||
// console.log(data);
|
|
||||||
data.forEach(function(provider) {
|
data.forEach(function(provider) {
|
||||||
var checked = "";
|
var checked = "";
|
||||||
if (provider.active) {
|
if (provider.active) {
|
||||||
checked = "checked";
|
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);
|
$("#metadata_provider").append($provider_button);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -94,20 +93,42 @@ $(function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on("change", ".pill", function () {
|
$(document).on("change", ".pill", function () {
|
||||||
var id = $(this).data("control");
|
var element = $(this);
|
||||||
var val = $(this).prop('checked');
|
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({
|
$.ajax({
|
||||||
method:"post",
|
method:"post",
|
||||||
contentType: "application/json; charset=utf-8",
|
contentType: "application/json; charset=utf-8",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url: getPath() + "/metadata/provider",
|
url: getPath() + "/metadata/provider/" + id,
|
||||||
data: JSON.stringify({id : id, value: val}),
|
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) {
|
$("#meta-search").on("submit", function (e) {
|
||||||
e.preventDefault();
|
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);
|
doSearch(keyword);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -115,6 +136,7 @@ $(function () {
|
||||||
populate_provider();
|
populate_provider();
|
||||||
var bookTitle = $("#book_title").val();
|
var bookTitle = $("#book_title").val();
|
||||||
$("#keyword").val(bookTitle);
|
$("#keyword").val(bookTitle);
|
||||||
|
keyword = bookTitle;
|
||||||
doSearch(bookTitle);
|
doSearch(bookTitle);
|
||||||
});
|
});
|
||||||
$("#metaModal").on("show.bs.modal", function(e) {
|
$("#metaModal").on("show.bs.modal", function(e) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user