From 781d2ece5a558046ef70fc3954cd272bbc2f32e3 Mon Sep 17 00:00:00 2001 From: maximstewart Date: Tue, 9 Feb 2021 17:14:32 -0600 Subject: [PATCH] Added modal logic, fixed favorites logic --- src/core/__init__.py | 3 +- src/core/config.py | 2 + src/core/routes/Routes.py | 3 +- src/core/static/js/events.js | 6 ++- src/core/static/js/post-ajax.js | 28 +--------- src/core/static/js/react-ui-logic.js | 54 +++++++++++++++++-- src/core/static/js/ui-logic.js | 8 ++- src/core/templates/layout.html | 7 +++ .../{ => modals}/favorites-modal.html | 2 - .../templates/{ => modals}/file-modal.html | 2 + .../templates/{ => modals}/options-modal.html | 2 + src/core/templates/pages/index.html | 2 +- src/wsgi.py | 2 +- 13 files changed, 79 insertions(+), 42 deletions(-) rename src/core/templates/{ => modals}/favorites-modal.html (97%) rename src/core/templates/{ => modals}/file-modal.html (98%) rename src/core/templates/{ => modals}/options-modal.html (97%) diff --git a/src/core/__init__.py b/src/core/__init__.py index 6b8c7e1..8f92ea8 100644 --- a/src/core/__init__.py +++ b/src/core/__init__.py @@ -16,7 +16,8 @@ from core.utils import Logger app = Flask(__name__) -app.config.from_object("core.config.Config") +app.config.from_object("core.config.ProductionConfig") +# app.config.from_object("core.config.DevelopmentConfig") oidc = OpenIDConnect(app) login_manager = LoginManager(app) diff --git a/src/core/config.py b/src/core/config.py index 7dd22cf..98044eb 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -18,6 +18,7 @@ class Config(object): TITLE = APP_NAME DEBUG = False TESTING = False + THREADED =True SECRET_KEY = secrets.token_hex(32) PERMANENT_SESSION_LIFETIME = timedelta(days = 7).total_seconds() @@ -55,6 +56,7 @@ class DevelopmentConfig(Config): DEBUG = True OIDC_ID_TOKEN_COOKIE_SECURE = False OIDC_REQUIRE_VERIFIED_EMAIL = False + USE_RELOADER = True class TestingConfig(Config): diff --git a/src/core/routes/Routes.py b/src/core/routes/Routes.py index f5e675a..4284a9d 100644 --- a/src/core/routes/Routes.py +++ b/src/core/routes/Routes.py @@ -124,7 +124,8 @@ def loadFavorite(_id): ID = int(_id) fave = db.session.query(Favorites).filter_by(id = ID).first() view = get_window_controller().get_window(1).get_view(0) - view.set_path(fave.link) + print(fave.link) + view.set_path_with_sub_path(fave.link) return '{"refresh": "true"}' except Exception as e: print(repr(e)) diff --git a/src/core/static/js/events.js b/src/core/static/js/events.js index b42b1ec..de003d1 100644 --- a/src/core/static/js/events.js +++ b/src/core/static/js/events.js @@ -21,7 +21,11 @@ document.body.onload = (eve) => { } - +const loadFavePath = (e) => { + const target = e.target; + const faveId = target.getAttribute("faveid"); + loadFavorite(faveId); +} const openFile = (eve) => { const target = eve.target; diff --git a/src/core/static/js/post-ajax.js b/src/core/static/js/post-ajax.js index b47255e..7f16887 100644 --- a/src/core/static/js/post-ajax.js +++ b/src/core/static/js/post-ajax.js @@ -8,8 +8,7 @@ const postAjaxController = (data, action) => { if (data.hasOwnProperty('path_head')) updateHTMLDirList(data); if (data.hasOwnProperty('faves_list')) - // generateFavesList(data.faves_list); - console.log("faves stub..."); + renderFavesList(data); if (data.hasOwnProperty("refresh")) { if (data.refresh == "true") { reloadDirectory(); @@ -18,31 +17,6 @@ const postAjaxController = (data, action) => { } -const generateFavesList = (data) => { - let listView = document.getElementById("faves-list"); - clearChildNodes(listView); - - data.forEach(faveArry => { - let fave = faveArry[0] - let faveId = faveArry[1] - let liTag = document.createElement("LI"); - let parts = (fave.includes("/")) ? fave.split("/") : fave.split("\\"); - - let part = parts[parts.length - 1] - if (part.toLowerCase().includes("season")) { - part = parts[parts.length - 2] + "/" + part - } - - let txtNode = document.createTextNode(part); - liTag.setAttribute("class", "btn btn-secondary btn-sm"); - liTag.setAttribute("name", fave); - liTag.setAttribute("title", fave); - liTag.setAttribute("onclick", "loadFave(" + faveId +")"); - liTag.appendChild(txtNode); - listView.appendChild(liTag); - }); -} - const updateHTMLDirList = async (data) => { let images = data.list.images[0]; diff --git a/src/core/static/js/react-ui-logic.js b/src/core/static/js/react-ui-logic.js index e18520b..1ffb972 100644 --- a/src/core/static/js/react-ui-logic.js +++ b/src/core/static/js/react-ui-logic.js @@ -30,10 +30,7 @@ const setFileIconType = (fileName) => { return [icoPath, ftype] } -// Create a ES6 class component class FilesList extends React.Component { - // Use the render function to return JSX component - constructor(props) { super(props); this.openThis = this.openThis.bind(this); @@ -102,6 +99,49 @@ class FilesList extends React.Component { } } + +class FavoritesList extends React.Component { + constructor(props) { + super(props); + this.loadFaveEvent = this.loadFaveEvent.bind(this); + } + + loadFaveEvent(e) { + e.preventDefault(); + loadFavePath(e); + } + + render() { + let final = []; + let faves = this.props.faves_list; + + for (let fave of faves) { + let title = fave[0] + let _faveId = fave[1] + let liTag = document.createElement("LI"); + let parts = (title.includes("/")) ? title.split("/") : title.split("\\"); + + let name = parts[parts.length - 1] + if (name.toLowerCase().includes("season")) { + name = name[name.length - 2] + "/" + name + } + + final.push( +
  • + {name} +
  • + ); + } + + return ( + + {final} + + ); + } +} + + const renderFilesList = (data = null) => { const filesListElm = document.getElementById('files'); ReactDOM.render( @@ -109,3 +149,11 @@ const renderFilesList = (data = null) => { filesListElm ) } + +const renderFavesList = (data = null) => { + const favesListElm = document.getElementById("faves-list"); + ReactDOM.render( + React.createElement(FavoritesList, data), + favesListElm + ) +} diff --git a/src/core/static/js/ui-logic.js b/src/core/static/js/ui-logic.js index 8366dc7..cf20bb9 100644 --- a/src/core/static/js/ui-logic.js +++ b/src/core/static/js/ui-logic.js @@ -1,6 +1,6 @@ const reloadDirectory = () => { - let target = document.getElementById('refresh-btn') - const hash = target.getAttribute("hash"); + const target = document.getElementById('refresh-btn'); + const hash = target.getAttribute("hash"); listFilesAjax(hash); } @@ -172,8 +172,6 @@ const disableEdit = (elm) => { const updateBackground = (srcLink, isvideo = true) => { try { let elm = document.getElementById("bg"); - - console.log(srcLink); if (isvideo) { if (elm.getAttribute('src') === "") { elm.src = srcLink; @@ -201,7 +199,7 @@ const manageFavorites = (elm) => { } -const loadFave = (id) => { +const loadFavorite = (id) => { loadFavoriteLink(id); document.getElementById("favorites-modal") .getElementsByClassName("modal-footer")[0] diff --git a/src/core/templates/layout.html b/src/core/templates/layout.html index 2bf8cf6..7c5f726 100644 --- a/src/core/templates/layout.html +++ b/src/core/templates/layout.html @@ -91,6 +91,13 @@ + + {% include "modals/options-modal.html" %} + {% include "modals/favorites-modal.html" %} + {% include "modals/file-modal.html" %} + + + {% block body_scripts %} diff --git a/src/core/templates/favorites-modal.html b/src/core/templates/modals/favorites-modal.html similarity index 97% rename from src/core/templates/favorites-modal.html rename to src/core/templates/modals/favorites-modal.html index 8a0595a..405edde 100644 --- a/src/core/templates/favorites-modal.html +++ b/src/core/templates/modals/favorites-modal.html @@ -1,5 +1,3 @@ -{% extends "pages/index.html" %} - {% block favorites_modal %} +{% endblock file_modal %} diff --git a/src/core/templates/options-modal.html b/src/core/templates/modals/options-modal.html similarity index 97% rename from src/core/templates/options-modal.html rename to src/core/templates/modals/options-modal.html index 9833809..9533872 100644 --- a/src/core/templates/options-modal.html +++ b/src/core/templates/modals/options-modal.html @@ -1,3 +1,4 @@ +{% block options_modal %} +{% endblock options_modal %} diff --git a/src/core/templates/pages/index.html b/src/core/templates/pages/index.html index df3a536..5185cce 100644 --- a/src/core/templates/pages/index.html +++ b/src/core/templates/pages/index.html @@ -27,7 +27,7 @@ {% block body_scripts_additional %} - + diff --git a/src/wsgi.py b/src/wsgi.py index 164776d..1bec6c6 100644 --- a/src/wsgi.py +++ b/src/wsgi.py @@ -11,4 +11,4 @@ eventlet.monkey_patch() from core import app if __name__ == '__main__': - app.run(debug=False) + app.run()