Commit c8454314 authored by Aster's avatar Aster Committed by waltermazza
Browse files

General Bug Fixes and Improvements

parent 5851545f
{
"name": "arter/amos-comments",
"description": "Comments for contents - plugin",
"keywords": [
"amos",
"yii2",
"comments"
],
"keywords": ["amos", "yii2", "comments"],
"type": "plugin",
"license": "BSD-3-Clause",
"require": {
......
......@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see https://repo.art-er.it Developers' community
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
......@@ -31,33 +31,27 @@ use yii\base\Event;
class AmosComments extends AmosModule implements ModuleInterface, BootstrapInterface
{
public static $CONFIG_FOLDER = 'config';
/**
* @var string|boolean the layout that should be applied for views within this module. This refers to a view name
* relative to [[layoutPath]]. If this is not set, it means the layout value of the [[module|parent module]]
* will be taken. If this is false, layout will be disabled within this module.
*/
public $layout = 'main';
/**
* @inheritdoc
*/
public $controllerNamespace = 'arter\amos\comments\controllers';
public $newFileMode = 0666;
public $name = 'Comments';
public $newFileMode = 0666;
public $name = 'Comments';
public $layoutInverted = false;
public $layoutInverted = false;
/**
* @var array $modelsEnabled
*/
public $modelsEnabled = [];
public $maxCommentAttachments = 5;
public $modelsEnabled = [];
public $maxCommentAttachments = 5;
public $enableMailsNotification = true;
/**
......@@ -65,12 +59,36 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
*/
public $enableUserSendMailCheckbox = true;
/**
* This is the html used to render the subject of the e-mail. In the view is available the variable $profile
* that is an instance of 'arter\amos\admin\models\UserProfile'
* @var string
*/
public $htmlMailContentSubject = '@vendor/arter/amos-comments/src/views/comment/email/content_subject';
// public $htmlMailContentTitle = [
// 'arter\amos\news\models\News' => '@vendor/arter/amos-comments/src/views/comment/email/content_subject_news',
// 'arter\amos\discussioni\models\DiscussioniTopic' => '@vendor/arter/amos-comments/src/views/comment/email/content_subject_discussioni',
// 'arter\amos\documenti\models\Documenti' => '@vendor/arter/amos-comments/src/views/comment/email/content_subjcet_documenti'
// ];
public $htmlMailContentSubjectDefault = '@vendor/arter/amos-comments/src/views/comment/email/content_subject';
/**
* This is the html used to render the subject of the e-mail. In the view is available the variable $profile
* that is an instance of 'arter\amos\admin\models\UserProfile'
* @var string
*/
public $htmlMailContentTitle = '@vendor/arter/amos-comments/src/views/comment/email/content_title';
// public $htmlMailContentTitle = [
// 'arter\amos\news\models\News' => '@vendor/arter/amos-comments/src/views/comment/email/content_title_news',
// 'arter\amos\discussioni\models\DiscussioniTopic' => '@vendor/arter/amos-comments/src/views/comment/email/content_title_discussioni',
// 'arter\amos\documenti\models\Documenti' => '@vendor/arter/amos-comments/src/views/comment/email/content_title_documenti'
// ];
/*
*
*/
public $htmlMailContentTitleDefault = '@vendor/arter/amos-comments/src/views/comment/email/content_title';
/**
* This is the html used to render the message of the e-mail. In the view is available the variable $profile
......@@ -84,6 +102,10 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
// 'arter\amos\documenti\models\Documenti' => '@vendor/arter/amos-comments/src/views/comment/email/content_documenti'
// ];
/*
*
*/
public $htmlMailContentDefault = '@vendor/arter/amos-comments/src/views/comment/email/content';
/**
* Sets if the notify checkbox must be visible into the comments accordion
* @var bool
......@@ -101,6 +123,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
* @var boolean $enableCommentOnlyWithScope
*/
public $enableCommentOnlyWithScope = false;
public $disableAutoDisplay = ['amos\planner\models\PlanWork'];
/**
* If a true notify the context model (DiscussioniTopic) if is created a comment
......@@ -108,6 +131,18 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
*/
public $enableNotifyCommentForDiscussions = true;
/**
*
* @var type 3 by SORT_DESC, 4 by SORT_ASC
*/
public $orderDisplayComments = 3;
/**
*
* @var type
*/
public $disablePagination = false;
/**
* @return string
*/
......@@ -115,18 +150,18 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{
return 'comments';
}
/**
* @inheritdoc
*/
public function init()
{
parent::init();
\Yii::setAlias('@arter/amos/' . static::getModuleName() . '/controllers', __DIR__ . '/controllers/');
\Yii::setAlias('@arter/amos/'.static::getModuleName().'/controllers', __DIR__.'/controllers/');
// custom initialization code goes here
\Yii::configure($this, require(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'));
\Yii::configure($this, require(__DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'));
}
/**
* @inheritdoc
*/
......@@ -134,7 +169,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{
return NULL;
}
/**
* @inheritdoc
*/
......@@ -142,7 +177,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{
return [];
}
/**
* @inheritdoc
*/
......@@ -150,7 +185,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{
return [];
}
/**
* @inheritdoc
*/
......@@ -158,8 +193,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{
Event::on(AmosView::className(), AmosView::AFTER_RENDER_CONTENT, [new CommentComponent(), 'showComments']);
}
/**
* @param $model
*/
......@@ -169,14 +203,14 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
->joinWith('commentReplies', true, 'LEFT JOIN')
->andWhere(['context' => $model->className(), 'context_id' => $model->id])
->groupBy('comment.id');
/** @var \arter\amos\comments\models\Comment $lastComment */
$countComment = $query->count();
$query = Comment::find()
$query = Comment::find()
->joinWith('commentReplies', true, 'LEFT JOIN')
->andWhere(['context' => $model->className(), 'context_id' => $model->id])
->andWhere(['is not', CommentReply::tableName() . '.id', null]);
->andWhere(['is not', CommentReply::tableName().'.id', null]);
$countComment += $query->count();
return $countComment;
}
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see https://repo.art-er.it Developers' community
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\comments\assets
* @category CategoryName
* @author Elite Division S.r.l.
*/
namespace arter\amos\comments\assets;
use yii\web\AssetBundle;
/**
* Class CommentsAsset
* @package arter\amos\comments\assets
*/
class CommentsBootstrapitaliaAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $sourcePath = '@vendor/arter/amos-comments/src/assets/web';
/**
* @inheritdoc
*/
public $css = [
];
/**
* @inheritdoc
*/
public $js = [
'js/comments_bootstrapitalia.js'
];
/**
* @inheritdoc
*/
public $depends = [
'yii\web\JqueryAsset',
];
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ Comments.completeAjax = function () {
$('#comments_anchor').prop('disabled', false);
};
Comments.saveComment = function (context_id, context) {
Comments.saveComment = function (context_id, context, csrfKey, csrfValue) {
// Identify comment container of the content.
var comment_container = $("#bk-contribute");
......@@ -43,6 +43,9 @@ Comments.saveComment = function (context_id, context) {
formData.append('Comment[context]', context);
formData.append('Comment[context_id]', context_id);
formData.append('Comment[comment_text]', comment_text);
if (csrfKey !== null && csrfKey !== 'undefined') {
formData.append(csrfKey, csrfValue);
}
// It retrieves the comment attachments.
var commentAttachments = $('#commentAttachments').prop('files');
......@@ -79,6 +82,10 @@ Comments.saveComment = function (context_id, context) {
if (response.error) {
alert(response.error.msg);
} else {
var urlRedirect = $('#url-redirect').val();
if(urlRedirect != '' && urlRedirect != undefined){
window.location.href = urlRedirect;
}
Comments.reloadComments();
comment_textarea.val('');
Comments.emptyRedactorEditor(comment_textarea.attr('id'));
......@@ -102,7 +109,7 @@ Comments.reply = function (reply_id) {
comment_reply_container.find('.redactor-editor').focus();
};
Comments.saveCommentReply = function (comment_id) {
Comments.saveCommentReply = function (comment_id, csrfKey, csrfValue) {
// Identify the container of the comment reply
var comment_reply_container = $("#bk-comment-reply-" + comment_id);
......@@ -118,6 +125,9 @@ Comments.saveCommentReply = function (comment_id) {
var formData = new FormData();
formData.append('CommentReply[comment_id]', comment_id);
formData.append('CommentReply[comment_reply_text]', comment_reply_text);
if (csrfKey !== null && csrfKey !== 'undefined') {
formData.append(csrfKey, csrfValue);
}
// It retrieves the comment reply attachments.
var commentReplyAttachmentsId = '#commentReplyAttachments' + comment_id;
......@@ -163,8 +173,7 @@ Comments.saveCommentReply = function (comment_id) {
$('#ajax-error-comment-reply-modal-id').modal('show');
}
});
}
else {
} else {
$('#empty-comment-reply-modal-id').modal('show');
}
};
......
var Comments = {};
Comments.comment = function (context_id) {
// Identify comment container of the content.
var comment_container = $("#bk-contribute");
// If it's hidden, it show it
if (comment_container.is(":hidden")) {
comment_container.show();
}
// In other case it hide it
else {
comment_container.hide();
}
};
Comments.beforeSendAjax = function () {
$('#comments-loader').toggleClass('hidden show');
$('#contribute-btn').prop('disabled', true);
$('#comments_anchor').prop('disabled', true);
};
Comments.completeAjax = function () {
$('#comments-loader').toggleClass('show hidden');
$('#contribute-btn').prop('disabled', false);
$('#comments_anchor').prop('disabled', false);
};
Comments.saveComment = function (context_id, context, csrfKey, csrfValue) {
// Identify comment container of the content.
var comment_container = $("#bk-contribute");
// It retrieves the comment textarea.
var comment_textarea = comment_container.find("[name='contribute-area']");
// It retrieves the comment text.
var comment_text = comment_textarea.val();
// If the comment text is not empty...
if (comment_text) {
// ...it build params.
var formData = new FormData();
formData.append('Comment[context]', context);
formData.append('Comment[context_id]', context_id);
formData.append('Comment[comment_text]', comment_text);
if (csrfKey !== null && csrfKey !== 'undefined') {
formData.append(csrfKey, csrfValue);
}
// It retrieves the comment attachments.
var commentAttachments = $('#commentAttachments').prop('files');
$.each(commentAttachments, function (key, value) {
formData.append('commentAttachments[]', value);
});
// Find the "send_notify_mail" inputs and add the values to form data.
var sendNotifyMailInputs = comment_container.find(":input[name^='send_notify_mail']");
sendNotifyMailInputs.each(function (index) {
if (($(this).attr('name') === 'send_notify_mail') && ($(this).attr('type') === 'checkbox')) {
// It retrieves the checkbox value.
var send_notify_mail_val = ($(this).is(":checked") ? 1 : 0);
formData.append('send_notify_mail', send_notify_mail_val);
} else {
formData.append($(this).attr('name'), $(this).val());
}
});
$.ajax({
url: '/comments/comment/create-ajax',
contentType: false,
processData: false,
data: formData,
type: 'post',
dataType: 'json',
beforeSend: function () {
Comments.beforeSendAjax();
},
complete: function (jjqXHR, textStatus) {
Comments.completeAjax();
},
success: function (response) {
if (response.error) {
alert(response.error.msg);
} else {
Comments.reloadComments();
comment_textarea.val('');
Comments.emptyRedactorEditor(comment_textarea.attr('id'));
$('#commentAttachments').val('');
}
},
error: function (response) {
console.log(response);
$('#ajax-error-comment-modal-id').modal('show');
}
});
} else {
$('#empty-comment-modal-id').modal('show');
}
};
Comments.reply = function (reply_id) {
// Identify the container of the comment reply
var comment_reply_container = $("#bk-comment-reply-" + reply_id);
comment_reply_container.toggleClass('hidden show');
comment_reply_container.find('.redactor-editor').focus();
};
Comments.saveCommentReply = function (comment_id, csrfKey, csrfValue) {
// Identify the container of the comment reply
var comment_reply_container = $("#bk-comment-reply-" + comment_id);
// It retrieves the comment reply textarea.
var comment_reply_textarea = comment_reply_container.find("[name='comment-reply-area']");
// It retrieves the comment reply text.
var comment_reply_text = comment_reply_textarea.val();
// If the comment text is not empty...
if (comment_reply_text) {
// ...it build params.
var formData = new FormData();
formData.append('CommentReply[comment_id]', comment_id);
formData.append('CommentReply[comment_reply_text]', comment_reply_text);
if (csrfKey !== null && csrfKey !== 'undefined') {
formData.append(csrfKey, csrfValue);
}
// It retrieves the comment reply attachments.
var commentReplyAttachmentsId = '#commentReplyAttachments' + comment_id;
var commentReplyAttachments = $(commentReplyAttachmentsId).prop('files');
$.each(commentReplyAttachments, function (key, value) {
formData.append('commentReplyAttachments[]', value);
});
// Find the "send_reply_notify_mail" inputs and add the values to form data.
var sendNotifyMailInputs = comment_reply_container.find(":input[name^='send_reply_notify_mail']");
sendNotifyMailInputs.each(function (index) {
if ($(this).attr('name') === 'send_reply_notify_mail') {
// It retrieves the checkbox value.
var send_reply_notify_mail_val = ($(this).is(":checked") ? 1 : 0);
formData.append('send_reply_notify_mail', send_reply_notify_mail_val);
} else {
formData.append($(this).attr('name'), $(this).val());
}
});
$.ajax({
url: '/comments/comment-reply/create-ajax',
contentType: false,
processData: false,
data: formData,
type: 'post',
dataType: 'json',
beforeSend: function () {
Comments.beforeSendAjax();
},
complete: function (jjqXHR, textStatus) {
Comments.completeAjax();
},
success: function (response) {
if (response.error) {
alert(response.error.msg);
} else {
Comments.reloadComments();
}
},
error: function (response) {
console.log(response);
$('#ajax-error-comment-reply-modal-id').modal('show');
}
});
} else {
$('#empty-comment-reply-modal-id').modal('show');
}
};
Comments.reloadComments = function () {
$.pjax.defaults.timeout = 15000;
$.pjax.reload({container: '#pjax-block-comments', async: false});
};
Comments.emptyRedactorEditor = function (editorId) {
tinyMCE.get(editorId).setContent('');
};
......@@ -37,6 +37,23 @@ COMMENTS WIDGET
.subtitle-comments { /* comments */
border-bottom: 2px solid @white-color;
padding-bottom: @padding-min;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
padding: 20px 0;
.icon-link-black {
color: black;
}
h2 {
margin: 0;
}
.subtitle-text-container {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
}
}
.answer .answer-details .comment-reply-container {
......
......@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see https://repo.art-er.it Developers' community
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
......@@ -26,6 +26,7 @@ use arter\amos\core\utilities\Email;
use Yii;
use yii\base\BaseObject;
use yii\helpers\ArrayHelper;
use arter\amos\comments\models\CommentDisabledNotificationUsers;
/**
* Class PartecipantsNotification
......@@ -81,9 +82,45 @@ class PartecipantsNotification extends BaseObject
$users = $this->getRecipients($contextModel, $contextModelClassName);
// filter the user ID by excluding user_id from comment_disabled_notification_users
$users = $this->excludeCommentDisabledNotificationUsers($users);
$this->sendEmail($users, $contextModel, $model, $model_reply);
}
/**
* Method to exclude user with comment disabled notification from CommentDisabledNotificationUsers
*
* @param array $users
* @return array $list_users_id
*/
protected function excludeCommentDisabledNotificationUsers($users){
$comment_disabled_notification_users =
ArrayHelper::getColumn(
CommentDisabledNotificationUsers::find()->andWhere(['deleted_at' => null])->asArray()->all(),
function ($element) {
return $element['user_id'];
}
);
$list_users_id = null;
foreach ((array)$users as $key => $user_id) {
// check if user is not in array comment_disabled_notification_users
if( !in_array($user_id, $comment_disabled_notification_users) ){
$list_users_id[$key] = $user_id;
}
}
return $list_users_id;
}
/**
* This method returns an array that contains the ids of the users to be notified.
* @param Record $contextModel
......@@ -94,10 +131,17 @@ class PartecipantsNotification extends BaseObject
{
$users = $this->getDiscussionsRecipients($contextModel);
if (empty($users) && method_exists($contextModel, 'getRecipients')) {
$users = $contextModel->getRecipients();
}
if (empty($users)) {
$users = $this->getDefaultRecipients($contextModel, $contextModelClassName);
}
return $users;