Commit f9ed24854ace4d48a9fa40c661c586fbced5cf61

Authored by felipebormann
2 parents d5a407b8 ac4841d3

Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring

amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/black.sassc
No preview for this file type
amadeus/static/css/.sass-cache/a7f87b90919294b62ab4f8079e31dcda8f485534/red.sassc
No preview for this file type
amadeus/static/js/mural_category.js
... ... @@ -14,7 +14,10 @@ $('.mural-category').on('shown.bs.collapse', function(e) {
14 14  
15 15 var post_section = $(this).find('.posts'),
16 16 without = $(this).find('.no-subjects'),
17   - loading = $(this).find('.loading-posts');
  17 + loading = $(this).find('.loading-posts'),
  18 + more = $(this).find('.more-posts'),
  19 + filters = $(this).find('.post-filters'),
  20 + mural = post_section.parent().parent();
18 21  
19 22 if (post_section.children().length == 0) {
20 23 var url = $(this).find('.mural').data('url');
... ... @@ -28,13 +31,139 @@ $('.mural-category').on('shown.bs.collapse', function(e) {
28 31 if (data.count > 0) {
29 32 post_section.append(data.posts);
30 33  
  34 + mural.data('pages', data.num_pages);
  35 + mural.data('page', data.num_page);
  36 +
  37 + setTimeout(function () { postHeightLimits() }, 100);
  38 +
  39 + if (data.num_page < data.num_pages) {
  40 + more.show();
  41 + } else {
  42 + more.hide();
  43 + }
  44 +
  45 + $('.mural_badge').each(function () {
  46 + var actual = $(this).text();
  47 +
  48 + if (actual != "+99") {
  49 + actual = parseInt(actual, 10) - data.unviewed;
  50 +
  51 + if (actual <= 0) {
  52 + $(this).hide();
  53 + } else {
  54 + $(this).text(actual);
  55 + }
  56 + }
  57 + });
  58 +
  59 + $('.cat_badge').each(function () {
  60 + var actual = $(this).text();
  61 +
  62 + if (actual != "+99") {
  63 + actual = parseInt(actual, 10) - data.unviewed;
  64 +
  65 + if (actual < 0) {
  66 + actual = 0;
  67 + }
  68 +
  69 + $(this).text(actual);
  70 + }
  71 + });
  72 +
31 73 without.hide();
32 74 } else {
  75 + more.hide();
  76 +
33 77 without.show();
34 78 }
35 79 }
36 80 });
37 81 }
  82 +
  83 + more.click(function () {
  84 + var url = mural.data('url'),
  85 + pageNum = mural.data('page'),
  86 + numberPages = mural.data('pages'),
  87 + favorites = mural.data('fav'),
  88 + mine = mural.data('mine'),
  89 + showing = new_posts.join(',');
  90 +
  91 + if (pageNum == numberPages) {
  92 + return false
  93 + }
  94 +
  95 + pageNum = pageNum + 1;
  96 +
  97 + more.hide();
  98 +
  99 + loading.show();
  100 +
  101 + $.ajax({
  102 + url: url,
  103 + data: {'page': pageNum, 'favorite': favorites, 'mine': mine, 'showing': showing},
  104 + dataType: 'json',
  105 + success: function (data) {
  106 + loading.hide();
  107 +
  108 + post_section.append(data.posts);
  109 +
  110 + mural.data('pages', data.num_pages);
  111 + mural.data('page', data.num_page);
  112 +
  113 + setTimeout(function () { postHeightLimits() }, 100);
  114 +
  115 + if (data.num_page < data.num_pages) {
  116 + more.show();
  117 + } else {
  118 + more.hide();
  119 + }
  120 + }
  121 + });
  122 + });
  123 +
  124 + filters.submit(function () {
  125 + var favorite = $(this).find("input[name='favorite']").is(':checked') ? "True" : "",
  126 + mine = $(this).find("input[name='mine']").is(':checked') ? "True" : "",
  127 + url = mural.data('url');
  128 +
  129 + post_section.html('');
  130 +
  131 + more.hide();
  132 + loading.show();
  133 +
  134 + $.ajax({
  135 + url: url,
  136 + data: {'favorite': favorite, 'mine': mine},
  137 + dataType: 'json',
  138 + success: function (data) {
  139 + loading.hide();
  140 +
  141 + if (data.count > 0) {
  142 + post_section.append(data.posts);
  143 +
  144 + mural.data('pages', data.num_pages);
  145 + mural.data('page', data.num_page);
  146 +
  147 + if (data.num_page < data.num_pages) {
  148 + more.show();
  149 + } else {
  150 + more.hide();
  151 + }
  152 +
  153 + setTimeout(function () { postHeightLimits() }, 100);
  154 +
  155 + without.hide();
  156 + } else {
  157 + without.show();
  158 + }
  159 +
  160 + mural.data('fav', favorite);
  161 + mural.data('mine', mine);
  162 + }
  163 + });
  164 +
  165 + return false;
  166 + });
38 167 }
39 168 });
40 169  
... ...
mural/templates/mural/list_category.html
... ... @@ -17,7 +17,7 @@
17 17 <div id="core-subjects-options-div">
18 18 <ul class="core-subjects-options">
19 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" %} ({{ totals.category }})</li></a>
  20 + <a href="{% url 'mural:manage_category' %}"><li class="active">{% trans "Per Category" %} (<span class="cat_badge">{{ totals.category }}</span>)</li></a>
