From 55cc375aea236e73745505a6c84c1bba9824a3b9 Mon Sep 17 00:00:00 2001 From: iou1name Date: Mon, 24 Sep 2018 13:46:46 -0400 Subject: [PATCH] add 'next page' button to quest page --- quest/events.py | 7 +++++++ quest/jinja2/quest/quest.html | 5 +++++ quest/static/quest.css | 14 ++++++++++++++ quest/static/quest.js | 5 +++++ quest/views.py | 4 ++++ 5 files changed, 35 insertions(+) diff --git a/quest/events.py b/quest/events.py index d7d4447..0e5db02 100644 --- a/quest/events.py +++ b/quest/events.py @@ -13,6 +13,7 @@ import random import bleach from django.db import IntegrityError from django.utils.timezone import localtime +from django.urls import reverse from quest.models import * from quest.tools import handle_img @@ -420,6 +421,12 @@ def new_page(socket, data): ) p.save() + data = {} + data['page_num'] = p.page_num + data['title'] = title + data['url'] = reverse('quest:quest', args=[socket.quest_id, p.page_num]) + socket.send('new_page', data) + events = {} for obj in dir(): diff --git a/quest/jinja2/quest/quest.html b/quest/jinja2/quest/quest.html index c3eec58..764b365 100644 --- a/quest/jinja2/quest/quest.html +++ b/quest/jinja2/quest/quest.html @@ -148,6 +148,11 @@ {% endif %} + {% if page_num != pages.reverse()[0].page_num %} +
+ +
+ {% endif %}

Chat

diff --git a/quest/static/quest.css b/quest/static/quest.css index cfe7b30..555f7f8 100644 --- a/quest/static/quest.css +++ b/quest/static/quest.css @@ -96,6 +96,20 @@ h3 { width: 100%; } +#nextPageContainer { + width: 100%; + height: 5em; + padding: 1em; + box-sizing: border-box; + text-align: center; +} + +#nextPage { + height: 100%; + width: 100%; + box-sizing: border-box; +} + #chatPane { height: calc(100% - var(--header-height)); width: 30%; diff --git a/quest/static/quest.js b/quest/static/quest.js index d559d17..0452027 100644 --- a/quest/static/quest.js +++ b/quest/static/quest.js @@ -154,6 +154,11 @@ socket.events['vote'] = function(data) { socket.events['set_option_box'] = function(data) { document.getElementById('pollInput-' + data.option_id).checked = data.polarity; } +socket.events['new_page'] = function(data) { + if (page_num != data.page_num-1) { return; } + let html_str = '
'; + document.getElementById('questPane').innerHTML = document.getElementById('questPane').innerHTML + html_str; +} /* Websocket send */ function vote(post_id, option_id) { diff --git a/quest/views.py b/quest/views.py index 129d2cc..a208918 100644 --- a/quest/views.py +++ b/quest/views.py @@ -23,6 +23,10 @@ def quest(request, quest_id, page_num=1): pages = PageTitle.objects.filter(quest=quest).order_by('page_num') messages = quest.message_set.all() posts = quest.post_set.filter(page_num=page_num) + if posts.count() == 0: + page_num = pages.reverse()[0].page_num + return redirect('quest:quest', quest_id=quest.id, page_num=page_num) + # TODO: filter by page_num as well dice_rolls = DiceRoll.objects.filter(dicecall__post__quest=quest) poll_options = PollOption.objects.filter(poll__post__quest=quest) poll_votes = PollVote.objects.filter(option__poll__post__quest=quest)