Merge changes from topic 'hashtags-fixes'

* changes:
  Clean up Actions.CORE
  Fix: Only show Add/Remove Hashtags UI elements if user has capability
This commit is contained in:
David Pursehouse 2015-05-08 09:53:42 +00:00 committed by Gerrit Code Review
commit a3ce3d212b
3 changed files with 26 additions and 13 deletions

View File

@ -36,9 +36,8 @@ import java.util.TreeSet;
class Actions extends Composite {
private static final String[] CORE = {
"abandon", "restore", "revert", "topic",
"cherrypick", "submit", "rebase", "message",
"publish", "followup", "/"};
"abandon", "cherrypick", "followup", "hashtags", "publish",
"rebase", "restore", "revert", "submit", "topic", "/"};
interface Binder extends UiBinder<FlowPanel, Actions> {}
private static final Binder uiBinder = GWT.create(Binder.class);

View File

@ -51,6 +51,8 @@ public class Hashtags extends Composite {
private static final String REMOVE;
private static final String DATA_ID = "data-id";
private boolean canEdit;
static {
REMOVE = DOM.createUniqueId().replace('-', '_');
init(REMOVE);
@ -121,9 +123,10 @@ public class Hashtags extends Composite {
}
void set(ChangeInfo info) {
canEdit = info.has_actions() && info.actions().containsKey("hashtags");
this.changeId = info.legacy_id();
display(info);
openForm.setVisible(Gerrit.isSignedIn());
openForm.setVisible(canEdit);
}
@UiHandler("openForm")
@ -165,13 +168,15 @@ public class Hashtags extends Composite {
"#" + PageLinks.toChangeQuery("hashtag:\"" + hashtagName + "\""))
.setAttribute("role", "listitem")
.append("#").append(hashtagName)
.closeAnchor()
.openElement("button")
.setAttribute("title", "Remove hashtag")
.setAttribute("onclick", REMOVE + "(event)")
.append("×")
.closeElement("button")
.closeSpan();
.closeAnchor();
if (canEdit) {
html.openElement("button")
.setAttribute("title", "Remove hashtag")
.setAttribute("onclick", REMOVE + "(event)")
.append("×")
.closeElement("button");
}
html.closeSpan();
if (itr.hasNext()) {
html.append(' ');
}

View File

@ -20,6 +20,7 @@ import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.server.validators.ValidationException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@ -29,7 +30,8 @@ import java.io.IOException;
import java.util.Set;
@Singleton
public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInput> {
public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInput>,
UiAction<ChangeResource>{
private HashtagsUtil hashtagsUtil;
@Inject
@ -51,4 +53,11 @@ public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInpu
throw new ResourceConflictException(e.getMessage());
}
}
}
@Override
public UiAction.Description getDescription(ChangeResource resource) {
return new UiAction.Description()
.setLabel("Edit Hashtags")
.setVisible(resource.getControl().canEditHashtags());
}
}