Skip to content

Commit

Permalink
web ui reports version with config
Browse files Browse the repository at this point in the history
cli reports version
bugfix for date picker
  • Loading branch information
iandennismiller committed Jul 1, 2023
1 parent ff9f571 commit d594845
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 25 deletions.
8 changes: 8 additions & 0 deletions src/gthnk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from trogon import tui

from . import Gthnk
from .__meta__ import __version__
from .model.journal import Journal
from .filetree.buffer import FileBuffer

Expand All @@ -13,6 +14,13 @@
def cli():
"Gthnk: a journaling tool"


@cli.command()
def version():
"Print the version of Gthnk"
print(f"Gthnk {__version__}")


@cli.command()
@click.option('--current', is_flag=True, default=False, help="Print the current configuration")
@click.argument('gthnk_path', default="/tmp/gthnk", required=False)
Expand Down
8 changes: 7 additions & 1 deletion src/gthnk_web/home/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import datetime
import flask

from gthnk.__meta__ import __version__
from ..app import gthnk


home = flask.Blueprint(
'home',
__name__,
Expand All @@ -14,7 +18,9 @@
def config_view():
"Render the config page."
return flask.render_template('config.html.j2',
configuration=flask.current_app.config
configuration=flask.current_app.config,
version=__version__,
num_journal_days=len(gthnk.journal),
)

@home.route('/')
Expand Down
12 changes: 10 additions & 2 deletions src/gthnk_web/home/templates/config.html.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% extends 'base.html.j2' %}

{% from "_formhelpers.html.j2" import render_field_nodiv %}

{% set current_page = 'config-view' %}

{% block content %}
Expand All @@ -15,6 +13,11 @@

<div class="gthnk-card" id="entries">
<style type="text/css">.key { display: inline-block; width: 12em; }</style>
<p>
<span class="key">Version</span>
<span class="value">{{ version }}</span>
</p>

<p>
<span class="key">Input Files</span>
<span class="value">{{ configuration['INPUT_FILES'] }}</span>
Expand All @@ -30,6 +33,11 @@
<span class="value">{{ configuration['BASE_URL'] }}</span>
</p>

<p>
<span class="key">Number of Days in Journal</span>
<span class="value">{{ num_journal_days }}</span>
</p>

</div>
</div>
<div class="col-xl-1"></div>
Expand Down
7 changes: 5 additions & 2 deletions src/gthnk_web/journal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
@journal.route("nearest/<date>")
def nearest_day(date):
"Redirect to the nearest day."
datestamp = str(datetime.datetime.strptime(date, "%Y-%m-%d").date())
day = gthnk.journal.get_nearest_day(datestamp)
try:
datestamp = str(datetime.datetime.strptime(date, "%Y-%m-%d").date())
except ValueError:
return flask.redirect(flask.url_for('.latest'))

day = gthnk.journal.get_nearest_day(datestamp)
if day:
return flask.redirect(flask.url_for('.day_view', date=day.datestamp))
return flask.redirect(flask.url_for('.latest'))
Expand Down
1 change: 1 addition & 0 deletions src/gthnk_web/journal/static/dynamic-day.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function update_day(date_str) {
stop_checking_status();
}

update_calendar();
window.history.pushState({}, date_str, url="/journal/" + date_str + ".html");
}

Expand Down
43 changes: 24 additions & 19 deletions src/gthnk_web/root/static/gthnk.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@ $('.toast').toast('show');
// 1.3.15
// https://github.com/dangrossman/bootstrap-daterangepicker/tree/0d7f4f26618e09ba6d2488a7e42273fd2fb07ae7

if (typeof(today) == 'undefined') {
var picker_date = new Date();
}
else {
var picker_date = moment(today); // set this value in the html body, within script tags
}

$('a#calendar_button').daterangepicker(
{
"format": 'YYYY-MM-DD',
"singleDatePicker": true,
"showDropdowns": true,
"autoApply": true,
"opens": "left",
"startDate": picker_date
},
function(start, end, label) {
window.location = "/journal/nearest/" + start.format('YYYY-MM-DD');
function update_calendar() {
if (typeof(today) == 'undefined') {
var picker_date = new Date();
}
);
else {
var picker_date = moment(today); // set this value in the html body, within script tags
}

$('a#calendar_button').daterangepicker(
{
"format": 'YYYY-MM-DD',
"singleDatePicker": true,
"showDropdowns": true,
"autoApply": true,
"opens": "left",
"startDate": picker_date
},
function(start, end, label) {
window.location = "/journal/nearest/" + start.format('YYYY-MM-DD');
}
);
}

/**********
* dark mode
Expand Down Expand Up @@ -56,3 +58,6 @@ var toggle_darkmode = function() {

// run immediately to prevent flicker
set_darkmode(localStorage.getItem("dark-mode"));

// run to set date
update_calendar();
2 changes: 1 addition & 1 deletion src/gthnk_web/root/templates/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{% endif -%}

<li class="nav-item">
<a class="nav-link" href="{{ url_for('journal.latest') }}" title="configuration"><i class="fas fa-book"></i></a>
<a class="nav-link" href="{{ url_for('journal.latest') }}" title="latest day"><i class="fas fa-book"></i></a>
</li>

<li class="nav-item">
Expand Down

0 comments on commit d594845

Please sign in to comment.