Add general overall dashboard

master
Felix Stupp 3 years ago
parent cb0d5dae29
commit 0c1b82a9cd
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -11,7 +11,7 @@ import logging
import os
import random
from urllib.parse import urlencode, quote_plus
from typing import Any, Callable, Dict, Iterable, List, Optional, Union
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Union
from flask import Flask, jsonify, make_response, request, redirect
from flask.templating import render_template
@ -174,8 +174,33 @@ def timedelta(seconds: int) -> str:
@flask_app.route("/")
def hello_world():
return '<a href=/collection>Collections</a> & <a href=/media>Media</a>'
def dashboard():
# config
pinned_limit = 10
media_limit = 10
# for links from pinned collections
pinned_collections: Iterable[MediaCollection] = orm.select(m for m in MediaCollection if m.pinned and not m.ignored).order_by(MediaCollection.release_date, MediaCollection.title, MediaCollection.id)
links_from_pinned_collections: List[MediaCollectionLink] = list()
episodes_from_pinned_collections: Set[MediaElement] = set()
for coll in pinned_collections:
next_link = coll.next_episode
if next_link is not None and next_link.element not in episodes_from_pinned_collections and next_link.element.can_considered:
links_from_pinned_collections.append(next_link)
episodes_from_pinned_collections.add(next_link.element)
if len(links_from_pinned_collections) >= pinned_limit:
break
# for media
media_list: Iterable[MediaElement] = orm.select(m for m in MediaElement if not (m.ignored or m.watched)).order_by(orm.desc(MediaElement.release_date), MediaElement.id)
def get_considerable():
for element in media_list:
if element not in episodes_from_pinned_collections and element.can_considered:
yield element
# render
return render_template(
"dashboard.htm",
links_from_pinned_collections = links_from_pinned_collections,
media_list = common.limit_iter(get_considerable(), media_limit),
)
@flask_app.route("/collection")

@ -1,5 +1,6 @@
import itertools
import subprocess
from typing import Literal, Union
from typing import Iterable, List, Literal, TypeVar, Union
def call(args, check=True, stdin=None) -> subprocess.CompletedProcess:
proc = subprocess.run(args, capture_output=True, check=check, text=True, stdin=stdin)
@ -11,3 +12,8 @@ def update_bool_value(old_value: bool, new_value: Union[bool, Literal["toggle"]]
if type(new_value) != bool:
raise Exception(f"Invalid type of new_value: Expected bool or literal \"toggle\", got type={type(new_value)!r}, value={new_value!r}")
return new_value
T = TypeVar("T")
def limit_iter(iter: Iterable[T], limit: int) -> List[T]:
return list(itertools.islice(iter, limit))

@ -0,0 +1,23 @@
{% import "macros.htm" as macros %}
<!DOCTYPE html>
<html>
{% set title = "Dashboard" %}
<head>
<meta charset="utf-8"/>
<title>{{ title }}</title>
{{ macros.shared_style() }}
</head>
<body>
{{ macros.body_header() }}
<h1>{{ title }}</h1>
<h2>From Pinned Collections</h2>
{% if links_from_pinned_collections %}
{{ macros.link_differ_table(links_from_pinned_collections) }}
{% else %}
<i>No pinned collections with episodes to watch found!</i>
{% endif %}
<a href="/collection/pinned"></a>
<h2>Other Latest Videos</h2>
{{ macros.media_table(media_list) }}
</body>
</html>

@ -155,3 +155,35 @@
{% endfor %}
</table>
{%- endmacro %}
{% macro link_differ_table(link_list) %}
<table>
<tr>
<th>Date</th>
<th>To Watch</th>
<th>Actions</th>
<th>Title</th>
<th>From Collection</th>
</tr>
{% for link in link_list %}
<tr>
<td>
{{ link.element.release_date.strftime("%d.%m.%Y") }}
</td>
<td>
{{ link.element.left_length | timedelta }}
</td>
<td>
{{ media_element_buttons(link.element) }}
</td>
<td>
<a href="{{ link.element.info_link }}">{{ link.element.title }}</a>
</td>
<td>
<a href="{{ link.collection.info_link }}">{{ link.collection.id }}</a>
{{- link_position_marker(link, prefix=true) -}}
</td>
</tr>
{% endfor %}
</table>
{%- endmacro %}

Loading…
Cancel
Save