Commit aa7c77b1c0bb0e931646b346bfbb53362325a777

Authored by Zambom
1 parent 97b3f507

Adding category mural filter and load posts

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,7 +14,10 @@ $('.mural-category').on('shown.bs.collapse', function(e) {
14 14
15 var post_section = $(this).find('.posts'), 15 var post_section = $(this).find('.posts'),
16 without = $(this).find('.no-subjects'), 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 if (post_section.children().length == 0) { 22 if (post_section.children().length == 0) {
20 var url = $(this).find('.mural').data('url'); 23 var url = $(this).find('.mural').data('url');
@@ -28,13 +31,111 @@ $('.mural-category').on('shown.bs.collapse', function(e) { @@ -28,13 +31,111 @@ $('.mural-category').on('shown.bs.collapse', function(e) {
28 if (data.count > 0) { 31 if (data.count > 0) {
29 post_section.append(data.posts); 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 +
31 without.hide(); 45 without.hide();
32 } else { 46 } else {
  47 + more.hide();
  48 +
33 without.show(); 49 without.show();
34 } 50 }
35 } 51 }
36 }); 52 });
37 } 53 }
  54 +
  55 + more.click(function () {
  56 + var url = mural.data('url'),
  57 + pageNum = mural.data('page'),
  58 + numberPages = mural.data('pages'),
  59 + favorites = mural.data('fav'),
  60 + mine = mural.data('mine'),
  61 + showing = new_posts.join(',');
  62 +
  63 + if (pageNum == numberPages) {
  64 + return false
  65 + }
  66 +
  67 + pageNum = pageNum + 1;
  68 +
  69 + more.hide();
  70 +
  71 + loading.show();
  72 +
  73 + $.ajax({
  74 + url: url,
  75 + data: {'page': pageNum, 'favorite': favorites, 'mine': mine, 'showing': showing},
  76 + dataType: 'json',
  77 + success: function (data) {
  78 + loading.hide();
  79 +
  80 + post_section.append(data.posts);
  81 +
  82 + mural.data('pages', data.num_pages);
  83 + mural.data('page', data.num_page);
  84 +
  85 + setTimeout(function () { postHeightLimits() }, 100);
  86 +
  87 + if (data.num_page < data.num_pages) {
  88 + more.show();
  89 + } else {
  90 + more.hide();
  91 + }
  92 + }
  93 + });
  94 + });
  95 +
  96 + filters.submit(function () {
  97 + var favorite = $(this).find("input[name='favorite']").is(':checked') ? "True" : "",
  98 + mine = $(this).find("input[name='mine']").is(':checked') ? "True" : "",
  99 + url = mural.data('url');
  100 +
  101 + post_section.html('');
  102 +
  103 + more.hide();
  104 + loading.show();
  105 +
  106 + $.ajax({
  107 + url: url,
  108 + data: {'favorite': favorite, 'mine': mine},
  109 + dataType: 'json',
  110 + success: function (data) {
  111 + loading.hide();
  112 +
  113 + if (data.count > 0) {
  114 + post_section.append(data.posts);
  115 +
  116 + mural.data('pages', data.num_pages);
  117 + mural.data('page', data.num_page);
  118 +
  119 + if (data.num_page < data.num_pages) {
  120 + more.show();
  121 + } else {
  122 + more.hide();
  123 + }
  124 +
  125 + setTimeout(function () { postHeightLimits() }, 100);
  126 +
  127 + without.hide();
  128 + } else {
  129 + without.show();
  130 + }
  131 +
  132 + mural.data('fav', favorite);
  133 + mural.data('mine', mine);
  134 + }
  135 + });
  136 +
  137 + return false;
  138 + });
38 } 139 }
39 }); 140 });
40 141
mural/templates/mural/list_category.html
@@ -80,9 +80,19 @@ @@ -80,9 +80,19 @@
80 </div> 80 </div>
81 </div> 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 <div class="posts"> 83 <div class="posts">
85 </div> 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 <div class="text-center no-subjects" style="display:none"> 96 <div class="text-center no-subjects" style="display:none">
87 <i class="fa fa-list"></i> 97 <i class="fa fa-list"></i>
88 <h4>{% trans 'There are no posts in this mural yet.' %}</h4> 98 <h4>{% trans 'There are no posts in this mural yet.' %}</h4>
@@ -91,7 +101,7 @@ @@ -91,7 +101,7 @@
91 <div class="col-md-3 col-sm-3 col-xs-3 post-filter"> 101 <div class="col-md-3 col-sm-3 col-xs-3 post-filter">
92 <h4>{% trans 'Filter' %}</h4> 102 <h4>{% trans 'Filter' %}</h4>
93 103
94 - <form id="post-filters" action="" method="GET"> 104 + <form class="post-filters" action="" method="GET">
95 <div class="checkbox"> 105 <div class="checkbox">
96 <label> 106 <label>
97 <input name="favorite" type="checkbox"> {% trans 'Favorite posts' %} <i class="fa fa-thumb-tack"></i> 107 <input name="favorite" type="checkbox"> {% trans 'Favorite posts' %} <i class="fa fa-thumb-tack"></i>
@@ -103,7 +113,7 @@ @@ -103,7 +113,7 @@
103 </label> 113 </label>
104 </div> 114 </div>
105 <button type="submit" class="btn btn-success btn-raised btn-block">{% trans 'Filter' %}</button> 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 </form> 117 </form>
108 </div> 118 </div>
109 </div> 119 </div>
mural/views.py
@@ -219,11 +219,27 @@ def load_category_posts(request, category): @@ -219,11 +219,27 @@ def load_category_posts(request, category):
219 'request': request, 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 showing = request.GET.get('showing', '') 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")  
225 226
226 - paginator = Paginator(posts, 10) 227 + if not favorites:
  228 + if mines:
  229 + 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)
  230 + else:
  231 + 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)
  232 + else:
  233 + if mines:
  234 + 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)
  235 + else:
  236 + 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)
  237 +
  238 + if showing: #Exclude ajax creation posts results
  239 + showing = showing.split(',')
  240 + posts = posts.exclude(id__in = showing)
  241 +
  242 + paginator = Paginator(posts.order_by("-most_recent"), 2)
227 243
228 try: 244 try:
229 page_number = int(request.GET.get('page', 1)) 245 page_number = int(request.GET.get('page', 1))