Commit fa5642a94fae9897a10d9008a843c4afed5cd485

Authored by Zambom
1 parent ee2ca54d

Adding mural badges

amadeus/static/js/socket.js
@@ -28,7 +28,7 @@ function muralNotificationPost(content) { @@ -28,7 +28,7 @@ function muralNotificationPost(content) {
28 var page = window.location.pathname, 28 var page = window.location.pathname,
29 render = (content.paths.indexOf(page) != -1); 29 render = (content.paths.indexOf(page) != -1);
30 30
31 - if (render) { 31 + if ((render && page.indexOf(content.post_type) != -1) || (render && content.post_type == "general")) {
32 if (content.accordion) { 32 if (content.accordion) {
33 var section = $(content.container); 33 var section = $(content.container);
34 34
@@ -58,6 +58,37 @@ function muralNotificationPost(content) { @@ -58,6 +58,37 @@ function muralNotificationPost(content) {
58 58
59 $(this).show(); 59 $(this).show();
60 }); 60 });
  61 +
  62 + $('.mural-tabs').find('li').each(function () {
  63 + var identity = $(this).data('mural');
  64 +
  65 + if (identity == content.post_type) {
  66 + var span = $(this).find('span'),
  67 + actual = span.text();
  68 +
  69 + actual = parseInt(actual, 10) + 1;
  70 +
  71 + span.text(actual);
  72 + }
  73 + });
  74 +
  75 + if (content.post_type == "subject") {
  76 + var slug = content.container.substring(1, content.container.length),
  77 + subject_mbadge = $("#subject_" + slug).find('.mural_notify'),
  78 + actual = subject_mbadge.text();
  79 +
  80 + if (actual != "+99") {
  81 + actual = parseInt(actual, 10) + 1;
  82 +
  83 + if (actual > 99) {
  84 + actual = "+99";
  85 + }
  86 +
  87 + subject_mbadge.text(actual);
  88 + }
  89 +
  90 + subject_mbadge.show();
  91 + }
61 } 92 }
62 93
63 if (("Notification" in window)) { 94 if (("Notification" in window)) {
@@ -105,18 +136,18 @@ function muralNotificationMuralDelete(content) { @@ -105,18 +136,18 @@ function muralNotificationMuralDelete(content) {
105 function muralNotificationComment(content) { 136 function muralNotificationComment(content) {
106 var page = window.location.pathname, 137 var page = window.location.pathname,
107 render = (content.paths.indexOf(page) != -1), 138 render = (content.paths.indexOf(page) != -1),
108 - checker = ""; 139 + checker = "general";
109 140
110 switch (content.post_type) { 141 switch (content.post_type) {
111 case "categorypost": 142 case "categorypost":
112 - checker = "category"; 143 + checker = "categories";
113 break; 144 break;
114 case "subjectpost": 145 case "subjectpost":
115 - checker = "subject"; 146 + checker = "subjects";
116 break; 147 break;
117 } 148 }
118 149
119 - if ((render && page.indexOf(checker) != -1) || (render && content.post_type == "generalpost")) { 150 + if ((render && page.indexOf(checker) != -1) || (render && content.post_type == "generalpost" && page.indexOf("categories") == -1 && page.indexOf("subjects") == -1)) {
120 var section = $(content.container); 151 var section = $(content.container);
121 152
122 if (section.is(":visible") || section.is(":hidden")) { 153 if (section.is(":visible") || section.is(":hidden")) {
@@ -125,6 +156,8 @@ function muralNotificationComment(content) { @@ -125,6 +156,8 @@ function muralNotificationComment(content) {
125 comments.append(content.complete); 156 comments.append(content.complete);
126 } 157 }
127 } else { 158 } else {
  159 + console.log("Lester");
  160 +
128 $('.mural_badge').each(function () { 161 $('.mural_badge').each(function () {
129 var actual = $(this).text(); 162 var actual = $(this).text();
130 163
@@ -140,6 +173,36 @@ function muralNotificationComment(content) { @@ -140,6 +173,36 @@ function muralNotificationComment(content) {
140 173
141 $(this).show(); 174 $(this).show();
142 }); 175 });
  176 +
  177 + $('.mural-tabs').find('li').each(function () {
  178 + var identity = $(this).data('mural');
  179 +
  180 + if ((identity == checker) || (identity == "general" && content.post_type == "generalpost")) {
  181 + var span = $(this).find('span'),
  182 + actual = span.text();
  183 +
  184 + actual = parseInt(actual, 10) + 1;
  185 +
  186 + span.text(actual);
  187 + }
  188 + });
  189 +
  190 + if (content.post_type == "subjectpost") {
  191 + var subject_mbadge = $("#subject_" + content.type_slug).find('.mural_notify'),
  192 + actual = subject_mbadge.text();
  193 +
  194 + if (actual != "+99") {
  195 + actual = parseInt(actual, 10) + 1;
  196 +
  197 + if (actual > 99) {
  198 + actual = "+99";
  199 + }
  200 +
  201 + subject_mbadge.text(actual);
  202 + }
  203 +
  204 + subject_mbadge.show();
  205 + }
143 } 206 }
144 207
145 if (("Notification" in window)) { 208 if (("Notification" in window)) {
mural/models.py
@@ -32,7 +32,11 @@ class Mural(KnowsChild): @@ -32,7 +32,11 @@ class Mural(KnowsChild):
32 32
33 @always_as_child 33 @always_as_child
34 def get_space(self): 34 def get_space(self):
35 - pass 35 + pass
  36 +
  37 + @always_as_child
  38 + def get_space_slug(self):
  39 + pass
36 40
37 @always_as_child 41 @always_as_child
38 def update_link(self): 42 def update_link(self):
@@ -51,6 +55,9 @@ class GeneralPost(Mural): @@ -51,6 +55,9 @@ class GeneralPost(Mural):
51 def get_space(self): 55 def get_space(self):
52 return self.space 56 return self.space
53 57
  58 + def get_space_slug(self):
  59 + return ""
  60 +
54 def update_link(self): 61 def update_link(self):
55 return "mural:update_general" 62 return "mural:update_general"
56 63
@@ -66,6 +73,9 @@ class CategoryPost(Mural): @@ -66,6 +73,9 @@ class CategoryPost(Mural):
66 def get_space(self): 73 def get_space(self):
67 return self.space.id 74 return self.space.id
68 75
  76 + def get_space_slug(self):
  77 + return self.space.slug
  78 +
69 def update_link(self): 79 def update_link(self):
70 return "mural:update_category" 80 return "mural:update_category"
71 81
@@ -82,6 +92,9 @@ class SubjectPost(Mural): @@ -82,6 +92,9 @@ class SubjectPost(Mural):
82 def get_space(self): 92 def get_space(self):
83 return self.space.id 93 return self.space.id
84 94
  95 + def get_space_slug(self):
  96 + return self.space.slug
  97 +
85 def update_link(self): 98 def update_link(self):
86 return "mural:update_subject" 99 return "mural:update_subject"
87 100
mural/templates/mural/list.html
@@ -13,10 +13,10 @@ @@ -13,10 +13,10 @@
13 13
14 {% block content %} 14 {% block content %}
15 <div id="core-subjects-options-div"> 15 <div id="core-subjects-options-div">
16 - <ul class="core-subjects-options">  
17 - <a href="{% url 'mural:manage_general' %}"><li class="active">{% trans "General" %} ({{ totals.general }})</li></a>  
18 - <a href="{% url 'mural:manage_category' %}"><li>{% trans "Per Category" %} ({{ totals.category }})</li></a>  
19 - <a href="{% url 'mural:manage_subject' %}"><li>{% trans "Per Subject" %} ({{ totals.subject }})</li></a> 16 + <ul class="core-subjects-options mural-tabs">
  17 + <a href="{% url 'mural:manage_general' %}"><li data-mural="general" class="active">{% trans "General" %} (<span>{{ totals.general }}</span>)</li></a>
  18 + <a href="{% url 'mural:manage_category' %}"><li data-mural="categories">{% trans "Per Category" %} (<span>{{ totals.category }}</span>)</li></a>
  19 + <a href="{% url 'mural:manage_subject' %}"><li data-mural="subjects">{% trans "Per Subject" %} (<span>{{ totals.subject }}</span>)</li></a>
20 </ul> 20 </ul>
21 </div> 21 </div>
22 22
mural/templates/mural/list_category.html
@@ -15,10 +15,10 @@ @@ -15,10 +15,10 @@
15 <input type="hidden" value="{% url 'mural:manage_category' %}" class="mural_url" /> 15 <input type="hidden" value="{% url 'mural:manage_category' %}" class="mural_url" />
16 16
17 <div id="core-subjects-options-div"> 17 <div id="core-subjects-options-div">
18 - <ul class="core-subjects-options">  
19 - <a href="{% url 'mural:manage_general' %}"><li>{% trans "General" %} ({{ totals.general }})</li></a>  
20 - <a href="{% url 'mural:manage_category' %}"><li class="active">{% trans "Per Category" %} (<span class="ung_badge">{{ totals.category }}</span>)</li></a>  
21 - <a href="{% url 'mural:manage_subject' %}"><li>{% trans "Per Subject" %} ({{ totals.subject }})</li></a> 18 + <ul class="core-subjects-options mural-tabs">
  19 + <a href="{% url 'mural:manage_general' %}"><li data-mural="general">{% trans "General" %} (<span>{{ totals.general }}</span>)</li></a>
  20 + <a href="{% url 'mural:manage_category' %}"><li data-mural="categories" class="active">{% trans "Per Category" %} (<span class="ung_badge">{{ totals.category }}</span>)</li></a>
  21 + <a href="{% url 'mural:manage_subject' %}"><li data-mural="subjects">{% trans "Per Subject" %} (<span>{{ totals.subject }}</span>)</li></a>
22 </ul> 22 </ul>
23 </div> 23 </div>
24 24
mural/templates/mural/list_subject.html
@@ -15,10 +15,10 @@ @@ -15,10 +15,10 @@
15 <input type="hidden" value="{% url 'mural:manage_subject' %}" class="mural_url" /> 15 <input type="hidden" value="{% url 'mural:manage_subject' %}" class="mural_url" />
16 16
17 <div id="core-subjects-options-div"> 17 <div id="core-subjects-options-div">
18 - <ul class="core-subjects-options">  
19 - <a href="{% url 'mural:manage_general' %}"><li>{% trans "General" %} ({{ totals.general }})</li></a>  
20 - <a href="{% url 'mural:manage_category' %}"><li>{% trans "Per Category" %} ({{ totals.category }})</li></a>  
21 - <a href="{% url 'mural:manage_subject' %}"><li class="active">{% trans "Per Subject" %} (<span class="ung_badge">{{ totals.subject }}</span>)</li></a> 18 + <ul class="core-subjects-options mural-tabs">
  19 + <a href="{% url 'mural:manage_general' %}"><li data-mural="general">{% trans "General" %} (<span>{{ totals.general }}</span>)</li></a>
  20 + <a href="{% url 'mural:manage_category' %}"><li data-mural="categories">{% trans "Per Category" %} (<span>{{ totals.category }}</span>)</li></a>
  21 + <a href="{% url 'mural:manage_subject' %}"><li data-mural="subjects" class="active">{% trans "Per Subject" %} (<span class="ung_badge">{{ totals.subject }}</span>)</li></a>
22 </ul> 22 </ul>
23 </div> 23 </div>
24 24
@@ -134,4 +134,5 @@ @@ -134,4 +134,5 @@
134 <script type="text/javascript" src="{% static 'js/category.js' %}"></script> 134 <script type="text/javascript" src="{% static 'js/category.js' %}"></script>
135 <script type="text/javascript" src="{% static 'js/mural.js' %}"></script> 135 <script type="text/javascript" src="{% static 'js/mural.js' %}"></script>
136 <script type="text/javascript" src="{% static 'js/mural_ungeneral.js' %}"></script> 136 <script type="text/javascript" src="{% static 'js/mural_ungeneral.js' %}"></script>
  137 + <script type="text/javascript" src="{% static 'subjects/js/modal_subject.js' %}"></script>
137 {% endblock %} 138 {% endblock %}
138 \ No newline at end of file 139 \ No newline at end of file
mural/views.py
@@ -129,7 +129,8 @@ class GeneralCreate(LoginRequiredMixin, generic.edit.CreateView): @@ -129,7 +129,8 @@ class GeneralCreate(LoginRequiredMixin, generic.edit.CreateView):
129 "simple_notify": _("%s has made a post in General")%(str(self.object.user)), 129 "simple_notify": _("%s has made a post in General")%(str(self.object.user)),
130 "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request), 130 "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request),
131 "container": ".post", 131 "container": ".post",
132 - "accordion": False 132 + "accordion": False,
  133 + "post_type": "general"
133 } 134 }
134 135
135 notification = json.dumps(notification) 136 notification = json.dumps(notification)
@@ -360,7 +361,8 @@ class CategoryCreate(LoginRequiredMixin, generic.edit.CreateView): @@ -360,7 +361,8 @@ class CategoryCreate(LoginRequiredMixin, generic.edit.CreateView):
360 "simple_notify": _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)), 361 "simple_notify": _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)),
361 "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request), 362 "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request),
362 "container": "#" + slug, 363 "container": "#" + slug,
363 - "accordion": True 364 + "accordion": True,
  365 + "post_type": "categories"
364 } 366 }
365 367
366 notification = json.dumps(notification) 368 notification = json.dumps(notification)
@@ -602,7 +604,8 @@ class SubjectCreate(LoginRequiredMixin, generic.edit.CreateView): @@ -602,7 +604,8 @@ class SubjectCreate(LoginRequiredMixin, generic.edit.CreateView):
602 "simple_notify": _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)), 604 "simple_notify": _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)),
603 "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request), 605 "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request),
604 "container": "#" + slug, 606 "container": "#" + slug,
605 - "accordion": True 607 + "accordion": True,
  608 + "post_type": "subjects"
