Commit 6d1a1af1c8c7038994ce3853fff85e4f381fd436
1 parent
8ea454ec
Exists in
master
and in
2 other branches
Adding subjects messages page
Showing
8 changed files
with
174 additions
and
3 deletions
Show diff stats
amadeus/static/js/socket.js
@@ -290,6 +290,23 @@ function messageReceived(content) { | @@ -290,6 +290,23 @@ function messageReceived(content) { | ||
290 | 290 | ||
291 | span.text(actual); | 291 | span.text(actual); |
292 | } | 292 | } |
293 | + | ||
294 | + if (content.subtype == "subject") { | ||
295 | + var subject_cbadge = $("#subject_" + content.space).find('.chat_notify'), | ||
296 | + actual = subject_cbadge.text(); | ||
297 | + | ||
298 | + if (actual != "+99") { | ||
299 | + actual = parseInt(actual, 10) + 1; | ||
300 | + | ||
301 | + if (actual > 99) { | ||
302 | + actual = "+99"; | ||
303 | + } | ||
304 | + | ||
305 | + subject_cbadge.text(actual); | ||
306 | + } | ||
307 | + | ||
308 | + subject_cbadge.show(); | ||
309 | + } | ||
293 | } | 310 | } |
294 | 311 | ||
295 | if (("Notification" in window)) { | 312 | if (("Notification" in window)) { |
chat/templates/chat/list.html
@@ -54,6 +54,9 @@ | @@ -54,6 +54,9 @@ | ||
54 | {% include 'chat/_view.html' with space="0" space_type='general' %} | 54 | {% include 'chat/_view.html' with space="0" space_type='general' %} |
55 | {% endfor %} | 55 | {% endfor %} |
56 | </div> | 56 | </div> |
57 | + | ||
58 | + {% pagination request paginator page_obj %} | ||
59 | + | ||
57 | </div> | 60 | </div> |
58 | {% else %} | 61 | {% else %} |
59 | <div class="text-center no-subjects"> | 62 | <div class="text-center no-subjects"> |
@@ -0,0 +1,97 @@ | @@ -0,0 +1,97 @@ | ||
1 | +{% extends 'subjects/view.html' %} | ||
2 | + | ||
3 | +{% load static i18n pagination permissions_tags subject_counter %} | ||
4 | +{% load django_bootstrap_breadcrumbs %} | ||
5 | + | ||
6 | +{% block breadcrumbs %} | ||
7 | + {{ block.super }} | ||
8 | + | ||
9 | + {% trans 'Messages' as bread %} | ||
10 | + | ||
11 | + {% breadcrumb bread 'chat:subject_view' subject.slug %} | ||
12 | +{% endblock %} | ||
13 | + | ||
14 | +{% block content %} | ||
15 | + {% subject_permissions request.user subject as has_subject_permissions %} | ||
16 | + | ||
17 | + {% if subject.visible %} | ||
18 | + <div class="panel panel-info subject-panel chat-panel" id="subject_{{subject.slug}}"> | ||
19 | + <div class="panel-heading"> | ||
20 | + {% elif has_subject_permissions %} | ||
21 | + <div class="panel panel-info subject-panel-invisible chat-panel" id="subject_{{subject.slug}}"> | ||
22 | + <div class="panel-heading panel-invisible"> | ||
23 | + {% endif %} | ||
24 | + <div class="row"> | ||
25 | + <div class="col-md-12 category-header"> | ||
26 | + <h4 class="panel-title" style="margin-top: 10px; margin-bottom: 8px"> | ||
27 | + <span>{{subject.name}}</span> | ||
28 | + </h4> | ||
29 | + | ||
30 | + <div class="col-md-5 pull-right category-card-items"> | ||
31 | + {% if request.user in subject.professor.all or request.user in subject.category.coordinators.all or request.user.is_staff %} | ||
32 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
33 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
34 | + </a> | ||
35 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
36 | + {% if request.user not in subject.professor.all %} | ||
37 | + <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
38 | + {% endif %} | ||
39 | + <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
40 | + <li><a href="{% url 'groups:index' subject.slug %}"><i class="fa fa-group fa-fw" aria-hidden="true"></i>{% trans 'Groups' %}</a></li> | ||
41 | + <li><a href="javascript:delete_subject.get('{% url 'subjects:delete' subject.slug %}?view=index','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | ||
42 | + </ul> | ||
43 | + {% endif %} | ||
44 | + | ||
45 | + </div> | ||
46 | + </div> | ||
47 | + </div> | ||
48 | + </div> | ||
49 | + <div id="{{subject.slug}}" class="panel-collapse panel-body in collapse chat-collapse"> | ||
50 | + <div class="panel panel-default"> | ||
51 | + <div class="panel-body"> | ||
52 | + <div class="col-md-8"> | ||
53 | + <form action="" method="GET" class="form-horizontal"> | ||
54 | + <div class="form-group"> | ||
55 | + <div class="col-md-11 col-sm-11 col-xs-11"> | ||
56 | + <input type="text" class="form-control" name="search" value="{{ search }}" placeholder="{% trans 'Search...' %}" /> | ||
57 | + </div> | ||
58 | + <div class="col-md-1 col-sm-1 col-xs-1"> | ||
59 | + <button type="submit" class="btn btn-fab btn-fab-mini"> | ||
60 | + <i class="fa fa-search"></i> | ||
61 | + </button> | ||
62 | + </div> | ||
63 | + </div> | ||
64 | + </form> | ||
65 | + </div> | ||
66 | + <div class="col-md-4"> | ||
67 | + <a href="" class="pull-right btn btn-default btn-raised btn-md">{% trans 'List all participants' %}</a> | ||
68 | + </div> | ||
69 | + </div> | ||
70 | + </div> | ||
71 | + | ||
72 | + {% if conversations.count > 0 %} | ||
73 | + <div class="panel category-panel-content panel-body"> | ||
74 | + <h2 class="my-subjects-title"><b>{% trans 'Conversations' %}</b></h2> | ||
75 | + | ||
76 | + <div class="talks-group"> | ||
77 | + {% for chat in conversations %} | ||
78 | + {% include 'chat/_view.html' with space=subject.id space_type='subject' %} | ||
79 | + {% endfor %} | ||
80 | + </div> | ||
81 | + | ||
82 | + {% pagination request paginator page_obj %} | ||
83 | + </div> | ||
84 | + {% else %} | ||
85 | + <div class="text-center no-subjects"> | ||
86 | + <i class="fa fa-envelope-o"></i> | ||
87 | + <h4>{% trans 'You do not posses messages in this space yet.' %}</h4> | ||
88 | + </div> | ||
89 | + {% endif %} | ||
90 | + </div> | ||
91 | + | ||
92 | + <div class="modal fade" id="chat-modal-info" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"></div> | ||
93 | + | ||
94 | + <div class="modal fade" id="chat-modal-form" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"></div> | ||
95 | + | ||
96 | + <script type="text/javascript" src="{% static 'js/chat.js' %}"></script> | ||
97 | +{% endblock %} | ||
0 | \ No newline at end of file | 98 | \ No newline at end of file |
chat/urls.py
@@ -5,6 +5,7 @@ urlpatterns = [ | @@ -5,6 +5,7 @@ urlpatterns = [ | ||
5 | url(r'^$', views.GeneralIndex.as_view(), name='manage_general'), | 5 | url(r'^$', views.GeneralIndex.as_view(), name='manage_general'), |
6 | url(r'^categories/$', views.CategoryIndex.as_view(), name='manage_category'), | 6 | url(r'^categories/$', views.CategoryIndex.as_view(), name='manage_category'), |
7 | url(r'^subjects/$', views.SubjectIndex.as_view(), name='manage_subject'), | 7 | url(r'^subjects/$', views.SubjectIndex.as_view(), name='manage_subject'), |
8 | + url(r'^subject/(?P<slug>[\w_-]+)/$', views.SubjectView.as_view(), name='subject_view'), | ||
8 | url(r'^participants/$', views.GeneralParticipants.as_view(), name='participants_general'), | 9 | url(r'^participants/$', views.GeneralParticipants.as_view(), name='participants_general'), |
9 | url(r'^category/talks/(?P<category>[\w_-]+)/$', views.CategoryTalks.as_view(), name='category_talks'), | 10 | url(r'^category/talks/(?P<category>[\w_-]+)/$', views.CategoryTalks.as_view(), name='category_talks'), |
10 | url(r'^category/participants/(?P<category>[\w_-]+)/$', views.CategoryParticipants.as_view(), name='participants_category'), | 11 | url(r'^category/participants/(?P<category>[\w_-]+)/$', views.CategoryParticipants.as_view(), name='participants_category'), |
chat/views.py
@@ -15,6 +15,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin | @@ -15,6 +15,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin | ||
15 | from django.contrib.auth.decorators import login_required | 15 | from django.contrib.auth.decorators import login_required |
16 | from django.db.models import Q | 16 | from django.db.models import Q |
17 | 17 | ||
18 | +from amadeus.permissions import has_subject_view_permissions | ||
19 | + | ||
18 | from channels import Group | 20 | from channels import Group |
19 | import json | 21 | import json |
20 | 22 | ||
@@ -37,7 +39,6 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView): | @@ -37,7 +39,6 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView): | ||
37 | 39 | ||
38 | def get_queryset(self): | 40 | def get_queryset(self): |
39 | user = self.request.user | 41 | user = self.request.user |
40 | - page = self.request.GET.get('page', False) | ||
41 | 42 | ||
42 | conversations = Conversation.objects.filter((Q(user_one = user) | Q(user_two = user)) & Q(categorytalk__isnull = True) & Q(subjecttalk__isnull = True)) | 43 | conversations = Conversation.objects.filter((Q(user_one = user) | Q(user_two = user)) & Q(categorytalk__isnull = True) & Q(subjecttalk__isnull = True)) |
43 | 44 | ||
@@ -250,6 +251,42 @@ class SubjectParticipants(LoginRequiredMixin, generic.ListView): | @@ -250,6 +251,42 @@ class SubjectParticipants(LoginRequiredMixin, generic.ListView): | ||
250 | 251 | ||
251 | return context | 252 | return context |
252 | 253 | ||
254 | +class SubjectView(LoginRequiredMixin, generic.ListView): | ||
255 | + login_url = reverse_lazy("users:login") | ||
256 | + redirect_field_name = 'next' | ||
257 | + | ||
258 | + template_name = 'chat/subject_view.html' | ||
259 | + context_object_name = "conversations" | ||
260 | + paginate_by = 10 | ||
261 | + | ||
262 | + def dispatch(self, request, *args,**kwargs): | ||
263 | + subject = get_object_or_404(Subject, slug = kwargs.get('slug', '')) | ||
264 | + | ||
265 | + if not has_subject_view_permissions(request.user, subject): | ||
266 | + return redirect(reverse_lazy('subjects:home')) | ||
267 | + | ||
268 | + return super(SubjectView, self).dispatch(request, *args, **kwargs) | ||
269 | + | ||
270 | + def get_queryset(self): | ||
271 | + user = self.request.user | ||
272 | + slug = self.kwargs.get('slug') | ||
273 | + subject = get_object_or_404(Subject, slug = slug) | ||
274 | + | ||
275 | + conversations = SubjectTalk.objects.filter((Q(user_one = user) | Q(user_two = user)) & Q(space = subject)) | ||
276 | + | ||
277 | + return conversations | ||
278 | + | ||
279 | + def get_context_data(self, **kwargs): | ||
280 | + context = super(SubjectView, self).get_context_data(**kwargs) | ||
281 | + | ||
282 | + slug = self.kwargs.get('slug', None) | ||
283 | + subject = get_object_or_404(Subject, slug = slug) | ||
284 | + | ||
285 | + context['title'] = _('%s - Messages')%(str(subject)) | ||
286 | + context['subject'] = subject | ||
287 | + | ||
288 | + return context | ||
289 | + | ||
253 | class ParticipantProfile(LoginRequiredMixin, generic.DetailView): | 290 | class ParticipantProfile(LoginRequiredMixin, generic.DetailView): |
254 | login_url = reverse_lazy("users:login") | 291 | login_url = reverse_lazy("users:login") |
255 | redirect_field_name = 'next' | 292 | redirect_field_name = 'next' |
subjects/templates/subjects/subject_card.html
@@ -39,7 +39,10 @@ | @@ -39,7 +39,10 @@ | ||
39 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> | 39 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> |
40 | {% notifies_number subject request.user %} | 40 | {% notifies_number subject request.user %} |
41 | </a> | 41 | </a> |
42 | - <a href="" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Messages' %}"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | 42 | + <a href="{% url 'chat:subject_view' subject.slug %}" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Messages' %}"> |
43 | + <i class="fa fa-envelope-o" aria-hidden="true"></i> | ||
44 | + {% chat_number subject request.user %} | ||
45 | + </a> | ||
43 | <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Mural' %}"> | 46 | <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Mural' %}"> |
44 | <i class="fa fa-list" aria-hidden="true"></i> | 47 | <i class="fa fa-list" aria-hidden="true"></i> |
45 | {% mural_number subject request.user %} | 48 | {% mural_number subject request.user %} |
subjects/templates/subjects/view.html
@@ -61,7 +61,10 @@ | @@ -61,7 +61,10 @@ | ||
61 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> | 61 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> |
62 | {% notifies_number subject request.user %} | 62 | {% notifies_number subject request.user %} |
63 | </a> | 63 | </a> |
64 | - <a href="" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Messages' %}"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | 64 | + <a href="{% url 'chat:subject_view' subject.slug %}" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Messages' %}"> |
65 | + <i class="fa fa-envelope-o" aria-hidden="true"></i> | ||
66 | + {% chat_number subject request.user %} | ||
67 | + </a> | ||
65 | <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Mural' %}"> | 68 | <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Mural' %}"> |
66 | <i class="fa fa-list" aria-hidden="true"></i> | 69 | <i class="fa fa-list" aria-hidden="true"></i> |
67 | {% mural_number subject request.user %} | 70 | {% mural_number subject request.user %} |
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 chat.models import ChatVisualizations | ||
5 | from mural.models import MuralVisualizations | 6 | from mural.models import MuralVisualizations |
6 | from notifications.models import Notification | 7 | from notifications.models import Notification |
7 | 8 | ||
@@ -39,6 +40,15 @@ def mural_number(subject, user): | @@ -39,6 +40,15 @@ def mural_number(subject, user): | ||
39 | return context | 40 | return context |
40 | 41 | ||
41 | @register.inclusion_tag('subjects/badge.html') | 42 | @register.inclusion_tag('subjects/badge.html') |
43 | +def chat_number(subject, user): | ||
44 | + context = {} | ||
45 | + | ||
46 | + context['number'] = ChatVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & Q(message__talk__subjecttalk__space = subject)).count() | ||
47 | + context['custom_class'] = 'chat_notify' | ||
48 | + | ||
49 | + return context | ||
50 | + | ||
51 | +@register.inclusion_tag('subjects/badge.html') | ||
42 | def resource_mural_number(resource, user): | 52 | def resource_mural_number(resource, user): |
43 | context = {} | 53 | context = {} |
44 | 54 |