Skip to content

The Unified and Autonomous Development Platform

Fix issue #1077 - A issue criteria to filter issues belong to current project

Robin Shen67d0b9a3142a
diff --git a/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java b/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java
index 1886964c7c..e94d19a8c7 100644
--- a/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java
+++ b/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java
@@ -167,7 +167,9 @@ public class IssueQuery extends EntityQuery<Issue> implements Comparator<Issue>
int operator = ctx.operator.getType();
if (validate)
checkField(fieldName, operator, option);
- if (fieldName.equals(IssueSchedule.NAME_MILESTONE)) {
+ if (fieldName.equals(Issue.NAME_PROJECT)) {
+ return new ProjectIsCurrentCriteria();
+ } else if (fieldName.equals(IssueSchedule.NAME_MILESTONE)) {
return new MilestoneIsEmptyCriteria();
} else {
FieldSpec fieldSpec = getGlobalIssueSetting().getFieldSpec(fieldName);
@@ -393,9 +395,10 @@ public class IssueQuery extends EntityQuery<Issue> implements Comparator<Issue>
throw newOperatorException(fieldName, operator);
break;
case IssueQueryLexer.IsCurrent:
- if (!(fieldSpec instanceof BuildChoiceField && option.withCurrentBuildCriteria()
- || fieldSpec instanceof PullRequestChoiceField && option.withCurrentPullRequestCriteria())
- || fieldSpec instanceof CommitField && option.withCurrentCommitCriteria())
+ if (!(fieldName.equals(Issue.NAME_PROJECT) && option.withCurrentProjectCriteria()
+ || fieldSpec instanceof BuildChoiceField && option.withCurrentBuildCriteria()
+ || fieldSpec instanceof PullRequestChoiceField && option.withCurrentPullRequestCriteria()
+ || fieldSpec instanceof CommitField && option.withCurrentCommitCriteria()))
throw newOperatorException(fieldName, operator);
break;
case IssueQueryLexer.IsPrevious:
diff --git a/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQueryParseOption.java b/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQueryParseOption.java
index c7be273762..cc1d24c320 100644
--- a/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQueryParseOption.java
+++ b/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQueryParseOption.java
@@ -6,6 +6,8 @@ public class IssueQueryParseOption implements Serializable {
private static final long serialVersionUID = 1L;
+ private boolean withCurrentProjectCriteria;
+
private boolean withCurrentUserCriteria;
private boolean withCurrentIssueCriteria;
@@ -18,6 +20,15 @@ public class IssueQueryParseOption implements Serializable {
private boolean withOrder = true;
+ public boolean withCurrentProjectCriteria() {
+ return withCurrentProjectCriteria;
+ }
+
+ public IssueQueryParseOption withCurrentProjectCriteria(boolean withCurrentProjectCriteria) {
+ this.withCurrentProjectCriteria = withCurrentProjectCriteria;
+ return this;
+ }
+
public boolean withCurrentUserCriteria() {
return withCurrentUserCriteria;
}
@@ -73,6 +84,7 @@ public class IssueQueryParseOption implements Serializable {
}
public IssueQueryParseOption enableAll(boolean enabled) {
+ withCurrentProjectCriteria = enabled;
withCurrentBuildCriteria = enabled;
withCurrentCommitCriteria = enabled;
withCurrentIssueCriteria = enabled;
diff --git a/server-core/src/main/java/io/onedev/server/search/entity/issue/ProjectIsCurrentCriteria.java b/server-core/src/main/java/io/onedev/server/search/entity/issue/ProjectIsCurrentCriteria.java
new file mode 100644
index 0000000000..38aa6e777d
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/search/entity/issue/ProjectIsCurrentCriteria.java
@@ -0,0 +1,36 @@
+package io.onedev.server.search.entity.issue;
+
+import io.onedev.commons.utils.ExplicitException;
+import io.onedev.server.model.Issue;
+import io.onedev.server.model.Project;
+import io.onedev.server.util.criteria.Criteria;
+
+import javax.persistence.criteria.*;
+
+public class ProjectIsCurrentCriteria extends Criteria<Issue> {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Predicate getPredicate(CriteriaQuery<?> query, From<Issue, Issue> from, CriteriaBuilder builder) {
+ if (Project.get() != null)
+ return builder.equal(from.join(Issue.PROP_PROJECT, JoinType.INNER), Project.get());
+ else
+ throw new ExplicitException("No project in query context");
+ }
+
+ @Override
+ public boolean matches(Issue issue) {
+ if (Project.get() != null)
+ return Project.get().equals(issue.getProject());
+ else
+ throw new ExplicitException("No project in query context");
+ }
+
+ @Override
+ public String toStringWithoutParens() {
+ return quote(Issue.NAME_PROJECT) + " "
+ + IssueQuery.getRuleName(IssueQueryLexer.IsCurrent);
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/list/IssueListPanel.html b/server-core/src/main/java/io/onedev/server/web/component/issue/list/IssueListPanel.html
index 571075d7cd..7afb5d9ef5 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/list/IssueListPanel.html
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/list/IssueListPanel.html
@@ -1,99 +1,104 @@
-<wicket:panel>
- <div class="issue-list card">
- <div class="card-body">
- <div class="d-flex mb-4">
- <form wicket:id="query" class="clearable-wrapper flex-grow-1">
- <div class="input-group">
- <input wicket:id="input" spellcheck="false" autocomplete="off" class="form-control" placeholder="Query and order issues here">
- <span class="input-group-append">
- <button wicket:id="submit" type="submit" class="btn btn-outline-secondary btn-icon" title="Query"><wicket:svg href="magnify" class="icon"></wicket:svg></button>
- </span>
- </div>
- </form>
- <a wicket:id="newIssue" class="add-new btn btn-primary btn-icon flex-shrink-0 ml-3" title="Create new issue"><wicket:svg href="plus" class="icon"/></a>
- </div>
- <div class="mb-5">
- <a wicket:id="showSavedQueries" class="show-saved-queries text-gray d-inline-block mr-4 mb-2 text-nowrap">
- <wicket:svg href="eye" class="icon"></wicket:svg> Show Saved Queries
- </a>
- <a wicket:id="saveQuery" class="save-query text-gray d-inline-block mr-4 mb-2 text-nowrap">
- <wicket:svg href="save" class="icon"></wicket:svg> Save Query
- </a>
- <a wicket:id="operations" class="text-gray mr-4 mb-2 d-inline-block text-nowrap">
- <wicket:svg href="ellipsis-circle" class="icon rotate-180"></wicket:svg> Operations
- </a>
- <a wicket:id="fieldsAndLinks" class="fields-and-links text-gray mr-4 mb-2 d-inline-block text-nowrap">
- <wicket:svg href="select" class="icon"></wicket:svg> Fields & Links
- </a>
- <a wicket:id="import" class="import-issues text-gray mr-4 mb-2 d-inline-block text-nowrap">
- <wicket:svg href="import" class="icon"></wicket:svg> Import
- </a>
- <a wicket:id="orderBy" class="order-by text-gray mr-4 mb-2 d-inline-block text-nowrap">
- <wicket:svg href="sort" class="icon"></wicket:svg> Order By
- </a>
- </div>
- <div wicket:id="body" class="body">
- <div wicket:id="feedback"></div>
- <table wicket:id="issues" class="table"></table>
- </div>
- </div>
- </div>
- <wicket:fragment wicket:id="contentFrag">
- <div class="primary d-flex mb-3">
- <div class="mr-4 flex-grow-1">
- <wicket:container wicket:id="numberAndTitle"></wicket:container>
- <a wicket:id="copy" title="Copy issue number and title" class="copy mr-3 btn btn-icon btn-xs btn-light btn-hover-primary">
- <wicket:svg href="copy" class="icon"></wicket:svg>
- </a>
- <a wicket:id="links" class="link link-info d-inline-flex align-items-center mr-2"><span wicket:id="label"></span><wicket:svg href="arrow" class="icon icon-sm"/></a>
- </div>
- <div class="flex-shrink-0 d-none d-lg-block text-muted">
- <span class="votes mr-2" title="Votes">
- <wicket:svg href="thumb-up" class="icon"></wicket:svg> <span wicket:id="votes"></span>
- </span>
- <span class="comments" title="Comments">
- <wicket:svg href="comments" class="icon"></wicket:svg> <span wicket:id="comments"></span>
- </span>
- </div>
- </div>
- <div class="secondary d-flex flex-wrap">
- <div class="flex-grow-1 d-flex flex-wrap">
- <div wicket:id="fields" class="field"></div>
- </div>
- <div class="last-update d-none d-lg-block text-muted font-size-sm">
- <a wicket:id="user" class="link-gray"></a> <span wicket:id="activity"></span> <span wicket:id="date"></span>
- </div>
- </div>
- <wicket:enclosure child="linkedIssues">
- <div class="linked-issues pl-4">
- <div wicket:id="linkedIssues" class="linked-issue"><div wicket:id="content"></div></div>
- </div>
- </wicket:enclosure>
- </wicket:fragment>
- <wicket:fragment wicket:id="stateFrag">
- <div wicket:id="transit" class="state"><span wicket:id="state"></span></div>
- </wicket:fragment>
- <wicket:fragment wicket:id="fieldsAndLinksFrag">
- <div class="issue-fields-and-links">
- <form wicket:id="form">
- <div class="modal-header">
- <h5 id="modal-title" class="modal-title">Fields & Links</h5>
- <button wicket:id="close" type="button" class="close"><wicket:svg href="times" class="icon"/></button>
- </div>
- <div class="modal-body">
- <div wicket:id="editor"></div>
- </div>
- <div class="modal-footer">
- <input wicket:id="save" type="submit" class="dirty-aware btn btn-primary" value="Save">
- <button wicket:id="useDefault" class="btn btn-primary">Use Default</button>
- <a wicket:id="cancel" class="btn btn-secondary">Cancel</a>
- </div>
- </form>
- </div>
- </wicket:fragment>
- <wicket:fragment wicket:id="unauthorizedLinkedIssueFrag">
- <div class="mb-3">
- <span wicket:id="number" class="mr-2"></span> <wicket:svg href="warning" class="icon"></wicket:svg> <i>You are not authorized to access this issue</i>
- </div>
- </wicket:fragment>
+<wicket:panel>
+ <div class="issue-list card">
+ <div class="card-body">
+ <div class="d-flex mb-4">
+ <form wicket:id="query" class="clearable-wrapper flex-grow-1">
+ <div class="input-group">
+ <input wicket:id="input" spellcheck="false" autocomplete="off" class="form-control" placeholder="Query and order issues here">
+ <span class="input-group-append">
+ <button wicket:id="submit" type="submit" class="btn btn-outline-secondary btn-icon" title="Query"><wicket:svg href="magnify" class="icon"></wicket:svg></button>
+ </span>
+ </div>
+ </form>
+ <a wicket:id="newIssue" class="add-new btn btn-primary btn-icon flex-shrink-0 ml-3" title="Create new issue"><wicket:svg href="plus" class="icon"/></a>
+ </div>
+ <div class="mb-5">
+ <a wicket:id="showSavedQueries" class="show-saved-queries text-gray d-inline-block mr-4 mb-2 text-nowrap">
+ <wicket:svg href="eye" class="icon"></wicket:svg> Show Saved Queries
+ </a>
+ <a wicket:id="saveQuery" class="save-query text-gray d-inline-block mr-4 mb-2 text-nowrap">
+ <wicket:svg href="save" class="icon"></wicket:svg> Save Query
+ </a>
+ <a wicket:id="operations" class="text-gray mr-4 mb-2 d-inline-block text-nowrap">
+ <wicket:svg href="ellipsis-circle" class="icon rotate-180"></wicket:svg> Operations
+ </a>
+ <a wicket:id="fieldsAndLinks" class="fields-and-links text-gray mr-4 mb-2 d-inline-block text-nowrap">
+ <wicket:svg href="select" class="icon"></wicket:svg> Fields & Links
+ </a>
+ <a wicket:id="import" class="import-issues text-gray mr-4 mb-2 d-inline-block text-nowrap">
+ <wicket:svg href="import" class="icon"></wicket:svg> Import
+ </a>
+ <a wicket:id="orderBy" class="order-by text-gray mr-4 mb-2 d-inline-block text-nowrap">
+ <wicket:svg href="sort" class="icon"></wicket:svg> Order By
+ </a>
+ </div>
+ <div wicket:id="body" class="body">
+ <div wicket:id="feedback"></div>
+ <table wicket:id="issues" class="table"></table>
+ <div wicket:id="tips" class="form-text text-muted">
+ <wicket:svg href="bulb" class="icon icon-sm"/>
+ By default issues of parent and child projects will also be listed.
+ Use query <code>&quot;Project&quot; is current</code> to show issues only belong to this project
+ </div>
+ </div>
+ </div>
+ </div>
+ <wicket:fragment wicket:id="contentFrag">
+ <div class="primary d-flex mb-3">
+ <div class="mr-4 flex-grow-1">
+ <wicket:container wicket:id="numberAndTitle"></wicket:container>
+ <a wicket:id="copy" title="Copy issue number and title" class="copy mr-3 btn btn-icon btn-xs btn-light btn-hover-primary">
+ <wicket:svg href="copy" class="icon"></wicket:svg>
+ </a>
+ <a wicket:id="links" class="link link-info d-inline-flex align-items-center mr-2"><span wicket:id="label"></span><wicket:svg href="arrow" class="icon icon-sm"/></a>
+ </div>
+ <div class="flex-shrink-0 d-none d-lg-block text-muted">
+ <span class="votes mr-2" title="Votes">
+ <wicket:svg href="thumb-up" class="icon"></wicket:svg> <span wicket:id="votes"></span>
+ </span>
+ <span class="comments" title="Comments">
+ <wicket:svg href="comments" class="icon"></wicket:svg> <span wicket:id="comments"></span>
+ </span>
+ </div>
+ </div>
+ <div class="secondary d-flex flex-wrap">
+ <div class="flex-grow-1 d-flex flex-wrap">
+ <div wicket:id="fields" class="field"></div>
+ </div>
+ <div class="last-update d-none d-lg-block text-muted font-size-sm">
+ <a wicket:id="user" class="link-gray"></a> <span wicket:id="activity"></span> <span wicket:id="date"></span>
+ </div>
+ </div>
+ <wicket:enclosure child="linkedIssues">
+ <div class="linked-issues pl-4">
+ <div wicket:id="linkedIssues" class="linked-issue"><div wicket:id="content"></div></div>
+ </div>
+ </wicket:enclosure>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="stateFrag">
+ <div wicket:id="transit" class="state"><span wicket:id="state"></span></div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="fieldsAndLinksFrag">
+ <div class="issue-fields-and-links">
+ <form wicket:id="form">
+ <div class="modal-header">
+ <h5 id="modal-title" class="modal-title">Fields & Links</h5>
+ <button wicket:id="close" type="button" class="close"><wicket:svg href="times" class="icon"/></button>
+ </div>
+ <div class="modal-body">
+ <div wicket:id="editor"></div>
+ </div>
+ <div class="modal-footer">
+ <input wicket:id="save" type="submit" class="dirty-aware btn btn-primary" value="Save">
+ <button wicket:id="useDefault" class="btn btn-primary">Use Default</button>
+ <a wicket:id="cancel" class="btn btn-secondary">Cancel</a>
+ </div>
+ </form>
+ </div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="unauthorizedLinkedIssueFrag">
+ <div class="mb-3">
+ <span wicket:id="number" class="mr-2"></span> <wicket:svg href="warning" class="icon"></wicket:svg> <i>You are not authorized to access this issue</i>
+ </div>
+ </wicket:fragment>
</wicket:panel>
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/component/issue/list/IssueListPanel.java b/server-core/src/main/java/io/onedev/server/web/component/issue/list/IssueListPanel.java
index f9449ccb26..f2a55f4501 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/issue/list/IssueListPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/issue/list/IssueListPanel.java
@@ -177,6 +177,8 @@ public abstract class IssueListPanel extends Panel {
@Nullable
private Object parse(@Nullable String queryString, IssueQuery baseQuery) {
IssueQueryParseOption option = new IssueQueryParseOption().withCurrentUserCriteria(true);
+ if (getProject() != null)
+ option.withCurrentProjectCriteria(true);
try {
return IssueQuery.merge(baseQuery, IssueQuery.parse(getProject(), queryString, option, true));
} catch (Exception e) {
@@ -379,6 +381,8 @@ public abstract class IssueListPanel extends Panel {
queryInput = new TextField<String>("input", queryStringModel);
IssueQueryParseOption option = new IssueQueryParseOption().withCurrentUserCriteria(true);
+ if (getProject() != null)
+ option.withCurrentProjectCriteria(true);
queryInput.add(new IssueQueryBehavior(new AbstractReadOnlyModel<Project>() {
@@ -1337,6 +1341,7 @@ public abstract class IssueListPanel extends Panel {
}
});
+ body.add(new WebMarkupContainer("tips").setVisible(getProject() != null));
if (getPagingHistorySupport() != null)
issuesTable.setCurrentPage(getPagingHistorySupport().getCurrentPage());
diff --git a/server-core/src/main/java/io/onedev/server/web/component/project/stats/issue/IssueStatsPanel.java b/server-core/src/main/java/io/onedev/server/web/component/project/stats/issue/IssueStatsPanel.java
index 35499ac6f3..a20a07314f 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/project/stats/issue/IssueStatsPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/project/stats/issue/IssueStatsPanel.java
@@ -5,6 +5,9 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import com.google.common.collect.Lists;
+import io.onedev.server.search.entity.issue.ProjectIsCurrentCriteria;
+import io.onedev.server.util.criteria.AndCriteria;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
@@ -52,8 +55,9 @@ public class IssueStatsPanel extends Panel {
@Override
protected void onInitialize() {
super.onInitialize();
-
- PageParameters params = ProjectIssueListPage.paramsOf(getProject(), null, 0);
+
+ IssueQuery query = new IssueQuery(new ProjectIsCurrentCriteria());
+ PageParameters params = ProjectIssueListPage.paramsOf(getProject(), query.toString(), 0);
Link<Void> issuesLink = new BookmarkablePageLink<Void>("issues", ProjectIssueListPage.class, params);
issuesLink.add(new Label("label", new AbstractReadOnlyModel<String>() {
@@ -80,7 +84,9 @@ public class IssueStatsPanel extends Panel {
Project project = getProject();
Map.Entry<Integer, Long> entry = item.getModelObject();
StateSpec stateSpec = getIssueSetting().getStateSpecs().get(entry.getKey());
- IssueQuery query = new IssueQuery(new StateCriteria(stateSpec.getName(), IssueQueryLexer.Is));
+ IssueQuery query = new IssueQuery(new AndCriteria<>(Lists.newArrayList(
+ new ProjectIsCurrentCriteria(),
+ new StateCriteria(stateSpec.getName(), IssueQueryLexer.Is))));
PageParameters params = ProjectIssueListPage.paramsOf(project, query.toString(), 0);
Link<Void> stateLink = new BookmarkablePageLink<Void>("link", ProjectIssueListPage.class, params);
stateLink.add(new Label("label", entry.getValue() + " " + stateSpec.getName()));
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/annotation/IssueQuery.java b/server-core/src/main/java/io/onedev/server/web/editable/annotation/IssueQuery.java
index b8d1171b0e..3d6c490d4f 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/annotation/IssueQuery.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/annotation/IssueQuery.java
@@ -14,6 +14,8 @@ import io.onedev.server.util.validation.IssueQueryValidator;
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy=IssueQueryValidator.class)
public @interface IssueQuery {
+ boolean withCurrentProjectCriteria() default false;
+
boolean withCurrentUserCriteria() default false;
boolean withCurrentIssueCriteria() default false;
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/issue/IssueQueryEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/issue/IssueQueryEditSupport.java
index 32e1047fe4..db414e02b8 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/issue/IssueQueryEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/issue/IssueQueryEditSupport.java
@@ -65,6 +65,7 @@ public class IssueQueryEditSupport implements EditSupport {
IssueQuery issueQuery = Preconditions.checkNotNull(
getDescriptor().getPropertyGetter().getAnnotation(IssueQuery.class));
IssueQueryParseOption option = new IssueQueryParseOption()
+ .withCurrentProjectCriteria(issueQuery.withCurrentProjectCriteria())
.withCurrentBuildCriteria(issueQuery.withCurrentBuildCriteria())
.withCurrentCommitCriteria(issueQuery.withCurrentCommitCriteria())
.withCurrentIssueCriteria(issueQuery.withCurrentIssueCriteria())