Add new screen to list tags of a project

Change-Id: I67681e967b48e853aba2949c5c67d3f5056d66cc
This commit is contained in:
David Pursehouse 2015-09-11 12:28:09 +09:00 committed by Edwin Kempin
parent d313af3a1d
commit 9b91ca4c0c
11 changed files with 297 additions and 11 deletions

View File

@ -89,6 +89,10 @@ public class PageLinks {
return "/admin/projects/" + p.get() + ",branches";
}
public static String toProjectTags(Project.NameKey p) {
return "/admin/projects/" + p.get() + ",tags";
}
public static String toAccountQuery(String fullname, Status status) {
return toChangeQuery(op("owner", fullname) + " " + status(status));
}

View File

@ -66,6 +66,7 @@ import com.google.gerrit.client.admin.ProjectDashboardsScreen;
import com.google.gerrit.client.admin.ProjectInfoScreen;
import com.google.gerrit.client.admin.ProjectListScreen;
import com.google.gerrit.client.admin.ProjectScreen;
import com.google.gerrit.client.admin.ProjectTagsScreen;
import com.google.gerrit.client.api.ExtensionScreen;
import com.google.gerrit.client.api.ExtensionSettingsScreen;
import com.google.gerrit.client.change.ChangeScreen;
@ -738,6 +739,11 @@ public class Dispatcher {
return new ProjectBranchesScreen(k);
}
if (ProjectScreen.TAGS.equals(panel)
|| matchPrefix(ProjectScreen.TAGS, panel)) {
return new ProjectTagsScreen(k);
}
if (ProjectScreen.ACCESS.equals(panel)) {
return new ProjectAccessScreen(k);
}

View File