606 } 609 }
607 610
608 notification = json.dumps(notification) 611 notification = json.dumps(notification)
@@ -801,8 +804,9 @@ class CommentCreate(LoginRequiredMixin, generic.edit.CreateView): @@ -801,8 +804,9 @@ class CommentCreate(LoginRequiredMixin, generic.edit.CreateView):
801 "user_icon": self.object.user.image_url, 804 "user_icon": self.object.user.image_url,
802 "simple_notify": _("%s has commented in a post")%(str(self.object.user)), 805 "simple_notify": _("%s has commented in a post")%(str(self.object.user)),
803 "complete": render_to_string("mural/_view_comment.html", {"comment": self.object}, self.request), 806 "complete": render_to_string("mural/_view_comment.html", {"comment": self.object}, self.request),
804 - "container": "#post-id" + str(post.get_id()),  
805 - "post_type": post._my_subclass 807 + "container": "#post-" + str(post.get_id()),
  808 + "post_type": post._my_subclass,
  809 + "type_slug": post.get_space_slug()
806 } 810 }
807 811
808 notification = json.dumps(notification) 812 notification = json.dumps(notification)
subjects/templates/subjects/badge.html
1 -{% if number > 0 %}  
2 - <span class="badge notify_badge">{% if number > 99 %} +99 {% else %} {{ number }} {% endif %}</span>  
3 -{% endif %}  
4 \ No newline at end of file 1 \ No newline at end of file
  2 +<span class="badge notify_badge {{ custom_class }}" {% if number <= 0 %} style="display:none" {% endif %}>{% if number > 99 %} +99 {% else %} {{ number }} {% endif %}</span>
