diff --git a/README.md b/README.md index 5009464..893c065 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# codimd_note_overview +# CodiMD note overview + +a searchable list of existing markdown files from CodiMD, i.e., [https://hackmd.wiai.de/](https://hackmd.wiai.de/), featuring sortable columns and fancy emojis where applicable. + + + +## Testing locally + + +Execute `docker build . --tag codimd; docker run -p 5000:5000 --env TESTING=True codimd` to run the app in testing mode locally. No database credentials are required for test + +### Open issues + +* make the layout responsive +* either read the DB credentials and URL from the environment or the config file +* load test data from a local file when run in testing mode +* add more/real testing data +* the up and down arrows in the table head fields are not invisible +* add more emojis ヘ( ^o^)ノ\(^_^ ) diff --git a/demo.jpg b/demo.jpg new file mode 100644 index 0000000..f5d8ca5 Binary files /dev/null and b/demo.jpg differ diff --git a/src/main.py b/src/main.py index fedd4c6..3859c6f 100644 --- a/src/main.py +++ b/src/main.py @@ -1,32 +1,31 @@ import psycopg2 - from flask import Flask, render_template - import os - from datetime import datetime -if os.environ.get('PRODUCTION'): - import config -else: - import config - app = Flask(__name__) app.debug = True -sql_statement = 'SELECT "id","title","alias","shortid","viewcount","lastchangeAt","permission","content" FROM "Notes" ORDER BY "lastchangeAt" DESC;' +SQL_FETCH_NOTES = 'SELECT "id","title","alias","shortid","viewcount","lastchangeAt","permission","content" FROM "Notes" ORDER BY "lastchangeAt" DESC;' + +# if the environment contains a variable TESTING that is set to "True" then run the application in testing mode +if os.environ.get('TESTING') == "True": + ENV_TESTING = True +else: + ENV_TESTING = False @app.route("/") def main(): - if os.environ.get('PRODUCTION'): - return production() - else: + if ENV_TESTING: return testing() + else: + return production() def production(): + import config DB_HOST = os.environ.get('DB_HOST') DB_NAME = os.environ.get('POSTGRES_DB') DB_USER = os.environ.get('POSTGRES_USER') @@ -36,7 +35,7 @@ def production(): conn = psycopg2.connect(host=DB_HOST, database=DB_NAME, user=DB_USER, password=DB_PASSWORD) cur = conn.cursor() - cur.execute(sql_statement) + cur.execute(SQL_FETCH_NOTES) notes = cur.fetchall() cur.close() conn.close() @@ -74,22 +73,10 @@ def testing(): 'permission': "freely" } - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) - notes_arr.append(x) + for _ in range(20): + notes_arr.append(x) - return render_template('index.html', notes=notes_arr, host=config.CODI_URL) + return render_template('index.html', notes=notes_arr, host="localhost") if __name__ == '__main__': diff --git a/src/static/css/main.css b/src/static/css/main.css deleted file mode 100644 index a5857e4..0000000 --- a/src/static/css/main.css +++ /dev/null @@ -1,16 +0,0 @@ -table.dataTable thead .sorting:after, -table.dataTable thead .sorting:before, -table.dataTable thead .sorting_asc:after, -table.dataTable thead .sorting_asc:before, -table.dataTable thead .sorting_asc_disabled:after, -table.dataTable thead .sorting_asc_disabled:before, -table.dataTable thead .sorting_desc:after, -table.dataTable thead .sorting_desc:before, -table.dataTable thead .sorting_desc_disabled:after, -table.dataTable thead .sorting_desc_disabled:before { - bottom: .5em; -} - -.dataTables_length, .dataTables_info, .dataTables_paginate { - visibility: hidden -} \ No newline at end of file diff --git a/src/static/css/style.css b/src/static/css/style.css new file mode 100644 index 0000000..119063a --- /dev/null +++ b/src/static/css/style.css @@ -0,0 +1,11 @@ + +/* Hide stuff from dataTables that we do not neeed */ +.dataTables_length, .dataTables_info, .dataTables_paginate { + visibility: hidden +} + +/* Add some spacing above and below the search field */ +.dataTables_filter { + padding-top: 10%; + padding-bottom: 10%; +} \ No newline at end of file diff --git a/src/static/js/script.js b/src/static/js/script.js new file mode 100644 index 0000000..f4788c7 --- /dev/null +++ b/src/static/js/script.js @@ -0,0 +1,7 @@ + +// make the table a dataTable and show all entries by default +$(document).ready(function () { + $('#example').DataTable({ + "lengthMenu": [[-1], ["All"]] + }); +}); diff --git a/src/static/js/sort.js b/src/static/js/sort.js deleted file mode 100644 index 0c70ffc..0000000 --- a/src/static/js/sort.js +++ /dev/null @@ -1,5 +0,0 @@ -$(document).ready(function () { - $('#example').DataTable({ - "lengthMenu": [[-1],["All"]] - }); -}); diff --git a/src/templates/index.html b/src/templates/index.html index 32d4b9e..ec1490b 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -3,24 +3,26 @@
-| {{note['shortid']}} | +{{note['shortid']}} | {{note['title']}} | {{note['alias']}} | {{note['lastchangeAt'].strftime('%d.%m.%Y %H:%M')}} | @@ -45,7 +47,6 @@ {% endfor %}