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 | 290 | |
291 | 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 | 312 | if (("Notification" in window)) { | ... | ... |
chat/templates/chat/list.html
... | ... | @@ -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 | 98 | \ No newline at end of file | ... | ... |
chat/urls.py
... | ... | @@ -5,6 +5,7 @@ urlpatterns = [ |
5 | 5 | url(r'^$', views.GeneralIndex.as_view(), name='manage_general'), |
6 | 6 | url(r'^categories/$', views.CategoryIndex.as_view(), name='manage_category'), |
7 | 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 | 9 | url(r'^participants/$', views.GeneralParticipants.as_view(), name='participants_general'), |
9 | 10 | url(r'^category/talks/(?P<category>[\w_-]+)/$', views.CategoryTalks.as_view(), name='category_talks'), |
10 | 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 | 15 | from django.contrib.auth.decorators import login_required |
16 | 16 | from django.db.models import Q |
17 | 17 | |
18 | +from amadeus.permissions import has_subject_view_permissions | |
19 | + | |
18 | 20 | from channels import Group |
19 | 21 | import json |
20 | 22 | |
... | ... | @@ -37,7 +39,6 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView): |
37 | 39 | |
38 | 40 | def get_queryset(self): |
39 | 41 | user = self.request.user |
40 | - page = self.request.GET.get('page', False) | |
41 | 42 | |
42 | 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 | 251 | |
251 | 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 | 290 | class ParticipantProfile(LoginRequiredMixin, generic.DetailView): |
254 | 291 | login_url = reverse_lazy("users:login") |
255 | 292 | redirect_field_name = 'next' | ... | ... |
subjects/templates/subjects/subject_card.html
... | ... | @@ -39,7 +39,10 @@ |
39 | 39 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> |
40 | 40 | {% notifies_number subject request.user %} |
41 | 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 | 46 | <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Mural' %}"> |
44 | 47 | <i class="fa fa-list" aria-hidden="true"></i> |
45 | 48 | {% mural_number subject request.user %} | ... | ... |
subjects/templates/subjects/view.html
... | ... | @@ -61,7 +61,10 @@ |
61 | 61 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> |
62 | 62 | {% notifies_number subject request.user %} |
63 | 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 | 68 | <a href="{% url 'mural:subject_view' subject.slug %}" class="pull-right action_icon" data-toggle="tooltip" data-placement="bottom" title="{% trans 'Mural' %}"> |
66 | 69 | <i class="fa fa-list" aria-hidden="true"></i> |
67 | 70 | {% mural_number subject request.user %} | ... | ... |
subjects/templatetags/subject_counter.py
... | ... | @@ -2,6 +2,7 @@ import datetime |
2 | 2 | from django import template |
3 | 3 | from django.db.models import Q |
4 | 4 | |
5 | +from chat.models import ChatVisualizations | |
5 | 6 | from mural.models import MuralVisualizations |
6 | 7 | from notifications.models import Notification |
7 | 8 | |
... | ... | @@ -39,6 +40,15 @@ def mural_number(subject, user): |
39 | 40 | return context |
40 | 41 | |
41 | 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 | 52 | def resource_mural_number(resource, user): |
43 | 53 | context = {} |
44 | 54 | ... | ... |