Commit 2eb4aceb927e55d244203aacd25985251dbe92d7
1 parent
fa8acea4
Exists in
master
and in
3 other branches
Adding topic sort
Showing
7 changed files
with
113 additions
and
2 deletions
Show diff stats
amadeus/static/css/base/amadeus.css
@@ -73,11 +73,11 @@ a:focus { | @@ -73,11 +73,11 @@ a:focus { | ||
73 | /* side bar menu ends*/ | 73 | /* side bar menu ends*/ |
74 | 74 | ||
75 | /* category app starts */ | 75 | /* category app starts */ |
76 | -.category-panel > .panel-heading, .subject-panel > .panel-heading, .special-panel > .panel-heading { | 76 | +.category-panel > .panel-heading, .subject-panel > .panel-heading, .special-panel > .panel-heading, .topic-panel > .panel-heading { |
77 | padding: 2px 0px; | 77 | padding: 2px 0px; |
78 | } | 78 | } |
79 | 79 | ||
80 | -.subject-panel-invisible > .panel-heading{ | 80 | +.subject-panel-invisible > .panel-heading, .topic-panel-invisible > .panel-heading { |
81 | padding: 2px 0px; | 81 | padding: 2px 0px; |
82 | } | 82 | } |
83 | 83 |
amadeus/static/css/themes/green.css
@@ -59,6 +59,15 @@ a, a:focus, a:hover { | @@ -59,6 +59,15 @@ a, a:focus, a:hover { | ||
59 | background-color: #039BE5 !important; | 59 | background-color: #039BE5 !important; |
60 | } | 60 | } |
61 | 61 | ||
62 | +.topic-panel > .panel-heading { | ||
63 | + background-color: #7BA5B9 !important; | ||
64 | +} | ||
65 | + | ||
66 | +.topic-panel-invisible > .panel-heading { | ||
67 | + background-color: #BDBDBD !important; | ||
68 | + color: #F5F5F5; | ||
69 | +} | ||
70 | + | ||
62 | .category-header i { | 71 | .category-header i { |
63 | color: white; | 72 | color: white; |
64 | } | 73 | } |
subjects/templates/subjects/view.html
@@ -84,6 +84,7 @@ | @@ -84,6 +84,7 @@ | ||
84 | <a href="{% url 'topics:create' subject.slug %}" class="btn btn-sm btn-success btn-raised btn-block">{% trans "Create new topic" %}</a> | 84 | <a href="{% url 'topics:create' subject.slug %}" class="btn btn-sm btn-success btn-raised btn-block">{% trans "Create new topic" %}</a> |
85 | {% endif %} | 85 | {% endif %} |
86 | 86 | ||
87 | + {% include 'topics/list.html' with subject=subject %} | ||
87 | </div> | 88 | </div> |
88 | </div> | 89 | </div> |
89 | {% endblock content %} | 90 | {% endblock content %} |
90 | \ No newline at end of file | 91 | \ No newline at end of file |
topics/models.py
@@ -18,6 +18,7 @@ class Topic(models.Model): | @@ -18,6 +18,7 @@ class Topic(models.Model): | ||
18 | class Meta: | 18 | class Meta: |
19 | verbose_name = _('Topic') | 19 | verbose_name = _('Topic') |
20 | verbose_name_plural = _('Topics') | 20 | verbose_name_plural = _('Topics') |
21 | + ordering = ['order'] | ||
21 | 22 | ||
22 | def __str__(self): | 23 | def __str__(self): |
23 | return self.name | 24 | return self.name |
24 | \ No newline at end of file | 25 | \ No newline at end of file |
@@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
1 | +{% load static i18n pagination permissions_tags %} | ||
2 | +{% load django_bootstrap_breadcrumbs %} | ||
3 | + | ||
4 | +{% subject_permissions request.user subject as has_subject_permissions %} | ||
5 | + | ||
6 | +<div class="panel-group subject-group" id="topics-accordion" role="tablist" aria-multiselectable="true"> | ||
7 | + {% for topic in subject.topic_subject.all %} | ||
8 | + {% if not topic.repository and topic.visible or has_subject_permissions %} | ||
9 | + <div class="panel panel-info {% if not topic.visible or topic.repository %} topic-panel-invisible {% else %} topic-panel {% endif %} topic-panel"> | ||
10 | + <div class="panel-heading"> | ||
11 | + <div class="row"> | ||
12 | + <div class="col-md-12 category-header"> | ||
13 | + <h4 class="panel-title"> | ||
14 | + <a class="category-course-link pull-left" data-parent="#topics-accordion" data-toggle="collapse" href="#{{topic.slug}}"> | ||
15 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{ topic }} | ||
16 | + </a> | ||
17 | + </h4> | ||
18 | + | ||
19 | + {% if has_subject_permissions %} | ||
20 | + <div class="col-md-5 pull-right category-card-items"> | ||
21 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
22 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
23 | + </a> | ||
24 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
25 | + <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
26 | + <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
27 | + <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> | ||
28 | + </ul> | ||
29 | + <a href="" ><i class="fa fa-arrows" aria-hidden="true"></i></a> | ||
30 | + </div> | ||
31 | + {% endif %} | ||
32 | + </div> | ||
33 | + </div> | ||
34 | + </div> | ||
35 | + <div id="{{topic.slug}}" class="panel-collapse collapse category-panel-content"> | ||
36 | + <input type="hidden" class="id_inp" name="id" value="{{ topic.id }}" /> | ||
37 | + <input type="hidden" class="order_inp" name="order" value="{{ topic.order }}" /> | ||
38 | + </div> | ||
39 | + </div> | ||
40 | + {% endif %} | ||
41 | + {% endfor %} | ||
42 | +</div> | ||
43 | + | ||
44 | +<script type="text/javascript"> | ||
45 | + $("#topics-accordion").sortable({ // utilizado para fazer a re-organização dos tópicos | ||
46 | + delay: 100, | ||
47 | + distance: 5, | ||
48 | + handler: 'i.fa-arrows', | ||
49 | + update: function( event, ui ) { | ||
50 | + var cont = 1; | ||
51 | + var data = []; | ||
52 | + | ||
53 | + $("#topics-accordion").find('.order_inp').each(function () { | ||
54 | + $(this).val(cont++); | ||
55 | + | ||
56 | + data.push({ | ||
57 | + 'topic_id': $(this).parent().find('.id_inp').val(), | ||
58 | + 'topic_order': $(this).val() | ||
59 | + }); | ||
60 | + }); | ||
61 | + | ||
62 | + data = JSON.stringify(data); | ||
63 | + | ||
64 | + sendUpdate(data); | ||
65 | + }, | ||
66 | + }); | ||
67 | + | ||
68 | + function sendUpdate(data) { | ||
69 | + $.ajax({ | ||
70 | + url: '{% url "topics:update_order" %}', | ||
71 | + dataType: 'json', | ||
72 | + data: {'data': data}, | ||
73 | + success: function(response) { | ||
74 | + console.log(response); | ||
75 | + }, | ||
76 | + error: function(response) { | ||
77 | + console.log(response); | ||
78 | + } | ||
79 | + }); | ||
80 | + } | ||
81 | +</script> | ||
0 | \ No newline at end of file | 82 | \ No newline at end of file |
topics/urls.py
@@ -5,4 +5,5 @@ from . import views | @@ -5,4 +5,5 @@ from . import views | ||
5 | 5 | ||
6 | urlpatterns = [ | 6 | urlpatterns = [ |
7 | url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateView.as_view(), name = 'create'), | 7 | url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateView.as_view(), name = 'create'), |
8 | + url(r'^update_order/$', views.update_order, name = 'update_order'), | ||
8 | ] | 9 | ] |
topics/views.py
1 | from django.shortcuts import get_object_or_404, redirect, render | 1 | from django.shortcuts import get_object_or_404, redirect, render |
2 | from django.views import generic | 2 | from django.views import generic |
3 | from django.contrib import messages | 3 | from django.contrib import messages |
4 | +from django.http import JsonResponse | ||
4 | from django.core.urlresolvers import reverse, reverse_lazy | 5 | from django.core.urlresolvers import reverse, reverse_lazy |
5 | from django.utils.translation import ugettext_lazy as _ | 6 | from django.utils.translation import ugettext_lazy as _ |
6 | from django.contrib.auth.mixins import LoginRequiredMixin | 7 | from django.contrib.auth.mixins import LoginRequiredMixin |
7 | 8 | ||
9 | +import json | ||
10 | + | ||
8 | from amadeus.permissions import has_subject_permissions | 11 | from amadeus.permissions import has_subject_permissions |
9 | 12 | ||
10 | from subjects.models import Subject | 13 | from subjects.models import Subject |
@@ -66,3 +69,18 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): | @@ -66,3 +69,18 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): | ||
66 | messages.success(self.request, _('Topic "%s" was created on virtual enviroment "%s" successfully!')%(self.object.name, self.object.subject.name)) | 69 | messages.success(self.request, _('Topic "%s" was created on virtual enviroment "%s" successfully!')%(self.object.name, self.object.subject.name)) |
67 | 70 | ||
68 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) | 71 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) |
72 | + | ||
73 | +def update_order(request): | ||
74 | + data = request.GET.get('data', None) | ||
75 | + | ||
76 | + if not data is None: | ||
77 | + data = json.loads(data) | ||
78 | + | ||
79 | + for t_data in data: | ||
80 | + topic = get_object_or_404(Topic, id = t_data['topic_id']) | ||
81 | + topic.order = t_data['topic_order'] | ||
82 | + topic.save() | ||
83 | + | ||
84 | + return JsonResponse({'message': 'ok'}) | ||
85 | + | ||
86 | + return JsonResponse({'message': 'No data received'}) | ||
69 | \ No newline at end of file | 87 | \ No newline at end of file |