From bdd983bcd54fe800868f6c62fb632899f281f767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20G=C3=B6tz?= Date: Mon, 28 Jan 2019 17:53:26 +0100 Subject: [PATCH] Update env vars --- docker-compose.yml | 2 ++ src/main.py | 21 +++++++++++++++--- src/static/css/main.css | 47 ++++++++++++++++++++++++++++++++++++++++ src/static/js/sort.js | 10 ++++----- src/templates/index.html | 26 ++++++++++++---------- 5 files changed, 86 insertions(+), 20 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f0be0fe..e5ccdb9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,3 +12,5 @@ services: - 8080:5000 networks: - db_net + env_file: + - /home/michigg/Nextcloud/Documents/OFU_Fachschaft/Server/hackmd_overview_addon/hackmd/docker.env diff --git a/src/main.py b/src/main.py index 7316e26..98dbbfd 100644 --- a/src/main.py +++ b/src/main.py @@ -1,23 +1,38 @@ import psycopg2 import config from flask import Flask, render_template +from pprint import pprint +import os app = Flask(__name__) app.debug = True -sql_statement = 'SELECT "id","title","alias","shortid","viewcount","lastchangeAt" FROM "Notes" ORDER BY "lastchangeAt" DESC;' +sql_statement = 'SELECT "id","title","alias","shortid","viewcount","lastchangeAt","permission","content" FROM "Notes" ORDER BY "lastchangeAt" DESC;' @app.route("/") def main(): + DB_HOST = os.environ.get('DB_HOST') + DB_NAME = os.environ.get('POSTGRES_DB') + DB_USER = os.environ.get('POSTGRES_USER') + DB_PASSWORD = os.environ.get('POSTGRES_PASSWORD') + try: - conn = psycopg2.connect(host=config.DB_HOST, database=config.DB_Name, user=config.DB_USER, password=config.DB_PASSWORD) + conn = psycopg2.connect(host=DB_HOST, database=DB_NAME, user=DB_USER, + password=DB_PASSWORD) cur = conn.cursor() cur.execute(sql_statement) notes = cur.fetchall() + pprint(notes) + print("NOTES LEN", len(notes)) cur.close() conn.close() - return render_template('index.html', notes=notes, host=config.CODI_URL) + notes_arr = [] + for note in notes: + notes_arr.append( + {'id': note[0], 'title': note[1], 'alias': note[2], 'shortid': note[3], 'viewcount': note[4], + 'lastchangeAt': note[5], 'permission': note[6], 'content': note[7]}) + return render_template('index.html', notes=notes_arr, host=config.CODI_URL) except Exception as e: return render_template('index.html') diff --git a/src/static/css/main.css b/src/static/css/main.css index e69de29..3825489 100644 --- a/src/static/css/main.css +++ b/src/static/css/main.css @@ -0,0 +1,47 @@ +/*.extra-content {*/ +/*display: none;*/ +/*text-decoration: none !important;*/ +/*color: #0b2e13;*/ +/*}*/ + +/*.sortable a {*/ +/*display: inline-block;*/ +/*}*/ + +/*.sortable a:hover .extra-content {*/ +/*display: block;*/ +/*text-decoration: none !important;*/ +/*}*/ + +/*.sortable a:hover .extra-content p {*/ +/*display: block;*/ +/*text-decoration: none !important;*/ +/*}*/ + +.fancy-tooltip { + position: relative; + display: inline-block; +} + +.fancy-tooltip .tooltiptext { + visibility: hidden; + width: 300px; + background-color: #555; + color: #fff; + text-align: center; + border-radius: 6px; + padding: 5px 0; + position: absolute; + z-index: 1; + bottom: -170%; + left: 50%; + margin-left: -60px; + opacity: 0; + transition: opacity 0.3s; + line-height: 1em; +} + +.fancy-tooltip:hover .tooltiptext { + visibility: visible; + opacity: 1; +} \ No newline at end of file diff --git a/src/static/js/sort.js b/src/static/js/sort.js index 41703d7..4dab712 100644 --- a/src/static/js/sort.js +++ b/src/static/js/sort.js @@ -17,8 +17,8 @@ function convertToArray() { function sortByTitle() { var sort_by_title = function (a, b) { - let x = a.getElementsByClassName('card-title')[0]; - let y = b.getElementsByClassName('card-title')[0]; + let x = a.getElementsByClassName('note-title')[0]; + let y = b.getElementsByClassName('note-title')[0]; return x.innerHTML.toLowerCase().localeCompare(y.innerHTML.toLowerCase()); }; @@ -30,8 +30,8 @@ function sortByTitle() { function sortByDate() { console.log('Sort Date'); var sort_by_date = function (a, b) { - a = a.getElementsByClassName('date')[0]; - b = b.getElementsByClassName('date')[0]; + a = a.getElementsByClassName('note-date')[0]; + b = b.getElementsByClassName('note-date')[0]; if (a && b) { a = a.innerHTML.split(' '); let a_date = a[0].split('.'); @@ -58,4 +58,4 @@ function sortByDate() { var notesArr = convertToArray(); notesArr.sort(sort_by_date); updateParent(notesArr); -} \ No newline at end of file +} diff --git a/src/templates/index.html b/src/templates/index.html index 9f34de1..c6da70a 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -4,6 +4,7 @@ CodiMD Notes + @@ -21,21 +22,22 @@
{% for note in notes %} - {% if note[1] and note[2] %} -