Commit 5f472d6bb35a4a4cd61c9c7127f80da1b9a0b6a9

Authored by Zambom
1 parent 91e85324

Adding mural post notifications badge

amadeus/context_processors.py
@@ -2,6 +2,7 @@ from datetime import datetime @@ -2,6 +2,7 @@ from datetime import datetime
2 2
3 from themes.models import Themes 3 from themes.models import Themes
4 from notifications.models import Notification 4 from notifications.models import Notification
  5 +from mural.models import MuralVisualizations
5 6
6 def theme(request): 7 def theme(request):
7 context = {} 8 context = {}
@@ -22,4 +23,16 @@ def notifies(request): @@ -22,4 +23,16 @@ def notifies(request):
22 23
23 context['notifications_count'] = notifications 24 context['notifications_count'] = notifications
24 25
  26 + return context
  27 +
  28 +def mural_notifies(request):
  29 + context = {}
  30 +
  31 + notifications = 0
  32 +
  33 + if request.user.is_authenticated:
  34 + notifications = MuralVisualizations.objects.filter(viewed = False, user = request.user).count()
  35 +
  36 + context['mural_notifications_count'] = notifications
  37 +
25 return context 38 return context
26 \ No newline at end of file 39 \ No newline at end of file
amadeus/settings.py
@@ -109,6 +109,7 @@ TEMPLATES = [ @@ -109,6 +109,7 @@ TEMPLATES = [
109 'django.contrib.messages.context_processors.messages', 109 'django.contrib.messages.context_processors.messages',
110 'amadeus.context_processors.theme', 110 'amadeus.context_processors.theme',
111 'amadeus.context_processors.notifies', 111 'amadeus.context_processors.notifies',
  112 + 'amadeus.context_processors.mural_notifies',
112 ], 113 ],
113 }, 114 },
114 }, 115 },
amadeus/static/css/base/amadeus.css
@@ -1043,7 +1043,7 @@ li.item .notify_badge { @@ -1043,7 +1043,7 @@ li.item .notify_badge {
1043 padding: 10px 0px 8px 0px; 1043 padding: 10px 0px 8px 0px;
1044 } 1044 }
1045 1045
1046 -.post .post-comment .user-img { 1046 +.post .post-comment .user-img div {
1047 display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */ 1047 display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
1048 display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */ 1048 display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */
1049 display: -ms-flexbox; /* TWEENER - IE 10 */ 1049 display: -ms-flexbox; /* TWEENER - IE 10 */
amadeus/static/css/base/amadeus_responsive.css
1 @media(min-width: 1200px) { 1 @media(min-width: 1200px) {
2 - .mural .post_make .user-img { 2 + .mural .post_make .user-img, .post .post-img {
3 height: 70px; 3 height: 70px;
4 } 4 }
5 5
  6 + .post .post-comment .user-img div {
  7 + height: 38px;
  8 + }
  9 +
6 .mural .post_make .user-img img { 10 .mural .post_make .user-img img {
7 max-width: 70px; 11 max-width: 70px;
8 max-height: 70px; 12 max-height: 70px;
@@ -18,10 +22,14 @@ @@ -18,10 +22,14 @@
18 padding: 15px; 22 padding: 15px;
19 } 23 }
20 24
21 - .mural .post_make .user-img { 25 + .mural .post_make .user-img, .post .post-img {
22 height: 65px; 26 height: 65px;
23 } 27 }
24 28
  29 + .post .post-comment .user-img div {
  30 + height: 38px;
  31 + }
  32 +
25 .mural .post_make .user-img img { 33 .mural .post_make .user-img img {
26 max-width: 65px; 34 max-width: 65px;
27 max-height: 65px; 35 max-height: 65px;
@@ -87,7 +95,7 @@ @@ -87,7 +95,7 @@
87 display:none; 95 display:none;
88 } 96 }
89 97
90 - .mural .post_make .user-img { 98 + .mural .post_make .user-img, .post .post-img {
91 height: 60px; 99 height: 60px;
92 } 100 }
93 101
@@ -161,7 +169,7 @@ @@ -161,7 +169,7 @@
161 } 169 }
162 170
163 @media(max-width: 680px) { 171 @media(max-width: 680px) {
164 - .mural .post_make .user-img { 172 + .mural .post_make .user-img, .post .post-img {
165 height: 50px; 173 height: 50px;
166 } 174 }
167 175
amadeus/static/css/themes/green.css
@@ -496,7 +496,7 @@ a.add-row { @@ -496,7 +496,7 @@ a.add-row {
496 background: #FFFFFF; 496 background: #FFFFFF;
497 } 497 }
498 498
499 -.mural .post_make .user-img { 499 +.mural .post_make .user-img, .post .post-img, .post .post-comment .user-img div {
500 background: #CCCCCC; 500 background: #CCCCCC;
501 } 501 }
502 502
amadeus/static/js/socket.js
@@ -15,6 +15,22 @@ socket.onmessage = function(e) { @@ -15,6 +15,22 @@ socket.onmessage = function(e) {
15 $('.posts').prepend(content.complete); 15 $('.posts').prepend(content.complete);
16 16
17 $('.no-subjects').attr('style', 'display:none'); 17 $('.no-subjects').attr('style', 'display:none');
  18 + } else {
  19 + $('.mural_badge').each(function () {
  20 + var actual = $(this).text();
  21 +
  22 + if (actual != "+99") {
  23 + actual = parseInt(actual, 10) + 1;
  24 +
  25 + if (actual > 99) {
  26 + actual = "+99";
  27 + }
  28 +
  29 + $(this).text(actual);
  30 + }
  31 +
  32 + $(this).show();
  33 + });
18 } 34 }
19 35
20 if (("Notification" in window)) { 36 if (("Notification" in window)) {
amadeus/templates/base.html
@@ -190,9 +190,10 @@ @@ -190,9 +190,10 @@
190 <i class="fa fa-graduation-cap" aria-hidden="true"></i> 190 <i class="fa fa-graduation-cap" aria-hidden="true"></i>
191 </a> 191 </a>
192 </li> 192 </li>
193 - <li class="item {{ mural_menu_active }}" data-toggle="tooltip" data-placement="right" title="{% trans "Timeline" %}"> 193 + <li class="item {{ mural_menu_active }} action_icon" data-toggle="tooltip" data-placement="right" title="{% trans "Timeline" %}">
194 <a href="{% url 'mural:manage_general' %}"> 194 <a href="{% url 'mural:manage_general' %}">
195 <i class="fa fa-list" aria-hidden="true" ></i> 195 <i class="fa fa-list" aria-hidden="true" ></i>
  196 + <span class="badge notify_badge mural_badge" {% if mural_notifications_count == 0 %} style="display:none" {% endif %}>{% if mural_notifications_count > 99 %} +99 {% else %} {{ mural_notifications_count }} {% endif %}</span>
196 </a> 197 </a>
197 </li> 198 </li>
198 <li class="item" data-toggle="tooltip" data-placement="right" title="{% trans "Messages" %}"> 199 <li class="item" data-toggle="tooltip" data-placement="right" title="{% trans "Messages" %}">
@@ -241,9 +242,10 @@ @@ -241,9 +242,10 @@
241 <i class="fa fa-graduation-cap" aria-hidden="true"></i> 242 <i class="fa fa-graduation-cap" aria-hidden="true"></i>
242 </a> 243 </a>
243 </li> 244 </li>
244 - <li class="item {{ mural_menu_active }}" data-toggle="tooltip" data-placement="top" title="{% trans "Timeline" %}"> 245 + <li class="item {{ mural_menu_active }} action_icon" data-toggle="tooltip" data-placement="top" title="{% trans "Timeline" %}">
245 <a href="{% url 'mural:manage_general' %}" 246 <a href="{% url 'mural:manage_general' %}"
246 <i class="fa fa-list" aria-hidden="true" ></i> 247 <i class="fa fa-list" aria-hidden="true" ></i>
  248 + <span class="badge notify_badge mural_badge" {% if mural_notifications_count == 0 %} style="display:none" {% endif %}>{% if mural_notifications_count > 99 %} +99 {% else %} {{ mural_notifications_count }} {% endif %}</span>
247 </a> 249 </a>
248 </li> 250 </li>
249 <li class="item" data-toggle="tooltip" data-placement="top" title="{% trans "Messages" %}"> 251 <li class="item" data-toggle="tooltip" data-placement="top" title="{% trans "Messages" %}">
mural/templates/mural/_view.html
@@ -45,7 +45,9 @@ @@ -45,7 +45,9 @@
45 </div> 45 </div>
46 <div class="col-md-12 post-comment"> 46 <div class="col-md-12 post-comment">
47 <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 user-img"> 47 <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 user-img">
48 - <img src="{{ request.user.image_url }}" class="img-responsive" /> 48 + <div>
  49 + <img src="{{ request.user.image_url }}" class="img-responsive" />
  50 + </div>
49 </div> 51 </div>
50 <div class="col-lg-11 col-md-11 col-sm-11 col-xs-11 comment-field"> 52 <div class="col-lg-11 col-md-11 col-sm-11 col-xs-11 comment-field">
51 <div> 53 <div>
mural/views.py
@@ -33,10 +33,14 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView): @@ -33,10 +33,14 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView):
33 33
34 general = GeneralPost.objects.extra(select={"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_generalpost.mural_ptr_id))"}).order_by("-most_recent") 34 general = GeneralPost.objects.extra(select={"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_generalpost.mural_ptr_id))"}).order_by("-most_recent")
35 35
36 - self.totals['general'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__generalpost__isnull = False) | Q(comment__post__generalpost__isnull = False))).distinct().count() 36 + general_visualizations = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__generalpost__isnull = False) | Q(comment__post__generalpost__isnull = False))).distinct()
  37 +
  38 + self.totals['general'] = general_visualizations.count()
