mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Added import btn, Catalog overide, started server backend
This commit is contained in:
@@ -21,17 +21,17 @@ $(document).ready(function(){
|
||||
var s_string = "search by Title, Author, Tags, or Collections";
|
||||
customlog([cmp_height]);
|
||||
$(".search_submit").click(function(){
|
||||
var query = $('.nav_search').val();
|
||||
console.log(query);
|
||||
window.location.href = '/search/'+query;
|
||||
var query = $('.nav_search').val();
|
||||
console.log(query);
|
||||
window.location.href = '/search/'+query;
|
||||
});
|
||||
$('.nav_search').on('keypress', function (e) {
|
||||
if(e.which === 13){
|
||||
$(this).attr("disabled", "disabled");
|
||||
var query = $('.nav_search').val();
|
||||
window.location.href = '/search/'+query;
|
||||
$(this).removeAttr("disabled");
|
||||
}
|
||||
if(e.which === 13){
|
||||
$(this).attr("disabled", "disabled");
|
||||
var query = $('.nav_search').val();
|
||||
window.location.href = '/search/'+query;
|
||||
$(this).removeAttr("disabled");
|
||||
}
|
||||
});
|
||||
$('.nav_link').on('mouseover', function (e){
|
||||
var popover_str = $(this).attr('alt');
|
||||
@@ -59,13 +59,13 @@ $(document).ready(function(){
|
||||
});
|
||||
$('.input_box').focusout(function(){
|
||||
if ($(this).hasClass('nav_search') && $(this).val() == "") {
|
||||
$(this).attr("value", s_string);
|
||||
$(this).attr("value", s_string);
|
||||
}
|
||||
if ($(this).attr("id") == "username" && $(this).val() == "") {
|
||||
$(this).attr("value", u_string);
|
||||
$(this).attr("value", u_string);
|
||||
}
|
||||
if ($(this).attr("id") == "password" && $(this).val() == "") {
|
||||
$(this).attr("value", p_string);
|
||||
$(this).attr("value", p_string);
|
||||
}
|
||||
});
|
||||
$('#btn_login').on('click', function(){
|
||||
@@ -130,7 +130,7 @@ $(document).ready(function(){
|
||||
});
|
||||
});
|
||||
$('#btn_logout').on('click', function() {
|
||||
//window.location.href = '/logout';
|
||||
//window.location.href = '/logout';
|
||||
var isopen = $('#pop_over_0').dialog("isOpen");
|
||||
if (isopen) {
|
||||
$('#pop_over_0').dialog("close");
|
||||
@@ -165,7 +165,39 @@ $(document).ready(function(){
|
||||
// Now open this dialog
|
||||
$('#pop_over_0').dialog("open");
|
||||
});
|
||||
$('.logout-btn').on('click', function(){window.location.href = '/logout'});
|
||||
$(document).on('click', '.logout-btn', function(){window.location.href = '/logout'});
|
||||
$(document).on('click', '.import-btn', function(){
|
||||
$.ajax({
|
||||
type: "GET", url: "/live", data: {hook: 'import_books'},
|
||||
success: function (response) {
|
||||
// Set the dialog title
|
||||
$('#pop_over_0').dialog({
|
||||
title: "User Controls",
|
||||
maxHeight: (win_height - 100),
|
||||
minWidth: $("#horiz_nav_main").width(),
|
||||
hide: {effect: "blind", duration: 1000},
|
||||
show: {effect: "blind", duration: 1000},
|
||||
position: {
|
||||
my: "top", at: "bottom", of: $("#horiz_nav_main")
|
||||
}
|
||||
});
|
||||
// clear and create a new container
|
||||
$('#pop_over_0').html('<div id=usercp class="mx-auto">');
|
||||
// Populate the container from response.data
|
||||
$('#usercp').append('<div class="row" id="usercp-inner">');
|
||||
$('#usercp-inner').append(response.data);
|
||||
$('#usercp-inner').append('</div>');
|
||||
$('#usercp').append('</div>');
|
||||
// Close the container
|
||||
$('#pop_over').append('</div>');
|
||||
// Now open this dialog
|
||||
$('#pop_over_0').dialog("open");
|
||||
},
|
||||
error: function (response) {
|
||||
customlog(["Failure", response]);
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#coll_button').on('click', function(){
|
||||
var isopen = $('#pop_over_0').dialog("isOpen");
|
||||
if (isopen){
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import asyncio
|
||||
|
||||
from base64 import b64decode, b64encode
|
||||
from pathlib import Path
|
||||
|
||||
from backend.lib.config import Config
|
||||
from backend.lib.hooks import ACatalogue
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth import authenticate, get_user_model, login, logout
|
||||
@@ -393,17 +398,28 @@ def live(request, **kwargs):
|
||||
if hook == "collection_listing":
|
||||
collections = collections_list()
|
||||
return JsonResponse({"data": collections}, status=200)
|
||||
|
||||
elif hook == "details":
|
||||
try: _pk = request.GET['pk']
|
||||
except KeyError as e: return False
|
||||
book = book_details(Books.objects.get(pk=_pk))
|
||||
return JsonResponse({"data": book}, status=200)
|
||||
|
||||
elif hook == "register":
|
||||
html = render_to_string('signup.html', {'form': SignUpForm}, request)
|
||||
html += render_to_string('login.html', {'form': UserLoginForm}, request)
|
||||
return JsonResponse({"data": html})
|
||||
elif hook == "update_books":
|
||||
print("Update Books")
|
||||
|
||||
elif hook == "import_books":
|
||||
breakpoint()
|
||||
filename = "../data/{}-{}.sock".format(request.user.username, time.strftime("%H:%M:%S"))
|
||||
catalogue = ACatalogue()
|
||||
async def responder(socket):
|
||||
await catalogue.import_books(socket=socket)
|
||||
return JsonResponse({"data": filename})
|
||||
asyncio.run(responder(filename))
|
||||
|
||||
|
||||
else: return JsonResponse(err_txt, status=404)
|
||||
|
||||
return JsonResponse({"data": "Response sent"}, status=200)
|
||||
|
||||
Reference in New Issue
Block a user