From 898277d56c98e0317ebda7593e5669761319dde8 Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Sat, 3 Apr 2021 15:38:18 +0300 Subject: [PATCH 1/4] Issues-511: Replay placement --- .../class.discussioncontroller.php | 8 ++++- .../controllers/class.postcontroller.php | 6 ++-- vanilla/applications/vanilla/js/discussion.js | 30 +++++++++++++++---- .../views/discussion/helper_functions.php | 2 +- vanilla/js/global.js | 8 +++++ 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/vanilla/applications/vanilla/controllers/class.discussioncontroller.php b/vanilla/applications/vanilla/controllers/class.discussioncontroller.php index 666047e..177aa68 100644 --- a/vanilla/applications/vanilla/controllers/class.discussioncontroller.php +++ b/vanilla/applications/vanilla/controllers/class.discussioncontroller.php @@ -796,7 +796,7 @@ public function deleteComment($commentID = '', $transientKey = '') { if ($comment && $discussion) { $defaultTarget = discussionUrl($discussion); - + $this->json('DiscussionID', $discussionID); // Make sure comment is this user's or they have Delete permission. if ($comment->InsertUserID != $session->UserID || !c('Vanilla.Comments.AllowSelfDelete')) { $this->categoryPermission($discussion->CategoryID, 'Vanilla.Comments.Delete'); @@ -811,6 +811,12 @@ public function deleteComment($commentID = '', $transientKey = '') { // Delete the comment. if (!$this->CommentModel->deleteID($commentID)) { $this->Form->addError('Failed to delete comment'); + } else { + // FIX: https://github.com/topcoder-platform/forums/issues/511 + // Allow plugins to handle it + $this->EventArguments['DiscussionID'] = $discussionID; + $this->EventArguments['CommentID'] = $commentID; + $this->fireEvent('AfterCommentDeleted'); } } else { $this->Form->addError('Invalid comment'); diff --git a/vanilla/applications/vanilla/controllers/class.postcontroller.php b/vanilla/applications/vanilla/controllers/class.postcontroller.php index 3803e90..5ffd811 100644 --- a/vanilla/applications/vanilla/controllers/class.postcontroller.php +++ b/vanilla/applications/vanilla/controllers/class.postcontroller.php @@ -395,10 +395,12 @@ public function discussion($categoryUrlCode = '', $announce = '') { $this->EventArguments['Discussion'] = $discussion; $this->fireEvent('AfterDiscussionSave'); + // FIX: https://github.com/topcoder-platform/forums/issues/511 + // if /discussion/{discussionID}/p{Page} is used then view mode is flat if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { - redirectTo(discussionUrl($discussion, 1).'?new=1'); + redirectTo(discussionUrl($discussion).'?new=1'); } else { - $this->setRedirectTo(discussionUrl($discussion, 1, true).'?new=1'); + $this->setRedirectTo(discussionUrl($discussion).'?new=1'); } } else { // If this was a draft save, notify the user about the save diff --git a/vanilla/applications/vanilla/js/discussion.js b/vanilla/applications/vanilla/js/discussion.js index 1ad3720..fd5ebfd 100755 --- a/vanilla/applications/vanilla/js/discussion.js +++ b/vanilla/applications/vanilla/js/discussion.js @@ -135,6 +135,7 @@ jQuery(document).ready(function($) { $('div.Popup,.Overlay').remove(); var commentID = json.CommentID; + var parentCommentID = json.ParentCommentID; // Assign the comment id to the form if it was defined if (commentID != null && commentID != '') { @@ -194,11 +195,19 @@ jQuery(document).ready(function($) { $(json.Data).prependTo('ul.Comments,.DiscussionTable'); $('ul.Comments li:first').effect("highlight", {}, "slow"); } else { - $(json.Data) - .appendTo('ul.Comments,.DiscussionTable') - .effect("highlight", {}, "slow") - .trigger('contentLoad'); -// $('ul.Comments li:last,.DiscussionTable li:last').effect("highlight", {}, "slow"); + var viewMode = json['ReplyTo.ViewMode']; + if(viewMode === 'threaded') { + item = $('ul.Comments'); + $('ul.Comments li').remove(); + $(item).append(json.Data) + //.effect("highlight", {}, "slow") + .trigger('contentLoad'); + } else { + $(json.Data) + .appendTo('ul.Comments,.DiscussionTable') + //.effect("highlight", {}, "slow") + .trigger('contentLoad'); + } } } // Remove any "More" pager links (because it is typically replaced with the latest comment by this function) @@ -367,7 +376,7 @@ jQuery(document).ready(function($) { confirmHeading: gdn.definition('ConfirmDeleteCommentHeading', 'Delete Comment'), confirmText: gdn.definition('ConfirmDeleteCommentText', 'Are you sure you want to delete this comment?'), followConfirm: false, - deliveryType: 'BOOL', // DELIVERY_TYPE_BOOL + deliveryType: gdn.urlQueryParam( $('a.DeleteComment').attr('href'), 'deliveryType'), //'VIEW' - threaded, 'BOOL' - flat afterConfirm: function(json, sender) { var row = $(sender).parents('li.ItemComment'); if (json.ErrorMessage) { @@ -378,6 +387,15 @@ jQuery(document).ready(function($) { $(this).remove(); }); gdn.processTargets(json.Targets); + + var viewMode = json['ReplyTo.ViewMode']; + if(viewMode === 'threaded') { + item = $('ul.Comments'); + $('ul.Comments li').remove(); + $(item).append(json.Data); + //.effect("highlight", {}, "slow"); + } + // Let listeners know that the comment was deleted. $(document).trigger('CommentDeleted'); } diff --git a/vanilla/applications/vanilla/views/discussion/helper_functions.php b/vanilla/applications/vanilla/views/discussion/helper_functions.php index c666ba0..8d29f50 100644 --- a/vanilla/applications/vanilla/views/discussion/helper_functions.php +++ b/vanilla/applications/vanilla/views/discussion/helper_functions.php @@ -114,7 +114,7 @@ function writeComment($comment, $sender, $session, $currentOffset) { // FIX: https://github.com/topcoder-platform/forums/issues/488: // ViewMode should be set before displaying comment - $viewMode = $sender->data('ViewMode'); + $viewMode = $sender->data('ReplyTo.ViewMode'); ?>
  • diff --git a/vanilla/js/global.js b/vanilla/js/global.js index 1bd0671..4870122 100644 --- a/vanilla/js/global.js +++ b/vanilla/js/global.js @@ -740,6 +740,14 @@ jQuery(document).ready(function($) { return urlFormat.replace("{Path}", path); }; + // Get query param from url + gdn.urlQueryParam = function (url, name) { + var results = new RegExp('[\?&]' + name + '=([^&#]*)') + .exec(url); + + return (results !== null) ? results[1] || 0 : false; + } + // Fill in placeholders. if (!gdn.elementSupports('input', 'placeholder')) { $('input:text,textarea').not('.NoIE').each(function() { From 7188a77091213469e2ad4aa4a124bef68f034942 Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Sat, 3 Apr 2021 15:40:47 +0300 Subject: [PATCH 2/4] Issues-511:Reply placement (fixed missing ';') --- vanilla/js/global.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vanilla/js/global.js b/vanilla/js/global.js index 4870122..db62050 100644 --- a/vanilla/js/global.js +++ b/vanilla/js/global.js @@ -746,7 +746,7 @@ jQuery(document).ready(function($) { .exec(url); return (results !== null) ? results[1] || 0 : false; - } + }; // Fill in placeholders. if (!gdn.elementSupports('input', 'placeholder')) { From 09d68745c50de6afc8c89121630e4e2b9fb0f8fd Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Sat, 3 Apr 2021 21:05:10 +0300 Subject: [PATCH 3/4] Issues-523: Set 'update' type for a query and recalculate count of watched categories if it's null --- config/vanilla/bootstrap.early.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/vanilla/bootstrap.early.php b/config/vanilla/bootstrap.early.php index af21e5a..06b250f 100644 --- a/config/vanilla/bootstrap.early.php +++ b/config/vanilla/bootstrap.early.php @@ -162,7 +162,13 @@ // Set count of WatchedCategories for users Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = ( select count(c.CategoryID) from GDN_Category c, (select distinct CAST(SUBSTRING_INDEX(um.Name, ".", -1) as UNSIGNED) as CategoryID from GDN_UserMeta um - where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID)'); + where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID)', 'update'); } + + // FIX: https://github.com/topcoder-platform/forums/issues/479 + // Re-calculate count of WatchedCategories if WatchedCategories is null + Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = ( + select count(c.CategoryID) from GDN_Category c, (select distinct CAST(SUBSTRING_INDEX(um.Name, ".", -1) as UNSIGNED) as CategoryID from GDN_UserMeta um + where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID) where CountWatchedCategories is null', 'update'); } \ No newline at end of file From 87468c5a95f22386577e203c27a8038d5bb94b59 Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Sat, 3 Apr 2021 23:00:15 +0300 Subject: [PATCH 4/4] Issues-518: Fixed highlting a menu item in the left nav --- .../views/modules/discussionfilter.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/vanilla/applications/vanilla/views/modules/discussionfilter.php b/vanilla/applications/vanilla/views/modules/discussionfilter.php index 1839692..b08456b 100644 --- a/vanilla/applications/vanilla/views/modules/discussionfilter.php +++ b/vanilla/applications/vanilla/views/modules/discussionfilter.php @@ -40,14 +40,28 @@
      fireEvent('BeforeDiscussionFilters'); - // if (c('Vanilla.Categories.ShowTabs')) { if (c('Vanilla.Categories.Use')) { + $menuOptions = []; + $CssClass = 'AllCategories'; - if ((strtolower($Controller->ControllerName) == 'categoriescontroller' && in_array(strtolower($Controller->RequestMethod),['index', 'all'])) - || strpos(strtolower($Controller->Request->path()) , 'categories') === 0) { - $CssClass .= ' Active'; + $isActive = false; + if($Controller instanceof CategoriesController || $Controller instanceof DiscussionController + || $Controller instanceof PostController) { + $isActive = true; + } + + $menuOptions['AllCategories']['Url'] = anchor('Public Forums', '/categories'); + $menuOptions['AllCategories']['IsActive'] = $isActive; + $menuOptions['AllCategories']['CssClass'] = $CssClass; + + $Controller->EventArguments['Menu'] = &$menuOptions; + $Controller->fireEvent('BeforeRenderDiscussionFilters'); + foreach($menuOptions as $key => $value) { + if($menuOptions[$key]['IsActive'] === true) { + $menuOptions[$key]['CssClass'] .= ' Active'; + } + echo '
    • ' . $menuOptions[$key]['Url'] . '
    • '; } - echo '
    • '.anchor('Public Forums', '/categories').'
    • '; } /*