From: hernani Date: Tue, 14 Sep 2010 17:37:03 +0000 (+0000) Subject: Adds question and answer metrics (chars and words) on the editors, and in the "more... X-Git-Tag: live~539 X-Git-Url: https://git.openstreetmap.org/osqa.git/commitdiff_plain/cb4f846ea59604ea425b6726ce27ac7cd6d383d5 Adds question and answer metrics (chars and words) on the editors, and in the "more" menu for staff or superusers. Small css tweaks and a typo on the bulk manager. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@595 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js index 79cda45..bca7a5c 100644 --- a/forum/skins/default/media/js/osqa.main.js +++ b/forum/skins/default/media/js/osqa.main.js @@ -449,7 +449,7 @@ $(function() { $container.slideDown('slow'); $add_comment_link.fadeOut('slow'); $textarea.focus(); - window.setInterval(function() { + interval = window.setInterval(function() { process_form_changes(); }, 200); } @@ -529,6 +529,39 @@ $(function() { return false; }); }); + + if ($('#editor').length) { + var $editor = $('#editor'); + var $previewer = $('#previewer'); + var $container = $('#editor-metrics'); + + var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; + var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; + var editor_interval = null; + + $editor.focus(function() { + if (editor_interval == null) { + editor_interval = window.setInterval(function() { + recalc_metrics(); + }, 200); + } + }); + + function recalc_metrics() { + var text = $previewer.text(); + + var char_count = text.length; + var fullStr = text + " "; + var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); + var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); + var splitString = cleanedStr.split(" "); + var word_count = splitString.length - 1; + + var metrics = char_count + " " + (char_count == 1 ? messages.character : messages.characters); + metrics += " / " + word_count + " " + (word_count == 1 ? messages.word : messages.words); + $container.html(metrics); + } + } }); //var scriptUrl, interestingTags, ignoredTags, tags, $; diff --git a/forum/skins/default/templates/answer_edit.html b/forum/skins/default/templates/answer_edit.html index 2737294..c9d8466 100644 --- a/forum/skins/default/templates/answer_edit.html +++ b/forum/skins/default/templates/answer_edit.html @@ -75,6 +75,7 @@
{% trans "toggle preview" %} + {% if settings.WIKI_ON %}
{{ form.wiki }} {{ form.wiki.label_tag }} diff --git a/forum/skins/default/templates/ask.html b/forum/skins/default/templates/ask.html index 4e64fba..b027ce4 100644 --- a/forum/skins/default/templates/ask.html +++ b/forum/skins/default/templates/ask.html @@ -124,6 +124,7 @@ {% trans "toggle preview" %} + {% if settings.WIKI_ON %} {{ form.wiki }} {{ form.wiki.label_tag }} diff --git a/forum/skins/default/templates/base_content.html b/forum/skins/default/templates/base_content.html index 26a0d52..f92161e 100644 --- a/forum/skins/default/templates/base_content.html +++ b/forum/skins/default/templates/base_content.html @@ -34,7 +34,11 @@ cancel: "{% trans "Cancel" %}", close: "{% trans "Close" %}", ok: "{% trans "Ok" %}", - matching_tags_url: "{% url matching_tags %}" + matching_tags_url: "{% url matching_tags %}", + word: "{% trans "word" %}", + words: "{% trans "words" %}", + character: "{% trans "character" %}", + characters: "{% trans "characters" %}" } /* ]] */ diff --git a/forum/skins/default/templates/osqaadmin/nodeman.html b/forum/skins/default/templates/osqaadmin/nodeman.html index 816558d..997fab5 100644 --- a/forum/skins/default/templates/osqaadmin/nodeman.html +++ b/forum/skins/default/templates/osqaadmin/nodeman.html @@ -186,20 +186,14 @@ margin-right: 12px; } - #result_list tr.row1 td.deleted { + #result_list tr td.deleted { background-color: #FDD; + border-bottom: 1px solid #a9a9a9; } - #result_list tr.row2 td.deleted { - background-color: #FEE; - } - - #result_list tr.row1 td.accepted { + #result_list tr td.accepted { background-color: #DFD; - } - - #result_list tr.row2 td.accepted { - background-color: #EFD; + border-bottom: 1px solid #a9a9a9; } span.question-deleted { @@ -418,7 +412,7 @@ - + diff --git a/forum/skins/default/templates/question.html b/forum/skins/default/templates/question.html index 16c6a55..1b5b8e3 100644 --- a/forum/skins/default/templates/question.html +++ b/forum/skins/default/templates/question.html @@ -221,6 +221,7 @@ {% trans "toggle preview" %} + {% if settings.WIKI_ON %} {{ answer.wiki }} diff --git a/forum/skins/default/templates/question_edit.html b/forum/skins/default/templates/question_edit.html index 69bf688..12163be 100644 --- a/forum/skins/default/templates/question_edit.html +++ b/forum/skins/default/templates/question_edit.html @@ -116,6 +116,7 @@ {% trans "toggle preview" %} + {% if settings.WIKI_ON %} {{ form.wiki }} {{ form.wiki.label_tag }} diff --git a/forum/templatetags/node_tags.py b/forum/templatetags/node_tags.py index 8a685ce..33bd45f 100644 --- a/forum/templatetags/node_tags.py +++ b/forum/templatetags/node_tags.py @@ -1,7 +1,10 @@ from datetime import datetime, timedelta +import re from forum.models import Question, Action -from django.utils.translation import ugettext as _ +from django.utils.translation import ungettext, ugettext as _ +from django.utils.html import strip_tags +from django.utils.safestring import mark_safe from django.core.urlresolvers import reverse from django import template from forum.actions import * @@ -134,6 +137,21 @@ def post_controls(post, user): menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}), command=True, withprompt=True)) + if user.is_superuser or user.is_staff: + plain_text = strip_tags(post.html) + + char_count = len(plain_text) + fullStr = plain_text + " " + left_trimmedStr = re.sub(re.compile(r"^[^\w]+", re.IGNORECASE), "", fullStr) + cleanedStr = re.sub(re.compile(r"[^\w]+", re.IGNORECASE), " ", left_trimmedStr) + splitString = cleanedStr.split(" ") + word_count = len(splitString) - 1 + + metrics = mark_safe("%s %s / %s %s" % (char_count, ungettext('character', 'characters', char_count), + word_count, ungettext('word', 'words', word_count))) + + menu.append(post_control(metrics, "#", command=False, withprompt=False)) + return {'controls': controls, 'menu': menu, 'post': post, 'user': user} @register.inclusion_tag('node/comments.html')