Add support for deleting tags through the web ui
Change-Id: I187afab26dbf678e1b808029f45e28801f340238
This commit is contained in:
@@ -185,6 +185,8 @@ public interface AdminConstants extends Constants {
|
||||
|
||||
String buttonAddTag();
|
||||
|
||||
String buttonDeleteTag();
|
||||
|
||||
String saveHeadButton();
|
||||
|
||||
String cancelHeadButton();
|
||||
|
||||
@@ -88,6 +88,7 @@ initialRevision = Initial Revision
|
||||
buttonAddBranch = Create Branch
|
||||
buttonAddTag = Create Tag
|
||||
buttonDeleteBranch = Delete
|
||||
buttonDeleteTag = Delete
|
||||
saveHeadButton = Save
|
||||
cancelHeadButton = Cancel
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.gerrit.client.ConfirmationCallback;
|
||||
import com.google.gerrit.client.ConfirmationDialog;
|
||||
import com.google.gerrit.client.ErrorDialog;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.VoidResult;
|
||||
import com.google.gerrit.client.access.AccessMap;
|
||||
import com.google.gerrit.client.access.ProjectAccessInfo;
|
||||
import com.google.gerrit.client.projects.ProjectApi;
|
||||
@@ -43,6 +44,8 @@ import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.dom.client.KeyPressHandler;
|
||||
import com.google.gwt.event.dom.client.KeyUpEvent;
|
||||
import com.google.gwt.event.dom.client.KeyUpHandler;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.CheckBox;
|
||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||
@@ -52,6 +55,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.InlineHTML;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||
import java.util.HashSet;
|
||||
@@ -62,6 +66,7 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
private Hyperlink prev;
|
||||
private Hyperlink next;
|
||||
private TagsTable tagTable;
|
||||
private Button delTag;
|
||||
private Button addTag;
|
||||
private HintTextBox nameTxtBox;
|
||||
private HintTextBox irevTxtBox;
|
||||
@@ -95,6 +100,7 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
}
|
||||
|
||||
private void updateForm() {
|
||||
tagTable.updateDeleteButton();
|
||||
addTag.setEnabled(true);
|
||||
nameTxtBox.setEnabled(true);
|
||||
irevTxtBox.setEnabled(true);
|
||||
@@ -160,8 +166,19 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
|
||||
tagTable = new TagsTable();
|
||||
|
||||
delTag = new Button(AdminConstants.I.buttonDeleteTag());
|
||||
delTag.setStyleName(Gerrit.RESOURCES.css().branchTableDeleteButton());
|
||||
delTag.addClickHandler(
|
||||
new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
tagTable.deleteChecked();
|
||||
}
|
||||
});
|
||||
|
||||
HorizontalPanel buttons = new HorizontalPanel();
|
||||
buttons.setStyleName(Gerrit.RESOURCES.css().branchTablePrevNextLinks());
|
||||
buttons.add(delTag);
|
||||
buttons.add(prev);
|
||||
buttons.add(next);
|
||||
add(tagTable);
|
||||
@@ -272,6 +289,8 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
}
|
||||
|
||||
private class TagsTable extends NavigationTable<TagInfo> {
|
||||
private ValueChangeHandler<Boolean> updateDeleteHandler;
|
||||
boolean canDelete;
|
||||
|
||||
TagsTable() {
|
||||
table.setWidth("");
|
||||
@@ -282,6 +301,14 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
fmt.addStyleName(0, 1, Gerrit.RESOURCES.css().iconHeader());
|
||||
fmt.addStyleName(0, 2, Gerrit.RESOURCES.css().dataHeader());
|
||||
fmt.addStyleName(0, 3, Gerrit.RESOURCES.css().dataHeader());
|
||||
|
||||
updateDeleteHandler =
|
||||
new ValueChangeHandler<Boolean>() {
|
||||
@Override
|
||||
public void onValueChange(ValueChangeEvent<Boolean> event) {
|
||||
updateDeleteButton();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Set<String> getCheckedRefs() {
|
||||
@@ -306,11 +333,74 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
}
|
||||
}
|
||||
|
||||
void deleteChecked() {
|
||||
final Set<String> refs = getCheckedRefs();
|
||||
|
||||
SafeHtmlBuilder b = new SafeHtmlBuilder();
|
||||
b.openElement("b");
|
||||
b.append(Gerrit.C.tagDeletionConfirmationMessage());
|
||||
b.closeElement("b");
|
||||
|
||||
b.openElement("p");
|
||||
boolean first = true;
|
||||
for (String ref : refs) {
|
||||
if (!first) {
|
||||
b.append(",").br();
|
||||
}
|
||||
b.append(ref);
|
||||
first = false;
|
||||
}
|
||||
b.closeElement("p");
|
||||
|
||||
if (refs.isEmpty()) {
|
||||
updateDeleteButton();
|
||||
return;
|
||||
}
|
||||
|
||||
delTag.setEnabled(false);
|
||||
ConfirmationDialog confirmationDialog =
|
||||
new ConfirmationDialog(
|
||||
Gerrit.C.tagDeletionDialogTitle(),
|
||||
b.toSafeHtml(),
|
||||
new ConfirmationCallback() {
|
||||
@Override
|
||||
public void onOk() {
|
||||
deleteTags(refs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
tagTable.updateDeleteButton();
|
||||
}
|
||||
});
|
||||
confirmationDialog.center();
|
||||
}
|
||||
|
||||
private void deleteTags(final Set<String> tags) {
|
||||
ProjectApi.deleteTags(
|
||||
getProjectKey(),
|
||||
tags,
|
||||
new GerritCallback<VoidResult>() {
|
||||
@Override
|
||||
public void onSuccess(VoidResult result) {
|
||||
query = new Query(match).start(start).run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
query = new Query(match).start(start).run();
|
||||
super.onFailure(caught);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void display(List<TagInfo> tags) {
|
||||
displaySubset(tags, 0, tags.size());
|
||||
}
|
||||
|
||||
void displaySubset(List<TagInfo> tags, int fromIndex, int toIndex) {
|
||||
canDelete = false;
|
||||
|
||||
while (1 < table.getRowCount()) {
|
||||
table.removeRow(table.getRowCount() - 1);
|
||||
}
|
||||
@@ -324,7 +414,14 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
}
|
||||
|
||||
void populate(int row, TagInfo k) {
|
||||
table.setText(row, 1, "");
|
||||
if (k.canDelete()) {
|
||||
CheckBox sel = new CheckBox();
|
||||
sel.addValueChangeHandler(updateDeleteHandler);
|
||||
table.setWidget(row, 1, sel);
|
||||
canDelete = true;
|
||||
} else {
|
||||
table.setText(row, 1, "");
|
||||
}
|
||||
|
||||
table.setWidget(row, 2, new InlineHTML(highlight(k.getShortName(), match)));
|
||||
|
||||
@@ -344,6 +441,25 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
setRowItem(row, k);
|
||||
}
|
||||
|
||||
boolean hasTagCanDelete() {
|
||||
return canDelete;
|
||||
}
|
||||
|
||||
void updateDeleteButton() {
|
||||
boolean on = false;
|
||||
for (int row = 1; row < table.getRowCount(); row++) {
|
||||
Widget w = table.getWidget(row, 1);
|
||||
if (w != null && w instanceof CheckBox) {
|
||||
CheckBox sel = (CheckBox) w;
|
||||
if (sel.getValue()) {
|
||||
on = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
delTag.setEnabled(on);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onOpenRow(int row) {
|
||||
if (row > 0) {
|
||||
@@ -421,6 +537,7 @@ public class ProjectTagsScreen extends PaginatedProjectScreen {
|
||||
prev.setVisible(false);
|
||||
}
|
||||
|
||||
delTag.setVisible(tagTable.hasTagCanDelete());
|
||||
Set<String> checkedRefs = tagTable.getCheckedRefs();
|
||||
tagTable.setChecked(checkedRefs);
|
||||
updateForm();
|
||||
|
||||
Reference in New Issue
Block a user