From 5df438d6bad8114b318cee13c2c4c5c39833f222 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Thu, 27 Sep 2018 22:28:51 +0200 Subject: [PATCH] Use GroupedUserList for reaction details instead of own implementation See #2508 --- .../templates/reactionTabbedUserList.tpl | 34 ------- .../Core/Ui/Reaction/CountButtons.js | 93 +++---------------- .../data/reaction/ReactionAction.class.php | 45 ++++----- 3 files changed, 36 insertions(+), 136 deletions(-) delete mode 100644 com.woltlab.wcf/templates/reactionTabbedUserList.tpl diff --git a/com.woltlab.wcf/templates/reactionTabbedUserList.tpl b/com.woltlab.wcf/templates/reactionTabbedUserList.tpl deleted file mode 100644 index a76d4bbc2c..0000000000 --- a/com.woltlab.wcf/templates/reactionTabbedUserList.tpl +++ /dev/null @@ -1,34 +0,0 @@ - - -{if !$reactionUserList|empty} -
    - {foreach from=$reactionUserList item=reaction} - {assign var=user value=$reaction->getUserProfile()} - {include file='userListItem'} - {/foreach} -
- -
-{else} -

{lang}wcf.reactions.summary.noReactions{/lang}

-{/if} - - \ No newline at end of file diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js index c8673d98c1..d22ef57b1f 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js @@ -38,9 +38,7 @@ define( } this._containers = new Dictionary(); - this._details = new ObjectMap(); this._objectType = objectType; - this._cache = new Dictionary(); this._options = Core.extend({ // selectors @@ -90,15 +88,6 @@ define( } }, - /** - * Invalidates the cache for the object with the given objectId. - * - * @param {int} objectId - */ - invalidateCache: function(objectId) { - this._cache.delete(objectId); - }, - /** * Update the count buttons with the given data. * @@ -150,8 +139,6 @@ define( if (triggerChange) { DomChangeListener.trigger(); } - - this.invalidateCache(objectId); }, /** @@ -183,20 +170,17 @@ define( * @param {int} objectId */ _initReactionCountButton: function(element, objectId) { - element.addEventListener(WCF_CLICK_EVENT, this._showReactionOverlay.bind(this, elData(element, 'reaction-type-id'), objectId)); + element.addEventListener(WCF_CLICK_EVENT, this._showReactionOverlay.bind(this, objectId)); }, /** - * Shows the reaction overly for a specific object and reaction type. + * Shows the reaction overly for a specific object. * - * @param {int} reactionTypeId * @param {int} objectId */ - _showReactionOverlay: function(reactionTypeId, objectId) { + _showReactionOverlay: function(objectId) { this._currentObjectId = objectId; - this._currentPageNo = 1; - this._currentReactionTypeId = reactionTypeId; - this._showPage(); + this._showOverlay(); }, /** @@ -204,70 +188,19 @@ define( * * @param {int} pageNo */ - _showPage: function(pageNo) { - if (pageNo !== undefined) { - this._currentPageNo = pageNo; - } + _showOverlay: function() { + this._options.parameters.data.containerID = this._objectType + '-' + this._currentObjectId; + this._options.parameters.data.objectID = this._currentObjectId; + this._options.parameters.data.objectType = this._objectType; - if (this._cache.has(this._currentObjectId) && this._cache.get(this._currentObjectId).has(this._currentReactionTypeId)) { - // validate pageNo - if (this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount') !== 0 && (this._currentPageNo < 1 || this._currentPageNo > this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount'))) { - throw new RangeError("pageNo must be between 1 and " + this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount') + " (" + this._currentPageNo + " given)."); - } - } - else { - // init objectId cache - if (!this._cache.has(this._currentObjectId)) { - this._cache.set(this._currentObjectId, new Dictionary()); - } - - // init reaction type id cache for objectId - this._cache.get(this._currentObjectId).set(this._currentReactionTypeId, new Dictionary()); - } - - if (this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).has(this._currentPageNo)) { - var dialog = UiDialog.open(this, this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get(this._currentPageNo)); - UiDialog.setTitle('userReactionOverlay-' + this._objectType, this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('title')); - - if (this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount') > 1) { - var element = elBySel('.jsPagination', dialog.content); - if (element !== null) { - new UiPagination(element, { - activePage: this._currentPageNo, - maxPage: this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).get('pageCount'), - callbackSwitch: this._showPage.bind(this) - }); - } - } - - // init tab menu - var tabMenu = elBySel('.tabMenu ul', dialog.content); - var elements = elBySelAll('li', tabMenu); - for (var i = 0, length = elements.length; i < length; i++) { - elements[i].addEventListener(WCF_CLICK_EVENT, this._showReactionOverlay.bind(this, elData(elements[i], 'reaction-type-id'), this._currentObjectId)); - } - } - else { - this._options.parameters.pageNo = this._currentPageNo; - this._options.parameters.reactionTypeID = this._currentReactionTypeId; - this._options.parameters.data.containerID = this._currentReactionTypeId; - this._options.parameters.data.objectID = this._currentObjectId; - this._options.parameters.data.objectType = this._objectType; - - Ajax.api(this, { - parameters: this._options.parameters - }); - } + Ajax.api(this, { + parameters: this._options.parameters + }); }, _ajaxSuccess: function(data) { - if (data.returnValues.pageCount !== undefined) { - this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).set('pageCount', ~~data.returnValues.pageCount); - } - - this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).set(this._currentPageNo, data.returnValues.template); - this._cache.get(this._currentObjectId).get(this._currentReactionTypeId).set('title', data.returnValues.title); - this._showPage(); + UiDialog.open(this, data.returnValues.template); + UiDialog.setTitle('userReactionOverlay-' + this._objectType, data.returnValues.title); }, _ajaxSetup: function() { diff --git a/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php b/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php index ab27badd98..ad1e37fb47 100644 --- a/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php +++ b/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php @@ -19,6 +19,7 @@ use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; use wcf\system\reaction\ReactionHandler; use wcf\system\user\activity\point\UserActivityPointHandler; +use wcf\system\user\GroupedUserList; use wcf\system\WCF; /** @@ -78,15 +79,6 @@ class ReactionAction extends AbstractDatabaseObjectAction { if (!WCF::getSession()->getPermission('user.like.canViewLike')) { throw new PermissionDeniedException(); } - - $this->readInteger('reactionTypeID'); - $this->readInteger('pageNo'); - - $this->reactionType = ReactionTypeCache::getInstance()->getReactionTypeByID($this->parameters['reactionTypeID']); - - if ($this->reactionType === null) { - throw new IllegalLinkException(); - } } /** @@ -98,24 +90,33 @@ class ReactionAction extends AbstractDatabaseObjectAction { $likeList = new ViewableLikeList(); $likeList->getConditionBuilder()->add('objectID = ?', [$this->parameters['data']['objectID']]); $likeList->getConditionBuilder()->add('objectTypeID = ?', [$this->objectType->objectTypeID]); - $likeList->getConditionBuilder()->add('reactionTypeID = ?', [$this->reactionType->reactionTypeID]); - $likeList->sqlLimit = 25; - $likeList->sqlOffset = ($this->parameters['pageNo'] - 1) * 10; $likeList->sqlOrderBy = 'time DESC'; - $pageCount = ceil($likeList->countObjects() / 10); $likeList->readObjects(); - WCF::getTPL()->assign([ - 'reactionUserList' => $likeList->getObjects(), - 'reactions' => ReactionTypeCache::getInstance()->getEnabledReactionTypes(), - 'reactionTypeID' => $this->reactionType->reactionTypeID - ]); + $data = []; + foreach ($likeList as $item) { + if ($item->getReactionType()->isDisabled) continue; + + // we cast the reactionTypeID to a string, so that we can sort the array + if (!isset($data[(string)$item->getReactionType()->reactionTypeID])) { + $data[(string)$item->getReactionType()->reactionTypeID] = new GroupedUserList($item->getReactionType()->getTitle()); + } + + $data[(string)$item->getReactionType()->reactionTypeID]->addUserIDs([$item->userID]); + } + + GroupedUserList::loadUsers(); + + uksort($data, function ($a, $b) { + $sortOrderA = ReactionTypeCache::getInstance()->getReactionTypeByID($a)->showOrder; + $sortOrderB = ReactionTypeCache::getInstance()->getReactionTypeByID($b)->showOrder; + + return ($sortOrderA < $sortOrderB) ? -1 : 1; + + }); return [ - 'reactionTypeID' => $this->reactionType->reactionTypeID, - 'pageNo' => $this->parameters['pageNo'], - 'pageCount' => $pageCount, - 'template' => WCF::getTPL()->fetch('reactionTabbedUserList'), + 'template' => WCF::getTPL()->fetch('groupedUserList', 'wcf', ['groupedUsers' => $data]), 'title' => WCF::getLanguage()->get('wcf.reactions.summary.title') ]; } -- 2.20.1