Add action to edit the project configuration in the browser
Add an 'Edit Config' button to the ProjectInfoScreen that creates a
new change for the 'refs/meta/config' branch and opens the
'project.config' file in the EditScreen.
This allows project owners to easily edit the 'project.config' file
from the browser. This is useful since not all configuration options
might be available from the UI.
Change-Id: I4ada81090149b6058a206e0df745b42f33a29b85
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java
index 20ff993..86f543a 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java
@@ -143,4 +143,7 @@
String buttonCreateDescription();
String buttonCreateChange();
String buttonCreateChangeDescription();
+ String buttonEditConfig();
+ String buttonEditConfigDescription();
+ String editConfigMessage();
}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties
index 26b8123..4446354 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties
@@ -167,3 +167,6 @@
buttonCreateDescription = Insert the description of the change.
buttonCreateChange = Create Change
buttonCreateChangeDescription = Create change directly in the browser.
+buttonEditConfig = Edit Config
+buttonEditConfigDescription = Creates a change to edit the project configuration in the browser.
+editConfigMessage = Edit Project Config
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/EditConfigAction.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/EditConfigAction.java
new file mode 100644
index 0000000..86a31ee
--- /dev/null
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/EditConfigAction.java
@@ -0,0 +1,45 @@
+// 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 com.google.gerrit.client.Dispatcher;
+import com.google.gerrit.client.Gerrit;
+import com.google.gerrit.client.changes.ChangeApi;
+import com.google.gerrit.client.changes.ChangeInfo;
+import com.google.gerrit.client.rpc.GerritCallback;
+import com.google.gerrit.reviewdb.client.PatchSet;
+import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gwt.user.client.ui.Button;
+
+public class EditConfigAction {
+ static void call(final Button b, final String project) {
+ b.setEnabled(false);
+
+ ChangeApi.createChange(project, RefNames.REFS_CONFIG,
+ Util.C.editConfigMessage(), null, new GerritCallback<ChangeInfo>() {
+ @Override
+ public void onSuccess(ChangeInfo result) {
+ Gerrit.display(Dispatcher.toEditScreen(
+ new PatchSet.Id(result.legacy_id(), 1), "project.config"));
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ b.setEnabled(true);
+ super.onFailure(caught);
+ }
+ });
+ }
+}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
index e1fb925..6cb9295 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java
@@ -581,6 +581,10 @@
if (showCreateChange) {
actionsPanel.add(createChangeAction());
}
+
+ if (isOwner) {
+ actionsPanel.add(createEditConfigAction());
+ }
}
private Button createChangeAction() {
@@ -596,6 +600,19 @@
return createChange;
}
+ private Button createEditConfigAction() {
+ final Button editConfig = new Button(Util.C.buttonEditConfig());
+ editConfig.setStyleName("");
+ editConfig.setTitle(Util.C.buttonEditConfigDescription());
+ editConfig.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ EditConfigAction.call(editConfig, getProjectKey().get());
+ }
+ });
+ return editConfig;
+ }
+
private void doSave() {
enableForm(false);
saveProject.setEnabled(false);