From 75d9f3aa69271970d7b8e5422780f062c4a98f01 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 2 Jan 2022 22:23:57 +0100 Subject: Added new blueprint for future stats and added a new bar chart in the history page. --- newspipe/templates/history.html | 134 +++++++++++++++++++++++++++++++++------- newspipe/web/views/__init__.py | 2 + newspipe/web/views/article.py | 7 ++- newspipe/web/views/stats.py | 18 ++++++ package-lock.json | 12 ++++ package.json | 1 + runserver.py | 1 + 7 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 newspipe/web/views/stats.py diff --git a/newspipe/templates/history.html b/newspipe/templates/history.html index 0638993c..35712ca3 100644 --- a/newspipe/templates/history.html +++ b/newspipe/templates/history.html @@ -1,26 +1,118 @@ {% extends "layout.html" %} +{% block head %} +{{ super() }} + + +{% endblock %} {% block content %}
-

{{ _('History') }}

- {% if month != None %} -

{{ year }}

-

{{ month | month_name }}

- {% elif year != None %} -

 {{ _('all years') }}

-

{{ year }}

- {% endif %} - +

{{ _('History') }}

+ + {% if month != None %} +

{{ year }}

+

{{ month | month_name }}

+ {% elif year != None %} +

 {{ _('all years') }}

+

{{ year }}

+ {% endif %} + + {% if month == None %} +
+
+ +
+
+ {% endif %} + + {% if year != None and month != None %} +
+
+
    + {% for date in articles_counter | sort(reverse = True) %} + {% for article in articles %} +
  • {{ article.date | datetime }} - {{ article.title | safe }}
  • + {% endfor %} + {% endfor %} +
+
+
+ {% endif %}
+ {% endblock %} diff --git a/newspipe/web/views/__init__.py b/newspipe/web/views/__init__.py index 950cb5b6..bfd25e4e 100644 --- a/newspipe/web/views/__init__.py +++ b/newspipe/web/views/__init__.py @@ -7,6 +7,7 @@ from newspipe.web.views.category import categories_bp, category_bp from newspipe.web.views.feed import feed_bp, feeds_bp from newspipe.web.views.icon import icon_bp from newspipe.web.views.user import user_bp +from newspipe.web.views.stats import stats_bp __all__ = [ "home", @@ -24,4 +25,5 @@ __all__ = [ "feeds_bp", "icon_bp", "user_bp", + "stats_bp" ] diff --git a/newspipe/web/views/article.py b/newspipe/web/views/article.py index a7d4fa93..a59722e0 100644 --- a/newspipe/web/views/article.py +++ b/newspipe/web/views/article.py @@ -94,9 +94,12 @@ def delete(article_id=None): @articles_bp.route("/history//", methods=["GET"]) @login_required def history(year=None, month=None): - cntr, artcles = ArticleController(current_user.id).get_history(year, month) + if month is not None: + cntr, articles = ArticleController(current_user.id).get_history(year, month) + else: + cntr, articles = {}, [] return render_template( - "history.html", articles_counter=cntr, articles=artcles, year=year, month=month + "history.html", articles_counter=cntr, articles=articles, year=year, month=month ) diff --git a/newspipe/web/views/stats.py b/newspipe/web/views/stats.py new file mode 100644 index 00000000..d890524c --- /dev/null +++ b/newspipe/web/views/stats.py @@ -0,0 +1,18 @@ + +from flask import ( + Blueprint, + jsonify +) +from newspipe.controllers import ArticleController +from flask_login import current_user, login_required + +stats_bp = Blueprint("stats", __name__, url_prefix="/stats") + + +@stats_bp.route("/history.json", methods=["GET"]) +@stats_bp.route("/history.json/", methods=["GET"]) +@stats_bp.route("/history.json//", methods=["GET"]) +@login_required +def history(year=None, month=None): + cntr, _ = ArticleController(current_user.id).get_history(year, month) + return jsonify(cntr) diff --git a/package-lock.json b/package-lock.json index bdb25d35..921a32a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "newspipe", "version": "9.1.0", "hasInstallScript": true, "license": "AGPL-3.0", @@ -12,6 +13,7 @@ "@popperjs/core": "^2.11.0", "bootstrap": "^5.1.3", "bootstrap-select": "^1.14.0-beta2", + "chart.js": "^3.7.0", "fork-awesome": "^1.2.0", "moment": "^2.29.1" }, @@ -49,6 +51,11 @@ "jquery": "1.9.1 - 3" } }, + "node_modules/chart.js": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-3.7.0.tgz", + "integrity": "sha512-31gVuqqKp3lDIFmzpKIrBeum4OpZsQjSIAqlOpgjosHDJZlULtvwLEZKtEhIAZc7JMPaHlYMys40Qy9Mf+1AAg==" + }, "node_modules/fork-awesome": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/fork-awesome/-/fork-awesome-1.2.0.tgz", @@ -90,6 +97,11 @@ "integrity": "sha512-Q63QUbConUwA+/Te7tCJcv0nE3SI/J+rNI5A1mdX1KxP6lW0pFQy+4KVP6VwgZEcwkoPfrwjvAo6WT7fdl+Sdg==", "requires": {} }, + "chart.js": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-3.7.0.tgz", + "integrity": "sha512-31gVuqqKp3lDIFmzpKIrBeum4OpZsQjSIAqlOpgjosHDJZlULtvwLEZKtEhIAZc7JMPaHlYMys40Qy9Mf+1AAg==" + }, "fork-awesome": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/fork-awesome/-/fork-awesome-1.2.0.tgz", diff --git a/package.json b/package.json index 568fe391..b0ff38f0 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@popperjs/core": "^2.11.0", "bootstrap": "^5.1.3", "bootstrap-select": "^1.14.0-beta2", + "chart.js": "^3.7.0", "fork-awesome": "^1.2.0", "moment": "^2.29.1" }, diff --git a/runserver.py b/runserver.py index 89b8f553..32e5e8e7 100755 --- a/runserver.py +++ b/runserver.py @@ -49,6 +49,7 @@ with application.app_context(): application.register_blueprint(views.user_bp) application.register_blueprint(views.bookmarks_bp) application.register_blueprint(views.bookmark_bp) + application.register_blueprint(views.stats_bp) register_commands(application) -- cgit