The Unified and Autonomous Development Platform
Issue query auto-complete
Robin Shencef547bd4e51
diff --git a/core/pom.xml b/core/pom.xmlindex 1298793433..e7eca83978 100644--- a/core/pom.xml+++ b/core/pom.xml@@ -248,6 +248,11 @@<artifactId>xstream</artifactId><version>1.4.9</version></dependency>+ <dependency>+ <groupId>com.joestelmach</groupId>+ <artifactId>natty</artifactId>+ <version>0.13</version>+ </dependency><dependency><groupId>org.codehaus.groovy</groupId><artifactId>groovy</artifactId>diff --git a/core/src/main/java/io/onedev/server/manager/impl/DefaultIssueFieldManager.java b/core/src/main/java/io/onedev/server/manager/impl/DefaultIssueFieldManager.javaindex ddd0037144..6fd92e240e 100644--- a/core/src/main/java/io/onedev/server/manager/impl/DefaultIssueFieldManager.java+++ b/core/src/main/java/io/onedev/server/manager/impl/DefaultIssueFieldManager.java@@ -4,6 +4,7 @@ import java.io.Serializable;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;+import java.util.Date;import java.util.HashMap;import java.util.HashSet;import java.util.List;@@ -41,7 +42,9 @@ import io.onedev.server.util.editable.EditableUtils;import io.onedev.server.util.inputspec.InputContext;import io.onedev.server.util.inputspec.InputSpec;import io.onedev.server.util.inputspec.choiceinput.ChoiceInput;+import io.onedev.server.util.inputspec.dateinput.DateInput;import io.onedev.server.util.inputspec.multichoiceinput.MultiChoiceInput;+import io.onedev.server.util.inputspec.numberinput.NumberInput;import io.onedev.server.web.editable.BeanDescriptor;import io.onedev.server.web.editable.PropertyDescriptor;import io.onedev.server.web.page.project.issues.issuelist.workflowreconcile.InvalidFieldResolution;@@ -138,43 +141,47 @@ public class DefaultIssueFieldManager extends AbstractEntityManager<IssueField>Object fieldValue = propertyDescriptor.getPropertyValue(fieldBean);InputSpec fieldSpec = issue.getProject().getIssueWorkflow().getField(fieldName);if (fieldSpec != null) {- int ordinal;+ long ordinal = -1;- if (fieldValue != null && fieldSpec instanceof ChoiceInput) {- OneContext.push(new OneContext() {-- @Override- public Project getProject() {- return issue.getProject();- }-- @Override- public EditContext getEditContext(int level) {- return new EditContext() {-- @Override- public Object getInputValue(String name) {- return beanDescriptor.getMapOfDisplayNameToPropertyDescriptor().get(name).getPropertyValue(fieldBean);- }-- };- }-- @Override- public InputContext getInputContext() {- throw new UnsupportedOperationException();- }+ if (fieldValue != null) {+ if (fieldSpec instanceof ChoiceInput) {+ OneContext.push(new OneContext() {++ @Override+ public Project getProject() {+ return issue.getProject();+ }++ @Override+ public EditContext getEditContext(int level) {+ return new EditContext() {++ @Override+ public Object getInputValue(String name) {+ return beanDescriptor.getMapOfDisplayNameToPropertyDescriptor().get(name).getPropertyValue(fieldBean);+ }++ };+ }++ @Override+ public InputContext getInputContext() {+ throw new UnsupportedOperationException();+ }++ });- });-- try {- List<String> choices = new ArrayList<>(((ChoiceInput)fieldSpec).getChoiceProvider().getChoices(false).keySet());- ordinal = choices.indexOf(fieldValue);- } finally {- OneContext.pop();+ try {+ List<String> choices = new ArrayList<>(((ChoiceInput)fieldSpec).getChoiceProvider().getChoices(false).keySet());+ ordinal = choices.indexOf(fieldValue);+ } finally {+ OneContext.pop();+ }+ } else if (fieldSpec instanceof NumberInput) {+ ordinal = Long.parseLong((String)fieldValue);+ } else if (fieldSpec instanceof DateInput) {+ ordinal = ((Date)fieldValue).getTime();}- } else {- ordinal = -1;}IssueField field = new IssueField();@@ -405,11 +412,11 @@ public class DefaultIssueFieldManager extends AbstractEntityManager<IssueField>for (Object[] row: (List<Object[]>)query.getResultList()) {String name = (String) row[0];String value = (String) row[1];- int ordinal = (int) row[2];+ long ordinal = (long) row[2];InputSpec fieldSpec = project.getIssueWorkflow().getField(name);if (fieldSpec != null) {List<String> choices = new ArrayList<>(((ChoiceInput)fieldSpec).getChoiceProvider().getChoices(true).keySet());- int newOrdinal = choices.indexOf(value);+ long newOrdinal = choices.indexOf(value);if (ordinal != newOrdinal) {query = getSession().createQuery("update IssueField set ordinal=:newOrdinal where name=:fieldName and value=:fieldValue and issue.id in (select id from Issue where project=:project)");query.setParameter("fieldName", name);diff --git a/core/src/main/java/io/onedev/server/model/Issue.java b/core/src/main/java/io/onedev/server/model/Issue.javaindex b2e06f160e..06d37a2fd5 100644--- a/core/src/main/java/io/onedev/server/model/Issue.java+++ b/core/src/main/java/io/onedev/server/model/Issue.java@@ -1,16 +1,12 @@package io.onedev.server.model;-import java.lang.reflect.Field;-import java.lang.reflect.Method;import java.util.ArrayList;import java.util.Collection;import java.util.Date;import java.util.HashMap;-import java.util.HashSet;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;-import java.util.Set;import javax.annotation.Nullable;import javax.persistence.CascadeType;@@ -33,7 +29,6 @@ import io.onedev.server.util.MultiValueIssueField;import io.onedev.server.util.editable.annotation.Editable;import io.onedev.server.util.editable.annotation.Markdown;import io.onedev.server.util.inputspec.InputSpec;-import io.onedev.utils.BeanUtils;@Entity@Table(@@ -47,20 +42,33 @@ public class Issue extends AbstractEntity {private static final long serialVersionUID = 1L;- public static final Set<String> BUILTIN_FIELDS = new HashSet<>();+ public static final Map<String, String> BUILTIN_FIELDS = new HashMap<>();++ public static final String STATE = "State";++ public static final String TITLE = "Title";++ public static final String DESCRIPTION = "Description";++ public static final String SUBMITTER = "Submitter";++ public static final String SUBMIT_DATE = "Submit Date";++ public static final String VOTES = "Votes";static {- for (Method getter: BeanUtils.findGetters(Issue.class)) {- if (BeanUtils.findSetter(getter) != null) {- Field field = BeanUtils.findField(getter);- if (field != null && field.getAnnotation(ManyToOne.class) == null- && field.getAnnotation(OneToMany.class) == null) {- BUILTIN_FIELDS.add(field.getName());- }- }- }+ BUILTIN_FIELDS.put(STATE, "state");+ BUILTIN_FIELDS.put(TITLE, "title");+ BUILTIN_FIELDS.put(DESCRIPTION, "description");+ BUILTIN_FIELDS.put(SUBMITTER, "submitter");+ BUILTIN_FIELDS.put(SUBMIT_DATE, "submitDate");+ BUILTIN_FIELDS.put(VOTES, "votes");}+ public enum BuiltinField {+ state, title, description, submitter, submitDate, votes+ };+@Versionprivate long version;@@ -84,7 +92,7 @@ public class Issue extends AbstractEntity {private String submitterName;@Column(nullable=false)- private Date submitDate;+ private long submitDate;private int votes;@@ -147,11 +155,11 @@ public class Issue extends AbstractEntity {}public Date getSubmitDate() {- return submitDate;+ return new Date(submitDate);}public void setSubmitDate(Date submitDate) {- this.submitDate = submitDate;+ this.submitDate = submitDate.getTime();}public int getVotes() {diff --git a/core/src/main/java/io/onedev/server/model/IssueField.java b/core/src/main/java/io/onedev/server/model/IssueField.javaindex 8f0d2cc11b..91da80cd35 100644--- a/core/src/main/java/io/onedev/server/model/IssueField.java+++ b/core/src/main/java/io/onedev/server/model/IssueField.java@@ -18,6 +18,12 @@ public class IssueField extends AbstractEntity {private static final long serialVersionUID = 1L;+ public static final String NAME = "name";++ public static final String VALUE = "value";++ public static final String ORDINAL = "ordinal";+@ManyToOne(fetch=FetchType.LAZY)@JoinColumn(nullable=false)private Issue issue;@@ -32,7 +38,7 @@ public class IssueField extends AbstractEntity {private boolean collected;- private int ordinal;+ private long ordinal;public Issue getIssue() {return issue;@@ -66,11 +72,11 @@ public class IssueField extends AbstractEntity {this.type = type;}- public int getOrdinal() {+ public long getOrdinal() {return ordinal;}- public void setOrdinal(int ordinal) {+ public void setOrdinal(long ordinal) {this.ordinal = ordinal;}diff --git a/core/src/main/java/io/onedev/server/model/User.java b/core/src/main/java/io/onedev/server/model/User.javaindex bc53949629..8286b3285b 100644--- a/core/src/main/java/io/onedev/server/model/User.java+++ b/core/src/main/java/io/onedev/server/model/User.java@@ -2,6 +2,7 @@ package io.onedev.server.model;import java.util.ArrayList;import java.util.Collection;+import java.util.LinkedHashMap;import java.util.UUID;import javax.annotation.Nullable;@@ -9,6 +10,7 @@ import javax.persistence.CascadeType;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.Index;+import javax.persistence.Lob;import javax.persistence.OneToMany;import javax.persistence.Table;import javax.persistence.Version;@@ -87,6 +89,10 @@ public class User extends AbstractEntity implements AuthenticationInfo {@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)private Collection<PullRequestTask> requestTasks = new ArrayList<>();++ @Lob+ @Column(length=65535)+ private LinkedHashMap<String, String> issueQueries = new LinkedHashMap<>();@Overridepublic PrincipalCollection getPrincipals() {@@ -182,6 +188,14 @@ public class User extends AbstractEntity implements AuthenticationInfo {this.requestTasks = requestTasks;}+ public LinkedHashMap<String, String> getIssueQueries() {+ return issueQueries;+ }++ public void setIssueQueries(LinkedHashMap<String, String> issueQueries) {+ this.issueQueries = issueQueries;+ }+@SuppressWarnings("deprecation")@Overridepublic String toString() {diff --git a/core/src/main/java/io/onedev/server/model/support/issue/IssueListCustomization.java b/core/src/main/java/io/onedev/server/model/support/issue/IssueListCustomization.javaindex 023588c77f..a79d4c0fdd 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/IssueListCustomization.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/IssueListCustomization.java@@ -2,9 +2,10 @@ package io.onedev.server.model.support.issue;import java.io.Serializable;import java.util.ArrayList;+import java.util.LinkedHashMap;import java.util.List;+import java.util.Map;-import io.onedev.server.model.support.issue.query.IssueQuery;import io.onedev.server.util.editable.annotation.ChoiceProvider;import io.onedev.server.util.inputspec.InputSpec;import io.onedev.server.web.page.project.ProjectPage;@@ -14,16 +15,16 @@ public class IssueListCustomization implements Serializable {private static final long serialVersionUID = 1L;- private List<IssueQuery> presetQueries = new ArrayList<>();+ private Map<String, String> savedQueries = new LinkedHashMap<>();private List<String> displayFields = new ArrayList<>();- public List<IssueQuery> getPresetQueries() {- return presetQueries;+ public Map<String, String> getSavedQueries() {+ return savedQueries;}- public void setPresetQueries(List<IssueQuery> presetQueries) {- this.presetQueries = presetQueries;+ public void setSavedQueries(Map<String, String> savedQueries) {+ this.savedQueries = savedQueries;}@ChoiceProvider("getFieldChoices")@@ -54,12 +55,4 @@ public class IssueListCustomization implements Serializable {getDisplayFields().remove(fieldName);}- public IssueQuery getQuery() {- if (!presetQueries.isEmpty()) {- return presetQueries.iterator().next();- } else {- return new IssueQuery(null, new ArrayList<>());- }- }-}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/ArithmeticOperator.java b/core/src/main/java/io/onedev/server/model/support/issue/query/ArithmeticOperator.javadeleted file mode 100644index aee4ee6ec3..0000000000--- a/core/src/main/java/io/onedev/server/model/support/issue/query/ArithmeticOperator.java+++ /dev/null@@ -1,44 +0,0 @@-package io.onedev.server.model.support.issue.query;--import javax.persistence.criteria.CriteriaBuilder;-import javax.persistence.criteria.Expression;-import javax.persistence.criteria.Predicate;--public enum ArithmeticOperator {-- EQUALS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<Integer> left, int right) {- return builder.equal(left, right);- }-- },- NOT_EQUALS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<Integer> left, int right) {- return builder.notEqual(left, right);- }-- },- GREATER_THAN {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<Integer> left, int right) {- return builder.greaterThan(left, right);- }-- },- LESS_THAN {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<Integer> left, int right) {- return builder.lessThan(left, right);- }-- };-- public abstract Predicate getPredicate(CriteriaBuilder builder, Expression<Integer> left, int right);--}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/ChoiceFieldCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/ChoiceFieldCriteria.javaindex bcf4620032..8e79e8065b 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/ChoiceFieldCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/ChoiceFieldCriteria.java@@ -1,28 +1,39 @@package io.onedev.server.model.support.issue.query;+import javax.persistence.criteria.Join;import javax.persistence.criteria.Predicate;+import io.onedev.server.model.Issue;+import io.onedev.server.model.IssueField;+public class ChoiceFieldCriteria extends FieldCriteria {private static final long serialVersionUID = 1L;private final String value;- private final EnumOperator operator;+ private final long ordinal;++ private final int operator;- public ChoiceFieldCriteria(String name, String value, EnumOperator operator) {+ public ChoiceFieldCriteria(String name, String value, long ordinal, int operator) {super(name);this.value = value;+ this.ordinal = ordinal;this.operator = operator;}- public String getValue() {- return value;- }-@Overridepublic Predicate getPredicate(QueryBuildContext context) {- return operator.getPredicate(context.getBuilder(), context.getJoin(getFieldName()).get("value"), value);+ Join<Issue, ?> join = context.getJoin(getFieldName());+ if (operator == IssueQueryLexer.Is)+ return context.getBuilder().equal(join.get(IssueField.VALUE), value);+ else if (operator == IssueQueryLexer.IsNot)+ return context.getBuilder().notEqual(join.get(IssueField.VALUE), value);+ else if (operator == IssueQueryLexer.IsGreaterThan)+ return context.getBuilder().greaterThan(join.get(IssueField.ORDINAL), ordinal);+ else+ return context.getBuilder().lessThan(join.get(IssueField.ORDINAL), ordinal);}}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/DateFieldCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/DateFieldCriteria.javanew file mode 100644index 0000000000..b530b39ee9--- /dev/null+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/DateFieldCriteria.java@@ -0,0 +1,34 @@+package io.onedev.server.model.support.issue.query;++import java.util.Date;++import javax.persistence.criteria.Join;+import javax.persistence.criteria.Predicate;++import io.onedev.server.model.Issue;+import io.onedev.server.model.IssueField;++public class DateFieldCriteria extends FieldCriteria {++ private static final long serialVersionUID = 1L;++ private final Date value;++ private final int operator;++ public DateFieldCriteria(String name, Date value, int operator) {+ super(name);+ this.value = value;+ this.operator = operator;+ }++ @Override+ public Predicate getPredicate(QueryBuildContext context) {+ Join<Issue, ?> join = context.getJoin(getFieldName());+ if (operator == IssueQueryLexer.IsBefore)+ return context.getBuilder().lessThan(join.get(IssueField.ORDINAL), value.getTime());+ else+ return context.getBuilder().greaterThan(join.get(IssueField.ORDINAL), value.getTime());+ }++}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/DateOperator.java b/core/src/main/java/io/onedev/server/model/support/issue/query/DateOperator.javadeleted file mode 100644index 47e0d09ccc..0000000000--- a/core/src/main/java/io/onedev/server/model/support/issue/query/DateOperator.java+++ /dev/null@@ -1,30 +0,0 @@-package io.onedev.server.model.support.issue.query;--import java.util.Date;--import javax.persistence.criteria.CriteriaBuilder;-import javax.persistence.criteria.Expression;-import javax.persistence.criteria.Predicate;--public enum DateOperator {-- BEFORE {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<Date> left, Date right) {- return builder.lessThan(left, right);- }-- },- AFTER {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<Date> left, Date right) {- return builder.greaterThan(left, right);- }-- };-- public abstract Predicate getPredicate(CriteriaBuilder builder, Expression<Date> left, Date right);--}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/DescriptionCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/DescriptionCriteria.javaindex 84bc0c8886..9dd7f0ec54 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/DescriptionCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/DescriptionCriteria.java@@ -1,23 +1,30 @@package io.onedev.server.model.support.issue.query;+import javax.persistence.criteria.Expression;import javax.persistence.criteria.Predicate;+import io.onedev.server.model.Issue;+public class DescriptionCriteria extends IssueCriteria {private static final long serialVersionUID = 1L;private final String value;- private final TextOperator operator;+ private final int operator;- public DescriptionCriteria(String value, TextOperator operator) {+ public DescriptionCriteria(String value, int operator) {this.value = value;this.operator = operator;}@Overridepublic Predicate getPredicate(QueryBuildContext context) {- return operator.getPredicate(context.getBuilder(), context.getRoot().get("description"), value);+ Expression<String> attribute = context.getRoot().get(Issue.BUILTIN_FIELDS.get(Issue.DESCRIPTION));+ if (operator == IssueQueryLexer.Contains)+ return context.getBuilder().like(attribute, "%" + value + "%");+ else+ return context.getBuilder().notLike(attribute, "%" + value + "%");}}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/EnumOperator.java b/core/src/main/java/io/onedev/server/model/support/issue/query/EnumOperator.javadeleted file mode 100644index 9d19982026..0000000000--- a/core/src/main/java/io/onedev/server/model/support/issue/query/EnumOperator.java+++ /dev/null@@ -1,28 +0,0 @@-package io.onedev.server.model.support.issue.query;--import javax.persistence.criteria.CriteriaBuilder;-import javax.persistence.criteria.Expression;-import javax.persistence.criteria.Predicate;--public enum EnumOperator {-- EQUALS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right) {- return builder.equal(left, right);- }-- },- NOT_EQUALS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right) {- return builder.notEqual(left, right);- }-- };-- public abstract Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right);--}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/FieldIsEmpty.java b/core/src/main/java/io/onedev/server/model/support/issue/query/FieldIsEmpty.javadeleted file mode 100644index 7e0996ac03..0000000000--- a/core/src/main/java/io/onedev/server/model/support/issue/query/FieldIsEmpty.java+++ /dev/null@@ -1,18 +0,0 @@-package io.onedev.server.model.support.issue.query;--import javax.persistence.criteria.Predicate;--public class FieldIsEmpty extends FieldCriteria {-- private static final long serialVersionUID = 1L;-- public FieldIsEmpty(String name) {- super(name);- }-- @Override- public Predicate getPredicate(QueryBuildContext context) {- return context.getBuilder().isNull(context.getJoin(getFieldName()).get("value"));- }--}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/FieldIsNotEmpty.java b/core/src/main/java/io/onedev/server/model/support/issue/query/FieldIsNotEmpty.javadeleted file mode 100644index 119f8d7c7c..0000000000--- a/core/src/main/java/io/onedev/server/model/support/issue/query/FieldIsNotEmpty.java+++ /dev/null@@ -1,18 +0,0 @@-package io.onedev.server.model.support.issue.query;--import javax.persistence.criteria.Predicate;--public class FieldIsNotEmpty extends FieldCriteria {-- private static final long serialVersionUID = 1L;-- public FieldIsNotEmpty(String name) {- super(name);- }-- @Override- public Predicate getPredicate(QueryBuildContext context) {- return context.getBuilder().isNotNull(context.getJoin(getFieldName()).get("value"));- }--}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/FieldUnaryCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/FieldUnaryCriteria.javanew file mode 100644index 0000000000..ea43107437--- /dev/null+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/FieldUnaryCriteria.java@@ -0,0 +1,33 @@+package io.onedev.server.model.support.issue.query;++import javax.persistence.criteria.Path;+import javax.persistence.criteria.Predicate;++import io.onedev.server.model.IssueField;+import io.onedev.server.security.SecurityUtils;++public class FieldUnaryCriteria extends FieldCriteria {++ private static final long serialVersionUID = 1L;++ private final int operator;++ public FieldUnaryCriteria(String name, int operator) {+ super(name);+ this.operator = operator;+ }++ @Override+ public Predicate getPredicate(QueryBuildContext context) {+ Path<?> attribute = context.getJoin(getFieldName()).get(IssueField.VALUE);+ if (operator == IssueQueryLexer.IsEmpty)+ return context.getBuilder().isNull(attribute);+ else if (operator == IssueQueryLexer.IsNotEmpty)+ return context.getBuilder().isNotNull(attribute);+ else if (operator == IssueQueryLexer.IsMe || operator == IssueQueryLexer.ContainsMe)+ return context.getBuilder().equal(attribute, SecurityUtils.getUser());+ else+ return context.getBuilder().notEqual(attribute, SecurityUtils.getUser());+ }++}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/IssueQuery.g4 b/core/src/main/java/io/onedev/server/model/support/issue/query/IssueQuery.g4index 5d77ee287d..f830d980ad 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/IssueQuery.g4+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/IssueQuery.g4@@ -1,14 +1,106 @@grammar IssueQuery;query- : criteria* 'order by' FieldName (',' FieldName)* EOF+ : WS* criteria WS+ OrderBy WS+ order (WS+ 'and' WS+ order)* WS* EOF+ | WS* criteria WS* EOF+ | WS* OrderBy WS+ order (WS+ 'and' WS+ order)* WS* EOF+ | WS* EOF;criteria- : 'c'+ : Mine #MineCriteria+ | criteriaField=Quoted WS+ operator=(IsMe|IsNotMe|ContainsMe|DoesNotContainMe|IsEmpty|IsNotEmpty) #UnaryCriteria+ | criteriaField=Quoted WS+ operator=(Is|IsNot|IsGreaterThan|IsLessThan|IsBefore|IsAfter|Contains|DoesNotContain) WS+ criteriaValue=Quoted #ValueCriteria+ | criteria WS+ 'and' WS+ criteria #AndCriteria+ | criteria WS+ 'or' WS+ criteria #OrCriteria+ | '(' WS* criteria WS* ')' #BracedCriteria;-FieldName- : ~[~`!@#$%^&()=+;',/\\:*?\"|(){}<> \[\]]+order+ : orderField=Quoted WS* (WS+ direction=('asc'|'desc'))?+ ;++Mine+ : 'mine'+ ;++OrderBy+ : 'order' WS+ 'by';+Is+ : 'is'+ ;++IsNot+ : 'is' WS+ 'not'+ ;++IsMe+ : 'is' WS+ 'me'+ ;++IsNotMe+ : 'is' WS+ 'not' WS+ 'me'+ ;++Contains+ : 'contains'+ ;++DoesNotContain+ : 'does' WS+ 'not' WS+ 'contain'+ ;++ContainsMe+ : 'contains' WS+ 'me'+ ;++DoesNotContainMe+ : 'does' WS+ 'not' WS+ 'contain' WS+ 'me'+ ;++IsGreaterThan+ : 'is' WS+ 'greater' WS+ 'than'+ ;++IsLessThan+ : 'is' WS+ 'less' WS+ 'than'+ ;++IsAfter+ : 'is' WS+ 'after'+ ;++IsBefore+ : 'is' WS+ 'before'+ ;++IsEmpty+ : 'is' WS+ 'empty'+ ;++IsNotEmpty+ : 'is' WS+ 'not' WS+ 'empty'+ ;++Quoted+ : '"' (ESCAPE|~["\\])+? '"'+ ;++/*+ * Use identifier to make the input "isnot" a whole token so that it becomes a "matchWith"+ * to provide suggestion for "is not"+ */+Identifier+ : [a-zA-Z]++ ;++WS+ : ' '+ ;++fragment+ESCAPE+ : '\\'["\\]+ ;diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/IssueQuery.java b/core/src/main/java/io/onedev/server/model/support/issue/query/IssueQuery.javaindex bdb5c41643..c5c3b123b8 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/IssueQuery.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/IssueQuery.java@@ -2,6 +2,7 @@ package io.onedev.server.model.support.issue.query;import java.io.Serializable;import java.util.ArrayList;+import java.util.Date;import java.util.List;import javax.annotation.Nullable;@@ -12,16 +13,57 @@ import javax.persistence.criteria.JoinType;import javax.persistence.criteria.Order;import javax.persistence.criteria.Root;+import org.antlr.v4.runtime.ANTLRInputStream;+import org.antlr.v4.runtime.BailErrorStrategy;+import org.antlr.v4.runtime.BaseErrorListener;+import org.antlr.v4.runtime.CommonTokenStream;+import org.antlr.v4.runtime.RecognitionException;+import org.antlr.v4.runtime.Recognizer;import org.hibernate.Session;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;+import org.unbescape.java.JavaEscape;+import io.onedev.server.OneDev;+import io.onedev.server.exception.OneException;+import io.onedev.server.manager.UserManager;import io.onedev.server.model.Issue;import io.onedev.server.model.IssueField;+import io.onedev.server.model.Project;+import io.onedev.server.model.User;+import io.onedev.server.model.support.issue.query.IssueQueryParser.AndCriteriaContext;+import io.onedev.server.model.support.issue.query.IssueQueryParser.BracedCriteriaContext;+import io.onedev.server.model.support.issue.query.IssueQueryParser.CriteriaContext;+import io.onedev.server.model.support.issue.query.IssueQueryParser.MineCriteriaContext;+import io.onedev.server.model.support.issue.query.IssueQueryParser.OrCriteriaContext;+import io.onedev.server.model.support.issue.query.IssueQueryParser.OrderContext;+import io.onedev.server.model.support.issue.query.IssueQueryParser.QueryContext;+import io.onedev.server.model.support.issue.query.IssueQueryParser.UnaryCriteriaContext;+import io.onedev.server.model.support.issue.query.IssueQueryParser.ValueCriteriaContext;import io.onedev.server.model.support.issue.query.IssueSort.Direction;+import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;+import io.onedev.server.util.EditContext;+import io.onedev.server.util.OneContext;+import io.onedev.server.util.inputspec.InputContext;+import io.onedev.server.util.inputspec.InputSpec;+import io.onedev.server.util.inputspec.choiceinput.ChoiceInput;+import io.onedev.server.util.inputspec.dateinput.DateInput;+import io.onedev.server.util.inputspec.groupchoiceinput.GroupChoiceInput;+import io.onedev.server.util.inputspec.groupmultichoiceinput.GroupMultiChoiceInput;+import io.onedev.server.util.inputspec.multichoiceinput.MultiChoiceInput;+import io.onedev.server.util.inputspec.numberinput.NumberInput;+import io.onedev.server.util.inputspec.textinput.TextInput;+import io.onedev.server.util.inputspec.userchoiceinput.UserChoiceInput;+import io.onedev.server.util.inputspec.usermultichoiceinput.UserMultiChoiceInput;+import io.onedev.utils.WordUtils;public class IssueQuery implements Serializable {private static final long serialVersionUID = 1L;+ private static final Logger logger = LoggerFactory.getLogger(IssueQuery.class);+private final IssueCriteria criteria;private final List<IssueSort> sorts;@@ -31,6 +73,10 @@ public class IssueQuery implements Serializable {this.sorts = sorts;}+ public IssueQuery() {+ this(null, new ArrayList<>());+ }+public CriteriaQuery<Issue> buildCriteriaQuery(Session session) {CriteriaBuilder builder = session.getCriteriaBuilder();CriteriaQuery<Issue> query = builder.createQuery(Issue.class);@@ -41,18 +87,18 @@ public class IssueQuery implements Serializable {List<Order> orders = new ArrayList<>();for (IssueSort sort: sorts) {- if (Issue.BUILTIN_FIELDS.contains(sort.getField())) {+ if (Issue.BUILTIN_FIELDS.containsKey(sort.getField())) {if (sort.getDirection() == Direction.ASCENDING)- orders.add(builder.asc(root.get(sort.getField())));+ orders.add(builder.asc(root.get(Issue.BUILTIN_FIELDS.get(sort.getField()))));else- orders.add(builder.desc(root.get(sort.getField())));+ orders.add(builder.desc(root.get(Issue.BUILTIN_FIELDS.get(sort.getField()))));} else {Join<Issue, IssueField> join = root.join("fields", JoinType.LEFT);- join.on(builder.equal(join.get("name"), sort.getField()));+ join.on(builder.equal(join.get(IssueField.NAME), sort.getField()));if (sort.getDirection() == Direction.ASCENDING)- orders.add(builder.asc(join.get("ordinal")));+ orders.add(builder.asc(join.get(IssueField.ORDINAL)));else- orders.add(builder.desc(join.get("ordinal")));+ orders.add(builder.desc(join.get(IssueField.ORDINAL)));}}@@ -70,5 +116,320 @@ public class IssueQuery implements Serializable {public List<IssueSort> getSorts() {return sorts;}++ public static String getValue(String tokenText) {+ String value = tokenText.substring(1);+ return JavaEscape.unescapeJava(value.substring(0, value.length()-1));+ }++ public static int getIntValue(String value) {+ try {+ return Integer.parseInt(value);+ } catch (NumberFormatException e) {+ throw new OneException("Invalid number: " + value);+ }+ }++ public static IssueQuery parse(Project project, @Nullable String queryString) {+ if (queryString != null) {+ ANTLRInputStream is = new ANTLRInputStream(queryString);+ IssueQueryLexer lexer = new IssueQueryLexer(is);+ lexer.removeErrorListeners();+ lexer.addErrorListener(new BaseErrorListener() {++ @Override+ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,+ int charPositionInLine, String msg, RecognitionException e) {+ if (e != null) {+ logger.error("Error lexing issue query", e);+ } else if (msg != null) {+ logger.error("Error lexing issue query: " + msg);+ }+ throw new RuntimeException("Malformed issue query");+ }++ });+ CommonTokenStream tokens = new CommonTokenStream(lexer);+ IssueQueryParser parser = new IssueQueryParser(tokens);+ parser.removeErrorListeners();+ parser.setErrorHandler(new BailErrorStrategy());+ QueryContext queryContext = parser.query();+ CriteriaContext criteriaContext = queryContext.criteria();+ IssueCriteria issueCriteria;+ if (criteriaContext != null) {+ issueCriteria = new IssueQueryBaseVisitor<IssueCriteria>() {++ private long getValueOrdinal(ChoiceInput field, String value) {+ OneContext.push(new OneContext() {++ @Override+ public Project getProject() {+ return project;+ }++ @Override+ public EditContext getEditContext(int level) {+ return new EditContext() {++ @Override+ public Object getInputValue(String name) {+ return null;+ }++ };+ }++ @Override+ public InputContext getInputContext() {+ throw new UnsupportedOperationException();+ }++ });+ try {+ List<String> choices = new ArrayList<>(((ChoiceInput)field).getChoiceProvider().getChoices(true).keySet());+ return choices.indexOf(value);+ } finally {+ OneContext.pop();+ }+ }++ @Override+ public IssueCriteria visitMineCriteria(MineCriteriaContext ctx) {+ if (SecurityUtils.getUser() == null)+ throw new OneException("Please login to perform this query");++ IssueCriteria submitterCriteria = new SubmitterCriteria(SecurityUtils.getUser(), IssueQueryLexer.Is);+ List<IssueCriteria> fieldCriterias = new ArrayList<>();+ for (InputSpec field: project.getIssueWorkflow().getFields()) {+ if (field instanceof UserChoiceInput) {+ IssueCriteria fieldCriteria = new ChoiceFieldCriteria(field.getName(),+ SecurityUtils.getUser().getName(), -1, IssueQueryLexer.Is);+ fieldCriterias.add(fieldCriteria);+ } else if (field instanceof UserMultiChoiceInput) {+ IssueCriteria fieldCriteria = new MultiChoiceFieldCriteria(field.getName(),+ SecurityUtils.getUser().getName(), IssueQueryLexer.Contains);+ fieldCriterias.add(fieldCriteria);+ }+ }+ if (!fieldCriterias.isEmpty()) {+ fieldCriterias.add(0, submitterCriteria);+ return new OrCriteria(fieldCriterias);+ } else {+ return submitterCriteria;+ }+ }++ @Override+ public IssueCriteria visitUnaryCriteria(UnaryCriteriaContext ctx) {+ String fieldName = getValue(ctx.Quoted().getText());+ int operator = ctx.operator.getType();+ checkField(project, fieldName, operator);+ if (fieldName.equals(Issue.SUBMITTER))+ return new SubmitterUnaryCriteria(operator);+ else+ return new FieldUnaryCriteria(fieldName, operator);+ }++ @Override+ public IssueCriteria visitBracedCriteria(BracedCriteriaContext ctx) {+ return visit(ctx.criteria());+ }++ @Override+ public IssueCriteria visitValueCriteria(ValueCriteriaContext ctx) {+ String fieldName = getValue(ctx.Quoted(0).getText());+ String value = getValue(ctx.Quoted(1).getText());+ int operator = ctx.operator.getType();+ checkField(project, fieldName, operator);++ switch (operator) {+ case IssueQueryLexer.IsBefore:+ case IssueQueryLexer.IsAfter:+ Date dateValue = DateUtils.parseRelaxed(value);+ if (dateValue == null)+ throw new OneException("Unrecognized date: " + value);+ if (fieldName.equals(Issue.SUBMIT_DATE))+ return new SubmitDateCriteria(dateValue, operator);+ else+ return new DateFieldCriteria(fieldName, dateValue, operator);+ case IssueQueryLexer.Contains:+ case IssueQueryLexer.DoesNotContain:+ if (fieldName.equals(Issue.TITLE)) {+ return new TitleCriteria(value, operator);+ } else if (fieldName.equals(Issue.DESCRIPTION)) {+ return new DescriptionCriteria(value, operator);+ } else {+ InputSpec field = project.getIssueWorkflow().getField(fieldName);+ if (field instanceof TextInput)+ return new StringFieldCriteria(fieldName, value, operator);+ else+ return new MultiChoiceFieldCriteria(fieldName, value, operator);+ }+ case IssueQueryLexer.Is:+ case IssueQueryLexer.IsNot:+ if (fieldName.equals(Issue.STATE)) {+ return new StateCriteria(value, operator);+ } else if (fieldName.equals(Issue.VOTES)) {+ return new VoteCriteria(getIntValue(value), operator);+ } else if (fieldName.equals(Issue.SUBMITTER)) {+ User user = OneDev.getInstance(UserManager.class).findByName(value);+ if (user == null)+ throw new OneException("Unable to find user with login: " + value);+ return new SubmitterCriteria(user, operator);+ } else {+ InputSpec field = project.getIssueWorkflow().getField(fieldName);+ if (field instanceof NumberInput) {+ return new NumberFieldCriteria(fieldName, getIntValue(value), operator);+ } else if (field instanceof ChoiceInput) {+ long ordinal = getValueOrdinal((ChoiceInput) field, value);+ return new ChoiceFieldCriteria(fieldName, value, ordinal, operator);+ } else if (field instanceof UserChoiceInput+ || field instanceof GroupChoiceInput) {+ return new ChoiceFieldCriteria(fieldName, value, -1, operator);+ } else {+ return new StringFieldCriteria(fieldName, value, operator);+ }+ }+ case IssueQueryLexer.IsLessThan:+ case IssueQueryLexer.IsGreaterThan:+ if (fieldName.equals(Issue.VOTES)) {+ return new VoteCriteria(getIntValue(value), operator);+ } else {+ InputSpec field = project.getIssueWorkflow().getField(fieldName);+ if (field instanceof NumberInput)+ return new NumberFieldCriteria(fieldName, getIntValue(value), operator);+ else+ return new ChoiceFieldCriteria(fieldName, value, getValueOrdinal((ChoiceInput) field, value), operator);+ }+ default:+ throw new OneException("Unexpected operator " + getOperatorName(operator));+ }+ }++ @Override+ public IssueCriteria visitOrCriteria(OrCriteriaContext ctx) {+ List<IssueCriteria> childCriterias = new ArrayList<>();+ for (CriteriaContext childCtx: ctx.criteria())+ childCriterias.add(visit(childCtx));+ return new OrCriteria(childCriterias);+ }++ @Override+ public IssueCriteria visitAndCriteria(AndCriteriaContext ctx) {+ List<IssueCriteria> childCriterias = new ArrayList<>();+ for (CriteriaContext childCtx: ctx.criteria())+ childCriterias.add(visit(childCtx));+ return new AndCriteria(childCriterias);+ }++ }.visit(criteriaContext);+ } else {+ issueCriteria = null;+ }++ List<IssueSort> issueSorts = new ArrayList<>();+ for (OrderContext order: queryContext.order()) {+ String fieldName = getValue(order.Quoted().getText());+ if (!fieldName.equals(Issue.SUBMIT_DATE) && !fieldName.equals(Issue.VOTES)) {+ InputSpec field = project.getIssueWorkflow().getField(fieldName);+ if (!(field instanceof ChoiceInput) && !(field instanceof DateInput)+ && !(field instanceof NumberInput)) {+ throw new OneException("Can not order by field: " + fieldName);+ }+ }++ IssueSort issueSort = new IssueSort();+ issueSort.setField(fieldName);+ if (order.direction != null && order.direction.getText().equals("asc"))+ issueSort.setDirection(Direction.ASCENDING);+ else+ issueSort.setDirection(Direction.DESCENDING);+ issueSorts.add(issueSort);+ }++ return new IssueQuery(issueCriteria, issueSorts);+ } else {+ return new IssueQuery();+ }+ }++ private static OneException newOperatorException(String fieldName, int operator) {+ return new OneException("Field '" + fieldName + "' is not applicable for operator '" + getOperatorName(operator) + "'");+ }+ public static void checkField(Project project, String fieldName, int operator) {+ InputSpec field = project.getIssueWorkflow().getField(fieldName);+ if (field == null && !Issue.BUILTIN_FIELDS.containsKey(fieldName))+ throw new OneException("Field not found: " + fieldName);+ switch (operator) {+ case IssueQueryLexer.IsEmpty:+ case IssueQueryLexer.IsNotEmpty:+ if (Issue.BUILTIN_FIELDS.containsKey(fieldName))+ throw newOperatorException(fieldName, operator);+ break;+ case IssueQueryLexer.IsMe:+ case IssueQueryLexer.IsNotMe:+ if (!fieldName.equals(Issue.SUBMITTER) && !(field instanceof UserChoiceInput))+ throw newOperatorException(fieldName, operator);+ else if (SecurityUtils.getUser() == null)+ throw new OneException("Please login to perform this query");+ break;+ case IssueQueryLexer.ContainsMe:+ case IssueQueryLexer.DoesNotContainMe:+ if (!(field instanceof UserMultiChoiceInput))+ throw newOperatorException(fieldName, operator);+ else if (SecurityUtils.getUser() == null)+ throw new OneException("Please login to perform this query");+ break;+ case IssueQueryLexer.IsBefore:+ case IssueQueryLexer.IsAfter:+ if (!fieldName.equals(Issue.SUBMIT_DATE) && !(field instanceof DateInput))+ throw newOperatorException(fieldName, operator);+ break;+ case IssueQueryLexer.Contains:+ case IssueQueryLexer.DoesNotContain:+ if (!fieldName.equals(Issue.TITLE)+ && !fieldName.equals(Issue.DESCRIPTION)+ && !(field instanceof TextInput)+ && !(field instanceof MultiChoiceInput)+ && !(field instanceof UserMultiChoiceInput)+ && !(field instanceof GroupMultiChoiceInput)) {+ throw newOperatorException(fieldName, operator);+ }+ break;+ case IssueQueryLexer.Is:+ case IssueQueryLexer.IsNot:+ if (!fieldName.equals(Issue.STATE)+ && !fieldName.equals(Issue.VOTES)+ && !fieldName.equals(Issue.SUBMITTER)+ && !(field instanceof NumberInput)+ && !(field instanceof ChoiceInput)+ && !(field instanceof UserChoiceInput)+ && !(field instanceof GroupChoiceInput)+ && !(field instanceof TextInput)) {+ throw newOperatorException(fieldName, operator);+ }+ break;+ case IssueQueryLexer.IsLessThan:+ case IssueQueryLexer.IsGreaterThan:+ if (!fieldName.equals(Issue.VOTES)+ && !(field instanceof NumberInput)+ && !(field instanceof ChoiceInput))+ throw newOperatorException(fieldName, operator);+ break;+ }+ }++ public static String getOperatorName(int operator) {+ return WordUtils.uncamel(IssueQueryLexer.ruleNames[operator-1]).toLowerCase();+ }++ public static int getOperator(String operatorName) {+ for (int i=0; i<IssueQueryLexer.ruleNames.length; i++) {+ String ruleName = IssueQueryLexer.ruleNames[i];+ if (WordUtils.uncamel(ruleName).toLowerCase().equals(operatorName))+ return i+1;+ }+ throw new OneException("Unable to find operator: " + operatorName);+ }}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/MultiChoiceFieldCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/MultiChoiceFieldCriteria.javanew file mode 100644index 0000000000..1f271ea9a3--- /dev/null+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/MultiChoiceFieldCriteria.java@@ -0,0 +1,31 @@+package io.onedev.server.model.support.issue.query;++import javax.persistence.criteria.Path;+import javax.persistence.criteria.Predicate;++import io.onedev.server.model.IssueField;++public class MultiChoiceFieldCriteria extends FieldCriteria {++ private static final long serialVersionUID = 1L;++ private final String value;++ private final int operator;++ public MultiChoiceFieldCriteria(String name, String value, int operator) {+ super(name);+ this.value = value;+ this.operator = operator;+ }++ @Override+ public Predicate getPredicate(QueryBuildContext context) {+ Path<?> attribute = context.getJoin(getFieldName()).get(IssueField.VALUE);+ if (operator == IssueQueryLexer.Contains)+ return context.getBuilder().equal(attribute, value);+ else+ return context.getBuilder().notEqual(attribute, value);+ }++}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/NumberFieldCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/NumberFieldCriteria.javaindex af92d1faae..bfccabd451 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/NumberFieldCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/NumberFieldCriteria.java@@ -1,28 +1,35 @@package io.onedev.server.model.support.issue.query;+import javax.persistence.criteria.Path;import javax.persistence.criteria.Predicate;+import io.onedev.server.model.IssueField;+public class NumberFieldCriteria extends FieldCriteria {private static final long serialVersionUID = 1L;private final int value;- private final ArithmeticOperator operator;+ private final int operator;- public NumberFieldCriteria(String name, int value, ArithmeticOperator operator) {+ public NumberFieldCriteria(String name, int value, int operator) {super(name);this.value = value;this.operator = operator;}- public int getValue() {- return value;- }-@Overridepublic Predicate getPredicate(QueryBuildContext context) {- return operator.getPredicate(context.getBuilder(), context.getJoin(getFieldName()).get("value"), value);+ Path<Integer> attribute = context.getJoin(getFieldName()).get(IssueField.ORDINAL);+ if (operator == IssueQueryLexer.Is)+ return context.getBuilder().equal(attribute, value);+ else if (operator == IssueQueryLexer.IsNot)+ return context.getBuilder().notEqual(attribute, value);+ else if (operator == IssueQueryLexer.IsGreaterThan)+ return context.getBuilder().greaterThan(attribute, value);+ else+ return context.getBuilder().lessThan(attribute, value);}}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/StateCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/StateCriteria.javaindex c051b958b4..701de974bd 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/StateCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/StateCriteria.java@@ -1,23 +1,30 @@package io.onedev.server.model.support.issue.query;+import javax.persistence.criteria.Path;import javax.persistence.criteria.Predicate;+import io.onedev.server.model.Issue;+public class StateCriteria extends IssueCriteria {private static final long serialVersionUID = 1L;private final String value;- private final EnumOperator operator;+ private final int operator;- public StateCriteria(String value, EnumOperator operator) {+ public StateCriteria(String value, int operator) {this.value = value;this.operator = operator;}@Overridepublic Predicate getPredicate(QueryBuildContext context) {- return operator.getPredicate(context.getBuilder(), context.getRoot().get("state"), value);+ Path<?> attribute = context.getRoot().get(Issue.BUILTIN_FIELDS.get(Issue.STATE));+ if (operator == IssueQueryLexer.Is)+ return context.getBuilder().equal(attribute, value);+ else+ return context.getBuilder().notEqual(attribute, value);}-+}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/StringFieldCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/StringFieldCriteria.javaindex f3e65d3709..5ab84ee9b1 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/StringFieldCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/StringFieldCriteria.java@@ -1,16 +1,19 @@package io.onedev.server.model.support.issue.query;+import javax.persistence.criteria.Path;import javax.persistence.criteria.Predicate;+import io.onedev.server.model.IssueField;+public class StringFieldCriteria extends FieldCriteria {private static final long serialVersionUID = 1L;private final String value;- private final StringOperator operator;+ private final int operator;- public StringFieldCriteria(String name, String value, StringOperator operator) {+ public StringFieldCriteria(String name, String value, int operator) {super(name);this.value = value;this.operator = operator;@@ -22,7 +25,15 @@ public class StringFieldCriteria extends FieldCriteria {@Overridepublic Predicate getPredicate(QueryBuildContext context) {- return operator.getPredicate(context.getBuilder(), context.getJoin(getFieldName()).get("value"), value);+ Path<String> attribute = context.getJoin(getFieldName()).get(IssueField.VALUE);+ if (operator == IssueQueryLexer.Is)+ return context.getBuilder().equal(attribute, value);+ else if (operator == IssueQueryLexer.IsNot)+ return context.getBuilder().notEqual(attribute, value);+ else if (operator == IssueQueryLexer.Contains)+ return context.getBuilder().like(attribute, "%" + value + "%");+ else+ return context.getBuilder().notLike(attribute, "%" + value + "%");}}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/StringOperator.java b/core/src/main/java/io/onedev/server/model/support/issue/query/StringOperator.javadeleted file mode 100644index 9298512055..0000000000--- a/core/src/main/java/io/onedev/server/model/support/issue/query/StringOperator.java+++ /dev/null@@ -1,44 +0,0 @@-package io.onedev.server.model.support.issue.query;--import javax.persistence.criteria.CriteriaBuilder;-import javax.persistence.criteria.Expression;-import javax.persistence.criteria.Predicate;--public enum StringOperator {-- EQUALS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right) {- return builder.equal(left, right);- }-- },- NOT_EQUALS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right) {- return builder.notEqual(left, right);- }-- },- CONTAINS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right) {- return builder.like(left, "%" + right + "%");- }-- },- NOT_CONTAINS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right) {- return builder.notLike(left, "%" + right + "%");- }-- };-- public abstract Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right);--}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitDateCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitDateCriteria.javaindex 64bb602c2a..790ea1562b 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitDateCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitDateCriteria.java@@ -2,24 +2,31 @@ package io.onedev.server.model.support.issue.query;import java.util.Date;+import javax.persistence.criteria.Path;import javax.persistence.criteria.Predicate;+import io.onedev.server.model.Issue;+public class SubmitDateCriteria extends IssueCriteria {private static final long serialVersionUID = 1L;- private final DateOperator operator;+ private final int operator;private final Date value;- public SubmitDateCriteria(DateOperator operator, Date value) {+ public SubmitDateCriteria(Date value, int operator) {this.operator = operator;this.value = value;}@Overridepublic Predicate getPredicate(QueryBuildContext context) {- return operator.getPredicate(context.getBuilder(), context.getRoot().get("submitDate"), value);+ Path<Long> attribute = context.getRoot().get(Issue.BUILTIN_FIELDS.get(Issue.SUBMIT_DATE));+ if (operator == IssueQueryLexer.IsBefore)+ return context.getBuilder().lessThan(attribute, value.getTime());+ else+ return context.getBuilder().greaterThan(attribute, value.getTime());}}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitterCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitterCriteria.javaindex 145f9e4a0d..ad40dbde50 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitterCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitterCriteria.java@@ -1,28 +1,31 @@package io.onedev.server.model.support.issue.query;+import javax.persistence.criteria.Path;import javax.persistence.criteria.Predicate;-import io.onedev.server.OneDev;-import io.onedev.server.manager.UserManager;+import io.onedev.server.model.Issue;import io.onedev.server.model.User;public class SubmitterCriteria extends IssueCriteria {private static final long serialVersionUID = 1L;- private final String value;+ private final User value;- private final UserOperator operator;+ private final int operator;- public SubmitterCriteria(String value, UserOperator operator) {+ public SubmitterCriteria(User value, int operator) {this.value = value;this.operator = operator;}@Overridepublic Predicate getPredicate(QueryBuildContext context) {- User user = OneDev.getInstance(UserManager.class).findByName(value);- return operator.getPredicate(context.getBuilder(), context.getRoot().get("submitter"), user);+ Path<User> attribute = context.getRoot().get(Issue.BUILTIN_FIELDS.get(Issue.SUBMITTER));+ if (operator == IssueQueryLexer.Is)+ return context.getBuilder().equal(attribute, value);+ else+ return context.getBuilder().notEqual(attribute, value);}}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitterUnaryCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitterUnaryCriteria.javanew file mode 100644index 0000000000..6759232bc7--- /dev/null+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/SubmitterUnaryCriteria.java@@ -0,0 +1,28 @@+package io.onedev.server.model.support.issue.query;++import javax.persistence.criteria.Path;+import javax.persistence.criteria.Predicate;++import io.onedev.server.model.Issue;+import io.onedev.server.security.SecurityUtils;++public class SubmitterUnaryCriteria extends IssueCriteria {++ private static final long serialVersionUID = 1L;++ private final int operator;++ public SubmitterUnaryCriteria(int operator) {+ this.operator = operator;+ }++ @Override+ public Predicate getPredicate(QueryBuildContext context) {+ Path<?> attribute = context.getRoot().get(Issue.BUILTIN_FIELDS.get(Issue.SUBMITTER));+ if (operator == IssueQueryLexer.IsMe)+ return context.getBuilder().equal(attribute, SecurityUtils.getUser());+ else+ return context.getBuilder().notEqual(attribute, SecurityUtils.getUser());+ }++}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/TextOperator.java b/core/src/main/java/io/onedev/server/model/support/issue/query/TextOperator.javadeleted file mode 100644index 0ea47f744d..0000000000--- a/core/src/main/java/io/onedev/server/model/support/issue/query/TextOperator.java+++ /dev/null@@ -1,28 +0,0 @@-package io.onedev.server.model.support.issue.query;--import javax.persistence.criteria.CriteriaBuilder;-import javax.persistence.criteria.Expression;-import javax.persistence.criteria.Predicate;--public enum TextOperator {-- CONTAINS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right) {- return builder.like(left, "%" + right + "%");- }-- },- NOT_CONTAINS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right) {- return builder.notLike(left, "%" + right + "%");- }-- };-- public abstract Predicate getPredicate(CriteriaBuilder builder, Expression<String> left, String right);--}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/TitleCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/TitleCriteria.javaindex 408637db03..83e5d33bb3 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/TitleCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/TitleCriteria.java@@ -1,23 +1,31 @@package io.onedev.server.model.support.issue.query;+import javax.persistence.criteria.Path;import javax.persistence.criteria.Predicate;+import io.onedev.server.model.Issue;+import io.onedev.server.model.User;+public class TitleCriteria extends IssueCriteria {private static final long serialVersionUID = 1L;private final String value;- private final TextOperator operator;+ private final int operator;- public TitleCriteria(String value, TextOperator operator) {+ public TitleCriteria(String value, int operator) {this.value = value;this.operator = operator;}@Overridepublic Predicate getPredicate(QueryBuildContext context) {- return operator.getPredicate(context.getBuilder(), context.getRoot().get("title"), value);+ Path<String> attribute = context.getRoot().get(Issue.BUILTIN_FIELDS.get(Issue.TITLE));+ if (operator == IssueQueryLexer.Contains)+ return context.getBuilder().like(attribute, "%" + value + "%");+ else+ return context.getBuilder().notLike(attribute, "%" + value + "%");}}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/UserOperator.java b/core/src/main/java/io/onedev/server/model/support/issue/query/UserOperator.javadeleted file mode 100644index 8068f0223c..0000000000--- a/core/src/main/java/io/onedev/server/model/support/issue/query/UserOperator.java+++ /dev/null@@ -1,30 +0,0 @@-package io.onedev.server.model.support.issue.query;--import javax.persistence.criteria.CriteriaBuilder;-import javax.persistence.criteria.Expression;-import javax.persistence.criteria.Predicate;--import io.onedev.server.model.User;--public enum UserOperator {-- EQUALS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<User> left, User right) {- return builder.equal(left, right);- }-- },- NOT_EQUALS {-- @Override- public Predicate getPredicate(CriteriaBuilder builder, Expression<User> left, User right) {- return builder.notEqual(left, right);- }-- };-- public abstract Predicate getPredicate(CriteriaBuilder builder, Expression<User> left, User right);--}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/query/VoteCriteria.java b/core/src/main/java/io/onedev/server/model/support/issue/query/VoteCriteria.javaindex d5c8c6216e..2807d61854 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/query/VoteCriteria.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/query/VoteCriteria.java@@ -2,22 +2,32 @@ package io.onedev.server.model.support.issue.query;import javax.persistence.criteria.Predicate;+import io.onedev.server.model.Issue;+public class VoteCriteria extends IssueCriteria {private static final long serialVersionUID = 1L;- private final ArithmeticOperator operator;+ private final int operator;private final int value;- public VoteCriteria(ArithmeticOperator operator, int value) {+ public VoteCriteria(int value, int operator) {this.operator = operator;this.value = value;}@Overridepublic Predicate getPredicate(QueryBuildContext context) {- return operator.getPredicate(context.getBuilder(), context.getRoot().get("vote"), value);+ String fieldName = Issue.BUILTIN_FIELDS.get(Issue.VOTES);+ if (operator == IssueQueryLexer.Is)+ return context.getBuilder().equal(context.getRoot().get(fieldName), value);+ else if (operator == IssueQueryLexer.IsNot)+ return context.getBuilder().notEqual(context.getRoot().get(fieldName), value);+ else if (operator == IssueQueryLexer.IsGreaterThan)+ return context.getBuilder().greaterThan(context.getRoot().get(fieldName), value);+ else+ return context.getBuilder().lessThan(context.getRoot().get(fieldName), value);}}diff --git a/core/src/main/java/io/onedev/server/model/support/issue/workflow/StateSpec.java b/core/src/main/java/io/onedev/server/model/support/issue/workflow/StateSpec.javaindex 29e7d1903f..9a76b94b2d 100644--- a/core/src/main/java/io/onedev/server/model/support/issue/workflow/StateSpec.java+++ b/core/src/main/java/io/onedev/server/model/support/issue/workflow/StateSpec.java@@ -12,7 +12,6 @@ import io.onedev.server.util.editable.annotation.Color;import io.onedev.server.util.editable.annotation.Editable;import io.onedev.server.util.editable.annotation.NameOfEmptyValue;import io.onedev.server.util.inputspec.InputSpec;-import io.onedev.server.util.validation.annotation.Name;import io.onedev.server.web.page.project.setting.issueworkflow.states.IssueStatesPage;import io.onedev.server.web.util.WicketUtils;@@ -27,12 +26,11 @@ public class StateSpec implements Serializable {private boolean closed;- private String color = "#777";+ private String color = "#777777";private List<String> fields = new ArrayList<>();@Editable(order=100)- @Name@NotEmptypublic String getName() {return name;diff --git a/core/src/main/java/io/onedev/server/search/hit/FileHit.java b/core/src/main/java/io/onedev/server/search/hit/FileHit.javaindex e885eb84c8..773dd78a45 100644--- a/core/src/main/java/io/onedev/server/search/hit/FileHit.java+++ b/core/src/main/java/io/onedev/server/search/hit/FileHit.java@@ -15,11 +15,11 @@ public class FileHit extends QueryHit {private static final long serialVersionUID = 1L;- private final Range matchRange;+ private final Range match;- public FileHit(String blobPath, @Nullable Range matchRange) {+ public FileHit(String blobPath, @Nullable Range match) {super(blobPath, null);- this.matchRange = matchRange;+ this.match = match;}@Override@@ -33,7 +33,7 @@ public class FileHit extends QueryHit {if (fileName.contains("/"))fileName = StringUtils.substringAfterLast(fileName, "/");- return new HighlightableLabel(componentId, fileName, matchRange);+ return new HighlightableLabel(componentId, fileName, match);}@Override@@ -49,8 +49,8 @@ public class FileHit extends QueryHit {return null;}- public Range getMatchRange() {- return matchRange;+ public Range getMatch() {+ return match;}}diff --git a/core/src/main/java/io/onedev/server/search/hit/PathHit.java b/core/src/main/java/io/onedev/server/search/hit/PathHit.javaindex 7b558b503b..6ad938ce45 100644--- a/core/src/main/java/io/onedev/server/search/hit/PathHit.java+++ b/core/src/main/java/io/onedev/server/search/hit/PathHit.java@@ -14,11 +14,11 @@ public class PathHit extends QueryHit {private static final long serialVersionUID = 1L;- private final Range matchRange;+ private final Range match;- public PathHit(String blobPath, @Nullable Range matchRange) {+ public PathHit(String blobPath, @Nullable Range match) {super(blobPath, null);- this.matchRange = matchRange;+ this.match = match;}@Override@@ -28,7 +28,7 @@ public class PathHit extends QueryHit {@Overridepublic Component render(String componentId) {- return new HighlightableLabel(componentId, getBlobPath(), matchRange);+ return new HighlightableLabel(componentId, getBlobPath(), match);}@Override@@ -41,8 +41,8 @@ public class PathHit extends QueryHit {return null;}- public Range getMatchRange() {- return matchRange;+ public Range getMatch() {+ return match;}}diff --git a/core/src/main/java/io/onedev/server/search/hit/SymbolHit.java b/core/src/main/java/io/onedev/server/search/hit/SymbolHit.javaindex 178d1090e2..5dc38c34e4 100644--- a/core/src/main/java/io/onedev/server/search/hit/SymbolHit.java+++ b/core/src/main/java/io/onedev/server/search/hit/SymbolHit.java@@ -14,12 +14,12 @@ public class SymbolHit extends QueryHit {private final Symbol symbol;- private final Range matchRange;+ private final Range match;- public SymbolHit(String blobPath, Symbol symbol, @Nullable Range matchRange) {+ public SymbolHit(String blobPath, Symbol symbol, @Nullable Range match) {super(blobPath, symbol.getPosition());this.symbol = symbol;- this.matchRange = matchRange;+ this.match = match;}public Symbol getSymbol() {@@ -33,7 +33,7 @@ public class SymbolHit extends QueryHit {@Overridepublic Component render(String componentId) {- return symbol.render(componentId, matchRange);+ return symbol.render(componentId, match);}@Overridediff --git a/core/src/main/java/io/onedev/server/search/query/FileQuery.java b/core/src/main/java/io/onedev/server/search/query/FileQuery.javaindex 360bc906cb..a151697cdd 100644--- a/core/src/main/java/io/onedev/server/search/query/FileQuery.java+++ b/core/src/main/java/io/onedev/server/search/query/FileQuery.java@@ -44,14 +44,14 @@ public class FileQuery extends BlobQuery {if (caseSensitive) {if (WildcardUtils.matchString(fileNames, blobName)&& (excludeFileName == null || !excludeFileName.equals(blobName))) {- Range matchRange = WildcardUtils.rangeOfMatch(fileNames, blobName);- hits.add(new FileHit(blobPath, matchRange));+ Range match = WildcardUtils.rangeOfMatch(fileNames, blobName);+ hits.add(new FileHit(blobPath, match));}} else {if (WildcardUtils.matchString(fileNames, blobName.toLowerCase())&& (excludeFileName == null || !excludeFileName.equalsIgnoreCase(blobName))) {- Range matchRange = WildcardUtils.rangeOfMatch(fileNames, blobName.toLowerCase());- hits.add(new FileHit(blobPath, matchRange));+ Range match = WildcardUtils.rangeOfMatch(fileNames, blobName.toLowerCase());+ hits.add(new FileHit(blobPath, match));}}}diff --git a/core/src/main/java/io/onedev/server/search/query/SymbolQuery.java b/core/src/main/java/io/onedev/server/search/query/SymbolQuery.javaindex 6b52250c78..a2f4529ef6 100644--- a/core/src/main/java/io/onedev/server/search/query/SymbolQuery.java+++ b/core/src/main/java/io/onedev/server/search/query/SymbolQuery.java@@ -94,8 +94,8 @@ public class SymbolQuery extends BlobQuery {if (WildcardUtils.matchString(normalizedTerm, normalizedSymbolName)&& (normalizedExcludeTerm == null || !normalizedSymbolName.equals(normalizedExcludeTerm))&& (excludeBlobPath == null || !excludeBlobPath.equals(blobPath))) {- Range matchRange = WildcardUtils.rangeOfMatch(normalizedTerm, normalizedSymbolName);- hits.add(new SymbolHit(blobPath, symbol, matchRange));+ Range match = WildcardUtils.rangeOfMatch(normalizedTerm, normalizedSymbolName);+ hits.add(new SymbolHit(blobPath, symbol, match));}}} else {diff --git a/core/src/main/java/io/onedev/server/web/util/DateUtils.java b/core/src/main/java/io/onedev/server/util/DateUtils.javasimilarity index 55%rename from core/src/main/java/io/onedev/server/web/util/DateUtils.javarename to core/src/main/java/io/onedev/server/util/DateUtils.javaindex 12bea5b6d1..3b2fc6a1cf 100644--- a/core/src/main/java/io/onedev/server/web/util/DateUtils.java+++ b/core/src/main/java/io/onedev/server/util/DateUtils.java@@ -1,11 +1,15 @@-package io.onedev.server.web.util;+package io.onedev.server.util;import java.util.Date;+import java.util.List;++import javax.annotation.Nullable;import org.joda.time.DateTime;import org.ocpsoft.prettytime.PrettyTime;-import io.onedev.server.util.Constants;+import com.joestelmach.natty.DateGroup;+import com.joestelmach.natty.Parser;public class DateUtils extends org.apache.commons.lang3.time.DateUtils {@@ -23,4 +27,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {return Constants.DATETIME_FORMATTER.print(new DateTime(date));}+ @Nullable+ public static Date parseRelaxed(String relaxed) {+ Parser parser = new Parser();+ List<DateGroup> groups = parser.parse(relaxed);+ if (!groups.isEmpty() && !groups.get(0).getDates().isEmpty())+ return groups.get(0).getDates().get(0);+ else+ return null;+ }+}\ No newline at end of filediff --git a/core/src/main/java/io/onedev/server/util/validation/GroupNameValidator.java b/core/src/main/java/io/onedev/server/util/validation/GroupNameValidator.javaindex 4e24c1e3a8..825ae2ffbf 100644--- a/core/src/main/java/io/onedev/server/util/validation/GroupNameValidator.java+++ b/core/src/main/java/io/onedev/server/util/validation/GroupNameValidator.java@@ -3,29 +3,23 @@ package io.onedev.server.util.validation;import javax.validation.ConstraintValidator;import javax.validation.ConstraintValidatorContext;-import io.onedev.server.util.OneContext;import io.onedev.server.util.validation.annotation.GroupName;public class GroupNameValidator implements ConstraintValidator<GroupName, String> {- private static final NameValidator NAME_VALIDATOR = new NameValidator();-public void initialize(GroupName constaintAnnotation) {}public boolean isValid(String value, ConstraintValidatorContext constraintContext) {- boolean isValid = NAME_VALIDATOR.isValid(value, constraintContext);- if (isValid) {- if (OneContext.get().getInputContext().isReservedName(value)) {- constraintContext.disableDefaultConstraintViolation();- String message = "'" + value + "' is a reserved name";- constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();- return false;- } else {- return true;- }- } else {+ if (value == null) {+ return true;+ } else if (value.equals("new")) {+ constraintContext.disableDefaultConstraintViolation();+ String message = "'" + value + "' is a reserved name";+ constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();return false;+ } else {+ return true;}}diff --git a/core/src/main/java/io/onedev/server/util/validation/InputNameValidator.java b/core/src/main/java/io/onedev/server/util/validation/InputNameValidator.javaindex 7242680029..469ecee96a 100644--- a/core/src/main/java/io/onedev/server/util/validation/InputNameValidator.java+++ b/core/src/main/java/io/onedev/server/util/validation/InputNameValidator.java@@ -8,24 +8,19 @@ import io.onedev.server.util.validation.annotation.InputName;public class InputNameValidator implements ConstraintValidator<InputName, String> {- private static final NameValidator NAME_VALIDATOR = new NameValidator();-public void initialize(InputName constaintAnnotation) {}public boolean isValid(String value, ConstraintValidatorContext constraintContext) {- boolean isValid = NAME_VALIDATOR.isValid(value, constraintContext);- if (isValid) {- if (OneContext.get().getInputContext().isReservedName(value)) {- constraintContext.disableDefaultConstraintViolation();- String message = "'" + value + "' is a reserved name";- constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();- return false;- } else {- return true;- }- } else {+ if (value == null) {+ return true;+ } else if (OneContext.get().getInputContext().isReservedName(value)) {+ constraintContext.disableDefaultConstraintViolation();+ String message = "'" + value + "' is a reserved name";+ constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();return false;+ } else {+ return true;}}diff --git a/core/src/main/java/io/onedev/server/util/validation/NameValidator.java b/core/src/main/java/io/onedev/server/util/validation/NameValidator.javadeleted file mode 100644index dc52a4f846..0000000000--- a/core/src/main/java/io/onedev/server/util/validation/NameValidator.java+++ /dev/null@@ -1,29 +0,0 @@-package io.onedev.server.util.validation;--import java.util.regex.Pattern;--import javax.validation.ConstraintValidator;-import javax.validation.ConstraintValidatorContext;--import io.onedev.server.util.validation.annotation.Name;--public class NameValidator implements ConstraintValidator<Name, String> {-- private static final Pattern PATTERN = Pattern.compile("[\\w-\\.]+");-- public void initialize(Name constaintAnnotation) {- }-- public boolean isValid(String value, ConstraintValidatorContext constraintContext) {- if (value == null) {- return true;- } else if (!PATTERN.matcher(value).matches()) {- constraintContext.disableDefaultConstraintViolation();- String message = "Only alphanumeric, underscore, dash, and dot are accepted";- constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();- return false;- } else {- return true;- }- }-}diff --git a/core/src/main/java/io/onedev/server/util/validation/ProjectNameValidator.java b/core/src/main/java/io/onedev/server/util/validation/ProjectNameValidator.javaindex 266b650b31..94695030d7 100644--- a/core/src/main/java/io/onedev/server/util/validation/ProjectNameValidator.java+++ b/core/src/main/java/io/onedev/server/util/validation/ProjectNameValidator.java@@ -1,32 +1,35 @@package io.onedev.server.util.validation;+import java.util.regex.Pattern;+import javax.validation.ConstraintValidator;import javax.validation.ConstraintValidatorContext;-import io.onedev.server.util.OneContext;import io.onedev.server.util.validation.annotation.ProjectName;public class ProjectNameValidator implements ConstraintValidator<ProjectName, String> {- private static final NameValidator NAME_VALIDATOR = new NameValidator();+ private static final Pattern PATTERN = Pattern.compile("[\\w-\\.]+");public void initialize(ProjectName constaintAnnotation) {}public boolean isValid(String value, ConstraintValidatorContext constraintContext) {- boolean isValid = NAME_VALIDATOR.isValid(value, constraintContext);- if (isValid) {- if (OneContext.get().getInputContext().isReservedName(value)) {- constraintContext.disableDefaultConstraintViolation();- String message = "'" + value + "' is a reserved name";- constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();- return false;- } else {- return true;- }- } else {+ if (value == null) {+ return true;+ } else if (!PATTERN.matcher(value).matches()) {+ constraintContext.disableDefaultConstraintViolation();+ String message = "Only alphanumeric, underscore, dash, and dot are accepted";+ constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();return false;- }+ } else if (value.equals("new")) {+ constraintContext.disableDefaultConstraintViolation();+ String message = "'new' is reserved and can not be used as project name";+ constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();+ return false;+ } else {+ return true;+ }}}diff --git a/core/src/main/java/io/onedev/server/util/validation/UserNameValidator.java b/core/src/main/java/io/onedev/server/util/validation/UserNameValidator.javaindex 9118a53085..fbb3521348 100644--- a/core/src/main/java/io/onedev/server/util/validation/UserNameValidator.java+++ b/core/src/main/java/io/onedev/server/util/validation/UserNameValidator.java@@ -3,29 +3,23 @@ package io.onedev.server.util.validation;import javax.validation.ConstraintValidator;import javax.validation.ConstraintValidatorContext;-import io.onedev.server.util.OneContext;import io.onedev.server.util.validation.annotation.UserName;public class UserNameValidator implements ConstraintValidator<UserName, String> {- private static final NameValidator NAME_VALIDATOR = new NameValidator();-public void initialize(UserName constaintAnnotation) {}public boolean isValid(String value, ConstraintValidatorContext constraintContext) {- boolean isValid = NAME_VALIDATOR.isValid(value, constraintContext);- if (isValid) {- if (OneContext.get().getInputContext().isReservedName(value)) {- constraintContext.disableDefaultConstraintViolation();- String message = "'" + value + "' is a reserved name";- constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();- return false;- } else {- return true;- }- } else {+ if (value == null) {+ return true;+ } else if (value.equals("new")) {+ constraintContext.disableDefaultConstraintViolation();+ String message = "'" + value + "' is a reserved name";+ constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();return false;+ } else {+ return true;}}diff --git a/core/src/main/java/io/onedev/server/util/validation/annotation/GroupName.java b/core/src/main/java/io/onedev/server/util/validation/annotation/GroupName.javaindex 748ecd83a1..401c2ee607 100644--- a/core/src/main/java/io/onedev/server/util/validation/annotation/GroupName.java+++ b/core/src/main/java/io/onedev/server/util/validation/annotation/GroupName.java@@ -12,7 +12,6 @@ import io.onedev.server.util.validation.GroupNameValidator;@Target({ElementType.METHOD, ElementType.FIELD})@Retention(RetentionPolicy.RUNTIME)-@Name@Constraint(validatedBy=GroupNameValidator.class)public @interface GroupName {diff --git a/core/src/main/java/io/onedev/server/util/validation/annotation/Name.java b/core/src/main/java/io/onedev/server/util/validation/annotation/Name.javadeleted file mode 100644index 89c9958c87..0000000000--- a/core/src/main/java/io/onedev/server/util/validation/annotation/Name.java+++ /dev/null@@ -1,25 +0,0 @@-package io.onedev.server.util.validation.annotation;--import java.lang.annotation.ElementType;-import java.lang.annotation.Retention;-import java.lang.annotation.RetentionPolicy;-import java.lang.annotation.Target;--import javax.validation.Constraint;-import javax.validation.Payload;--import io.onedev.server.util.validation.NameValidator;--/**- * @author robin- */-@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE})-@Retention(RetentionPolicy.RUNTIME)-@Constraint(validatedBy=NameValidator.class)-public @interface Name {- String message() default "";-- Class<?>[] groups() default {};-- Class<? extends Payload>[] payload() default {};-}diff --git a/core/src/main/java/io/onedev/server/web/behavior/BranchPatternAssistBehavior.java b/core/src/main/java/io/onedev/server/web/behavior/BranchPatternAssistBehavior.javaindex 07342003c5..2a31ca51a3 100644--- a/core/src/main/java/io/onedev/server/web/behavior/BranchPatternAssistBehavior.java+++ b/core/src/main/java/io/onedev/server/web/behavior/BranchPatternAssistBehavior.java@@ -9,6 +9,7 @@ import org.apache.wicket.model.IModel;import io.onedev.codeassist.InputCompletion;import io.onedev.codeassist.InputStatus;import io.onedev.codeassist.InputSuggestion;+import io.onedev.codeassist.Substitution;import io.onedev.server.model.Project;import io.onedev.server.web.behavior.inputassist.InputAssistBehavior;import io.onedev.server.web.util.SuggestionUtils;@@ -39,10 +40,8 @@ public class BranchPatternAssistBehavior extends InputAssistBehavior {int caret = suggestion.getCaret();if (caret == -1)caret = suggestion.getContent().length();- InputCompletion completion = new InputCompletion(0, inputStatus.getContent().length(),- suggestion.getContent(), caret, suggestion.getLabel(),- null, suggestion.getMatchRange());- completions.add(completion);+ Substitution substitution = new Substitution(0, inputStatus.getContent().length(), suggestion.getContent());+ completions.add(new InputCompletion(substitution, caret, null, suggestion.getMatch()));}return completions;}diff --git a/core/src/main/java/io/onedev/server/web/behavior/PathPatternAssistBehavior.java b/core/src/main/java/io/onedev/server/web/behavior/PathPatternAssistBehavior.javaindex 2f8a9d3acf..7b8051874d 100644--- a/core/src/main/java/io/onedev/server/web/behavior/PathPatternAssistBehavior.java+++ b/core/src/main/java/io/onedev/server/web/behavior/PathPatternAssistBehavior.java@@ -9,6 +9,7 @@ import org.apache.wicket.model.IModel;import io.onedev.codeassist.InputCompletion;import io.onedev.codeassist.InputStatus;import io.onedev.codeassist.InputSuggestion;+import io.onedev.codeassist.Substitution;import io.onedev.server.model.Project;import io.onedev.server.web.behavior.inputassist.InputAssistBehavior;import io.onedev.server.web.util.SuggestionUtils;@@ -39,10 +40,8 @@ public class PathPatternAssistBehavior extends InputAssistBehavior {int caret = suggestion.getCaret();if (caret == -1)caret = suggestion.getContent().length();- InputCompletion completion = new InputCompletion(0, inputStatus.getContent().length(),- suggestion.getContent(), caret, suggestion.getLabel(),- null, suggestion.getMatchRange());- completions.add(completion);+ Substitution substitution = new Substitution(0, inputStatus.getContent().length(), suggestion.getContent());+ completions.add(new InputCompletion(substitution, caret, null, suggestion.getMatch()));}return completions;}diff --git a/core/src/main/java/io/onedev/server/web/behavior/TagPatternAssistBehavior.java b/core/src/main/java/io/onedev/server/web/behavior/TagPatternAssistBehavior.javaindex 96e282c2b0..813075b0fa 100644--- a/core/src/main/java/io/onedev/server/web/behavior/TagPatternAssistBehavior.java+++ b/core/src/main/java/io/onedev/server/web/behavior/TagPatternAssistBehavior.java@@ -6,16 +6,17 @@ import java.util.List;import org.apache.wicket.Component;import org.apache.wicket.model.IModel;+import com.google.common.collect.Lists;+import io.onedev.codeassist.InputCompletion;import io.onedev.codeassist.InputStatus;import io.onedev.codeassist.InputSuggestion;+import io.onedev.codeassist.Substitution;import io.onedev.server.model.Project;import io.onedev.server.web.behavior.inputassist.InputAssistBehavior;import io.onedev.server.web.util.SuggestionUtils;import io.onedev.utils.Range;-import com.google.common.collect.Lists;-@SuppressWarnings("serial")public class TagPatternAssistBehavior extends InputAssistBehavior {@@ -39,10 +40,8 @@ public class TagPatternAssistBehavior extends InputAssistBehavior {int caret = suggestion.getCaret();if (caret == -1)caret = suggestion.getContent().length();- InputCompletion completion = new InputCompletion(0, inputStatus.getContent().length(),- suggestion.getContent(), caret, suggestion.getLabel(),- null, suggestion.getMatchRange());- completions.add(completion);+ Substitution substitution = new Substitution(0, inputStatus.getContent().length(), suggestion.getContent());+ completions.add(new InputCompletion(substitution, caret, null, suggestion.getMatch()));}return completions;}diff --git a/core/src/main/java/io/onedev/server/web/behavior/blamemessage/BlameMessageBehavior.java b/core/src/main/java/io/onedev/server/web/behavior/blamemessage/BlameMessageBehavior.javaindex f0a82b2045..867f58e830 100644--- a/core/src/main/java/io/onedev/server/web/behavior/blamemessage/BlameMessageBehavior.java+++ b/core/src/main/java/io/onedev/server/web/behavior/blamemessage/BlameMessageBehavior.java@@ -11,8 +11,8 @@ import org.eclipse.jgit.revwalk.RevCommit;import org.unbescape.javascript.JavaScriptEscape;import io.onedev.server.model.Project;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.behavior.AbstractPostAjaxBehavior;-import io.onedev.server.web.util.DateUtils;public abstract class BlameMessageBehavior extends AbstractPostAjaxBehavior {diff --git a/core/src/main/java/io/onedev/server/web/behavior/inputassist/ANTLRAssistBehavior.java b/core/src/main/java/io/onedev/server/web/behavior/inputassist/ANTLRAssistBehavior.javaindex e8d17c20b3..e208fcb87c 100644--- a/core/src/main/java/io/onedev/server/web/behavior/inputassist/ANTLRAssistBehavior.java+++ b/core/src/main/java/io/onedev/server/web/behavior/inputassist/ANTLRAssistBehavior.java@@ -20,6 +20,8 @@ import org.antlr.v4.runtime.Recognizer;import org.antlr.v4.runtime.Token;import org.antlr.v4.runtime.TokenStream;+import com.google.common.base.Optional;+import io.onedev.codeassist.AntlrUtils;import io.onedev.codeassist.CodeAssist;import io.onedev.codeassist.InputCompletion;@@ -76,9 +78,8 @@ public abstract class ANTLRAssistBehavior extends InputAssistBehavior {}@Override- protected InputSuggestion wrapAsSuggestion(ParentedElement expectedElement, String suggestedLiteral,- boolean complete) {- return ANTLRAssistBehavior.this.wrapAsSuggestion(expectedElement, suggestedLiteral, complete);+ protected Optional<String> describe(ParentedElement expectedElement, String suggestedLiteral) {+ return ANTLRAssistBehavior.this.describe(expectedElement, suggestedLiteral);}@Override@@ -228,13 +229,22 @@ public abstract class ANTLRAssistBehavior extends InputAssistBehavior {return new ArrayList<>();}+ /**+ * Describe suggested literal+ *+ * @param expectedElement+ * element of the literal+ * @param suggestedLiteral+ * suggested literal+ * @return+ * an optional containing description of the literal, or <tt>null</tt> to suppress the suggestion+ */@Nullable- protected InputSuggestion wrapAsSuggestion(ParentedElement expectedElement,- String suggestedLiteral, boolean complete) {- if (StringUtils.isNotBlank(suggestedLiteral))- return new InputSuggestion(suggestedLiteral, -1, complete, null, null);- else- return new InputSuggestion(suggestedLiteral, -1, complete, "space", null);+ protected Optional<String> describe(ParentedElement expectedElement, String suggestedLiteral) {+ if (StringUtils.isNotBlank(suggestedLiteral))+ return Optional.absent();+ else+ return Optional.of("space");}}diff --git a/core/src/main/java/io/onedev/server/web/behavior/inputassist/AssistPanel.java b/core/src/main/java/io/onedev/server/web/behavior/inputassist/AssistPanel.javaindex aa0eb4cc4f..df47dbcec2 100644--- a/core/src/main/java/io/onedev/server/web/behavior/inputassist/AssistPanel.java+++ b/core/src/main/java/io/onedev/server/web/behavior/inputassist/AssistPanel.java@@ -87,12 +87,12 @@ class AssistPanel extends Panel {private Component newSuggestionItem(String itemId, InputCompletion suggestion) {WebMarkupContainer item = new WebMarkupContainer(itemId);WebMarkupContainer link = new WebMarkupContainer("link");- Range matchRange = suggestion.getMatchRange();- String label = suggestion.getLabel();- if (matchRange != null) {- String prefix = StringEscapeUtils.escapeHtml4(label.substring(0, matchRange.getFrom()));- String suffix = StringEscapeUtils.escapeHtml4(label.substring(matchRange.getTo()));- String matched = StringEscapeUtils.escapeHtml4(label.substring(matchRange.getFrom(), matchRange.getTo()));+ Range match = suggestion.getMatch();+ String label = suggestion.getSubstitution().getContent();+ if (match != null) {+ String prefix = StringEscapeUtils.escapeHtml4(label.substring(0, match.getFrom()));+ String suffix = StringEscapeUtils.escapeHtml4(label.substring(match.getTo()));+ String matched = StringEscapeUtils.escapeHtml4(label.substring(match.getFrom(), match.getTo()));link.add(new Label("label", prefix + "<b>" + matched + "</b>" + suffix).setEscapeModelStrings(false));} else {link.add(new Label("label", label));diff --git a/core/src/main/java/io/onedev/server/web/behavior/inputassist/InputAssistBehavior.java b/core/src/main/java/io/onedev/server/web/behavior/inputassist/InputAssistBehavior.javaindex c142f94863..9b3c5cce52 100644--- a/core/src/main/java/io/onedev/server/web/behavior/inputassist/InputAssistBehavior.java+++ b/core/src/main/java/io/onedev/server/web/behavior/inputassist/InputAssistBehavior.java@@ -136,7 +136,7 @@ public abstract class InputAssistBehavior extends AbstractPostAjaxBehavior {List<InputCompletion> suggestions = getSuggestions(new InputStatus(inputContent, inputCaret));for (Iterator<InputCompletion> it = suggestions.iterator(); it.hasNext();) {InputCompletion suggestion = it.next();- if (inputStatus.getContentBeforeCaret().equals(suggestion.getReplaceContent())) {+ if (inputStatus.getContentBeforeCaret().equals(suggestion.getSubstitution().getContent())) {it.remove();}}diff --git a/core/src/main/java/io/onedev/server/web/behavior/inputassist/input-assist.css b/core/src/main/java/io/onedev/server/web/behavior/inputassist/input-assist.cssindex 5530b7732e..f68ea9c8d1 100644--- a/core/src/main/java/io/onedev/server/web/behavior/inputassist/input-assist.css+++ b/core/src/main/java/io/onedev/server/web/behavior/inputassist/input-assist.css@@ -2,7 +2,7 @@padding: 8px;}.input-assist td {- padding: 2px 4px;+ padding: 4px 8px;}.input-assist a {color: #333;@@ -26,7 +26,7 @@.input-assist .suggestion a {padding-right: 12px;font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;- font-size: 13px;+ font-size: 12px;}.input-assist .help {margin-top: 8px;diff --git a/core/src/main/java/io/onedev/server/web/component/comment/CodeCommentListPanel.java b/core/src/main/java/io/onedev/server/web/component/comment/CodeCommentListPanel.javaindex 53a903b965..ec2e6940e9 100644--- a/core/src/main/java/io/onedev/server/web/component/comment/CodeCommentListPanel.java+++ b/core/src/main/java/io/onedev/server/web/component/comment/CodeCommentListPanel.java@@ -44,6 +44,7 @@ import io.onedev.server.model.User;import io.onedev.server.persistence.dao.Dao;import io.onedev.server.persistence.dao.EntityCriteria;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.WebConstants;import io.onedev.server.web.component.avatar.AvatarLink;import io.onedev.server.web.component.datatable.HistoryAwarePagingNavigator;@@ -55,7 +56,6 @@ import io.onedev.server.web.page.project.ProjectPage;import io.onedev.server.web.page.project.blob.ProjectBlobPage;import io.onedev.server.web.page.project.compare.RevisionComparePage;import io.onedev.server.web.page.project.pullrequests.requestdetail.changes.RequestChangesPage;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.PagingHistorySupport;@SuppressWarnings("serial")diff --git a/core/src/main/java/io/onedev/server/web/component/comment/CodeCommentPanel.java b/core/src/main/java/io/onedev/server/web/component/comment/CodeCommentPanel.javaindex acfa1eaeaa..b3d3130544 100644--- a/core/src/main/java/io/onedev/server/web/component/comment/CodeCommentPanel.java+++ b/core/src/main/java/io/onedev/server/web/component/comment/CodeCommentPanel.java@@ -48,6 +48,7 @@ import io.onedev.server.model.PullRequest;import io.onedev.server.model.User;import io.onedev.server.model.support.CompareContext;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.asset.caret.CaretResourceReference;import io.onedev.server.web.component.avatar.AvatarLink;import io.onedev.server.web.component.link.UserLink;@@ -56,7 +57,6 @@ import io.onedev.server.web.component.markdown.ContentVersionSupport;import io.onedev.server.web.component.markdown.MarkdownViewer;import io.onedev.server.web.page.project.blob.ProjectBlobPage;import io.onedev.server.web.page.project.pullrequests.requestdetail.changes.RequestChangesPage;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.ajaxlistener.ConfirmLeaveListener;import io.onedev.server.web.util.ajaxlistener.ConfirmListener;import io.onedev.server.web.websocket.PageDataChanged;diff --git a/core/src/main/java/io/onedev/server/web/component/contributorpanel/ContributorPanel.java b/core/src/main/java/io/onedev/server/web/component/contributorpanel/ContributorPanel.javaindex 663676f706..d74ef8ef33 100644--- a/core/src/main/java/io/onedev/server/web/component/contributorpanel/ContributorPanel.java+++ b/core/src/main/java/io/onedev/server/web/component/contributorpanel/ContributorPanel.java@@ -7,8 +7,8 @@ import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.panel.Panel;import org.eclipse.jgit.lib.PersonIdent;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.component.link.UserLink;-import io.onedev.server.web.util.DateUtils;@SuppressWarnings("serial")public class ContributorPanel extends Panel {diff --git a/core/src/main/java/io/onedev/server/web/component/diff/blob/text/TextDiffPanel.java b/core/src/main/java/io/onedev/server/web/component/diff/blob/text/TextDiffPanel.javaindex 36d0453577..e8150f47f8 100644--- a/core/src/main/java/io/onedev/server/web/component/diff/blob/text/TextDiffPanel.java+++ b/core/src/main/java/io/onedev/server/web/component/diff/blob/text/TextDiffPanel.java@@ -56,6 +56,7 @@ import io.onedev.server.model.support.MarkPos;import io.onedev.server.model.support.TextRange;import io.onedev.server.search.hit.QueryHit;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.util.diff.DiffBlock;import io.onedev.server.util.diff.DiffUtils;import io.onedev.server.util.diff.LineDiff;@@ -76,7 +77,6 @@ import io.onedev.server.web.page.project.blob.render.BlobRenderContext.Mode;import io.onedev.server.web.page.project.commits.CommitDetailPage;import io.onedev.server.web.page.project.pullrequests.requestdetail.changes.RequestChangesPage;import io.onedev.server.web.page.project.pullrequests.requestdetail.mergepreview.MergePreviewPage;-import io.onedev.server.web.util.DateUtils;import io.onedev.utils.Range;import io.onedev.utils.RangeUtils;import io.onedev.utils.StringUtils;diff --git a/core/src/main/java/io/onedev/server/web/component/diff/revision/RevisionDiffPanel.java b/core/src/main/java/io/onedev/server/web/component/diff/revision/RevisionDiffPanel.javaindex f8468e1ebe..10775541be 100644--- a/core/src/main/java/io/onedev/server/web/component/diff/revision/RevisionDiffPanel.java+++ b/core/src/main/java/io/onedev/server/web/component/diff/revision/RevisionDiffPanel.java@@ -61,6 +61,7 @@ import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanelimport io.onedev.codeassist.InputCompletion;import io.onedev.codeassist.InputStatus;import io.onedev.codeassist.InputSuggestion;+import io.onedev.codeassist.Substitution;import io.onedev.jsymbol.util.NoAntiCacheImage;import io.onedev.server.OneDev;import io.onedev.server.git.Blob;@@ -629,15 +630,11 @@ public class RevisionDiffPanel extends Panel {int caret = suggestion.getCaret();if (caret == -1)caret = suggestion.getContent().length();- InputCompletion completion;- if (exclude) {- completion = new InputCompletion(0, inputStatus.getContent().length(),- "-"+suggestion.getContent(), caret+1, null, null, suggestion.getMatchRange());- } else {- completion = new InputCompletion(0, inputStatus.getContent().length(), suggestion.getContent(),- caret, null, null, suggestion.getMatchRange());- }- completions.add(completion);+ String suggestedContent = suggestion.getContent();+ if (exclude)+ suggestedContent = "-" + suggestedContent;+ Substitution substitution = new Substitution(0, inputStatus.getContent().length(), suggestedContent);+ completions.add(new InputCompletion(substitution, caret, null, suggestion.getMatch()));}return completions;}diff --git a/core/src/main/java/io/onedev/server/web/component/projectlist/ProjectListPanel.java b/core/src/main/java/io/onedev/server/web/component/projectlist/ProjectListPanel.javaindex b6328b1c64..a4651d038b 100644--- a/core/src/main/java/io/onedev/server/web/component/projectlist/ProjectListPanel.java+++ b/core/src/main/java/io/onedev/server/web/component/projectlist/ProjectListPanel.java@@ -31,6 +31,7 @@ import org.eclipse.jgit.revwalk.RevCommit;import io.onedev.server.OneDev;import io.onedev.server.manager.ProjectManager;import io.onedev.server.model.Project;+import io.onedev.server.util.DateUtils;import io.onedev.server.util.facade.ProjectFacade;import io.onedev.server.web.WebConstants;import io.onedev.server.web.component.avatar.AvatarLink;@@ -38,7 +39,6 @@ import io.onedev.server.web.component.datatable.HistoryAwarePagingNavigator;import io.onedev.server.web.component.link.UserLink;import io.onedev.server.web.page.project.blob.ProjectBlobPage;import io.onedev.server.web.page.project.commits.CommitDetailPage;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.PagingHistorySupport;@SuppressWarnings("serial")diff --git a/core/src/main/java/io/onedev/server/web/component/reviewrequirementspec/ReviewRequirementSpecAssistBehavior.java b/core/src/main/java/io/onedev/server/web/component/reviewrequirementspec/ReviewRequirementSpecAssistBehavior.javaindex f31c1f2398..8252eb8a7f 100644--- a/core/src/main/java/io/onedev/server/web/component/reviewrequirementspec/ReviewRequirementSpecAssistBehavior.java+++ b/core/src/main/java/io/onedev/server/web/component/reviewrequirementspec/ReviewRequirementSpecAssistBehavior.java@@ -7,7 +7,7 @@ import java.util.List;import org.apache.wicket.Component;import org.apache.wicket.model.IModel;-import io.onedev.server.util.reviewrequirement.ReviewRequirementSpecParser;+import com.google.common.base.Optional;import io.onedev.codeassist.FenceAware;import io.onedev.codeassist.InputSuggestion;@@ -17,6 +17,7 @@ import io.onedev.codeassist.grammar.LexerRuleRefElementSpec;import io.onedev.codeassist.grammar.RuleRefElementSpec;import io.onedev.server.model.Project;import io.onedev.server.security.ProjectPrivilege;+import io.onedev.server.util.reviewrequirement.ReviewRequirementSpecParser;import io.onedev.server.web.behavior.inputassist.ANTLRAssistBehavior;import io.onedev.server.web.util.SuggestionUtils;@@ -95,8 +96,7 @@ public class ReviewRequirementSpecAssistBehavior extends ANTLRAssistBehavior {}@Override- protected InputSuggestion wrapAsSuggestion(ParentedElement expectedElement, String suggestedLiteral,- boolean complete) {+ protected Optional<String> describe(ParentedElement expectedElement, String suggestedLiteral) {String description;switch (suggestedLiteral) {case "all":@@ -111,7 +111,7 @@ public class ReviewRequirementSpecAssistBehavior extends ANTLRAssistBehavior {default:description = null;}- return new InputSuggestion(suggestedLiteral, description, null);+ return Optional.fromNullable(description);}@Overridediff --git a/core/src/main/java/io/onedev/server/web/editable/filechoice/FileChoiceEditor.java b/core/src/main/java/io/onedev/server/web/editable/filechoice/FileChoiceEditor.javaindex ac42f5a332..71c028f33f 100644--- a/core/src/main/java/io/onedev/server/web/editable/filechoice/FileChoiceEditor.java+++ b/core/src/main/java/io/onedev/server/web/editable/filechoice/FileChoiceEditor.java@@ -11,6 +11,7 @@ import org.apache.wicket.util.convert.ConversionException;import io.onedev.codeassist.InputCompletion;import io.onedev.codeassist.InputStatus;import io.onedev.codeassist.InputSuggestion;+import io.onedev.codeassist.Substitution;import io.onedev.server.util.editable.annotation.FileChoice;import io.onedev.server.web.behavior.inputassist.InputAssistBehavior;import io.onedev.server.web.editable.ErrorContext;@@ -60,10 +61,8 @@ public class FileChoiceEditor extends PropertyEditor<String> {int caret = suggestion.getCaret();if (caret == -1)caret = suggestion.getContent().length();- InputCompletion completion = new InputCompletion(0, inputStatus.getContent().length(),- suggestion.getContent(), caret, suggestion.getLabel(),- null, suggestion.getMatchRange());- completions.add(completion);+ Substitution substitution = new Substitution(0, inputStatus.getContent().length(), suggestion.getContent());+ completions.add(new InputCompletion(substitution, caret, null, suggestion.getMatch()));}return completions;}diff --git a/core/src/main/java/io/onedev/server/web/page/admin/serverinformation/ServerInformationPage.java b/core/src/main/java/io/onedev/server/web/page/admin/serverinformation/ServerInformationPage.javaindex bff26f6325..7f14ce2163 100644--- a/core/src/main/java/io/onedev/server/web/page/admin/serverinformation/ServerInformationPage.java+++ b/core/src/main/java/io/onedev/server/web/page/admin/serverinformation/ServerInformationPage.java@@ -8,8 +8,8 @@ import org.apache.wicket.model.LoadableDetachableModel;import de.agilecoders.wicket.core.markup.html.bootstrap.components.progress.ProgressBar;import de.agilecoders.wicket.core.markup.html.bootstrap.components.progress.ProgressBar.Type;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.page.admin.AdministrationPage;-import io.onedev.server.web.util.DateUtils;import io.onedev.utils.FileUtils;@SuppressWarnings("serial")diff --git a/core/src/main/java/io/onedev/server/web/page/base/base.css b/core/src/main/java/io/onedev/server/web/page/base/base.cssindex e0e8fdec06..8908146494 100644--- a/core/src/main/java/io/onedev/server/web/page/base/base.css+++ b/core/src/main/java/io/onedev/server/web/page/base/base.css@@ -7,6 +7,10 @@ body {.pointer {cursor: pointer;}+.drag-handle {+ cursor: move;+}+/* TOOLTIPS */.tooltip-inner {@@ -423,8 +427,6 @@ div.center {div.no-records {font-style: italic;font-size: 16px;- border-top: 1px solid #F0F0F0;- padding-top: 10px;}.middot:before {diff --git a/core/src/main/java/io/onedev/server/web/page/error/UnexpectedExceptionPage.java b/core/src/main/java/io/onedev/server/web/page/error/UnexpectedExceptionPage.javaindex 42eb9077dd..f3aa0698e2 100644--- a/core/src/main/java/io/onedev/server/web/page/error/UnexpectedExceptionPage.java+++ b/core/src/main/java/io/onedev/server/web/page/error/UnexpectedExceptionPage.java@@ -37,8 +37,8 @@ import com.google.common.base.Throwables;import io.onedev.server.OneDev;import io.onedev.server.manager.ConfigManager;import io.onedev.server.model.User;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.page.project.ProjectListPage;-import io.onedev.server.web.util.DateUtils;import io.onedev.utils.FileUtils;import io.onedev.utils.StringUtils;diff --git a/core/src/main/java/io/onedev/server/web/page/project/ProjectPage.java b/core/src/main/java/io/onedev/server/web/page/project/ProjectPage.javaindex 1ac06a9596..f9b90b4cea 100644--- a/core/src/main/java/io/onedev/server/web/page/project/ProjectPage.java+++ b/core/src/main/java/io/onedev/server/web/page/project/ProjectPage.java@@ -8,6 +8,7 @@ import java.util.Map;import javax.persistence.EntityNotFoundException;import org.apache.wicket.Component;+import org.apache.wicket.Page;import org.apache.wicket.RestartResponseException;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.behavior.AttributeAppender;@@ -15,6 +16,7 @@ import org.apache.wicket.markup.ComponentTag;import org.apache.wicket.markup.head.CssHeaderItem;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.html.link.BookmarkablePageLink;+import org.apache.wicket.markup.html.link.Link;import org.apache.wicket.markup.html.panel.Fragment;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;@@ -140,7 +142,26 @@ public abstract class ProjectPage extends LayoutPage {tabs.add(new ProjectTab(Model.of("Pull Requests"), "fa fa-fw fa-ext fa-branch-compare",0, RequestListPage.class, NewRequestPage.class, RequestDetailPage.class, InvalidRequestPage.class));- tabs.add(new ProjectTab(Model.of("Issues"), "fa fa-fw fa-bug", 0, IssueListPage.class, IssueDetailPage.class, NewIssuePage.class));+ tabs.add(new ProjectTab(Model.of("Issues"), "fa fa-fw fa-bug", 0, IssueListPage.class, IssueDetailPage.class, NewIssuePage.class) {++ @Override+ public Component render(String componentId) {+ return new ProjectTabLink(componentId, this) {++ @Override+ protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {+ String query = null;+ if (getLoginUser() != null && !getLoginUser().getIssueQueries().isEmpty())+ query = getLoginUser().getIssueQueries().values().iterator().next();+ if (query == null && !getProject().getIssueListCustomization().getSavedQueries().isEmpty())+ query = getProject().getIssueListCustomization().getSavedQueries().values().iterator().next();+ return new ViewStateAwarePageLink<Void>(linkId, IssueListPage.class, IssueListPage.paramsOf(getProject(), query));+ }++ };+ }++ });tabs.add(new ProjectTab(Model.of("Code Comments"), "fa fa-fw fa-comments",0, ProjectCodeCommentsPage.class));diff --git a/core/src/main/java/io/onedev/server/web/page/project/ProjectTabLink.java b/core/src/main/java/io/onedev/server/web/page/project/ProjectTabLink.javaindex eb7c88836f..993abd8008 100644--- a/core/src/main/java/io/onedev/server/web/page/project/ProjectTabLink.java+++ b/core/src/main/java/io/onedev/server/web/page/project/ProjectTabLink.java@@ -1,5 +1,6 @@package io.onedev.server.web.page.project;+import org.apache.wicket.Page;import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;@@ -23,9 +24,7 @@ public class ProjectTabLink extends Panel {protected void onInitialize() {super.onInitialize();- ProjectPage page = (ProjectPage) getPage();- Link<Void> link = new ViewStateAwarePageLink<Void>("link",- tab.getMainPageClass(), ProjectPage.paramsOf(page.getProject()));+ Link<?> link = newLink("link", tab.getMainPageClass());link.add(new WebMarkupContainer("icon").add(AttributeAppender.append("class", tab.getIconClass())));link.add(new Label("text", tab.getTitleModel()));@@ -33,5 +32,10 @@ public class ProjectTabLink extends Panel {link.add(new Label("count", tab.getCount()).setVisible(tab.getCount()!=0));add(link);}++ protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {+ ProjectPage page = (ProjectPage) getPage();+ return new ViewStateAwarePageLink<Void>("link",pageClass, ProjectPage.paramsOf(page.getProject()));+ }}diff --git a/core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/folder/LastCommitsResource.java b/core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/folder/LastCommitsResource.javaindex ddeb6f9d3a..485e25a37b 100644--- a/core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/folder/LastCommitsResource.java+++ b/core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/folder/LastCommitsResource.java@@ -24,9 +24,9 @@ import io.onedev.server.model.Project;import io.onedev.server.model.User;import io.onedev.server.persistence.dao.Dao;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.page.project.commits.CommitDetailPage;import io.onedev.server.web.page.user.UserProfilePage;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.avatar.AvatarManager;/**diff --git a/core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/SourceViewPanel.java b/core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/SourceViewPanel.javaindex 88061af106..49aff1cc62 100644--- a/core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/SourceViewPanel.java+++ b/core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/SourceViewPanel.java@@ -78,6 +78,7 @@ import io.onedev.server.model.support.TextRange;import io.onedev.server.search.SearchManager;import io.onedev.server.search.hit.QueryHit;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.behavior.AbstractPostAjaxBehavior;import io.onedev.server.web.behavior.blamemessage.BlameMessageBehavior;import io.onedev.server.web.component.comment.CodeCommentPanel;@@ -100,7 +101,6 @@ import io.onedev.server.web.page.project.blob.render.view.Markable;import io.onedev.server.web.page.project.blob.search.SearchMenuContributor;import io.onedev.server.web.page.project.commits.CommitDetailPage;import io.onedev.server.web.page.project.compare.RevisionComparePage;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.WicketUtils;import io.onedev.server.web.util.ajaxlistener.ConfirmLeaveListener;import io.onedev.server.web.websocket.PageDataChanged;diff --git a/core/src/main/java/io/onedev/server/web/page/project/blob/search/result/MatchedBlob.java b/core/src/main/java/io/onedev/server/web/page/project/blob/search/result/MatchedBlob.javaindex 37328e483b..05e3dc5bb7 100644--- a/core/src/main/java/io/onedev/server/web/page/project/blob/search/result/MatchedBlob.java+++ b/core/src/main/java/io/onedev/server/web/page/project/blob/search/result/MatchedBlob.java@@ -14,7 +14,7 @@ public class MatchedBlob implements Serializable {private final List<QueryHit> hits;- private Range matchRange;+ private Range match;public MatchedBlob(String blobPath, List<QueryHit> hits) {this.blobPath = blobPath;@@ -29,12 +29,12 @@ public class MatchedBlob implements Serializable {return hits;}- public Range getMatchRange() {- return matchRange;+ public Range getMatch() {+ return match;}- public void setMatchRange(Range matchRange) {- this.matchRange = matchRange;+ public void setMatch(Range match) {+ this.match = match;}}diff --git a/core/src/main/java/io/onedev/server/web/page/project/blob/search/result/SearchResultPanel.java b/core/src/main/java/io/onedev/server/web/page/project/blob/search/result/SearchResultPanel.javaindex 3234623631..fc5379cbb3 100644--- a/core/src/main/java/io/onedev/server/web/page/project/blob/search/result/SearchResultPanel.java+++ b/core/src/main/java/io/onedev/server/web/page/project/blob/search/result/SearchResultPanel.java@@ -88,9 +88,9 @@ public abstract class SearchResultPanel extends Panel {blob.getHits().add(hit);} else {FileHit fileHit = (FileHit) hit;- if (fileHit.getMatchRange() != null) {+ if (fileHit.getMatch() != null) {int index = blob.getBlobPath().lastIndexOf('/');- blob.setMatchRange(new Range(fileHit.getMatchRange().getFrom()+index+1, fileHit.getMatchRange().getTo()+index+1));+ blob.setMatch(new Range(fileHit.getMatch().getFrom()+index+1, fileHit.getMatch().getTo()+index+1));}}}@@ -448,7 +448,7 @@ public abstract class SearchResultPanel extends Panel {super.onInitialize();String blobPath = blobItem.getModelObject().getBlobPath();- add(new HighlightableLabel("label", blobPath, blobItem.getModelObject().getMatchRange()));+ add(new HighlightableLabel("label", blobPath, blobItem.getModelObject().getMatch()));if (activeBlobIndex == blobItem.getIndex() && activeHitIndex == -1)add(AttributeAppender.append("class", " active"));diff --git a/core/src/main/java/io/onedev/server/web/page/project/commits/CommitQueryBehavior.java b/core/src/main/java/io/onedev/server/web/page/project/commits/CommitQueryBehavior.javaindex f2d26d6476..ae37084a7b 100644--- a/core/src/main/java/io/onedev/server/web/page/project/commits/CommitQueryBehavior.java+++ b/core/src/main/java/io/onedev/server/web/page/project/commits/CommitQueryBehavior.java@@ -5,9 +5,13 @@ import java.util.LinkedHashMap;import java.util.List;import java.util.Map;+import org.apache.commons.collections4.CollectionUtils;import org.apache.wicket.Component;import org.apache.wicket.model.IModel;+import com.google.common.base.Optional;+import com.google.common.collect.Lists;+import io.onedev.codeassist.FenceAware;import io.onedev.codeassist.InputSuggestion;import io.onedev.codeassist.ParentedElement;@@ -34,10 +38,10 @@ public class CommitQueryBehavior extends ANTLRAssistBehavior {private static final String VALUE_CLOSE = ")";- private static final String[] DATE_EXAMPLES = new String[]{+ private static final List<String> DATE_EXAMPLES = Lists.newArrayList("one hour ago", "2 hours ago", "3PM", "noon", "today", "yesterday","yesterday midnight", "3 days ago", "last week", "last Monday",- "4 weeks ago", "1 month 2 days ago", "1 year ago"};+ "4 weeks ago", "1 month 2 days ago", "1 year ago");public CommitQueryBehavior(IModel<Project> projectModel) {super(CommitQueryParser.class, "query");@@ -85,7 +89,7 @@ public class CommitQueryBehavior extends ANTLRAssistBehavior {PatternApplied applied = WildcardUtils.applyPattern(unfencedLowerCaseMatchWith, content,false);if (applied != null)- suggestedInputs.put(applied.getText(), applied.getMatchRange());+ suggestedInputs.put(applied.getText(), applied.getMatch());}for (Map.Entry<String, Range> entry: suggestedInputs.entrySet())@@ -93,21 +97,11 @@ public class CommitQueryBehavior extends ANTLRAssistBehavior {break;case CommitQueryParser.BEFORE:case CommitQueryParser.AFTER:- if (!unfencedMatchWith.contains(VALUE_CLOSE)) {- if (unfencedMatchWith.length() != 0) {- String fenced = VALUE_OPEN + unfencedMatchWith + VALUE_CLOSE;- Range matchRange = new Range(0, fenced.length());- suggestions.add(new InputSuggestion(fenced, -1, true, getFencingDescription(),- matchRange));- }- suggestions.add(new InputSuggestion(- Constants.DATETIME_FORMATTER.print(System.currentTimeMillis())));- suggestions.add(new InputSuggestion(- Constants.DATE_FORMATTER.print(System.currentTimeMillis())));- for (String dateExample: DATE_EXAMPLES) {- suggestions.add(new InputSuggestion(dateExample));- }- }+ List<String> candidates = new ArrayList<>(DATE_EXAMPLES);+ candidates.add(Constants.DATETIME_FORMATTER.print(System.currentTimeMillis()));+ candidates.add(Constants.DATE_FORMATTER.print(System.currentTimeMillis()));+ suggestions.addAll(getSuggestions(candidates, unfencedLowerCaseMatchWith));+ CollectionUtils.addIgnoreNull(suggestions, suggestToFence(unfencedMatchWith));break;case CommitQueryParser.PATH:suggestions.addAll(SuggestionUtils.suggestPath(projectModel.getObject(), unfencedMatchWith));@@ -159,8 +153,7 @@ public class CommitQueryBehavior extends ANTLRAssistBehavior {}@Override- protected InputSuggestion wrapAsSuggestion(ParentedElement expectedElement,- String suggestedLiteral, boolean complete) {+ protected Optional<String> describe(ParentedElement expectedElement, String suggestedLiteral) {String description;switch (suggestedLiteral) {case "revision":@@ -190,7 +183,7 @@ public class CommitQueryBehavior extends ANTLRAssistBehavior {default:description = null;}- return new InputSuggestion(suggestedLiteral, description, null);+ return Optional.fromNullable(description);}}diff --git a/core/src/main/java/io/onedev/server/web/page/project/issues/issuedetail/IssueDetailPage.java b/core/src/main/java/io/onedev/server/web/page/project/issues/issuedetail/IssueDetailPage.javaindex f3dfc72bae..839ca52ae5 100644--- a/core/src/main/java/io/onedev/server/web/page/project/issues/issuedetail/IssueDetailPage.java+++ b/core/src/main/java/io/onedev/server/web/page/project/issues/issuedetail/IssueDetailPage.java@@ -47,6 +47,7 @@ import io.onedev.server.model.support.issue.workflow.IssueWorkflow;import io.onedev.server.model.support.issue.workflow.StateSpec;import io.onedev.server.model.support.issue.workflow.StateTransition;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.util.MultiValueIssueField;import io.onedev.server.util.inputspec.InputContext;import io.onedev.server.util.inputspec.InputSpec;@@ -61,7 +62,6 @@ import io.onedev.server.web.page.project.issues.issueedit.IssueEditPage;import io.onedev.server.web.page.project.issues.issuelist.IssueListPage;import io.onedev.server.web.page.project.issues.newissue.NewIssuePage;import io.onedev.server.web.util.ConfirmOnClick;-import io.onedev.server.web.util.DateUtils;@SuppressWarnings("serial")public class IssueDetailPage extends ProjectPage implements InputContext {diff --git a/core/src/main/java/io/onedev/server/web/page/project/issues/issueedit/IssueEditPage.java b/core/src/main/java/io/onedev/server/web/page/project/issues/issueedit/IssueEditPage.javaindex 166223b1c5..00d6cfb92e 100644--- a/core/src/main/java/io/onedev/server/web/page/project/issues/issueedit/IssueEditPage.java+++ b/core/src/main/java/io/onedev/server/web/page/project/issues/issueedit/IssueEditPage.java@@ -77,7 +77,7 @@ public class IssueEditPage extends ProjectPage implements InputContext {excludedFields.add(propertyDescriptors.get(fieldSpec.getName()).getPropertyName());}- form.add(BeanContext.editBean("fields", fieldBean));+ form.add(BeanContext.editBean("fields", fieldBean, excludedFields));form.add(new Button("save") {diff --git a/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueListPage.html b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueListPage.htmlindex de6dd4c862..896f152253 100644--- a/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueListPage.html+++ b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueListPage.html@@ -1,10 +1,36 @@<wicket:extend><div id="issue-list">- <div class="head clearfix">- <a wicket:id="newIssue" class="btn btn-success pull-left"><i class="fa fa-plus"></i> Create New</a>- <span class="pull-right">- <a wicket:id="fields" class="btn btn-default" title="Additional fields to display"><i class="fa fa-list-ul"></i></a>- </span>+ <div class="head">+ <div class="primary clearfix">+ <div class="pull-left">+ <form wicket:id="query" class="query">+ <div class="input-group">+ <input wicket:id="input" spellcheck="false" autocomplete="off" class="form-control" placeholder="Query and order issues here"></input>+ <span class="input-group-btn">+ <button type="submit" class="btn btn-default" title="Query"><i class="fa fa-search"></i></button>+ </span>+ </div>+ <div wicket:id="feedback"></div>+ </form>+ </div>+ <div class="pull-right">+ <a wicket:id="newIssue" class="btn btn-success open-new"><i class="fa fa-plus"></i> Open New</a>+ <a wicket:id="fields" class="btn btn-default" title="Additional fields to display"><i class="fa fa-list-ul"></i></a>+ </div>+ </div>+ <div wicket:id="additional" class="additional">+ <span class="label label-info">Saved Queries</span>+ <span class="btn-group user-queries">+ <wicket:container wicket:id="userQueries"><a wicket:id="link" class="btn btn-default btn-sm"><span wicket:id="label"></span></a></wicket:container>+ </span>+ <span class="btn-group project-queries">+ <wicket:container wicket:id="projectQueries"><a wicket:id="link" class="btn btn-default btn-sm"><span wicket:id="label"></span></a></wicket:container>+ </span>+ <span class="btn-group actions">+ <a wicket:id="save" class="btn btn-default btn-sm"><i class="fa fa-save"></i> Save</a>+ <a wicket:id="edit" class="btn btn-default btn-sm"><i class="fa fa-pencil"></i> Edit</a>+ </span>+ </div></div><div wicket:id="body" class="body"><wicket:enclosure child="reconcile">@@ -16,10 +42,10 @@<div class="primary"><div wicket:id="id" class="id"></div><div wicket:id="title" class="title"></div>- <div class="reporter">- <a wicket:id="reporterName"></a>+ <div class="submitter">+ <a wicket:id="submitterName"></a>opened- <span wicket:id="reportDate"></span>+ <span wicket:id="submitDate"></span></div></div><div class="additional">@@ -53,23 +79,61 @@</div></form></wicket:fragment>- <wicket:fragment wicket:id="sortsFrag">- <form wicket:id="form" class="issue-table-sorts leave-confirm">+ <wicket:fragment wicket:id="saveQueryFrag">+ <form wicket:id="form" class="save-issue-query"><div class="modal-header"><button wicket:id="close" type="button" class="close">×</button><h4 id="modal-title" class="modal-title">- Sort on Specified Fields+ Save Query</h4></div><div class="modal-body"><div wicket:id="editor"></div>- <div wicket:id="feedback"></div></div><div class="modal-footer clearfix">- <input wicket:id="save" type="submit" class="dirty-aware btn btn-primary" value="Save"></input>- <a wicket:id="saveAsDefault" class="dirty-aware btn btn-primary">Save as Default</a>+ <input wicket:id="save" type="submit" class="dirty-aware btn btn-primary" value="Save as Mine"></input>+ <a wicket:id="saveForAll" class="dirty-aware btn btn-primary">Save for All Users</a><a wicket:id="cancel" class="btn btn-default">Cancel</a></div></form></wicket:fragment>+ <wicket:fragment wicket:id="editSavedFrag">+ <div class="modal-header">+ <button wicket:id="close" type="button" class="close">×</button>+ <h4 wicket:id="title" id="modal-title" class="modal-title"></h4>+ </div>+ <div class="modal-body edit-saved-issue-query">+ <div wicket:id="content"></div>+ </div>+ <div class="modal-footer clearfix">+ <a wicket:id="save" class="dirty-aware btn btn-primary">Save</a>+ <a wicket:id="cancel" class="btn btn-default">Cancel</a>+ </div>+ <wicket:fragment wicket:id="tabFrag">+ <ul wicket:id="tab" class="nav nav-tabs"></ul>+ <div wicket:id="tabPanel"></div>+ </wicket:fragment>+ </wicket:fragment>+ <wicket:fragment wicket:id="queryListFrag">+ <table wicket:id="queries" class="table table-condensed">+ <thead>+ <tr>+ <th>Name</th>+ <th>Actions</th>+ </tr>+ </thead>+ <tbody>+ <tr wicket:id="queries">+ <td class="name">+ <span class="drag-handle fa fa-arrows" title="Drag to reorder fields"></span>+ <span wicket:id="name"></span>+ </td>+ <td class="actions">+ <a wicket:id="delete"><i class="fa fa-trash"></i></a>+ </td>+ </tr>+ </tbody>+ </table>+ <div wicket:id="noRecords" class="no-records">No saved queries</div>+ </wicket:fragment></wicket:extend>\ No newline at end of filediff --git a/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueListPage.java b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueListPage.javaindex 0435f25489..66cfd22faa 100644--- a/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueListPage.java+++ b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueListPage.java@@ -1,21 +1,34 @@package io.onedev.server.web.page.project.issues.issuelist;+import java.io.Serializable;+import java.util.ArrayList;+import java.util.Collections;import java.util.Iterator;+import java.util.LinkedHashMap;import java.util.List;+import java.util.Map;+import java.util.concurrent.atomic.AtomicReference;++import javax.annotation.Nullable;import org.apache.wicket.Component;import org.apache.wicket.MetaDataKey;import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.ajax.markup.html.form.AjaxButton;import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.markup.ComponentTag;import org.apache.wicket.markup.head.CssHeaderItem;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.form.Form;+import org.apache.wicket.markup.html.form.TextField;import org.apache.wicket.markup.html.link.BookmarkablePageLink;import org.apache.wicket.markup.html.link.Link;+import org.apache.wicket.markup.html.list.ListItem;+import org.apache.wicket.markup.html.list.ListView;import org.apache.wicket.markup.html.panel.Fragment;import org.apache.wicket.markup.repeater.Item;import org.apache.wicket.markup.repeater.RepeatingView;@@ -25,25 +38,39 @@ import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.model.Model;+import org.apache.wicket.model.PropertyModel;import org.apache.wicket.request.cycle.RequestCycle;import org.apache.wicket.request.mapper.parameter.PageParameters;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;import io.onedev.server.OneDev;import io.onedev.server.manager.IssueManager;import io.onedev.server.manager.ProjectManager;+import io.onedev.server.manager.UserManager;import io.onedev.server.model.Issue;import io.onedev.server.model.Project;import io.onedev.server.model.User;import io.onedev.server.model.support.issue.IssueListCustomization;+import io.onedev.server.model.support.issue.query.IssueQuery;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.util.MultiValueIssueField;import io.onedev.server.web.WebConstants;import io.onedev.server.web.WebSession;+import io.onedev.server.web.behavior.sortable.SortBehavior;+import io.onedev.server.web.behavior.sortable.SortPosition;import io.onedev.server.web.component.IssueStateLabel;import io.onedev.server.web.component.datatable.HistoryAwarePagingNavigator;import io.onedev.server.web.component.link.UserLink;import io.onedev.server.web.component.modal.ModalLink;import io.onedev.server.web.component.modal.ModalPanel;+import io.onedev.server.web.component.tabbable.AjaxActionTab;+import io.onedev.server.web.component.tabbable.Tab;+import io.onedev.server.web.component.tabbable.Tabbable;+import io.onedev.server.web.editable.BeanContext;+import io.onedev.server.web.editable.BeanEditor;import io.onedev.server.web.editable.PropertyDescriptor;import io.onedev.server.web.editable.choice.MultiChoiceEditor;import io.onedev.server.web.page.project.ProjectPage;@@ -51,21 +78,28 @@ import io.onedev.server.web.page.project.issues.fieldvalues.FieldValuesPanel;import io.onedev.server.web.page.project.issues.issuedetail.IssueDetailPage;import io.onedev.server.web.page.project.issues.issuelist.workflowreconcile.WorkflowReconcilePanel;import io.onedev.server.web.page.project.issues.newissue.NewIssuePage;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.PagingHistorySupport;+import io.onedev.utils.StringUtils;@SuppressWarnings("serial")public class IssueListPage extends ProjectPage {+ private static final Logger logger = LoggerFactory.getLogger(IssueListPage.class);+private static final String PARAM_CURRENT_PAGE = "currentPage";+ private static final String PARAM_QUERY = "query";+private static final MetaDataKey<IssueListCustomization> CUSTOMIZATION_KEY =new MetaDataKey<IssueListCustomization>() {};- private WebMarkupContainer body;+ private String query;++ private Component querySave;public IssueListPage(PageParameters params) {super(params);+ query = params.get(PARAM_QUERY).toOptionalString();}private IssueListCustomization getCustomization() {@@ -78,6 +112,35 @@ public class IssueListPage extends ProjectPage {@Overrideprotected void onInitialize() {super.onInitialize();++ TextField<String> input = new TextField<String>("input", new PropertyModel<String>(this, "query"));+ input.add(new IssueQueryBehavior(projectModel));++ if (getLoginUser() != null) {+ input.add(new AjaxFormComponentUpdatingBehavior("input"){++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ target.add(querySave);+ }++ });+ }+ Form<?> form = new Form<Void>("query") {++ @Override+ protected void onSubmit() {+ super.onSubmit();+ setResponsePage(IssueListPage.class, IssueListPage.paramsOf(getProject(), query));+ }++ };+ form.add(input);++ form.setOutputMarkupId(true);+ add(form);++ form.add(new NotificationPanel("feedback", form));add(new BookmarkablePageLink<Void>("newIssue", NewIssuePage.class, NewIssuePage.paramsOf(getProject())));@@ -173,83 +236,396 @@ public class IssueListPage extends ProjectPage {});- IDataProvider<Issue> dataProvider = new IDataProvider<Issue>() {-- private IssueManager getIssueManager() {- return OneDev.getInstance(IssueManager.class);- }-- @Override- public void detach() {- }+ WebMarkupContainer additional = new WebMarkupContainer("additional");+ additional.setVisible(getLoginUser() != null || !getProject().getIssueListCustomization().getSavedQueries().isEmpty());+ additional.setOutputMarkupId(true);+ add(additional);++ additional.add(querySave = new ModalLink("save") {@Override- public Iterator<? extends Issue> iterator(long first, long count) {- return getIssueManager().query(getCustomization().getQuery(), (int)first, (int)count).iterator();+ protected void onConfigure() {+ super.onConfigure();+ setEnabled(StringUtils.isNotBlank(query));+ setVisible(getLoginUser() != null);}@Override- public long size() {- return getIssueManager().count(getCustomization().getQuery().getCriteria());+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ configure();+ if (!isEnabled())+ tag.put("disabled", "disabled");}@Override- public IModel<Issue> model(Issue object) {- Long issueId = object.getId();- return new LoadableDetachableModel<Issue>() {+ protected Component newContent(String id, ModalPanel modal) {+ Fragment fragment = new Fragment(id, "saveQueryFrag", IssueListPage.this);+ Form<?> form = new Form<Void>("form") {@Override- protected Issue load() {- return OneDev.getInstance(IssueManager.class).load(issueId);+ protected void onError() {+ super.onError();+ RequestCycle.get().find(AjaxRequestTarget.class).add(this);}};+ SaveQueryBean bean = new SaveQueryBean();+ BeanEditor editor = BeanContext.editBean("editor", bean);+ form.add(editor);+ form.add(new AjaxButton("save") {++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);+ getLoginUser().getIssueQueries().put(bean.getName(), query);+ OneDev.getInstance(UserManager.class).save(getLoginUser());+ target.add(additional);+ modal.close();+ }++ });+ form.add(new AjaxButton("saveForAll") {++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);+ getProject().getIssueListCustomization().getSavedQueries().put(bean.getName(), query);+ OneDev.getInstance(ProjectManager.class).save(getProject());+ target.add(additional);+ modal.close();+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(SecurityUtils.canManage(getProject()));+ }++ });+ form.add(new AjaxLink<Void>("close") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ modal.close();+ }++ });+ form.add(new AjaxLink<Void>("cancel") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ modal.close();+ }++ });+ form.setOutputMarkupId(true);+ fragment.add(form);+ return fragment;}- };+ }.setOutputMarkupId(true));- body = new WebMarkupContainer("body");-- body.add(new ModalLink("reconcile") {+ additional.add(new ModalLink("edit") {@Override- protected Component newContent(String id, ModalPanel modal) {- return new WorkflowReconcilePanel(id) {+ protected void onConfigure() {+ super.onConfigure();+ if (SecurityUtils.canManage(getProject())) {+ setVisible(!getLoginUser().getIssueQueries().isEmpty()+ || !getProject().getIssueListCustomization().getSavedQueries().isEmpty());+ } else {+ setVisible(getLoginUser() != null && !getLoginUser().getIssueQueries().isEmpty());+ }+ }++ private WebMarkupContainer newQueryList(String componentId, List<String> queries) {+ Fragment fragment = new Fragment(componentId, "queryListFrag", IssueListPage.this);+ WebMarkupContainer table = new WebMarkupContainer("queries");+ fragment.add(table);+ table.add(new ListView<String>("queries", queries) {++ @Override+ protected void populateItem(ListItem<String> item) {+ item.add(new Label("name", item.getModelObject()));+ item.add(new AjaxLink<Void>("delete") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ queries.remove(item.getModelObject());+ target.add(fragment);+ }++ });+ }+ });+ table.add(new SortBehavior() {+@Override- protected Project getProject() {- return IssueListPage.this.getProject();+ protected void onSort(AjaxRequestTarget target, SortPosition from, SortPosition to) {+ int fromIndex = from.getItemIndex();+ int toIndex = to.getItemIndex();+ if (fromIndex < toIndex) {+ for (int i=0; i<toIndex-fromIndex; i++)+ Collections.swap(queries, fromIndex+i, fromIndex+i+1);+ } else {+ for (int i=0; i<fromIndex-toIndex; i++)+ Collections.swap(queries, fromIndex-i, fromIndex-i-1);+ }+ target.add(fragment);}++ }.sortable("tbody").handle(".drag-handle").helperClass("sort-helper"));++ fragment.add(new WebMarkupContainer("noRecords") {@Override- protected void onCancel(AjaxRequestTarget target) {+ protected void onConfigure() {+ super.onConfigure();+ setVisible(queries.isEmpty());+ }++ });+ fragment.setOutputMarkupId(true);+ return fragment;+ }++ @Override+ protected Component newContent(String id, ModalPanel modal) {+ Fragment fragment = new Fragment(id, "editSavedFrag", IssueListPage.this);+ List<String> userQueries = new ArrayList<>(getLoginUser().getIssueQueries().keySet());+ List<String> projectQueries = new ArrayList<>();+ if (SecurityUtils.canManage(getProject()))+ projectQueries.addAll(getProject().getIssueListCustomization().getSavedQueries().keySet());++ if (!userQueries.isEmpty() && !projectQueries.isEmpty()) {+ fragment.add(new Label("title", "Edit Saved Queries"));+ Fragment tabFragment = new Fragment("content", "tabFrag", fragment);+ List<Tab> tabs = new ArrayList<>();+ tabs.add(new AjaxActionTab(Model.of("Mine")) {++ @Override+ protected void onSelect(AjaxRequestTarget target, Component tabLink) {+ WebMarkupContainer queryList = newQueryList("tabPanel", userQueries);+ tabFragment.replace(queryList);+ target.add(queryList);+ }++ });+ tabs.add(new AjaxActionTab(Model.of("All Users")) {++ @Override+ protected void onSelect(AjaxRequestTarget target, Component tabLink) {+ WebMarkupContainer queryList = newQueryList("tabPanel", projectQueries);+ tabFragment.replace(queryList);+ target.add(queryList);+ }++ });+ tabFragment.add(new Tabbable("tab", tabs));+ tabFragment.add(newQueryList("tabPanel", userQueries));+ fragment.add(tabFragment);+ } else if (!userQueries.isEmpty()) {+ fragment.add(new Label("title", "Edit Saved Queries (Mine)"));+ fragment.add(newQueryList("content", userQueries));+ } else {+ fragment.add(new Label("title", "Edit Saved Queries (All Users)"));+ fragment.add(newQueryList("content", projectQueries));+ }++ fragment.add(new AjaxLink<Void>("save") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ LinkedHashMap<String, String> queryMap = new LinkedHashMap<>();+ for (String query: userQueries)+ queryMap.put(query, getLoginUser().getIssueQueries().get(query));+ getLoginUser().setIssueQueries(queryMap);+ OneDev.getInstance(UserManager.class).save(getLoginUser());++ if (SecurityUtils.canManage(getProject())) {+ queryMap = new LinkedHashMap<>();+ for (String query: projectQueries)+ queryMap.put(query, getProject().getIssueListCustomization().getSavedQueries().get(query));+ getProject().getIssueListCustomization().setSavedQueries(queryMap);+ OneDev.getInstance(ProjectManager.class).save(getProject());+ }modal.close();+ target.add(additional);}++ });+ fragment.add(new AjaxLink<Void>("cancel") {@Override- protected void onCompleted(AjaxRequestTarget target) {- setResponsePage(IssueListPage.this);+ public void onClick(AjaxRequestTarget target) {+ modal.close();}- };+ });+ fragment.add(new AjaxLink<Void>("close") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ modal.close();+ }++ });+ fragment.setOutputMarkupId(true);+ return fragment;+ }++ });+ additional.add(new ListView<SavedQuery>("userQueries", new LoadableDetachableModel<List<SavedQuery>>() {++ @Override+ protected List<SavedQuery> load() {+ List<SavedQuery> savedQueries = new ArrayList<>();+ for (Map.Entry<String, String> entry: getLoginUser().getIssueQueries().entrySet())+ savedQueries.add(new SavedQuery(entry.getKey(), entry.getValue()));+ return savedQueries;+ }++ }) {++ @Override+ protected void populateItem(ListItem<SavedQuery> item) {+ SavedQuery savedQuery = item.getModelObject();+ Link<Void> link = new BookmarkablePageLink<Void>("link", IssueListPage.class, IssueListPage.paramsOf(getProject(), savedQuery.query));+ link.add(new Label("label", savedQuery.name));+ item.add(link);}@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(!getProject().getIssueWorkflow().isReconciled());+ setVisible(getLoginUser() != null);}++ });++ additional.add(new ListView<SavedQuery>("projectQueries", new LoadableDetachableModel<List<SavedQuery>>() {@Override- public IModel<?> getBody() {- if (SecurityUtils.canManage(getProject()))- return Model.of("reconcile");- else- return Model.of("contact project administrator to reconcile");+ protected List<SavedQuery> load() {+ List<SavedQuery> savedQueries = new ArrayList<>();+ for (Map.Entry<String, String> entry: getProject().getIssueListCustomization().getSavedQueries().entrySet())+ savedQueries.add(new SavedQuery(entry.getKey(), entry.getValue()));+ return savedQueries;+ }++ }) {++ @Override+ protected void populateItem(ListItem<SavedQuery> item) {+ SavedQuery savedQuery = item.getModelObject();+ Link<Void> link = new BookmarkablePageLink<Void>("link", IssueListPage.class, IssueListPage.paramsOf(getProject(), savedQuery.query));+ link.add(new Label("label", savedQuery.name));+ item.add(link);}});+ AtomicReference<IssueQuery> parsedQuery = new AtomicReference<>(null);+ try {+ parsedQuery.set(IssueQuery.parse(getProject(), query));+ } catch (Exception e) {+ logger.error("Error parsing issue query: " + query, e);+ if (StringUtils.isNotBlank(e.getMessage()))+ form.error(e.getMessage());+ else+ form.error("Malformed issue query");+ }++ IDataProvider<Issue> dataProvider = new IDataProvider<Issue>() {++ private IssueManager getIssueManager() {+ return OneDev.getInstance(IssueManager.class);+ }++ @Override+ public void detach() {+ }++ @Override+ public Iterator<? extends Issue> iterator(long first, long count) {+ return getIssueManager().query(parsedQuery.get(), (int)first, (int)count).iterator();+ }++ @Override+ public long size() {+ return getIssueManager().count(parsedQuery.get().getCriteria());+ }++ @Override+ public IModel<Issue> model(Issue object) {+ Long issueId = object.getId();+ return new LoadableDetachableModel<Issue>() {++ @Override+ protected Issue load() {+ return OneDev.getInstance(IssueManager.class).load(issueId);+ }++ };+ }++ };++ WebMarkupContainer body = new WebMarkupContainer("body");++ if (SecurityUtils.canManage(getProject())) {+ body.add(new ModalLink("reconcile") {++ @Override+ protected Component newContent(String id, ModalPanel modal) {+ return new WorkflowReconcilePanel(id) {++ @Override+ protected Project getProject() {+ return IssueListPage.this.getProject();+ }++ @Override+ protected void onCancel(AjaxRequestTarget target) {+ modal.close();+ }++ @Override+ protected void onCompleted(AjaxRequestTarget target) {+ setResponsePage(IssueListPage.this);+ }++ };+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(!getProject().getIssueWorkflow().isReconciled());+ }++ @Override+ public IModel<?> getBody() {+ return Model.of("reconcile");+ }++ });+ } else {+ body.add(new Label("reconcile", "contact project administrator to reconcile") {++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ tag.setName("span");+ }++ });+ }++ body.setVisible(parsedQuery.get() != null);+body.setOutputMarkupId(true);DataView<Issue> issuesView = new DataView<Issue>("issues", dataProvider) {@@ -264,8 +640,8 @@ public class IssueListPage extends ProjectPage {titleFrag.add(link);item.add(titleFrag);- item.add(new UserLink("reporterName", User.getForDisplay(issue.getSubmitter(), issue.getSubmitterName())));- item.add(new Label("reportDate", DateUtils.formatAge(issue.getSubmitDate())));+ item.add(new UserLink("submitterName", User.getForDisplay(issue.getSubmitter(), issue.getSubmitterName())));+ item.add(new Label("submitDate", DateUtils.formatAge(issue.getSubmitDate())));item.add(new IssueStateLabel("state", item.getModel()));@@ -292,7 +668,7 @@ public class IssueListPage extends ProjectPage {@Overridepublic PageParameters newPageParameters(int currentPage) {- PageParameters params = paramsOf(getProject());+ PageParameters params = paramsOf(getProject(), query);params.add(PARAM_CURRENT_PAGE, currentPage+1);return params;}@@ -335,4 +711,23 @@ public class IssueListPage extends ProjectPage {response.render(CssHeaderItem.forReference(new IssueListResourceReference()));}+ public static PageParameters paramsOf(Project project, @Nullable String query) {+ PageParameters params = paramsOf(project);+ if (query != null)+ params.add(PARAM_QUERY, query);+ return params;+ }++ private static class SavedQuery implements Serializable {++ final String name;++ final String query;++ SavedQuery(String name, String query) {+ this.name = name;+ this.query = query;+ }+ }+}diff --git a/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueQueryBehavior.java b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueQueryBehavior.javanew file mode 100644index 0000000000..d6d07559ed--- /dev/null+++ b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/IssueQueryBehavior.java@@ -0,0 +1,241 @@+package io.onedev.server.web.page.project.issues.issuelist;++import java.util.ArrayList;+import java.util.List;+import java.util.stream.Collectors;++import org.apache.commons.collections4.CollectionUtils;+import org.apache.commons.lang3.StringUtils;+import org.apache.wicket.Component;+import org.apache.wicket.model.IModel;++import com.google.common.base.Optional;+import com.google.common.base.Preconditions;+import com.google.common.collect.Lists;++import io.onedev.codeassist.FenceAware;+import io.onedev.codeassist.InputSuggestion;+import io.onedev.codeassist.ParentedElement;+import io.onedev.codeassist.grammar.ElementSpec;+import io.onedev.codeassist.grammar.LexerRuleRefElementSpec;+import io.onedev.codeassist.grammar.RuleRefElementSpec;+import io.onedev.codeassist.parser.Element;+import io.onedev.server.OneDev;+import io.onedev.server.exception.OneException;+import io.onedev.server.manager.GroupManager;+import io.onedev.server.manager.UserManager;+import io.onedev.server.model.Issue;+import io.onedev.server.model.Project;+import io.onedev.server.model.User;+import io.onedev.server.model.support.issue.query.IssueQuery;+import io.onedev.server.model.support.issue.query.IssueQueryParser;+import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.Constants;+import io.onedev.server.util.EditContext;+import io.onedev.server.util.OneContext;+import io.onedev.server.util.inputspec.InputContext;+import io.onedev.server.util.inputspec.InputSpec;+import io.onedev.server.util.inputspec.choiceinput.ChoiceInput;+import io.onedev.server.util.inputspec.dateinput.DateInput;+import io.onedev.server.util.inputspec.groupchoiceinput.GroupChoiceInput;+import io.onedev.server.util.inputspec.groupmultichoiceinput.GroupMultiChoiceInput;+import io.onedev.server.util.inputspec.multichoiceinput.MultiChoiceInput;+import io.onedev.server.util.inputspec.numberinput.NumberInput;+import io.onedev.server.util.inputspec.textinput.TextInput;+import io.onedev.server.util.inputspec.userchoiceinput.UserChoiceInput;+import io.onedev.server.util.inputspec.usermultichoiceinput.UserMultiChoiceInput;+import io.onedev.server.web.behavior.inputassist.ANTLRAssistBehavior;+import io.onedev.utils.Range;++@SuppressWarnings("serial")+public class IssueQueryBehavior extends ANTLRAssistBehavior {++ private final IModel<Project> projectModel;++ private static final String VALUE_OPEN = "\"";++ private static final String VALUE_CLOSE = "\"";++ private static final List<String> DATE_EXAMPLES = Lists.newArrayList(+ "one hour ago", "2 hours ago", "3PM", "noon", "today", "yesterday",+ "yesterday midnight", "3 days ago", "last week", "last Monday",+ "4 weeks ago", "1 month 2 days ago", "1 year ago");++ public IssueQueryBehavior(IModel<Project> projectModel) {+ super(IssueQueryParser.class, "query");+ this.projectModel = projectModel;+ }++ @Override+ public void detach(Component component) {+ super.detach(component);+ projectModel.detach();+ }++ private Project getProject() {+ return projectModel.getObject();+ }++ @Override+ protected int getEndOfMatch(ElementSpec spec, String content) {+ if (content.startsWith(VALUE_OPEN+VALUE_CLOSE))+ return 2;+ else+ return super.getEndOfMatch(spec, content);+ }++ @Override+ protected List<InputSuggestion> suggest(ParentedElement expectedElement, String matchWith) {+ if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {+ LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();+ if (spec.getRuleName().equals("Quoted")) {+ return new FenceAware(codeAssist.getGrammar(), VALUE_OPEN, VALUE_CLOSE) {++ @Override+ protected List<InputSuggestion> match(String unfencedMatchWith) {+ String unfencedLowerCaseMatchWith = unfencedMatchWith.toLowerCase();+ List<InputSuggestion> suggestions = new ArrayList<>();+ Project project = getProject();++ if ("criteriaField".equals(spec.getLabel())) {+ List<String> candidates = new ArrayList<>(Issue.BUILTIN_FIELDS.keySet());+ for (InputSpec field: project.getIssueWorkflow().getFields())+ candidates.add(field.getName());+ suggestions.addAll(getSuggestions(candidates, unfencedLowerCaseMatchWith));+ } else if ("orderField".equals(spec.getLabel())) {+ List<String> candidates = Lists.newArrayList(Issue.VOTES, Issue.SUBMIT_DATE);+ for (InputSpec field: project.getIssueWorkflow().getFields()) {+ if (field instanceof NumberInput || field instanceof ChoiceInput || field instanceof DateInput)+ candidates.add(field.getName());+ }+ suggestions.addAll(getSuggestions(candidates, unfencedLowerCaseMatchWith));+ } else if ("criteriaValue".equals(spec.getLabel())) {+ List<Element> fieldElements = expectedElement.getParent().findChildrenByLabel("criteriaField", true);+ Preconditions.checkState(fieldElements.size() == 1);+ String fieldName = IssueQuery.getValue(fieldElements.get(0).getMatchedText());+ List<Element> operatorElements = expectedElement.getParent().findChildrenByLabel("operator", true);+ Preconditions.checkState(operatorElements.size() == 1);+ String operatorName = StringUtils.normalizeSpace(operatorElements.get(0).getMatchedText());++ try {+ IssueQuery.checkField(project, fieldName, IssueQuery.getOperator(operatorName));+ InputSpec field = project.getIssueWorkflow().getField(fieldName);+ if (field instanceof DateInput || fieldName.equals(Issue.SUBMIT_DATE)) {+ List<String> candidates = new ArrayList<>(DATE_EXAMPLES);+ candidates.add(Constants.DATETIME_FORMATTER.print(System.currentTimeMillis()));+ candidates.add(Constants.DATE_FORMATTER.print(System.currentTimeMillis()));+ suggestions.addAll(getSuggestions(candidates, unfencedLowerCaseMatchWith));+ CollectionUtils.addIgnoreNull(suggestions, suggestToFence(unfencedMatchWith));+ } else if (fieldName.equals(Issue.SUBMITTER) || field instanceof UserChoiceInput || field instanceof UserMultiChoiceInput) {+ for (User user: OneDev.getInstance(UserManager.class).findAll()) {+ Range match = Range.matchStart(user.getName(), unfencedLowerCaseMatchWith, false, true);+ if (match != null) {+ String description;+ if (!user.getDisplayName().equals(user.getName()))+ description = user.getDisplayName();+ else+ description = null;+ suggestions.add(new InputSuggestion(user.getName(), description, match));+ }+ }+ } else if (field instanceof GroupChoiceInput || field instanceof GroupMultiChoiceInput) {+ List<String> candidates = OneDev.getInstance(GroupManager.class).findAll().stream().map(it->it.getName()).collect(Collectors.toList());+ suggestions.addAll(getSuggestions(candidates, unfencedLowerCaseMatchWith));+ } else if (fieldName.equals(Issue.STATE)) {+ List<String> candidates = project.getIssueWorkflow().getStates().stream().map(it->it.getName()).collect(Collectors.toList());+ suggestions.addAll(getSuggestions(candidates, unfencedLowerCaseMatchWith));+ } else if (field instanceof ChoiceInput) {+ OneContext.push(newOneContext());+ try {+ List<String> candidates = new ArrayList<>(((ChoiceInput)field).getChoiceProvider().getChoices(true).keySet());+ suggestions.addAll(getSuggestions(candidates, unfencedLowerCaseMatchWith));+ } finally {+ OneContext.pop();+ }+ } else if (field instanceof MultiChoiceInput) {+ OneContext.push(newOneContext());+ try {+ List<String> candidates = new ArrayList<>(((MultiChoiceInput)field).getChoiceProvider().getChoices(true).keySet());+ suggestions.addAll(getSuggestions(candidates, unfencedLowerCaseMatchWith));+ } finally {+ OneContext.pop();+ }+ } else if (fieldName.equals(Issue.TITLE) || fieldName.equals(Issue.DESCRIPTION)+ || fieldName.equals(Issue.VOTES) || field instanceof NumberInput+ || field instanceof TextInput) {+ return null;+ }+ } catch (OneException ex) {+ }++ }+ return suggestions;+ }++ private OneContext newOneContext() {+ return new OneContext() {++ @Override+ public Project getProject() {+ return IssueQueryBehavior.this.getProject();+ }++ @Override+ public EditContext getEditContext(int level) {+ return new EditContext() {++ @Override+ public Object getInputValue(String name) {+ return null;+ }++ };+ }++ @Override+ public InputContext getInputContext() {+ throw new UnsupportedOperationException();+ }++ };+ }++ @Override+ protected String getFencingDescription() {+ return "quote as literal value";+ }++ }.suggest(expectedElement.getSpec(), matchWith);+ }+ }+ return null;+ }++ @Override+ protected Optional<String> describe(ParentedElement expectedElement, String suggestedLiteral) {+ if (suggestedLiteral.equals("mine")) {+ if (SecurityUtils.getUser() != null)+ return Optional.of("issues corresponding to me");+ else+ return null;+ } else if (expectedElement.getParent() != null+ && expectedElement.getParent().getParent() != null+ && expectedElement.getParent().getParent().getSpec() instanceof RuleRefElementSpec) {+ RuleRefElementSpec ruleRefElementSpec = (RuleRefElementSpec) expectedElement.getParent().getParent().getSpec();+ if (ruleRefElementSpec.getRuleName().equals("criteria")) {+ List<Element> fieldElements = expectedElement.getParent().getParent()+ .findChildrenByLabel("criteriaField", false);+ if (!fieldElements.isEmpty()) {+ String fieldName = IssueQuery.getValue(fieldElements.iterator().next().getMatchedText());+ try {+ IssueQuery.checkField(getProject(), fieldName, IssueQuery.getOperator(suggestedLiteral));+ } catch (OneException e) {+ return null;+ }+ }+ }+ }+ return super.describe(expectedElement, suggestedLiteral);+ }++}diff --git a/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/SaveQueryBean.java b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/SaveQueryBean.javanew file mode 100644index 0000000000..785ec70dc7--- /dev/null+++ b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/SaveQueryBean.java@@ -0,0 +1,28 @@+package io.onedev.server.web.page.project.issues.issuelist;++import java.io.Serializable;++import org.hibernate.validator.constraints.NotEmpty;++import io.onedev.server.util.editable.annotation.Editable;+import io.onedev.server.util.editable.annotation.OmitName;++@Editable+public class SaveQueryBean implements Serializable {++ private static final long serialVersionUID = 1L;++ private String name;++ @Editable(description="Specify a name to identify the saved query")+ @NotEmpty+ @OmitName+ public String getName() {+ return name;+ }++ public void setName(String name) {+ this.name = name;+ }++}\ No newline at end of filediff --git a/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/issue-list.css b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/issue-list.cssindex a5ba1d9c02..3fea024837 100644--- a/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/issue-list.css+++ b/core/src/main/java/io/onedev/server/web/page/project/issues/issuelist/issue-list.css@@ -1,6 +1,33 @@#issue-list>.head {margin-bottom: 20px;}+#issue-list>.head>.primary>.pull-left {+ width: 75%;+}+#issue-list>.head>.primary {+ margin-bottom: 20px;+}+#issue-list>.head>.primary .open-new {+ margin-right: 8px;+}+#issue-list>.head .alert {+ margin-top: 20px;+ margin-bottom: 0;+}+#issue-list>.head .list-unstyled {+ margin-bottom: 0;+}+#issue-list>.head>.additional>* {+ margin-right: 8px;+}+#issue-list>.head>.additional .actions>a {+ margin-right: 0;+}+#issue-list>.head>.additional .label {+ font-size: 16px;+ vertical-align: middle;+}+#issue-list .issue {border-bottom: 2px solid #DDD;margin-bottom: 12px;@@ -26,7 +53,7 @@font-size: 16px;font-weight: bold;}-#issue-list .issue .primary .reporter {+#issue-list .issue .primary .submitter {text-align: right;width: 300px;padding-right: 0;@@ -62,4 +89,12 @@#issue-list .issue .additional>.votes {text-align: right;padding-right: 0;+}++.edit-saved-issue-query .actions {+ width: 10%;+}+.edit-saved-issue-query .title {+ font-size: 16px;+ margin-bottom: 8px;}\ No newline at end of filediff --git a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/RequestDetailPage.java b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/RequestDetailPage.javaindex e298d64817..0bb82fb57b 100644--- a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/RequestDetailPage.java+++ b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/RequestDetailPage.java@@ -71,6 +71,7 @@ import io.onedev.server.model.support.MergeStrategy;import io.onedev.server.model.support.ProjectAndBranch;import io.onedev.server.persistence.dao.Dao;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.util.Verification;import io.onedev.server.web.component.comment.CommentInput;import io.onedev.server.web.component.comment.ProjectAttachmentSupport;@@ -92,7 +93,6 @@ import io.onedev.server.web.page.project.pullrequests.requestdetail.changes.Requimport io.onedev.server.web.page.project.pullrequests.requestdetail.codecomments.RequestCodeCommentsPage;import io.onedev.server.web.page.project.pullrequests.requestdetail.mergepreview.MergePreviewPage;import io.onedev.server.web.page.project.pullrequests.requestdetail.overview.RequestOverviewPage;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.WicketUtils;import io.onedev.server.web.util.ajaxlistener.ConfirmLeaveListener;import io.onedev.server.web.util.model.EntityModel;diff --git a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/CommentedPanel.java b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/CommentedPanel.javaindex ae0eb87ac8..57e43e8cda 100644--- a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/CommentedPanel.java+++ b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/CommentedPanel.java@@ -24,6 +24,7 @@ import io.onedev.server.model.PullRequest;import io.onedev.server.model.PullRequestComment;import io.onedev.server.model.User;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.component.comment.CommentInput;import io.onedev.server.web.component.comment.ProjectAttachmentSupport;import io.onedev.server.web.component.link.UserLink;@@ -31,7 +32,6 @@ import io.onedev.server.web.component.markdown.AttachmentSupport;import io.onedev.server.web.component.markdown.ContentVersionSupport;import io.onedev.server.web.component.markdown.MarkdownViewer;import io.onedev.server.web.page.project.pullrequests.requestdetail.overview.SinceChangesLink;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.ajaxlistener.ConfirmLeaveListener;import io.onedev.server.web.util.ajaxlistener.ConfirmListener;diff --git a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/OpenedPanel.java b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/OpenedPanel.javaindex 50c948a686..98bd4e4a4f 100644--- a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/OpenedPanel.java+++ b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/OpenedPanel.java@@ -23,13 +23,13 @@ import io.onedev.server.model.PullRequest;import io.onedev.server.model.User;import io.onedev.server.persistence.dao.Dao;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.component.comment.CommentInput;import io.onedev.server.web.component.comment.ProjectAttachmentSupport;import io.onedev.server.web.component.link.UserLink;import io.onedev.server.web.component.markdown.AttachmentSupport;import io.onedev.server.web.component.markdown.ContentVersionSupport;import io.onedev.server.web.component.markdown.MarkdownViewer;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.ajaxlistener.ConfirmLeaveListener;@SuppressWarnings("serial")diff --git a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/ReferencedPanel.java b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/ReferencedPanel.javaindex 5af403433e..99b1f49190 100644--- a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/ReferencedPanel.java+++ b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/ReferencedPanel.java@@ -8,12 +8,12 @@ import org.apache.wicket.model.IModel;import io.onedev.server.model.PullRequest;import io.onedev.server.model.PullRequestReference;import io.onedev.server.model.User;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.component.avatar.AvatarLink;import io.onedev.server.web.component.link.UserLink;import io.onedev.server.web.component.link.ViewStateAwarePageLink;import io.onedev.server.web.component.requeststatus.RequestStatusPanel;import io.onedev.server.web.page.project.pullrequests.requestdetail.overview.RequestOverviewPage;-import io.onedev.server.web.util.DateUtils;@SuppressWarnings("serial")class ReferencedPanel extends GenericPanel<PullRequestReference> {diff --git a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/StatusChangePanel.java b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/StatusChangePanel.javaindex 26421a6476..8254c4ffd4 100644--- a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/StatusChangePanel.java+++ b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestdetail/overview/activity/StatusChangePanel.java@@ -25,6 +25,7 @@ import io.onedev.server.model.PullRequest;import io.onedev.server.model.PullRequestStatusChange;import io.onedev.server.model.User;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.component.avatar.AvatarLink;import io.onedev.server.web.component.comment.CommentInput;import io.onedev.server.web.component.comment.ProjectAttachmentSupport;@@ -33,7 +34,6 @@ import io.onedev.server.web.component.markdown.AttachmentSupport;import io.onedev.server.web.component.markdown.ContentVersionSupport;import io.onedev.server.web.component.markdown.MarkdownViewer;import io.onedev.server.web.page.project.pullrequests.requestdetail.overview.SinceChangesLink;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.ajaxlistener.ConfirmLeaveListener;@SuppressWarnings("serial")diff --git a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestlist/RequestListPage.java b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestlist/RequestListPage.javaindex ee9445c9cd..8c48d4c8f0 100644--- a/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestlist/RequestListPage.java+++ b/core/src/main/java/io/onedev/server/web/page/project/pullrequests/requestlist/RequestListPage.java@@ -38,6 +38,7 @@ import io.onedev.server.model.PullRequest;import io.onedev.server.model.User;import io.onedev.server.persistence.dao.Dao;import io.onedev.server.persistence.dao.EntityCriteria;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.WebConstants;import io.onedev.server.web.component.avatar.AvatarLink;import io.onedev.server.web.component.datatable.HistoryAwarePagingNavigator;@@ -53,7 +54,6 @@ import io.onedev.server.web.page.project.ProjectPage;import io.onedev.server.web.page.project.pullrequests.newrequest.NewRequestPage;import io.onedev.server.web.page.project.pullrequests.requestdetail.overview.RequestOverviewPage;import io.onedev.server.web.page.project.pullrequests.requestlist.SearchOption.Status;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.PagingHistorySupport;@SuppressWarnings("serial")diff --git a/core/src/main/java/io/onedev/server/web/page/project/setting/issueworkflow/fields/FieldEditPanel.java b/core/src/main/java/io/onedev/server/web/page/project/setting/issueworkflow/fields/FieldEditPanel.javaindex 921212a4f0..029895fae2 100644--- a/core/src/main/java/io/onedev/server/web/page/project/setting/issueworkflow/fields/FieldEditPanel.java+++ b/core/src/main/java/io/onedev/server/web/page/project/setting/issueworkflow/fields/FieldEditPanel.java@@ -162,7 +162,7 @@ abstract class FieldEditPanel extends Panel implements InputContext {@Overridepublic boolean isReservedName(String inputName) {- for (String displayName: Issue.BUILTIN_FIELDS) {+ for (String displayName: Issue.BUILTIN_FIELDS.keySet()) {if (displayName.equals(inputName))return true;}diff --git a/core/src/main/java/io/onedev/server/web/page/project/setting/project-setting.css b/core/src/main/java/io/onedev/server/web/page/project/setting/project-setting.cssindex db043b6b72..3d09c93542 100644--- a/core/src/main/java/io/onedev/server/web/page/project/setting/project-setting.css+++ b/core/src/main/java/io/onedev/server/web/page/project/setting/project-setting.css@@ -18,9 +18,6 @@#project-setting .general-setting form .delete {margin-right: 0;}-#project-setting .drag-handle {- cursor: move;-}#project-setting .panel-list .drag-handle {margin-right: 8px;}diff --git a/core/src/main/java/io/onedev/server/web/page/project/stats/ContributionListPanel.java b/core/src/main/java/io/onedev/server/web/page/project/stats/ContributionListPanel.javaindex d3978617c9..0ca9a16c7c 100644--- a/core/src/main/java/io/onedev/server/web/page/project/stats/ContributionListPanel.java+++ b/core/src/main/java/io/onedev/server/web/page/project/stats/ContributionListPanel.java@@ -17,8 +17,8 @@ import org.apache.wicket.markup.repeater.Item;import org.apache.wicket.model.IModel;import org.apache.wicket.model.Model;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.WebConstants;-import io.onedev.server.web.util.DateUtils;@SuppressWarnings("serial")class ContributionListPanel extends Panel {diff --git a/core/src/main/java/io/onedev/server/web/page/project/stats/SourceLinesPage.java b/core/src/main/java/io/onedev/server/web/page/project/stats/SourceLinesPage.javaindex 10e0bcb515..4f2034ec74 100644--- a/core/src/main/java/io/onedev/server/web/page/project/stats/SourceLinesPage.java+++ b/core/src/main/java/io/onedev/server/web/page/project/stats/SourceLinesPage.java@@ -28,9 +28,9 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;import io.onedev.server.OneDev;import io.onedev.server.git.LineStats;import io.onedev.server.manager.CommitInfoManager;+import io.onedev.server.util.DateUtils;import io.onedev.server.util.Day;import io.onedev.server.web.WebConstants;-import io.onedev.server.web.util.DateUtils;@SuppressWarnings("serial")public class SourceLinesPage extends ProjectStatsPage {diff --git a/core/src/main/java/io/onedev/server/web/page/test/TestPage.java b/core/src/main/java/io/onedev/server/web/page/test/TestPage.javaindex 97919495d2..627344f955 100644--- a/core/src/main/java/io/onedev/server/web/page/test/TestPage.java+++ b/core/src/main/java/io/onedev/server/web/page/test/TestPage.java@@ -2,8 +2,6 @@ package io.onedev.server.web.page.test;import org.apache.wicket.markup.html.link.Link;-import io.onedev.server.OneDev;-import io.onedev.server.manager.IssueManager;import io.onedev.server.web.page.base.BasePage;@SuppressWarnings("serial")@@ -16,7 +14,6 @@ public class TestPage extends BasePage {@Overridepublic void onClick() {- OneDev.getInstance(IssueManager.class).test();}});diff --git a/core/src/main/java/io/onedev/server/web/page/user/TaskListPage.java b/core/src/main/java/io/onedev/server/web/page/user/TaskListPage.javaindex 0da7fe4676..6fffc836fb 100644--- a/core/src/main/java/io/onedev/server/web/page/user/TaskListPage.java+++ b/core/src/main/java/io/onedev/server/web/page/user/TaskListPage.java@@ -25,6 +25,7 @@ import io.onedev.server.model.PullRequestTask;import io.onedev.server.persistence.dao.Dao;import io.onedev.server.persistence.dao.EntityCriteria;import io.onedev.server.security.SecurityUtils;+import io.onedev.server.util.DateUtils;import io.onedev.server.web.WebConstants;import io.onedev.server.web.component.datatable.EntityDataProvider;import io.onedev.server.web.component.datatable.HistoryAwareDataTable;@@ -32,7 +33,6 @@ import io.onedev.server.web.component.datatable.SelectionColumn;import io.onedev.server.web.component.link.BranchLink;import io.onedev.server.web.component.link.ViewStateAwarePageLink;import io.onedev.server.web.page.project.pullrequests.requestdetail.overview.RequestOverviewPage;-import io.onedev.server.web.util.DateUtils;import io.onedev.server.web.util.PagingHistorySupport;@SuppressWarnings("serial")diff --git a/core/src/main/java/io/onedev/server/web/util/SuggestionUtils.java b/core/src/main/java/io/onedev/server/web/util/SuggestionUtils.javaindex a91afb0a7d..27d2f5c855 100644--- a/core/src/main/java/io/onedev/server/web/util/SuggestionUtils.java+++ b/core/src/main/java/io/onedev/server/web/util/SuggestionUtils.java@@ -37,8 +37,8 @@ public class SuggestionUtils {String branch = GitUtils.ref2branch(ref.getRef().getName());int index = branch.toLowerCase().indexOf(lowerCaseMatchWith);if (index != -1 && numSuggestions++<InputAssistBehavior.MAX_SUGGESTIONS) {- Range matchRange = new Range(index, index+lowerCaseMatchWith.length());- suggestions.add(new InputSuggestion(branch, null, matchRange));+ Range match = new Range(index, index+lowerCaseMatchWith.length());+ suggestions.add(new InputSuggestion(branch, null, match));}}return suggestions;@@ -52,8 +52,8 @@ public class SuggestionUtils {String tag = GitUtils.ref2tag(ref.getRef().getName());int index = tag.toLowerCase().indexOf(lowerCaseMatchWith);if (index != -1 && numSuggestions++<InputAssistBehavior.MAX_SUGGESTIONS) {- Range matchRange = new Range(index, index+lowerCaseMatchWith.length());- suggestions.add(new InputSuggestion(tag, null, matchRange));+ Range match = new Range(index, index+lowerCaseMatchWith.length());+ suggestions.add(new InputSuggestion(tag, null, match));}}return suggestions;@@ -67,8 +67,8 @@ public class SuggestionUtils {String name = user.getName();int index = name.toLowerCase().indexOf(lowerCaseMatchWith);if (index != -1 && numSuggestions++<InputAssistBehavior.MAX_SUGGESTIONS) {- Range matchRange = new Range(index, index+lowerCaseMatchWith.length());- suggestions.add(new InputSuggestion(name, matchRange));+ Range match = new Range(index, index+lowerCaseMatchWith.length());+ suggestions.add(new InputSuggestion(name, match));}}return suggestions;@@ -81,8 +81,8 @@ public class SuggestionUtils {String name = group.getName();int index = name.toLowerCase().indexOf(lowerCaseMatchWith);if (index != -1) {- Range matchRange = new Range(index, index+lowerCaseMatchWith.length());- suggestions.add(new InputSuggestion(name, matchRange));+ Range match = new Range(index, index+lowerCaseMatchWith.length());+ suggestions.add(new InputSuggestion(name, match));}}return suggestions;@@ -95,8 +95,8 @@ public class SuggestionUtils {for (String verificationName: OneDev.getInstance(VerificationManager.class).getVerificationNames(project)) {int index = verificationName.toLowerCase().indexOf(lowerCaseMatchWith);if (index != -1 && numSuggestions++<InputAssistBehavior.MAX_SUGGESTIONS) {- Range matchRange = new Range(index, index+lowerCaseMatchWith.length());- suggestions.add(new InputSuggestion(verificationName, matchRange));+ Range match = new Range(index, index+lowerCaseMatchWith.length());+ suggestions.add(new InputSuggestion(verificationName, match));}}return suggestions;@@ -132,15 +132,15 @@ public class SuggestionUtils {if (applied != null)allApplied.add(applied);}- allApplied.sort((o1, o2) -> o1.getMatchRange().getFrom() - o2.getMatchRange().getFrom());+ allApplied.sort((o1, o2) -> o1.getMatch().getFrom() - o2.getMatch().getFrom());Map<String, Set<String>> childrenCache = new HashMap<>();Map<String, Range> suggestedInputs = new LinkedHashMap<>();for (PatternApplied applied: allApplied) {- Range matchRange = applied.getMatchRange();- String suffix = applied.getText().substring(matchRange.getTo());+ Range match = applied.getMatch();+ String suffix = applied.getText().substring(match.getTo());int index = suffix.indexOf('/');- String suggestedInput = applied.getText().substring(0, matchRange.getTo());+ String suggestedInput = applied.getText().substring(0, match.getTo());if (index != -1) {suggestedInput += suffix.substring(0, index) + "/";while (true) {@@ -162,7 +162,7 @@ public class SuggestionUtils {} else {suggestedInput += suffix;}- suggestedInputs.put(suggestedInput, matchRange);+ suggestedInputs.put(suggestedInput, match);if (suggestedInputs.size() == InputAssistBehavior.MAX_SUGGESTIONS)break;}