commit
c20702b299
4 changed files with 80 additions and 40 deletions
11
app/static/js/customThemes.js
Normal file
11
app/static/js/customThemes.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
function changeTheme() {
|
||||||
|
// Get the selected theme for the dropdown
|
||||||
|
var themes_select = document.getElementById("themes_select");
|
||||||
|
var selected_theme = themes_select.options[themes_select.selectedIndex].text;
|
||||||
|
|
||||||
|
// Update the theme cookie
|
||||||
|
document.cookie = "theme=" + escape(selected_theme) + "; Path=/;"
|
||||||
|
|
||||||
|
// Finally reload the page to let the new theme take effect
|
||||||
|
location.reload();
|
||||||
|
}
|
|
@ -32,6 +32,7 @@ Haldis - {{ active_page|capitalize }}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
<script type="text/javascript" src="{{ url_for('static', filename='js/theme.js') }}"></script>
|
<script type="text/javascript" src="{{ url_for('static', filename='js/theme.js') }}"></script>
|
||||||
<script type="text/javascript" src="{{ url_for('static', filename='js/timer.js') }}"></script>
|
<script type="text/javascript" src="{{ url_for('static', filename='js/timer.js') }}"></script>
|
||||||
|
<script type="text/javascript" src="{{ url_for('static', filename='js/customThemes.js') }}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block navbar %}
|
{% block navbar %}
|
||||||
|
|
|
@ -6,4 +6,13 @@
|
||||||
<h3>Themes</h3>
|
<h3>Themes</h3>
|
||||||
<p><a class="changeThemeButton" id="customTheme">enable custom themes</a></p>
|
<p><a class="changeThemeButton" id="customTheme">enable custom themes</a></p>
|
||||||
<p><a class="changePerformance" id="highPerformance">enable high performance</a></p>
|
<p><a class="changePerformance" id="highPerformance">enable high performance</a></p>
|
||||||
|
<p>
|
||||||
|
<!-- Style attribute due to missing css -->
|
||||||
|
<select name="themes" id="themes_select" onchange="changeTheme()" style="width: 300px;">
|
||||||
|
<option disabled selected value> -- select a theme -- </option>
|
||||||
|
{% for theme in themes_list %}
|
||||||
|
<option value="{{ theme.optid }}">{{ theme }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -5,7 +5,7 @@ from datetime import datetime, timedelta
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from flask import Flask, render_template, make_response
|
from flask import Flask, render_template, make_response
|
||||||
from flask import request
|
from flask import request, jsonify
|
||||||
from flask import Blueprint, abort
|
from flask import Blueprint, abort
|
||||||
from flask import current_app as app
|
from flask import current_app as app
|
||||||
from flask import send_from_directory, url_for
|
from flask import send_from_directory, url_for
|
||||||
|
@ -30,17 +30,8 @@ def home() -> str:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@general_bp.route("/css")
|
def get_css_dict(css_path):
|
||||||
def css():
|
themes_dict = dict()
|
||||||
"Generate the css"
|
|
||||||
if request.cookies.get('performance', '') == 'highPerformance':
|
|
||||||
cssPath = 'static/css/themes/highPerformance/'
|
|
||||||
else:
|
|
||||||
cssPath = 'static/css/themes/lowPerformance/'
|
|
||||||
|
|
||||||
cookie_theme = request.cookies.get('theme', '')
|
|
||||||
if cookie_theme == 'customTheme':
|
|
||||||
# Here seasonal themes will be returned; matching the current date.
|
|
||||||
|
|
||||||
# Open the YAML file with all the themes.
|
# Open the YAML file with all the themes.
|
||||||
path = os.path.join(app.root_path, "views/themes.yml")
|
path = os.path.join(app.root_path, "views/themes.yml")
|
||||||
|
@ -57,7 +48,7 @@ def css():
|
||||||
current_year = current_date.year
|
current_year = current_date.year
|
||||||
|
|
||||||
# Check each theme in the dictionary and return the first one that is "correct"
|
# Check each theme in the dictionary and return the first one that is "correct"
|
||||||
for theme in themes.values():
|
for key, theme in themes.items():
|
||||||
if theme['type'] == 'static-date':
|
if theme['type'] == 'static-date':
|
||||||
start_day, start_month = theme['start'].split('/')
|
start_day, start_month = theme['start'].split('/')
|
||||||
start_date = datetime(year=current_year, day=int(
|
start_date = datetime(year=current_year, day=int(
|
||||||
|
@ -70,15 +61,43 @@ def css():
|
||||||
year=current_year, day=int(end_day), month=int(end_month))
|
year=current_year, day=int(end_day), month=int(end_month))
|
||||||
|
|
||||||
if start_date <= current_date <= end_date:
|
if start_date <= current_date <= end_date:
|
||||||
path = os.path.join(app.root_path, cssPath, theme['file'])
|
path = os.path.join(app.root_path, css_path, theme['file'])
|
||||||
break
|
themes_dict[key] = path
|
||||||
elif cookie_theme == 'darkmode':
|
themes_dict['darkmode'] = os.path.join(
|
||||||
path = os.path.join(
|
|
||||||
app.root_path, "static/css/themes/lowPerformance/darkmode.css")
|
app.root_path, "static/css/themes/lowPerformance/darkmode.css")
|
||||||
else:
|
themes_dict['lightmode'] = os.path.join(
|
||||||
path = os.path.join(
|
|
||||||
app.root_path, "static/css/themes/lowPerformance/lightmode.css")
|
app.root_path, "static/css/themes/lowPerformance/lightmode.css")
|
||||||
|
|
||||||
|
return themes_dict
|
||||||
|
|
||||||
|
|
||||||
|
# @general_bp.route("/css-list")
|
||||||
|
def css_list():
|
||||||
|
if request.cookies.get('performance', '') == 'highPerformance':
|
||||||
|
css_path = 'static/css/themes/highPerformance/'
|
||||||
|
else:
|
||||||
|
css_path = 'static/css/themes/lowPerformance/'
|
||||||
|
return list(get_css_dict(css_path).keys())
|
||||||
|
|
||||||
|
|
||||||
|
@general_bp.route("/css")
|
||||||
|
def css():
|
||||||
|
"Generate the css"
|
||||||
|
if request.cookies.get('performance', '') == 'highPerformance':
|
||||||
|
css_path = 'static/css/themes/highPerformance/'
|
||||||
|
else:
|
||||||
|
css_path = 'static/css/themes/lowPerformance/'
|
||||||
|
|
||||||
|
cookie_theme = request.cookies.get('theme', '')
|
||||||
|
|
||||||
|
themes_dict = get_css_dict(css_path)
|
||||||
|
|
||||||
|
# TODO: Fix to work with default cookie value [customTheme]
|
||||||
|
if cookie_theme == "customTheme":
|
||||||
|
path = f"{css_path}ligtmode.css"
|
||||||
|
else:
|
||||||
|
path = themes_dict[cookie_theme]
|
||||||
|
|
||||||
f = open(path)
|
f = open(path)
|
||||||
response = make_response(f.read())
|
response = make_response(f.read())
|
||||||
response.headers['Content-Type'] = 'text/css'
|
response.headers['Content-Type'] = 'text/css'
|
||||||
|
@ -119,7 +138,7 @@ def about() -> str:
|
||||||
@login_required
|
@login_required
|
||||||
def profile() -> str:
|
def profile() -> str:
|
||||||
"Generate the profile view"
|
"Generate the profile view"
|
||||||
return render_template("profile.html")
|
return render_template("profile.html", themes_list=css_list())
|
||||||
|
|
||||||
|
|
||||||
@general_bp.route("/favicon.ico")
|
@general_bp.route("/favicon.ico")
|
||||||
|
|
Loading…
Reference in a new issue