5 \ No newline at end of file 3 \ No newline at end of file
subjects/templates/subjects/subject_card.html
@@ -40,7 +40,10 @@ @@ -40,7 +40,10 @@
40 {% notifies_number subject request.user %} 40 {% notifies_number subject request.user %}
41 </a> 41 </a>
42 <a href="" class="pull-right action_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 42 <a href="" class="pull-right action_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></a>
43 - <a href="" class="pull-right action_icon"><i class="fa fa-list" aria-hidden="true"></i></a> 43 + <a href="" class="pull-right action_icon">
  44 + <i class="fa fa-list" aria-hidden="true"></i>
  45 + {% mural_number subject request.user %}
  46 + </a>
44 </div> 47 </div>
45 </div> 48 </div>
46 </div> 49 </div>
subjects/templates/subjects/view.html
@@ -29,10 +29,10 @@ @@ -29,10 +29,10 @@
29 {% subject_permissions request.user subject as has_subject_permissions %} 29 {% subject_permissions request.user subject as has_subject_permissions %}
30 30
31 {% if subject.visible %} 31 {% if subject.visible %}
32 - <div class="panel panel-info subject-panel"> 32 + <div class="panel panel-info subject-panel" id="subject_{{subject.slug}}">
33 <div class="panel-heading"> 33 <div class="panel-heading">
34 {% elif has_subject_permissions %} 34 {% elif has_subject_permissions %}
35 - <div class="panel panel-info subject-panel-invisible"> 35 + <div class="panel panel-info subject-panel-invisible" id="subject_{{subject.slug}}">
36 <div class="panel-heading panel-invisible"> 36 <div class="panel-heading panel-invisible">
37 {% endif %} 37 {% endif %}
38 <div class="row"> 38 <div class="row">
@@ -62,7 +62,10 @@ @@ -62,7 +62,10 @@
62 {% notifies_number subject request.user %} 62 {% notifies_number subject request.user %}
63 </a> 63 </a>
64 <a href="" class="pull-right action_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 64 <a href="" class="pull-right action_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></a>
65 - <a href="" class="pull-right action_icon"><i class="fa fa-list" aria-hidden="true"></i></a> 65 + <a href="" class="pull-right action_icon">
  66 + <i class="fa fa-list" aria-hidden="true"></i>
  67 + {% mural_number subject request.user %}
  68 + </a>