@ -708,6 +708,7 @@ public class Gerrit implements EntryPoint {
addLink(projectsBar, C.menuProjectsList(), PageLinks.ADMIN_PROJECTS);
projectsBar.addItem(new ProjectLinkMenuItem(C.menuProjectsInfo(), ProjectScreen.INFO));
projectsBar.addItem(new ProjectLinkMenuItem(C.menuProjectsBranches(), ProjectScreen.BRANCHES));
projectsBar.addItem(new ProjectLinkMenuItem(C.menuProjectsTags(), ProjectScreen.TAGS));
projectsBar.addItem(new ProjectLinkMenuItem(C.menuProjectsAccess(), ProjectScreen.ACCESS));
final LinkMenuItem dashboardsMenuItem =
new ProjectLinkMenuItem(C.menuProjectsDashboards(),

View File

@ -77,6 +77,7 @@ public interface GerritConstants extends Constants {
String menuProjectsList();
String menuProjectsInfo();
String menuProjectsBranches();
String menuProjectsTags();
String menuProjectsAccess();
String menuProjectsDashboards();
String menuProjectsCreate();

View File

@ -60,6 +60,7 @@ menuProjects = Projects
menuProjectsList = List
menuProjectsInfo = General
menuProjectsBranches = Branches
menuProjectsTags = Tags
menuProjectsAccess = Access
menuProjectsDashboards = Dashboards
menuProjectsCreate = Create New Project

View File

@ -104,6 +104,7 @@ public interface AdminConstants extends Constants {
String buttonDeleteBranch();
String saveHeadButton();
String cancelHeadButton();
String columnTagName();
String groupItemHelp();

View File

@ -83,6 +83,7 @@ buttonAddBranch = Create Branch
buttonDeleteBranch = Delete
saveHeadButton = Save
cancelHeadButton = Cancel
columnTagName = Tag Name
groupItemHelp = group

View File

@ -22,6 +22,7 @@ public abstract class ProjectScreen extends Screen {
public static final String BRANCHES = "branches";
public static final String ACCESS = "access";
public static final String DASHBOARDS = "dashboards";
public static final String TAGS = "tags";
protected static String savedPanel;
protected static Project.NameKey savedKey;

View File

@ -0,0 +1,232 @@
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.admin;
import static com.google.gerrit.client.ui.Util.highlight;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.projects.ProjectApi;
import com.google.gerrit.client.projects.TagInfo;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.Hyperlink;
import com.google.gerrit.client.ui.NavigationTable;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
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.FlexTable.FlexCellFormatter;
import com.google.gwtexpui.globalkey.client.NpTextBox;
import java.util.List;
public class ProjectTagsScreen extends PaginatedProjectScreen {
private NpTextBox filterTxt;
private Query query;
private Hyperlink prev;
private Hyperlink next;
private TagsTable tagsTable;
public ProjectTagsScreen(Project.NameKey toShow) {
super(toShow);
}
@Override
public String getScreenToken() {
return PageLinks.toProjectTags(getProjectKey());
}
@Override
protected void onInitUI() {
super.onInitUI();
initPageHeader();
prev = new Hyperlink(Util.C.pagedListPrev(), true, "");
prev.setVisible(false);
next = new Hyperlink(Util.C.pagedListNext(), true, "");
next.setVisible(false);
tagsTable = new TagsTable();
HorizontalPanel buttons = new HorizontalPanel();
buttons.setStyleName(Gerrit.RESOURCES.css().branchTablePrevNextLinks());
buttons.add(prev);
buttons.add(next);
add(tagsTable);
add(buttons);
}
@Override
protected void onLoad() {
super.onLoad();
query = new Query(match).start(start).run();
savedPanel = TAGS;
}
private void initPageHeader() {
parseToken();
HorizontalPanel hp = new HorizontalPanel();
hp.setStyleName(Gerrit.RESOURCES.css().projectFilterPanel());
Label filterLabel = new Label(Util.C.projectFilter());
filterLabel.setStyleName(Gerrit.RESOURCES.css().projectFilterLabel());
hp.add(filterLabel);
filterTxt = new NpTextBox();
filterTxt.setValue(match);
filterTxt.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
Query q = new Query(filterTxt.getValue());
if (match.equals(q.qMatch)) {
q.start(start);
} else if (query == null) {
q.run();
query = q;
}
}
});
hp.add(filterTxt);
add(hp);
}
private class TagsTable extends NavigationTable<TagInfo> {
TagsTable() {
table.setWidth("");
table.setText(0, 0, Util.C.columnTagName());
table.setText(0, 1, Util.C.columnBranchRevision());
FlexCellFormatter fmt = table.getFlexCellFormatter();
fmt.addStyleName(0, 0, Gerrit.RESOURCES.css().dataHeader());
fmt.addStyleName(0, 1, Gerrit.RESOURCES.css().dataHeader());
}
void display(List<TagInfo> tags) {
displaySubset(tags, 0, tags.size());
}
void displaySubset(List<TagInfo> tags, int fromIndex, int toIndex) {
while (1 < table.getRowCount()) {
table.removeRow(table.getRowCount() - 1);
}
for (TagInfo k : tags.subList(fromIndex, toIndex)) {
int row = table.getRowCount();
table.insertRow(row);
applyDataRowStyle(row);
populate(row, k);
}
}
void populate(int row, TagInfo k) {
table.setWidget(row, 0, new InlineHTML(highlight(k.getShortName(), match)));
if (k.revision() != null) {
table.setText(row, 1, k.revision());
} else {
table.setText(row, 1, "");
}
FlexCellFormatter fmt = table.getFlexCellFormatter();
String dataCellStyle = Gerrit.RESOURCES.css().dataCell();
fmt.addStyleName(row, 0, dataCellStyle);
fmt.addStyleName(row, 1, dataCellStyle);
setRowItem(row, k);
}
@Override
protected void onOpenRow(int row) {
if (row > 0) {
movePointerTo(row);
}
}
@Override
protected Object getRowItemKey(TagInfo item) {
return item.ref();
}
}
@Override
public void onShowView() {
super.onShowView();
if (match != null) {
filterTxt.setCursorPos(match.length());
}
filterTxt.setFocus(true);
}
private class Query {
private String qMatch;
private int qStart;
Query(String match) {
this.qMatch = match;
}
Query start(int start) {
this.qStart = start;
return this;
}
Query run() {
// Retrieve one more tag than page size to determine if there are more
// tags to display
ProjectApi.getTags(getProjectKey(), pageSize + 1, qStart, qMatch,
new ScreenLoadCallback<JsArray<TagInfo>>(ProjectTagsScreen.this) {
@Override
public void preDisplay(JsArray<TagInfo> result) {
if (!isAttached()) {
// View has been disposed.
} else if (query == Query.this) {
query = null;
showList(result);
} else {
query.run();
}
}
});
return this;
}
void showList(JsArray<TagInfo> result) {
setToken(getTokenForScreen(qMatch, qStart));
ProjectTagsScreen.this.match = qMatch;
ProjectTagsScreen.this.start = qStart;
if (result.length() <= pageSize) {
tagsTable.display(Natives.asList(result));
next.setVisible(false);
} else {
tagsTable.displaySubset(Natives.asList(result), 0,
result.length() - 1);
setupNavigationLink(next, qMatch, qStart + pageSize);
}
if (qStart > 0) {
setupNavigationLink(prev, qMatch, qStart - pageSize);
} else {
prev.setVisible(false);
}
if (!isCurrentView()) {
display();
}
}
}
}

View File

@ -44,6 +44,32 @@ public class ProjectApi {
.put(input, cb);
}
private static RestApi getRestApi(Project.NameKey name, String viewName,
int limit, int start, String match) {
RestApi call = project(name).view(viewName);
call.addParameter("n", limit);
call.addParameter("s", start);
if (match != null) {
if (match.startsWith("^")) {
call.addParameter("r", match);
} else {
call.addParameter("m", match);
}
}
return call;
}
/** Retrieve all visible tags of the project */
public static void getTags(Project.NameKey name,
AsyncCallback<JsArray<TagInfo>> cb) {
project(name).view("tags").get(cb);
}
public static void getTags(Project.NameKey name, int limit, int start,
String match, AsyncCallback<JsArray<TagInfo>> cb) {
getRestApi(name, "tags", limit, start, match).get(cb);
}
/** Create a new branch */
public static void createBranch(Project.NameKey name, String ref,
String revision, AsyncCallback<BranchInfo> cb) {
@ -60,17 +86,7 @@ public class ProjectApi {
public static void getBranches(Project.NameKey name, int limit, int start,
String match, AsyncCallback<JsArray<BranchInfo>> cb) {
RestApi call = project(name).view("branches");
call.addParameter("n", limit);
call.addParameter("s", start);
if (match != null) {
if (match.startsWith("^")) {
call.addParameter("r", match);
} else {
call.addParameter("m", match);
}
}
call.get(cb);
getRestApi(name, "branches", limit, start, match).get(cb);
}
/**

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.projects;
public class TagInfo extends RefInfo {
// TODO(dpursehouse) add extra tag-related fields (message, tagger, etc)
protected TagInfo() {
}
}