mirror of https://gitlab.com/tildes/tildes.git
Deimos
6 years ago
28 changed files with 308 additions and 256 deletions
-
7tildes/alembic/env.py
-
38tildes/alembic/versions/5cd2db18b722_rename_comment_tags_to_labels.py
-
2tildes/development.ini
-
2tildes/production.ini.example
-
2tildes/scripts/clean_private_data.py
-
10tildes/scss/_themes.scss
-
12tildes/scss/_variables.scss
-
24tildes/scss/modules/_btn.scss
-
12tildes/scss/modules/_comment.scss
-
2tildes/scss/modules/_label.scss
-
100tildes/static/js/behaviors/comment-label-button.js
-
100tildes/static/js/behaviors/comment-tag-button.js
-
6tildes/tildes/enums.py
-
2tildes/tildes/models/comment/__init__.py
-
50tildes/tildes/models/comment/comment.py
-
26tildes/tildes/models/comment/comment_label.py
-
22tildes/tildes/models/comment/comment_tree.py
-
6tildes/tildes/models/user/user.py
-
4tildes/tildes/routes.py
-
8tildes/tildes/schemas/comment.py
-
50tildes/tildes/templates/macros/comments.jinja2
-
4tildes/tildes/templates/notifications_unread.jinja2
-
4tildes/tildes/templates/topic.jinja2
-
4tildes/tildes/templates/user.jinja2
-
51tildes/tildes/views/api/web/comment.py
-
6tildes/tildes/views/notifications.py
-
6tildes/tildes/views/topic.py
-
4tildes/tildes/views/user.py
@ -0,0 +1,38 @@ |
|||||
|
"""Rename comment tags to labels |
||||
|
|
||||
|
Revision ID: 5cd2db18b722 |
||||
|
Revises: afa3128a9b54 |
||||
|
Create Date: 2018-09-25 01:05:55.606680 |
||||
|
|
||||
|
""" |
||||
|
from alembic import op |
||||
|
import sqlalchemy as sa |
||||
|
from sqlalchemy.dialects import postgresql |
||||
|
|
||||
|
# revision identifiers, used by Alembic. |
||||
|
revision = "5cd2db18b722" |
||||
|
down_revision = "afa3128a9b54" |
||||
|
branch_labels = None |
||||
|
depends_on = None |
||||
|
|
||||
|
|
||||
|
def upgrade(): |
||||
|
op.execute("ALTER TYPE commenttagoption RENAME TO commentlabeloption") |
||||
|
|
||||
|
op.rename_table("comment_tags", "comment_labels") |
||||
|
op.alter_column("comment_labels", "tag", new_column_name="label") |
||||
|
|
||||
|
op.alter_column( |
||||
|
"users", "comment_tag_weight", new_column_name="comment_label_weight" |
||||
|
) |
||||
|
|
||||
|
|
||||
|
def downgrade(): |
||||
|
op.alter_column( |
||||
|
"users", "comment_label_weight", new_column_name="comment_tag_weight" |
||||
|
) |
||||
|
|
||||
|
op.alter_column("comment_labels", "label", new_column_name="tag") |
||||
|
op.rename_table("comment_labels", "comment_tags") |
||||
|
|
||||
|
op.execute("ALTER TYPE commentlabeloption RENAME TO commenttagoption") |
@ -0,0 +1,100 @@ |
|||||
|
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
||||
|
$.onmount('[data-js-comment-label-button]', function() { |
||||
|
$(this).click(function(event) { |
||||
|
event.preventDefault(); |
||||
|
|
||||
|
var $comment = $(this).parents('.comment').first(); |
||||
|
var userLabels = $comment.attr('data-comment-user-labels'); |
||||
|
|
||||
|
// check if the label button div already exists and just remove it if so
|
||||
|
$labelButtons = $comment.find('.comment-itself:first').find('.comment-label-buttons'); |
||||
|
if ($labelButtons.length > 0) { |
||||
|
$labelButtons.remove(); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
var commentID = $comment.attr('data-comment-id36'); |
||||
|
var labelURL = '/api/web/comments/' + commentID + '/labels/'; |
||||
|
|
||||
|
var labeltemplate = document.querySelector('#comment-label-options'); |
||||
|
var clone = document.importNode(labeltemplate.content, true); |
||||
|
var options = clone.querySelectorAll('a'); |
||||
|
|
||||
|
for (i = 0; i < options.length; i++) { |
||||
|
var label = options[i]; |
||||
|
var labelName = label.textContent; |
||||
|
|
||||
|
var labelOptionActive = false; |
||||
|
if (userLabels.indexOf(labelName) !== -1) { |
||||
|
labelOptionActive = true; |
||||
|
} |
||||
|
|
||||
|
var labelPrompt = label.getAttribute("data-js-reason-prompt"); |
||||
|
|
||||
|
if (labelOptionActive) { |
||||
|
label.className += " btn btn-used"; |
||||
|
label.setAttribute('data-ic-delete-from', labelURL + labelName); |
||||
|
|
||||
|
// if the label requires a prompt, confirm that they want to remove it
|
||||
|
// (since we don't want to accidentally lose the reason they typed in)
|
||||
|
if (labelPrompt) { |
||||
|
label.setAttribute("data-ic-confirm", "Remove your "+labelName+" label?"); |
||||
|
} |
||||
|
|
||||
|
$(label).on('after.success.ic', function(evt) { |
||||
|
Tildes.removeUserLabel(commentID, evt.target.textContent); |
||||
|
}); |
||||
|
} else { |
||||
|
label.setAttribute('data-ic-put-to', labelURL + labelName); |
||||
|
|
||||
|
if (labelPrompt) { |
||||
|
label.setAttribute("data-ic-prompt", labelPrompt); |
||||
|
label.setAttribute("data-ic-prompt-name", "reason"); |
||||
|
} |
||||
|
|
||||
|
$(label).on('after.success.ic', function(evt) { |
||||
|
Tildes.addUserLabel(commentID, evt.target.textContent); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
label.setAttribute('data-ic-target', '#comment-' + commentID + ' .comment-itself:first'); |
||||
|
} |
||||
|
|
||||
|
// update Intercooler so it knows about these new elements
|
||||
|
Intercooler.processNodes(clone); |
||||
|
|
||||
|
$comment.find(".post-buttons").first().after(clone); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
Tildes.removeUserLabel = function(commentID, labelName) { |
||||
|
$comment = $("#comment-" + commentID); |
||||
|
var userLabels = $comment.attr('data-comment-user-labels').split(" "); |
||||
|
|
||||
|
// if the label isn't there, don't need to do anything
|
||||
|
labelIndex = userLabels.indexOf(labelName); |
||||
|
if (labelIndex === -1) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
// remove the label from the list and update the data attr
|
||||
|
userLabels.splice(labelIndex, 1); |
||||
|
$comment.attr('data-comment-user-labels', userLabels.join(" ")); |
||||
|
} |
||||
|
|
||||
|
Tildes.addUserLabel = function(commentID, labelName) { |
||||
|
$comment = $("#comment-" + commentID); |
||||
|
var userLabels = $comment.attr('data-comment-user-labels').split(" "); |
||||
|
|
||||
|
// don't add the label again if it's already there
|
||||
|
labelIndex = userLabels.indexOf(labelName); |
||||
|
if (labelIndex !== -1) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
// add the label to the list and update the data attr
|
||||
|
userLabels.push(labelName); |
||||
|
$comment.attr('data-comment-user-labels', userLabels.join(" ")); |
||||
|
} |
@ -1,100 +0,0 @@ |
|||||
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
|
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||
|
|
||||
$.onmount('[data-js-comment-tag-button]', function() { |
|
||||
$(this).click(function(event) { |
|
||||
event.preventDefault(); |
|
||||
|
|
||||
var $comment = $(this).parents('.comment').first(); |
|
||||
var user_tags = $comment.attr('data-comment-user-tags'); |
|
||||
|
|
||||
// check if the tagging button div already exists and just remove it if so
|
|
||||
$tagButtons = $comment.find('.comment-itself:first').find('.comment-tag-buttons'); |
|
||||
if ($tagButtons.length > 0) { |
|
||||
$tagButtons.remove(); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
var commentID = $comment.attr('data-comment-id36'); |
|
||||
var tagURL = '/api/web/comments/' + commentID + '/tags/'; |
|
||||
|
|
||||
var tagtemplate = document.querySelector('#comment-tag-options'); |
|
||||
var clone = document.importNode(tagtemplate.content, true); |
|
||||
var options = clone.querySelectorAll('a'); |
|
||||
|
|
||||
for (i = 0; i < options.length; i++) { |
|
||||
var tag = options[i]; |
|
||||
var tagName = tag.textContent; |
|
||||
|
|
||||
var tagOptionActive = false; |
|
||||
if (user_tags.indexOf(tagName) !== -1) { |
|
||||
tagOptionActive = true; |
|
||||
} |
|
||||
|
|
||||
var tagPrompt = tag.getAttribute("data-js-reason-prompt"); |
|
||||
|
|
||||
if (tagOptionActive) { |
|
||||
tag.className += " btn btn-used"; |
|
||||
tag.setAttribute('data-ic-delete-from', tagURL + tagName); |
|
||||
|
|
||||
// if the tag requires a prompt, confirm that they want to remove it
|
|
||||
// (since we don't want to accidentally lose the reason they typed in)
|
|
||||
if (tagPrompt) { |
|
||||
tag.setAttribute("data-ic-confirm", "Remove your "+tagName+" tag?"); |
|
||||
} |
|
||||
|
|
||||
$(tag).on('after.success.ic', function(evt) { |
|
||||
Tildes.removeUserTag(commentID, evt.target.textContent); |
|
||||
}); |
|
||||
} else { |
|
||||
tag.setAttribute('data-ic-put-to', tagURL + tagName); |
|
||||
|
|
||||
if (tagPrompt) { |
|
||||
tag.setAttribute("data-ic-prompt", tagPrompt); |
|
||||
tag.setAttribute("data-ic-prompt-name", "reason"); |
|
||||
} |
|
||||
|
|
||||
$(tag).on('after.success.ic', function(evt) { |
|
||||
Tildes.addUserTag(commentID, evt.target.textContent); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
tag.setAttribute('data-ic-target', '#comment-' + commentID + ' .comment-itself:first'); |
|
||||
} |
|
||||
|
|
||||
// update Intercooler so it knows about these new elements
|
|
||||
Intercooler.processNodes(clone); |
|
||||
|
|
||||
$comment.find(".post-buttons").first().after(clone); |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
Tildes.removeUserTag = function(commentID, tagName) { |
|
||||
$comment = $("#comment-" + commentID); |
|
||||
var user_tags = $comment.attr('data-comment-user-tags').split(" "); |
|
||||
|
|
||||
// if the tag isn't there, don't need to do anything
|
|
||||
tagIndex = user_tags.indexOf(tagName); |
|
||||
if (tagIndex === -1) { |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
// remove the tag from the list and update the data attr
|
|
||||
user_tags.splice(tagIndex, 1); |
|
||||
$comment.attr('data-comment-user-tags', user_tags.join(" ")); |
|
||||
} |
|
||||
|
|
||||
Tildes.addUserTag = function(commentID, tagName) { |
|
||||
$comment = $("#comment-" + commentID); |
|
||||
var user_tags = $comment.attr('data-comment-user-tags').split(" "); |
|
||||
|
|
||||
// don't add the tag again if it's already there
|
|
||||
tagIndex = user_tags.indexOf(tagName); |
|
||||
if (tagIndex !== -1) { |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
// add the tag to the list and update the data attr
|
|
||||
user_tags.push(tagName); |
|
||||
$comment.attr('data-comment-user-tags', user_tags.join(" ")); |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue