doortts doortts 2018-02-01
my-issues: Show mentioned issue count
@bd64f02fa7f2ba0e0e20a679be3472c66b399749
app/models/Issue.java
--- app/models/Issue.java
+++ app/models/Issue.java
@@ -691,4 +691,11 @@
     public List<IssueSharer> getSortedSharer() {
         return new ArrayList<>(sharers);
     }
+
+    public static int getCountOfMentionedOpenIssues(Long userId) {
+        return finder.where()
+                .in("id", Mention.getMentioningIssueIds(userId))
+                .eq("state", State.OPEN)
+                .findRowCount();
+    }
 }
app/models/Mention.java
--- app/models/Mention.java
+++ app/models/Mention.java
@@ -1,23 +1,10 @@
 /**
- * Yobi, Project Hosting SW
- *
- * Copyright 2014 NAVER Corp.
- * http://yobi.io
- *
- * @author Yi EungJun
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+ * Yona, 21st Century Project Hosting SW
+ * <p>
+ * Copyright Yona & Yobi Authors & NAVER Corp. & NAVER LABS Corp.
+ * https://yona.io
+ **/
+
 package models;
 
 import models.enumeration.ResourceType;
@@ -27,7 +14,13 @@
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.ManyToOne;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
+
+import static models.enumeration.ResourceType.ISSUE_COMMENT;
+import static models.enumeration.ResourceType.ISSUE_POST;
 
 @Entity
 public class Mention extends Model {
@@ -73,4 +66,37 @@
             mention.save();
         }
     }
+
+    public static List<Long> getMentioningIssueIds(Long mentionUserId) {
+        Set<Long> ids = new HashSet<>();
+        Set<Long> commentIds = new HashSet<>();
+
+        for (Mention mention : Mention.find.where()
+                .eq("user.id", mentionUserId)
+                .in("resourceType", ISSUE_POST, ISSUE_COMMENT)
+                .findList()) {
+
+            switch (mention.resourceType) {
+                case ISSUE_POST:
+                    ids.add(Long.valueOf(mention.resourceId));
+                    break;
+                case ISSUE_COMMENT:
+                    commentIds.add(Long.valueOf(mention.resourceId));
+                    break;
+                default:
+                    play.Logger.warn("'" + mention.resourceType + "' is not supported.");
+                    break;
+            }
+        }
+
+        if (!commentIds.isEmpty()) {
+            for (IssueComment comment : IssueComment.find.where()
+                    .idIn(new ArrayList<>(commentIds))
+                    .findList()) {
+                ids.add(comment.issue.id);
+            }
+        }
+
+        return new ArrayList<>(ids);
+    }
 }
app/models/support/SearchCondition.java
--- app/models/support/SearchCondition.java
+++ app/models/support/SearchCondition.java
@@ -21,9 +21,6 @@
 import java.text.SimpleDateFormat;
 import java.util.*;
 
-import static models.enumeration.ResourceType.ISSUE_COMMENT;
-import static models.enumeration.ResourceType.ISSUE_POST;
-
 public class SearchCondition extends AbstractPostingApp.SearchCondition implements Cloneable {
     public String state;
     public Boolean commentedCheck;
@@ -304,7 +301,7 @@
         if (mentionId != null) {
             User mentionUser = User.find.byId(mentionId);
             if(!mentionUser.isAnonymous()) {
-                List<Long> ids = getMentioningIssueIds(mentionUser);
+                List<Long> ids = Mention.getMentioningIssueIds(mentionId);
 
                 if (ids.isEmpty()) {
                     // No need to progress because the query matches nothing.
@@ -351,39 +348,6 @@
             }
         }
         return new ArrayList<>(issueIds);
-    }
-
-    private List<Long> getMentioningIssueIds(User mentionUser) {
-        Set<Long> ids = new HashSet<>();
-        Set<Long> commentIds = new HashSet<>();
-
-        for (Mention mention : Mention.find.where()
-                .eq("user", mentionUser)
-                .in("resourceType", ISSUE_POST, ISSUE_COMMENT)
-                .findList()) {
-
-            switch (mention.resourceType) {
-                case ISSUE_POST:
-                    ids.add(Long.valueOf(mention.resourceId));
-                    break;
-                case ISSUE_COMMENT:
-                    commentIds.add(Long.valueOf(mention.resourceId));
-                    break;
-                default:
-                    play.Logger.warn("'" + mention.resourceType + "' is not supported.");
-                    break;
-            }
-        }
-
-        if (!commentIds.isEmpty()) {
-            for (IssueComment comment : IssueComment.find.where()
-                    .idIn(new ArrayList<>(commentIds))
-                    .findList()) {
-                ids.add(comment.issue.id);
-            }
-        }
-
-        return new ArrayList<>(ids);
     }
 
     private List<Long> getSharedIssueIds(User user) {
app/views/issue/my_partial_list_quicksearch.scala.html
--- app/views/issue/my_partial_list_quicksearch.scala.html
+++ app/views/issue/my_partial_list_quicksearch.scala.html
@@ -5,6 +5,7 @@
 * https://yona.io
 **@
 @import models.support.SearchCondition
+@import org.apache.commons.lang3.StringUtils
 @(param:SearchCondition)
 
 @currentUserId = @{
@@ -54,7 +55,9 @@
             data-milestone-id="@param.milestoneId"
             data-mention-id="@currentUserId"
             data-sharer-id="">
-            @Messages("issue.list.mentionedOfMe")
+            @Messages("issue.list.mentionedOfMe") @if(StringUtils.isBlank(param.filter)) {
+                (@Issue.getCountOfMentionedOpenIssues(currentUserId))
+            }
         </a>
     </li>
     <li @if(param.sharerId == currentUserId){ class="active"}>
@@ -65,7 +68,9 @@
         data-milestone-id="@param.milestoneId"
         data-mention-id=""
         data-sharer-id="@currentUserId">
-        @Messages("issue.list.sharedWithMe") (@IssueSharer.getNumberOfIssuesSharedWithUser(currentUserId))
+        @Messages("issue.list.sharedWithMe") @if(StringUtils.isBlank(param.filter)) {
+            (@IssueSharer.getNumberOfIssuesSharedWithUser(currentUserId))
+        }
         </a>
     </li>
     }
Add a comment
List