21 21 <a href=""><li>{% trans "Per Subject" %} ({{ totals.subject }})</li></a>
22 22 </ul>
23 23 </div>
... ... @@ -80,9 +80,19 @@
80 80 </div>
81 81 </div>
82 82  
83   - <button type="button" class="btn btn-block btn-default btn-sm loading-posts"><span class="fa fa-spin fa-circle-o-notch"></span></button>
84 83 <div class="posts">
85 84 </div>
  85 +
  86 + <button type="button" class="btn btn-block btn-success btn-raised more-posts" style="display:none">
  87 + {% trans 'See more posts' %}
  88 + </button>
  89 +
  90 + <div class="alert alert-success loading-posts" role="alert">
  91 + <center>
  92 + <span class="fa fa-spin fa-circle-o-notch"></span>
  93 + </center>
  94 + </div>
  95 +
86 96 <div class="text-center no-subjects" style="display:none">
87 97 <i class="fa fa-list"></i>
88 98 <h4>{% trans 'There are no posts in this mural yet.' %}</h4>
... ... @@ -91,7 +101,7 @@
91 101 <div class="col-md-3 col-sm-3 col-xs-3 post-filter">
92 102 <h4>{% trans 'Filter' %}</h4>
93 103  
94   - <form id="post-filters" action="" method="GET">
  104 + <form class="post-filters" action="" method="GET">
95 105 <div class="checkbox">
96 106 <label>
97 107 <input name="favorite" type="checkbox"> {% trans 'Favorite posts' %} <i class="fa fa-thumb-tack"></i>
... ... @@ -103,7 +113,7 @@
103 113 </label>
104 114 </div>
105 115 <button type="submit" class="btn btn-success btn-raised btn-block">{% trans 'Filter' %}</button>
106   - <button type="button" id="clear_filter" class="btn btn-default btn-raised btn-block">{% trans 'Clean Filters' %}</button>
  116 + <button type="button" class="clear_filter btn btn-default btn-raised btn-block">{% trans 'Clean Filters' %}</button>
107 117 </form>
108 118 </div>
109 119 </div>
... ...
mural/views.py
... ... @@ -219,11 +219,35 @@ def load_category_posts(request, category):
219 219 'request': request,
220 220 }
221 221  
  222 + user = request.user
  223 + favorites = request.GET.get('favorite', False)
  224 + mines = request.GET.get('mine', False)
222 225 showing = request.GET.get('showing', '')
223   -
224   - posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category).order_by("-most_recent")
  226 + n_views = 0
225 227  
226   - paginator = Paginator(posts, 10)
  228 + if not favorites:
  229 + if mines:
  230 + posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category, mural_ptr__user = user)
  231 + else:
  232 + posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category)
  233 + else:
  234 + if mines:
  235 + posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category, favorites_post__isnull = False, favorites_post__user = user, mural_ptr__user = user)
  236 + else:
  237 + posts = CategoryPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_categorypost.mural_ptr_id))"}).filter(space__id = category, favorites_post__isnull = False, favorites_post__user = user)
  238 +
  239 + if showing: #Exclude ajax creation posts results
  240 + showing = showing.split(',')
  241 + posts = posts.exclude(id__in = showing)
  242 +
  243 + has_page = request.GET.get('page', None)
  244 +
  245 + if has_page is None:
  246 + views = MuralVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(comment__post__categorypost__space__id = category) | Q(post__categorypost__space__id = category)))
  247 + n_views = views.count()
  248 + views.update(viewed = True)
  249 +
  250 + paginator = Paginator(posts.order_by("-most_recent"), 10)
227 251  
228 252 try:
229 253 page_number = int(request.GET.get('page', 1))
... ... @@ -239,7 +263,7 @@ def load_category_posts(request, category):
239 263  
240 264 response = render_to_string("mural/_list_view.html", context, request)
241 265  
242   - return JsonResponse({"posts": response, "count": posts.count(), "num_pages": paginator.num_pages, "num_page": page_obj.number})
  266 + return JsonResponse({"posts": response, "unviewed": n_views, "count": posts.count(), "num_pages": paginator.num_pages, "num_page": page_obj.number})
243 267  
244 268 class CategoryIndex(LoginRequiredMixin, generic.ListView):
245 269 login_url = reverse_lazy("users:login")
... ...