From 6c72b2f7e0e3ba4c197df849a946f745819063a4 Mon Sep 17 00:00:00 2001 From: Brendan Lawton Date: Fri, 21 Jun 2024 11:09:14 +0200 Subject: [PATCH] db just checks cookie to see if voter voted. Buttons to show and hide results are removed. --- api-server/RunServer.py | 18 ++- sounding-board/src/views/SoundingBoard.vue | 139 ++++++++++++--------- 2 files changed, 87 insertions(+), 70 deletions(-) diff --git a/api-server/RunServer.py b/api-server/RunServer.py index a332693..4852526 100644 --- a/api-server/RunServer.py +++ b/api-server/RunServer.py @@ -86,7 +86,7 @@ def convertTuple(tup): # cur = con.cursor() # cur.execute("DROP TABLE votes") # cur.execute("DROP TABLE sessions") -# cur.execute("CREATE TABLE votes(oepnv, kiezbloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, ipAddr, cookie, sessionID, timestamp)") +# cur.execute("CREATE TABLE votes(oepnv, kiezbloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, cookie, sessionID, timestamp)") # cur.execute("CREATE TABLE sessions(sessionActive, sessionID, startTime, EndTime)") # cur.execute("DROP TABLE votes") @@ -173,14 +173,14 @@ def post_vote_to_db(): sessionID = int(convertTuple(cur.fetchone())) print(sessionID) - check_if_voter_exists = "SELECT * FROM votes WHERE cookie = ? AND ipAddr = ?" - cur.execute(check_if_voter_exists, (1, data['ipAddr'])) + check_if_voter_exists = "SELECT * FROM votes WHERE cookie = ?" + cur.execute(check_if_voter_exists, (data['cookie'],)) voter_exists = cur.fetchone() if (voter_exists != None): update_vote = """Update votes SET oepnv = ?, kiezBloecke = ?, fahrrad = ?, parkraum = ?, fahrenderAutoVerkehr = ?, drt= ?, sessionID = ?, timeStamp = ? - WHERE cookie = ? AND ipAddr = ?""" + WHERE cookie = ?""" cur.execute(update_vote, ( data['oepnv'], data['kiezBloecke'], @@ -190,8 +190,7 @@ def post_vote_to_db(): data['drt'], sessionID, data['timeStamp'], - 1, - data['ipAddr'])) + data['cookie'])) table_list = [a for a in cur.execute("SELECT * FROM votes ORDER BY ROWID ASC LIMIT 200")] print(table_list) @@ -202,9 +201,9 @@ def post_vote_to_db(): return jsonify({"message": "Vote received successfully"}), 200, {"Access-Control-Allow-Origin": "*"} else: - db_vote_insert = """INSERT INTO votes (oepnv, kiezBloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, ipAddr, cookie, sessionID, timeStamp) + db_vote_insert = """INSERT INTO votes (oepnv, kiezBloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, cookie, sessionID, timeStamp) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""" + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""" cur.execute(db_vote_insert, ( data['oepnv'], @@ -213,7 +212,6 @@ def post_vote_to_db(): data['parkraum'], data['fahrenderAutoVerkehr'], data['drt'], - data['ipAddr'], data['cookie'], sessionID, data['timeStamp'] @@ -241,7 +239,7 @@ def get_votes_from_db(session_id): # find_votes = "SELECT * FROM votes WHERE sessionID = ?" # cur.execute(find_votes, (session_id,)) # results = cur.fetchall() - votes = [{'oepnv': row[0], 'kiezBloecke': row[1], 'fahrrad': row[2], 'parkraum': row[3], 'fahrenderAutoVerkehr': row[4], 'drt': row[5], 'ipAddr': row[6], 'cookie': row[7], 'session_id': row[8], 'timeStamp': row[9]} for row in results] + votes = [{'oepnv': row[0], 'kiezBloecke': row[1], 'fahrrad': row[2], 'parkraum': row[3], 'fahrenderAutoVerkehr': row[4], 'drt': row[5], 'cookie': row[6], 'session_id': row[7], 'timeStamp': row[8]} for row in results] print(votes) # print(type(session_id)) # cur.execute("PRAGMA table_info(votes)") diff --git a/sounding-board/src/views/SoundingBoard.vue b/sounding-board/src/views/SoundingBoard.vue index 0cb2906..e179bca 100644 --- a/sounding-board/src/views/SoundingBoard.vue +++ b/sounding-board/src/views/SoundingBoard.vue @@ -52,10 +52,10 @@ .submit-vote-div .button.submit-button(@click="saveConditions") ✅ Stimme abgeben .voted-text(v-if="showVotedText") Sie haben abgestimmt. Wenn Sie nochmal abstimmen möchten, wird Ihre erste Stimme ersetzt. - .buttons - .button.reveal-button(@click="showResults") Ergebnisse anzeigen - .button.hide-button(@click="hideResults") Ergebnisse ausblenden - .error-text(v-if="!voted && resultsRequested") Sie müssen erstmal abstimmen + .vote-disclaimer *Wenn die Seite aktualisiert wird, bevor Sie Ihre Stimme abgeben, wählen Sie bitte Ihre Bedingungen erneut aus (auch wenn sie bereits gewählt sind) + //- .button.reveal-button(@click="showResults") Ergebnisse anzeigen + //- .button.hide-button(@click="hideResults") Ergebnisse ausblenden + //- .error-text(v-if="!voted && resultsRequested") Sie müssen erstmal abstimmen @@ -204,6 +204,8 @@ export default class VueComponent extends Vue { private serverURL = "https://vsp-lndw-sounding-board.fly.dev/" // private serverURL = "http://127.0.0.1:5000/" + + private badPage = false private lang = 'en' private mdParser = new MarkdownIt() @@ -234,8 +236,7 @@ export default class VueComponent extends Vue { parkraum: 'base', fahrenderAutoVerkehr: 'base', drt: 'base', - ipAddr: '', - cookie: false, + cookie: '', timeStamp: null, } @@ -675,52 +676,52 @@ export default class VueComponent extends Vue { return '' } - private showResults() { - this.resultsRequested = true - if (localStorage.getItem('LSvoted') == 'true' && this.resultsRequested == true) { - this.voted = true; - let results = Array.from( - document.getElementsByClassName('results') as HTMLCollectionOf - ) - results[0].style.display = 'flex' - if (window.innerWidth < 621) { - window.scrollTo({ - top: 2300, - behavior: 'smooth', - }) - } else if (window.innerWidth < 1200 && window.innerWidth > 620) { - window.scrollTo({ - top: 1300, - behavior: 'smooth', - }) - } else { - window.scrollTo({ - top: 1000, - behavior: 'smooth', - }) - } - } - } + // private showResults() { + // this.resultsRequested = true + // if (localStorage.getItem('LSvoted') == 'true' && this.resultsRequested == true) { + // this.voted = true; + // let results = Array.from( + // document.getElementsByClassName('results') as HTMLCollectionOf + // ) + // results[0].style.display = 'flex' + // if (window.innerWidth < 621) { + // window.scrollTo({ + // top: 2300, + // behavior: 'smooth', + // }) + // } else if (window.innerWidth < 1200 && window.innerWidth > 620) { + // window.scrollTo({ + // top: 1300, + // behavior: 'smooth', + // }) + // } else { + // window.scrollTo({ + // top: 1000, + // behavior: 'smooth', + // }) + // } + // } + // } - private hideResults() { - let results = Array.from( - document.getElementsByClassName('results') as HTMLCollectionOf - ) - results[0].style.display = 'none' - this.setPreset('base') - if (window.innerWidth < 621) { - window.scrollTo({ - top: 1800, - behavior: 'smooth', - }) - } else{ - window.scrollTo({ - top: 600, - behavior: 'smooth', - }) - } + // private hideResults() { + // let results = Array.from( + // document.getElementsByClassName('results') as HTMLCollectionOf + // ) + // results[0].style.display = 'none' + // this.setPreset('base') + // if (window.innerWidth < 621) { + // window.scrollTo({ + // top: 1800, + // behavior: 'smooth', + // }) + // } else{ + // window.scrollTo({ + // top: 600, + // behavior: 'smooth', + // }) + // } - } + // } private updateVoteConditions(factor: string, option: any) { if (factor == 'OePNV') this.voteConditions.oepnv = option @@ -743,14 +744,14 @@ export default class VueComponent extends Vue { } this.voteConditions.cookie = this.setCookie('hasVoted', true, 365) - fetch('https://api.ipify.org?format=json') - .then(x => x.json()) - .then(({ ip }) => { - this.voteConditions.ipAddr = ip - }) - .then(() => { - const vote = JSON.stringify(this.voteConditions) - }) + // fetch('https://api.ipify.org?format=json') + // .then(x => x.json()) + // .then(({ ip }) => { + // this.voteConditions.ipAddr = ip + // }) + // .then(() => { + // const vote = JSON.stringify(this.voteConditions) + // }) this.voteConditions.timeStamp = new Date().toLocaleString('de-DE'); @@ -791,7 +792,7 @@ export default class VueComponent extends Vue { expires = '; expires=' + date.toUTCString() } document.cookie = name + '=' + (value || '') + expires + '; path=/' - return value + return document.cookie } private addDescriptionToggle() { @@ -1030,7 +1031,7 @@ li.notes-item { .results { padding: 1rem 2rem 1rem 2rem; - display: none; + display: flex; width: 100%; } @@ -1196,6 +1197,24 @@ li.notes-item { white-space: normal; } +.vote-disclaimer +{ + font-weight: bold; + text-wrap: wrap; + max-width: 280px; + font-size: 11px; + line-height: 1.3; + margin-top: 10px; + margin-left: 10px; + word-wrap: break-word; + overflow-wrap: break-word; + word-break: break-word; + -webkit-hyphens: auto; + -ms-hyphens: auto; + hyphens: auto; + white-space: normal; +} + .submit-vote-div { display: flex; }