37 self.totals['category'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__categorypost__space__coordinators = user) | Q(comment__post__categorypost__space__coordinators = user) | Q(post__categorypost__space__subject_category__professor = user) | Q(post__categorypost__space__subject_category__students = user) | Q(comment__post__categorypost__space__subject_category__professor = user) | Q(comment__post__categorypost__space__subject_category__students = user))).distinct().count() 39 self.totals['category'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__categorypost__space__coordinators = user) | Q(comment__post__categorypost__space__coordinators = user) | Q(post__categorypost__space__subject_category__professor = user) | Q(post__categorypost__space__subject_category__students = user) | Q(comment__post__categorypost__space__subject_category__professor = user) | Q(comment__post__categorypost__space__subject_category__students = user))).distinct().count()
38 self.totals['subject'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__space__professor = user) | Q(comment__post__subjectpost__space__professor = user) | Q(post__subjectpost__space__students = user) | Q(comment__post__subjectpost__space__students = user))).distinct().count() 40 self.totals['subject'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__space__professor = user) | Q(comment__post__subjectpost__space__professor = user) | Q(post__subjectpost__space__students = user) | Q(comment__post__subjectpost__space__students = user))).distinct().count()
39 41
  42 + general_visualizations.update(viewed = True)
  43 +
40 return general 44 return general
41 45
42 def get_context_data(self, **kwargs): 46 def get_context_data(self, **kwargs):