66 </div> 69 </div>
67 </div> 70 </div>
68 </div> 71 </div>
subjects/templatetags/subject_counter.py
@@ -2,6 +2,7 @@ import datetime @@ -2,6 +2,7 @@ import datetime
2 from django import template 2 from django import template
3 from django.db.models import Q 3 from django.db.models import Q
4 4
  5 +from mural.models import MuralVisualizations
5 from notifications.models import Notification 6 from notifications.models import Notification
6 7
7 register = template.Library() 8 register = template.Library()
@@ -24,6 +25,25 @@ def notifies_number(subject, user): @@ -24,6 +25,25 @@ def notifies_number(subject, user):
24 context = {} 25 context = {}
25 26
26 context['number'] = Notification.objects.filter(task__resource__topic__subject = subject, creation_date = datetime.datetime.now(), viewed = False, user = user).count() 27 context['number'] = Notification.objects.filter(task__resource__topic__subject = subject, creation_date = datetime.datetime.now(), viewed = False, user = user).count()
  28 + context['custom_class'] = 'pendencies_notify'
  29 +
  30 + return context
  31 +
  32 +@register.inclusion_tag('subjects/badge.html')
  33 +def mural_number(subject, user):
  34 + context = {}
  35 +
  36 + context['number'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__space = subject) | Q(comment__post__subjectpost__space = subject))).count()
  37 + context['custom_class'] = 'mural_notify'
  38 +
  39 + return context
  40 +
  41 +@register.inclusion_tag('subjects/badge.html')
  42 +def resource_mural_number(resource, user):
  43 + context = {}
  44 +
  45 + context['number'] = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(post__subjectpost__resource = resource) | Q(comment__post__subjectpost__resource = resource))).count()
  46 + context['custom_class'] = 'mural_resource_notify'
