From 1443f47b5b4f43fdd25d951e8e0be353a20edede Mon Sep 17 00:00:00 2001 From: gorkemarslan Date: Thu, 13 Oct 2022 08:07:18 +0300 Subject: [PATCH 01/10] Add fields used thread template to models --- project/threads/models.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/project/threads/models.py b/project/threads/models.py index 219142dce..6d5711839 100644 --- a/project/threads/models.py +++ b/project/threads/models.py @@ -102,8 +102,8 @@ def image_url(self): # TODO: move this to utils is_draft = models.BooleanField(default=True) num_views = models.IntegerField(default=0) - num_civis = models.IntegerField(default=0) - num_solutions = models.IntegerField(default=0) + num_civis = models.IntegerField(default=0) # TODO To be dropped + num_solutions = models.IntegerField(default=0) # TODO To be dropped objects = ThreadManager() @@ -138,6 +138,15 @@ def solutions(self): return solution_list + @property + def contributors(self): + return get_user_model().objects.filter( + pk__in=self.civis.order_by("-created") + .values_list("author", flat=True) + .order_by("author") + .distinct() + ) + class CiviManager(models.Manager): def summarize(self, civi): @@ -208,6 +217,15 @@ def thread_sorted_by_score(self, civis_queryset, requested_user_id): queryset.all(), key=lambda c: c.score(requested_user_id), reverse=True ) + def problems(self, thread_id): + return self.filter(thread__id=thread_id, c_type="problem") + + def causes(self, thread_id): + return self.filter(thread__id=thread_id, c_type="cause") + + def solutions(self, thread_id): + return self.filter(thread__id=thread_id, c_type="solution") + class Civi(models.Model): objects = CiviManager() From b910e47f840171e8f6dcbf1de7283c9702e7a527 Mon Sep 17 00:00:00 2001 From: gorkemarslan Date: Thu, 13 Oct 2022 08:09:12 +0300 Subject: [PATCH 02/10] Create ThreadDetailView --- project/threads/urls/urls.py | 31 ++++++++++++++++--------------- project/threads/views.py | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/project/threads/urls/urls.py b/project/threads/urls/urls.py index ab823a2ed..90ddaf170 100644 --- a/project/threads/urls/urls.py +++ b/project/threads/urls/urls.py @@ -1,15 +1,16 @@ -from django.urls import path -from threads import views - - -urlpatterns = [ - path("thread//csv/", views.civi2csv, name="civi2csv"), - path("thread//", views.issue_thread, name="issue_thread"), - path("thread/", views.issue_thread, name="issue_thread"), - path("about/", views.AboutView.as_view(), name="about"), - path("support_us/", views.SupportUsView.as_view(), name="support_us"), - path("howitworks/", views.HowItWorksView.as_view(), name="how_it_works"), - path("declaration/", views.DeclarationView.as_view(), name="declaration"), - path("create-group/", views.create_group, name="create_group"), - path("", views.base_view, name="base"), -] +from django.urls import path +from threads import views + + +urlpatterns = [ + path("thread//csv/", views.civi2csv, name="civi2csv"), + path("thread//", views.issue_thread, name="issue_thread"), + path("thread//", views.ThreadDetailView.as_view(), name="thread-detail"), + path("thread/", views.issue_thread, name="issue_thread"), + path("about/", views.AboutView.as_view(), name="about"), + path("support_us/", views.SupportUsView.as_view(), name="support_us"), + path("howitworks/", views.HowItWorksView.as_view(), name="how_it_works"), + path("declaration/", views.DeclarationView.as_view(), name="declaration"), + path("create-group/", views.create_group, name="create_group"), + path("", views.base_view, name="base"), +] diff --git a/project/threads/views.py b/project/threads/views.py index 22c474780..7f57e9b8e 100644 --- a/project/threads/views.py +++ b/project/threads/views.py @@ -7,8 +7,10 @@ from django.db.models import F from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404 +from django.contrib.auth.mixins import LoginRequiredMixin from django.template.response import TemplateResponse from django.views.generic import TemplateView +from django.views.generic.detail import DetailView from django.views.decorators.csrf import csrf_exempt from rest_framework.decorators import action from rest_framework.response import Response @@ -25,6 +27,21 @@ ) +class ThreadDetailView(LoginRequiredMixin, DetailView): + model = Thread + context_object_name = "thread" + template_name = "thread_detail.html" + login_url = "accounts_login" + + def get_context_data(self, **kwargs): + context = super(ThreadDetailView, self).get_context_data(**kwargs) + context["categories"] = Category.objects.all() + context["problems"] = Civi.objects.problems(thread_id=context["thread"].id) + context["causes"] = Civi.objects.causes(thread_id=context["thread"].id) + context["solutions"] = Civi.objects.solutions(thread_id=context["thread"].id) + return context + + class ThreadViewSet(ModelViewSet): queryset = Thread.objects.order_by("-created") serializer_class = ThreadDetailSerializer From f34442161c126060c4a5c628a6d95992a5e6b61b Mon Sep 17 00:00:00 2001 From: gorkemarslan Date: Thu, 13 Oct 2022 08:11:57 +0300 Subject: [PATCH 03/10] Port thread to Django template syntax --- .../core/templates/static/less/thread.less | 9 + .../templates/threads/thread_details.html | 1087 +++++++++++++++++ 2 files changed, 1096 insertions(+) create mode 100644 project/threads/templates/threads/thread_details.html diff --git a/project/core/templates/static/less/thread.less b/project/core/templates/static/less/thread.less index d8b7703dc..68b0905f4 100644 --- a/project/core/templates/static/less/thread.less +++ b/project/core/templates/static/less/thread.less @@ -42,6 +42,10 @@ body { #thread { + .thread-wiki-holder { + display: none; + } + .thread-nav { background-color: transparent; border-bottom: 1px solid @dark-white; @@ -98,6 +102,11 @@ body { .title-item { width: 68%; } + + .thread-title:hover { + cursor: pointer; + } + .dropdown-wrapper { .dropdown-content { li { diff --git a/project/threads/templates/threads/thread_details.html b/project/threads/templates/threads/thread_details.html new file mode 100644 index 000000000..36cf70920 --- /dev/null +++ b/project/threads/templates/threads/thread_details.html @@ -0,0 +1,1087 @@ +{% extends "base.html" %} +{% load static %} +{% load i18n %} +{% block extra_css%} + + + +{% endblock extra_css %} +{% block content %} +{% include "global_nav.html" %} +
+
+ +
+
+
+
+ + + +
+
+
+ {% for civi in thread.civis.all %} +
+
+
+
{{ civi.c_type }}
+
+ {{ civi.title }} + + {% if civi.author.user.username == request.user.username %} +
+
+
+ + + + + + + + + + + + +
+
+ +
+ {% endif %} +
+
+
+
+ {% if civi.author.user.username == request.user.username %} + edit + delete_forever + + save + close + {% endif %} +
+
+
+
+
+ {{ civi.body }} + {% if civi.author.user.username == request.user.username %} +
+ +
+ {% endif %} +
+ {% if civi.linked_civis.count > 0 %} + + {% endif %} + {% if civi.images.count > 0 %} +
+
+ ATTACHMENTS ({{ civi.images.count }}) +
+ + {% for image in civi.images.all %} +
+ +
+ {% endfor %} +
+ {% endif %} + {% if thread.author.username == request.user.username %} +
+ + +
Images:
+
+ {% for image in civi.images.all %} +
+
+ clear +
+ + +
+ {% endfor %} +
+
+ +
+
Upload Images:
+
+
+ +
+ Add Images + +
+
+ +
+
+
+ + + +
+
+
+
+ {% endif %} + {% if not civi.thread.is_draft %} +
+
+
DISAGREE
+ +
+
+ +
+
+
NEUTRAL
+ +
+
+ +
+
+
AGREE
+ +
+
+
{{ civi.score|floatformat }}
+
+ {% endif %} +
+ +
+ {% endfor %} +
+
+
+
+
+
+
+ +
+
+
+
+ + +
{{ thread.civis.first.responses.first.title }}
+
+ +
+
+
+
+ + {% if thread.civi.responses %} +
+ {% else %} +
+
NO RESPONSES
+
+ {% endif %} +
+
+ +
+
+
+ + +
+
+
+ +
+{% endblock content %} +{% block extra_js %} + + + +{% endblock extra_js %} From 1baefb7bdfc58049ab7a96e43c80f3deaf50907b Mon Sep 17 00:00:00 2001 From: gorkemarslan Date: Thu, 13 Oct 2022 22:48:57 +0300 Subject: [PATCH 04/10] Add scrollbar --- project/core/templates/static/less/thread.less | 9 +++++++++ project/threads/templates/threads/thread_details.html | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/project/core/templates/static/less/thread.less b/project/core/templates/static/less/thread.less index 68b0905f4..39dfe01e2 100644 --- a/project/core/templates/static/less/thread.less +++ b/project/core/templates/static/less/thread.less @@ -46,6 +46,15 @@ body { display: none; } + .scrollbar{ + height: 95vh; + overflow-y: scroll; + } + + .force-overflow{ + min-height: 100vh; + } + .thread-nav { background-color: transparent; border-bottom: 1px solid @dark-white; diff --git a/project/threads/templates/threads/thread_details.html b/project/threads/templates/threads/thread_details.html index 36cf70920..56caeb101 100644 --- a/project/threads/templates/threads/thread_details.html +++ b/project/threads/templates/threads/thread_details.html @@ -519,8 +519,8 @@
-
-
+
+
{% for civi in thread.civis.all %}
From a8d74ba6550d8a2952c222698b72d05d64680dfd Mon Sep 17 00:00:00 2001 From: gorkemarslan Date: Thu, 13 Oct 2022 22:55:25 +0300 Subject: [PATCH 05/10] Fix votes --- project/threads/templates/threads/thread_details.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/project/threads/templates/threads/thread_details.html b/project/threads/templates/threads/thread_details.html index 56caeb101..ce10770de 100644 --- a/project/threads/templates/threads/thread_details.html +++ b/project/threads/templates/threads/thread_details.html @@ -614,7 +614,7 @@
{% for linked_civi in civi.linked_civis.all %} {% endfor %} @@ -734,18 +734,18 @@ class="rating-button vote vote_neutral" data-rating="neutral" > - {{ civi.votes.vote_neutral }} + {{ civi.votes.votes_neutral }}
AGREE
From 3bb50ff62c73debe9e0c9739dcb2565af4b5ba5b Mon Sep 17 00:00:00 2001 From: gorkemarslan Date: Thu, 13 Oct 2022 23:00:05 +0300 Subject: [PATCH 06/10] Fix issue outline --- .../core/templates/static/less/thread.less | 1 - .../templates/threads/thread_details.html | 40 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/project/core/templates/static/less/thread.less b/project/core/templates/static/less/thread.less index 39dfe01e2..cc51b9d06 100644 --- a/project/core/templates/static/less/thread.less +++ b/project/core/templates/static/less/thread.less @@ -586,7 +586,6 @@ body { .civi-nav-wrapper { margin: 0 0px 8px 16px; height: 100%; - display: none; .civi-nav-indiv { font-size: 14px; diff --git a/project/threads/templates/threads/thread_details.html b/project/threads/templates/threads/thread_details.html index ce10770de..615068d29 100644 --- a/project/threads/templates/threads/thread_details.html +++ b/project/threads/templates/threads/thread_details.html @@ -466,7 +466,7 @@ class="material-icons tiny civi-nav-state" id="civi-nav-state-{{ problem.id }}" > - @@ -487,7 +487,7 @@ class="material-icons tiny civi-nav-state" id="civi-nav-state-{{ cause.id }}" > - @@ -507,7 +507,7 @@ {% for solution in solutions %}
- @@ -522,7 +522,7 @@
{% for civi in thread.civis.all %} -
+
{{ civi.c_type }}
@@ -1043,11 +1043,16 @@ const civiCardElements = document.getElementsByClassName("civi-card") civiCardElements[0]?.classList?.add("current"); + let civiTypeIdArr = civiCardElements[0].id.split("-"); + document.getElementById(`civi-nav-${civiTypeIdArr[1]}-${civiTypeIdArr[2]}`).classList.add("current"); for(let i=0; i { document.getElementsByClassName("civi-card current")[0]?.classList?.remove("current"); + document.getElementsByClassName("civi-nav-link current")[0]?.classList?.remove("current"); civiCardElements[i].classList.add("current"); + let civiTypeIdArr = civiCardElements[i].id.split("-"); + document.getElementById(`civi-nav-${civiTypeIdArr[1]}-${civiTypeIdArr[2]}`).classList.add("current"); }) } @@ -1060,6 +1065,33 @@ document.getElementsByClassName("new-civi-card")[1].style.display = "block"; }); + document.getElementsByClassName("expand-nav")[0].addEventListener("click", () => { + if(document.getElementsByClassName("expand-nav")[0].classList.contains("expanded")){ + document.getElementsByClassName("expand-nav")[0].classList.remove("expanded") + document.getElementById("problem-nav").style.display = "none" + document.getElementById("cause-nav").style.display = "none" + document.getElementById("solution-nav").style.display = "none" + } else { + document.getElementsByClassName("expand-nav")[0].classList.add("expanded") + document.getElementById("problem-nav").style.display = "block" + document.getElementById("cause-nav").style.display = "block" + document.getElementById("solution-nav").style.display = "block" + } + }); + + const civiNavLinks = document.getElementsByClassName("civi-nav-link") + + for(let i=0; i { + location.href = '#' + civiNavLinks[i].id.replace('-nav', ''); + document.getElementsByClassName("civi-nav-link current")[0]?.classList?.remove("current"); + document.getElementsByClassName("civi-card current")[0]?.classList?.remove("current"); + civiNavLinks[i].classList.add("current"); + civiCardElements[i].classList.add("current"); + + }) + } + - - - - - - - - - - - - - - - +