Improved entity reference panel

This commit is contained in:
Robin Shen 2020-11-22 16:23:20 +08:00
parent 3a218b437a
commit c9290074a8
7 changed files with 54 additions and 18 deletions

View File

@ -9,5 +9,10 @@ public interface Referenceable {
long getNumber();
String getPrefix();
public static String asReference(Referenceable referenceable) {
return String.format("%s %s#%d", referenceable.getPrefix(),
referenceable.getProject().getName(), referenceable.getNumber());
}
}

View File

@ -32,6 +32,7 @@ import io.onedev.server.model.User;
import io.onedev.server.security.SecurityUtils;
import io.onedev.server.util.DateUtils;
import io.onedev.server.util.Input;
import io.onedev.server.util.Referenceable;
import io.onedev.server.util.criteria.Criteria;
import io.onedev.server.web.behavior.WebSocketObserver;
import io.onedev.server.web.component.build.ParamValuesLabel;
@ -276,13 +277,20 @@ public abstract class BuildSidePanel extends Panel {
});
add(new ReferencePanel("reference") {
@Override
protected Referenceable getReferenceable() {
return getBuild();
}
});
if (SecurityUtils.canManage(getBuild()))
add(newDeleteLink("delete"));
else
add(new WebMarkupContainer("delete").setVisible(false));
addOrReplace(new ReferencePanel("reference", getBuild()));
setOutputMarkupId(true);
}

View File

@ -27,3 +27,8 @@
.build-side>.properties>div:last-child>div {
padding-bottom: 0;
}
.build-side>div>.head {
font-weight: 600;
margin-bottom: 1rem;
}

View File

@ -1,8 +1,11 @@
<wicket:panel>
<div class="d-flex align-items-center">
<div class="mr-3 text-nowrap text-truncate">Reference: <span wicket:id="reference"></span></div>
<a wicket:id="copy" class="btn btn-xs btn-icon btn-light btn-hover-primary flex-shrink-0 ml-auto">
<wicket:svg href="copy" class="icon"></wicket:svg>
</a>
<div class="head">Reference</div>
<div class="body">
<div class="d-flex align-items-center flex-nowrap">
<span wicket:id="reference" class="text-nowrap text-truncate mr-3"></span>
<a wicket:id="copy" class="btn btn-xs btn-icon btn-light btn-hover-primary">
<wicket:svg href="copy" class="icon"></wicket:svg>
</a>
</div>
</div>
</wicket:panel>

View File

@ -6,23 +6,22 @@ import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
public class ReferencePanel extends Panel {
@SuppressWarnings("serial")
public abstract class ReferencePanel extends Panel {
private Referenceable entity;
public ReferencePanel(String id, Referenceable entity) {
public ReferencePanel(String id) {
super(id);
this.entity = entity;
}
@Override
protected void onInitialize() {
super.onInitialize();
String displayReference = String.format("%s#%d", entity.getProject(), entity.getNumber());
String reference = entity.getPrefix() + " " + displayReference;
String reference = Referenceable.asReference(getReferenceable());
add(new Label("reference", displayReference));
add(new Label("reference", reference));
add(new CopyToClipboardLink("copy", Model.of(reference)));
}
protected abstract Referenceable getReferenceable();
}

View File

@ -57,6 +57,7 @@ import io.onedev.server.search.entity.issue.StateCriteria;
import io.onedev.server.security.SecurityUtils;
import io.onedev.server.util.Input;
import io.onedev.server.util.IssueUtils;
import io.onedev.server.util.Referenceable;
import io.onedev.server.web.ajaxlistener.AppendLoadingIndicatorListener;
import io.onedev.server.web.behavior.WebSocketObserver;
import io.onedev.server.web.component.entity.watches.EntityWatchesPanel;
@ -107,13 +108,20 @@ public abstract class IssueSidePanel extends Panel {
});
addOrReplace(new ReferencePanel("reference") {
@Override
protected Referenceable getReferenceable() {
return getIssue();
}
});
if (SecurityUtils.canManageIssues(getProject()))
addOrReplace(newDeleteLink("delete"));
else
addOrReplace(new WebMarkupContainer("delete").setVisible(false));
addOrReplace(new ReferencePanel("reference", getIssue()));
super.onBeforeRender();
}

View File

@ -75,6 +75,7 @@ import io.onedev.server.search.entity.pullrequest.PullRequestQuery;
import io.onedev.server.security.SecurityUtils;
import io.onedev.server.util.DateUtils;
import io.onedev.server.util.ProjectScopedNumber;
import io.onedev.server.util.Referenceable;
import io.onedev.server.web.WebSession;
import io.onedev.server.web.behavior.ReferenceInputBehavior;
import io.onedev.server.web.behavior.WebSocketObserver;
@ -730,7 +731,14 @@ public abstract class PullRequestDetailPage extends ProjectPage implements PullR
});
fragment.add(new ReferencePanel("reference", getPullRequest()));
fragment.add(new ReferencePanel("reference") {
@Override
protected Referenceable getReferenceable() {
return getPullRequest();
}
});
fragment.add(new EntityWatchesPanel("watches") {