Added modal logic, fixed favorites logic

This commit is contained in:
maximstewart 2021-02-09 17:14:32 -06:00
parent e7d588691e
commit 781d2ece5a
13 changed files with 79 additions and 42 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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))

View File

@ -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;

View File

@ -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];

View File

@ -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(
<li onClick={this.loadFaveEvent} faveid={_faveId} class="btn btn-secondary btn-sm" name={name} title={name}>
{name}
</li>
);
}
return (
<React.Fragment>
{final}
</React.Fragment>
);
}
}
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
)
}

View File

@ -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]

View File

@ -91,6 +91,13 @@
</div>
{% include "modals/options-modal.html" %}
{% include "modals/favorites-modal.html" %}
{% include "modals/file-modal.html" %}
{% block body_scripts %}
<!-- For Bootstrap in this exact order... -->
<script src="{{ url_for('static', filename='js/libs/bootstrap/jquery-3.3.1.slim.min.js')}}"></script>

View File

@ -1,5 +1,3 @@
{% extends "pages/index.html" %}
{% block favorites_modal %}
<!-- Favorites modal -->
<div class="modal fade" id="favorites-modal" tabindex="-1" role="dialog">

View File

@ -1,3 +1,4 @@
{% block file_modal %}
<!-- File viewer modal -->
<div class="modal fade" id="file-view-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-xl" role="document">
@ -75,3 +76,4 @@
</div>
</div>
</div>
{% endblock file_modal %}

View File

@ -1,3 +1,4 @@
{% block options_modal %}
<!-- Other Options modal -->
<div class="modal fade" id="options-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-xl" role="document">
@ -40,3 +41,4 @@
</div>
</div>
</div>
{% endblock options_modal %}

View File

@ -27,7 +27,7 @@
{% block body_scripts_additional %}
<script type="text/babel" src="{{ url_for('static', filename='js/react-ui-logic.js')}}"></script>
<script type="text/jsx" src="{{ url_for('static', filename='js/react-ui-logic.js')}}"></script>
<script src="{{ url_for('static', filename='js/ui-logic.js')}}"></script>
<script src="{{ url_for('static', filename='js/post-ajax.js')}}"></script>
<script src="{{ url_for('static', filename='js/ajax.js')}}"></script>

View File

@ -11,4 +11,4 @@ eventlet.monkey_patch()
from core import app
if __name__ == '__main__':
app.run(debug=False)
app.run()