##// END OF EJS Templates
Added favorite thread popup
neko259 -
r1340:668e9798 default
parent child Browse files
Show More
@@ -19,7 +19,7 b" CONTEXT_NEW_NOTIFICATIONS_COUNT = 'new_n"
19 19 CONTEXT_USERNAME = 'username'
20 20 CONTEXT_TAGS_STR = 'tags_str'
21 21 CONTEXT_IMAGE_VIEWER = 'image_viewer'
22 CONTEXT_FAV_THREADS = 'fav_threads'
22 CONTEXT_HAS_FAV_THREADS = 'has_fav_threads'
23 23
24 24
25 25 def get_notifications(context, request):
@@ -45,8 +45,6 b' def user_and_ui_processor(request):'
45 45 fav_tags = settings_manager.get_fav_tags()
46 46 context[CONTEXT_TAGS] = fav_tags
47 47
48 _get_fav_threads(context, settings_manager)
49
50 48 context[CONTEXT_TAGS_STR] = Tag.objects.get_tag_url_list(fav_tags)
51 49 theme = settings_manager.get_theme()
52 50 context[CONTEXT_THEME] = theme
@@ -62,27 +60,9 b' def user_and_ui_processor(request):'
62 60 SETTING_IMAGE_VIEWER,
63 61 default=settings.get('View', 'DefaultImageViewer'))
64 62
63 context[CONTEXT_HAS_FAV_THREADS] =\
64 len(settings_manager.get_fav_threads()) > 0
65
65 66 get_notifications(context, request)
66 67
67 68 return context
68
69
70 def _get_fav_threads(context, settings_manager):
71 fav_threads_setting = settings_manager.get_fav_threads()
72 if fav_threads_setting:
73 fav_threads = Post.objects.filter(
74 id__in=fav_threads_setting.keys()).only('url', 'id', 'thread')\
75 .select_related('thread')
76
77 context_thread_list = []
78 for post in fav_threads:
79 new_replies = post.get_thread().get_replies_newer(fav_threads_setting[str(post.id)])
80
81 element = dict()
82 element['post'] = post
83 element['count'] = new_replies.count()
84 if element['count'] > 0:
85 element['new_post'] = new_replies.first().get_absolute_url()
86 context_thread_list.append(element)
87 context[CONTEXT_FAV_THREADS] = context_thread_list
88
1 NO CONTENT: modified file, binary diff hidden
@@ -478,3 +478,9 b' msgstr "\xd0\x9e\xd0\xba"'
478 478 #, python-format
479 479 msgid "File must be less than %s bytes"
480 480 msgstr "Π€Π°ΠΉΠ» Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ ΠΌΠ΅Π½Π΅Π΅ %s Π±Π°ΠΉΡ‚"
481
482 msgid "favorites"
483 msgstr "ΠΈΠ·Π±Ρ€Π°Π½Π½ΠΎΠ΅"
484
485 msgid "Loading..."
486 msgstr "Π—Π°Π³Ρ€ΡƒΠ·ΠΊΠ°..." No newline at end of file
@@ -133,4 +133,13 b' textarea, input {'
133 133
134 134 .tripcode {
135 135 padding: 2px;
136 }
137
138 #fav-panel {
139 display: none;
140 margin: 1ex;
141 }
142
143 #new-fav-post-count {
144 display: none;
136 145 } No newline at end of file
@@ -563,3 +563,7 b' ul {'
563 563 .tripcode {
564 564 color: white;
565 565 }
566
567 #fav-panel {
568 border: 1px solid white;
569 }
@@ -23,6 +23,8 b''
23 23 for the JavaScript code in this page.
24 24 */
25 25
26 var FAV_POST_UPDATE_PERIOD = 10000;
27
26 28 /**
27 29 * An email is a hidden file to prevent spam bots from posting. It has to be
28 30 * hidden.
@@ -40,6 +42,72 b' function highlightCode(node) {'
40 42 });
41 43 }
42 44
45 function updateFavPosts() {
46 var includePostBody = $('#fav-panel').is(":visible");
47 var url = '/api/new_posts/';
48 if (includePostBody) {
49 url += '?include_posts'
50 }
51 $.getJSON(url,
52 function(data) {
53 var allNewPostCount = 0;
54
55 if (includePostBody) {
56 var favoriteThreadPanel = $('#fav-panel');
57 favoriteThreadPanel.empty();
58 }
59
60 $.each(data, function (_, dict) {
61 var newPostCount = dict.new_post_count;
62 allNewPostCount += newPostCount;
63
64 if (includePostBody) {
65 var post = $(dict.post);
66
67 var id = post.find('.post_id');
68 var title = post.find('.title');
69
70 var favThreadNode = $('<div class="post"></div>');
71 favThreadNode.append(id);
72 favThreadNode.append(' ');
73 favThreadNode.append(title);
74
75 if (newPostCount > 0) {
76 favThreadNode.append(' (<a href="' + dict.newest_post_link + '">+' + newPostCount + "</a>)");
77 }
78
79 favoriteThreadPanel.append(favThreadNode);
80 }
81 });
82
83 var newPostCountNode = $('#new-fav-post-count');
84 if (allNewPostCount > 0) {
85 newPostCountNode.text('(+' + allNewPostCount + ')');
86 newPostCountNode.show();
87 } else {
88 newPostCountNode.hide();
89 }
90 }
91 );
92 }
93
94 function initFavPanel() {
95 updateFavPosts();
96 setInterval(updateFavPosts, FAV_POST_UPDATE_PERIOD);
97 $('#fav-panel-btn').click(function() {
98 $('#fav-panel').toggle();
99 updateFavPosts();
100
101 return false;
102 });
103
104 $(document).on('keyup.removepic', function(e) {
105 if(e.which === 27) {
106 $('#fav-panel').hide();
107 }
108 });
109 }
110
43 111 $( document ).ready(function() {
44 112 hideEmailFromForm();
45 113
@@ -53,4 +121,6 b' function highlightCode(node) {'
53 121 addRefLinkPreview();
54 122
55 123 highlightCode($(document));
124
125 initFavPanel();
56 126 });
@@ -113,7 +113,7 b' function getThreadDiff() {'
113 113 var data = {
114 114 uids: uids,
115 115 thread: threadId
116 }
116 };
117 117
118 118 var diffUrl = '/api/diff_thread/';
119 119
@@ -39,7 +39,10 b''
39 39 <a href="{% url 'tags' 'required'%}" title="{% trans 'Tag management' %}">{% trans "tags" %}</a>,
40 40 <a href="{% url 'search' %}" title="{% trans 'Search' %}">{% trans 'search' %}</a>,
41 41 <a href="{% url 'feed' %}" title="{% trans 'Feed' %}">{% trans 'feed' %}</a>,
42 <a href="{% url 'random' %}" title="{% trans 'Random images' %}">{% trans 'random' %}</a>
42 <a href="{% url 'random' %}" title="{% trans 'Random images' %}">{% trans 'random' %}</a>{% if has_fav_threads %},
43
44 <a href="#" id="fav-panel-btn">{% trans 'favorites' %} <span id="new-fav-post-count"></span></a>
45 {% endif %}
43 46
44 47 {% if username %}
45 48 <a class="right-link link" href="{% url 'notifications' username %}" title="{% trans 'Notifications' %}">
@@ -53,17 +56,7 b''
53 56 <a class="right-link link" href="{% url 'settings' %}">{% trans 'Settings' %}</a>
54 57 </div>
55 58
56 {% if fav_threads %}
57 <div class="image-mode-tab">
58 β˜…
59 {% for thread in fav_threads %}
60 {% comment %}
61 If there are new posts in the thread, show their count.
62 {% endcomment %}
63 {{ thread.post.get_link_view|safe }}{% if thread.count %} (<a href="{{ thread.new_post }}">+{{ thread.count }}</a>){% endif %}{% if not forloop.last %}, {% endif %}
64 {% endfor %}
65 </div>
66 {% endif %}
59 <div id="fav-panel"><div class="post">{% trans "Loading..." %}</div></div>
67 60
68 61 {% block content %}{% endblock %}
69 62
@@ -69,6 +69,7 b" urlpatterns = patterns('',"
69 69 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
70 70 name='api_notifications'),
71 71 url(r'^api/preview/$', api.api_get_preview, name='preview'),
72 url(r'^api/new_posts/$', api.api_get_new_posts, name='new_posts'),
72 73
73 74 # Search
74 75 url(r'^search/$', BoardSearchView.as_view(), name='search'),
@@ -1,3 +1,4 b''
1 from collections import OrderedDict
1 2 import json
2 3 import logging
3 4
@@ -58,8 +59,8 b' def api_get_threaddiff(request):'
58 59 diff_type = request.GET.get(PARAMETER_DIFF_TYPE, DIFF_TYPE_HTML)
59 60
60 61 for post in posts:
61 json_data[PARAMETER_UPDATED].append(get_post_data(post.id, diff_type,
62 request))
62 json_data[PARAMETER_UPDATED].append(post.get_post_data(
63 format_type=diff_type, request=request))
63 64 json_data[PARAMETER_LAST_UPDATE] = str(thread.last_edit_time)
64 65
65 66 # If the tag is favorite, update the counter
@@ -151,7 +152,7 b' def api_get_threads(request, count):'
151 152 opening_post = thread.get_opening_post()
152 153
153 154 # TODO Add tags, replies and images count
154 post_data = get_post_data(opening_post.id, include_last_update=True)
155 post_data = opening_post.get_post_data(include_last_update=True)
155 156 post_data['bumpable'] = thread.can_bump()
156 157 post_data['archived'] = thread.archived
157 158
@@ -197,7 +198,7 b' def api_get_thread_posts(request, openin'
197 198 json_post_list = []
198 199
199 200 for post in posts:
200 json_post_list.append(get_post_data(post.id))
201 json_post_list.append(post.get_post_data())
201 202 json_data['last_update'] = datetime_to_epoch(thread.last_edit_time)
202 203 json_data['posts'] = json_post_list
203 204
@@ -213,7 +214,7 b' def api_get_notifications(request, usern'
213 214
214 215 json_post_list = []
215 216 for post in posts:
216 json_post_list.append(get_post_data(post.id))
217 json_post_list.append(post.get_post_data())
217 218 return HttpResponse(content=json.dumps(json_post_list))
218 219
219 220
@@ -233,16 +234,41 b' def api_get_post(request, post_id):'
233 234 return HttpResponse(content=json)
234 235
235 236
236 # TODO Remove this method and use post method directly
237 def get_post_data(post_id, format_type=DIFF_TYPE_JSON, request=None,
238 include_last_update=False):
239 post = get_object_or_404(Post, id=post_id)
240 return post.get_post_data(format_type=format_type, request=request,
241 include_last_update=include_last_update)
242
243
244 237 def api_get_preview(request):
245 238 raw_text = request.POST['raw_text']
246 239
247 240 parser = Parser()
248 241 return HttpResponse(content=parser.parse(parser.preparse(raw_text)))
242
243
244 def api_get_new_posts(request):
245 """
246 Gets favorite threads and unread posts count.
247 """
248 posts = list()
249
250 include_posts = 'include_posts' in request.GET
251
252 settings_manager = get_settings_manager(request)
253 fav_threads = settings_manager.get_fav_threads()
254 fav_thread_ops = Post.objects.filter(id__in=fav_threads.keys())\
255 .order_by('-pub_time').prefetch_related('thread')
256
257 for op in fav_thread_ops:
258 last_read_post = fav_threads[str(op.id)]
259 new_posts = op.get_thread().get_replies_newer(last_read_post)
260 new_post_count = new_posts.count()
261 fav_thread_dict = dict()
262 fav_thread_dict['id'] = op.id
263 fav_thread_dict['new_post_count'] = new_post_count
264
265 if include_posts:
266 fav_thread_dict['post'] = op.get_post_data(
267 format_type=DIFF_TYPE_HTML)
268 if new_post_count > 0:
269 fav_thread_dict['newest_post_link'] = new_posts.first()\
270 .get_absolute_url()
271
272 posts.append(fav_thread_dict)
273
274 return HttpResponse(content=json.dumps(posts))
General Comments 0
You need to be logged in to leave comments. Login now