27 47
28 return context 48 return context
29 49
webpage/templates/webpages/view.html
1 {% extends 'subjects/view.html' %} 1 {% extends 'subjects/view.html' %}
2 2
3 -{% load static i18n pagination permissions_tags %} 3 +{% load static i18n pagination permissions_tags subject_counter %}
4 {% load django_bootstrap_breadcrumbs %} 4 {% load django_bootstrap_breadcrumbs %}
5 5
6 {% block javascript%} 6 {% block javascript%}
@@ -41,7 +41,10 @@ @@ -41,7 +41,10 @@
41 </h4> 41 </h4>
42 42
43 <div class="col-md-5 pull-right category-card-items"> 43 <div class="col-md-5 pull-right category-card-items">
44 - <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> 44 + <a href="" >
  45 + <i class="fa fa-list" aria-hidden="true"></i>
  46 + {% resource_mural_number webpage request.user %}
  47 + </a>
45 </div> 48 </div>
46 </div> 49 </div>
47 </div> 50 </div>
youtube_video/templates/youtube/view.html
1 {% extends 'subjects/view.html' %} 1 {% extends 'subjects/view.html' %}
2 2
3 -{% load static i18n pagination permissions_tags %} 3 +{% load static i18n pagination permissions_tags subject_counter %}
4 {% load django_bootstrap_breadcrumbs %} 4 {% load django_bootstrap_breadcrumbs %}
5 5
6 {% block javascript%} 6 {% block javascript%}
@@ -41,7 +41,10 @@ @@ -41,7 +41,10 @@
41 </h4> 41 </h4>
42 42
43 <div class="col-md-5 pull-right category-card-items"> 43 <div class="col-md-5 pull-right category-card-items">
44 - <a href=""><i class="fa fa-list" aria-hidden="true"></i></a> 44 + <a href="">
  45 + <i class="fa fa-list" aria-hidden="true"></i>
  46 + {% resource_mural_number youtube request.user %}
  47 + </a>
45 </div> 48 </div>
46 </div> 49 </div>
47 </div> 50 </div>