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

General Bug Fixes and Improvements

parent 5851545f
{ {
"name": "arter/amos-comments", "name": "arter/amos-comments",
"description": "Comments for contents - plugin", "description": "Comments for contents - plugin",
"keywords": [ "keywords": ["amos", "yii2", "comments"],
"amos",
"yii2",
"comments"
],
"type": "plugin", "type": "plugin",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"require": { "require": {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
...@@ -31,33 +31,27 @@ use yii\base\Event; ...@@ -31,33 +31,27 @@ use yii\base\Event;
class AmosComments extends AmosModule implements ModuleInterface, BootstrapInterface class AmosComments extends AmosModule implements ModuleInterface, BootstrapInterface
{ {
public static $CONFIG_FOLDER = 'config'; 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 * @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]] * 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. * will be taken. If this is false, layout will be disabled within this module.
*/ */
public $layout = 'main'; public $layout = 'main';
/** /**
* @inheritdoc * @inheritdoc
*/ */
public $controllerNamespace = 'arter\amos\comments\controllers'; public $controllerNamespace = 'arter\amos\comments\controllers';
public $newFileMode = 0666;
public $newFileMode = 0666; public $name = 'Comments';
public $layoutInverted = false;
public $name = 'Comments';
public $layoutInverted = false;
/** /**
* @var array $modelsEnabled * @var array $modelsEnabled
*/ */
public $modelsEnabled = []; public $modelsEnabled = [];
public $maxCommentAttachments = 5;
public $maxCommentAttachments = 5;
public $enableMailsNotification = true; public $enableMailsNotification = true;
/** /**
...@@ -65,12 +59,36 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -65,12 +59,36 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
*/ */
public $enableUserSendMailCheckbox = true; 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 * 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' * that is an instance of 'arter\amos\admin\models\UserProfile'
* @var string * @var string
*/ */
public $htmlMailContentTitle = '@vendor/arter/amos-comments/src/views/comment/email/content_title'; 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 * 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 ...@@ -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' // '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 * Sets if the notify checkbox must be visible into the comments accordion
* @var bool * @var bool
...@@ -101,6 +123,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -101,6 +123,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
* @var boolean $enableCommentOnlyWithScope * @var boolean $enableCommentOnlyWithScope
*/ */
public $enableCommentOnlyWithScope = false; public $enableCommentOnlyWithScope = false;
public $disableAutoDisplay = ['amos\planner\models\PlanWork'];
/** /**
* If a true notify the context model (DiscussioniTopic) if is created a comment * If a true notify the context model (DiscussioniTopic) if is created a comment
...@@ -108,6 +131,18 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -108,6 +131,18 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
*/ */
public $enableNotifyCommentForDiscussions = true; public $enableNotifyCommentForDiscussions = true;
/**
*
* @var type 3 by SORT_DESC, 4 by SORT_ASC
*/
public $orderDisplayComments = 3;
/**
*
* @var type
*/
public $disablePagination = false;
/** /**
* @return string * @return string
*/ */
...@@ -115,18 +150,18 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -115,18 +150,18 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{ {
return 'comments'; return 'comments';
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function init() public function init()
{ {
parent::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 // 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 * @inheritdoc
*/ */
...@@ -134,7 +169,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -134,7 +169,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{ {
return NULL; return NULL;
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -142,7 +177,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -142,7 +177,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{ {
return []; return [];
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -150,7 +185,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -150,7 +185,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{ {
return []; return [];
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -158,8 +193,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -158,8 +193,7 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
{ {
Event::on(AmosView::className(), AmosView::AFTER_RENDER_CONTENT, [new CommentComponent(), 'showComments']); Event::on(AmosView::className(), AmosView::AFTER_RENDER_CONTENT, [new CommentComponent(), 'showComments']);
} }
/** /**
* @param $model * @param $model
*/ */
...@@ -169,14 +203,14 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter ...@@ -169,14 +203,14 @@ class AmosComments extends AmosModule implements ModuleInterface, BootstrapInter
->joinWith('commentReplies', true, 'LEFT JOIN') ->joinWith('commentReplies', true, 'LEFT JOIN')
->andWhere(['context' => $model->className(), 'context_id' => $model->id]) ->andWhere(['context' => $model->className(), 'context_id' => $model->id])
->groupBy('comment.id'); ->groupBy('comment.id');
/** @var \arter\amos\comments\models\Comment $lastComment */ /** @var \arter\amos\comments\models\Comment $lastComment */
$countComment = $query->count(); $countComment = $query->count();
$query = Comment::find() $query = Comment::find()
->joinWith('commentReplies', true, 'LEFT JOIN') ->joinWith('commentReplies', true, 'LEFT JOIN')
->andWhere(['context' => $model->className(), 'context_id' => $model->id]) ->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(); $countComment += $query->count();
return $countComment; return $countComment;
} }
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @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 () { ...@@ -26,7 +26,7 @@ Comments.completeAjax = function () {
$('#comments_anchor').prop('disabled', false); $('#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. // Identify comment container of the content.
var comment_container = $("#bk-contribute"); var comment_container = $("#bk-contribute");
...@@ -43,6 +43,9 @@ Comments.saveComment = function (context_id, context) { ...@@ -43,6 +43,9 @@ Comments.saveComment = function (context_id, context) {
formData.append('Comment[context]', context); formData.append('Comment[context]', context);
formData.append('Comment[context_id]', context_id); formData.append('Comment[context_id]', context_id);
formData.append('Comment[comment_text]', comment_text); formData.append('Comment[comment_text]', comment_text);
if (csrfKey !== null && csrfKey !== 'undefined') {
formData.append(csrfKey, csrfValue);
}
// It retrieves the comment attachments. // It retrieves the comment attachments.
var commentAttachments = $('#commentAttachments').prop('files'); var commentAttachments = $('#commentAttachments').prop('files');
...@@ -79,6 +82,10 @@ Comments.saveComment = function (context_id, context) { ...@@ -79,6 +82,10 @@ Comments.saveComment = function (context_id, context) {
if (response.error) { if (response.error) {
alert(response.error.msg); alert(response.error.msg);
} else { } else {
var urlRedirect = $('#url-redirect').val();
if(urlRedirect != '' && urlRedirect != undefined){
window.location.href = urlRedirect;
}
Comments.reloadComments(); Comments.reloadComments();
comment_textarea.val(''); comment_textarea.val('');
Comments.emptyRedactorEditor(comment_textarea.attr('id')); Comments.emptyRedactorEditor(comment_textarea.attr('id'));
...@@ -102,7 +109,7 @@ Comments.reply = function (reply_id) { ...@@ -102,7 +109,7 @@ Comments.reply = function (reply_id) {
comment_reply_container.find('.redactor-editor').focus(); 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 // Identify the container of the comment reply
var comment_reply_container = $("#bk-comment-reply-" + comment_id); var comment_reply_container = $("#bk-comment-reply-" + comment_id);
...@@ -118,6 +125,9 @@ Comments.saveCommentReply = function (comment_id) { ...@@ -118,6 +125,9 @@ Comments.saveCommentReply = function (comment_id) {
var formData = new FormData(); var formData = new FormData();
formData.append('CommentReply[comment_id]', comment_id); formData.append('CommentReply[comment_id]', comment_id);
formData.append('CommentReply[comment_reply_text]', comment_reply_text); formData.append('CommentReply[comment_reply_text]', comment_reply_text);
if (csrfKey !== null && csrfKey !== 'undefined') {
formData.append(csrfKey, csrfValue);
}
// It retrieves the comment reply attachments. // It retrieves the comment reply attachments.
var commentReplyAttachmentsId = '#commentReplyAttachments' + comment_id; var commentReplyAttachmentsId = '#commentReplyAttachments' + comment_id;
...@@ -163,8 +173,7 @@ Comments.saveCommentReply = function (comment_id) { ...@@ -163,8 +173,7 @@ Comments.saveCommentReply = function (comment_id) {
$('#ajax-error-comment-reply-modal-id').modal('show'); $('#ajax-error-comment-reply-modal-id').modal('show');
} }
}); });
} } else {
else {
$('#empty-comment-reply-modal-id').modal('show'); $('#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');