Render more actions on change view
There are more actions that don't require additional input and can be rendered already now: * Delete draft change * Delete draft revision * Publish draft revision Also align the primary button to the right side of the container to even more visually emphasize, that this button does something different in this specific change context, except blue color. Status of the current revision is currently not correctly computed, because the current code only respects the change.status field in the change/revision status calculation. When cange.status is NEW, then the revision draft field must be read to correctly render draft revision status. This will be fixed in follow-up change. Test Plan: - Add draft change. Confirm that Publish and Delete buttons are visible and work as exptected - Add draft revision. Confirm that Publish and Delete buttons are visible and work as exptected Bug: Issue 3906 Change-Id: I9db90142088e165cf65b89abbe11a3d1dc6db634
This commit is contained in:
@@ -72,6 +72,7 @@ public class DeleteDraftChange implements
|
||||
public UiAction.Description getDescription(ChangeResource rsrc) {
|
||||
try {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Delete")
|
||||
.setTitle("Delete draft change " + rsrc.getId())
|
||||
.setVisible(allowDrafts
|
||||
&& rsrc.getChange().getStatus() == Status.DRAFT
|
||||
|
||||
@@ -184,6 +184,7 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
||||
try {
|
||||
int psCount = psUtil.byChange(db.get(), rsrc.getNotes()).size();
|
||||
return new UiAction.Description()
|
||||
.setLabel("Delete")
|
||||
.setTitle(String.format("Delete draft revision %d",
|
||||
rsrc.getPatchSet().getPatchSetId()))
|
||||
.setVisible(allowDrafts
|
||||
|
||||
@@ -126,6 +126,7 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
||||
public UiAction.Description getDescription(RevisionResource rsrc) {
|
||||
try {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Publish")
|
||||
.setTitle(String.format("Publish revision %d",
|
||||
rsrc.getPatchSet().getPatchSetId()))
|
||||
.setVisible(rsrc.getPatchSet().isDraft()
|
||||
|
||||
@@ -50,6 +50,7 @@ limitations under the License.
|
||||
primary$="[[_computePrimary(action.__key)]]"
|
||||
hidden$="[[!action.enabled]]"
|
||||
data-action-key$="[[action.__key]]"
|
||||
data-action-type$="[[action.__type]]"
|
||||
data-label$="[[action.label]]"
|
||||
on-tap="_handleActionTap"></gr-button>
|
||||
</template>
|
||||
@@ -58,6 +59,7 @@ limitations under the License.
|
||||
primary$="[[_computePrimary(action.__key)]]"
|
||||
disabled$="[[!action.enabled]]"
|
||||
data-action-key$="[[action.__key]]"
|
||||
data-action-type$="[[action.__type]]"
|
||||
data-label$="[[action.label]]"
|
||||
data-loading-label$="[[_computeLoadingLabel(action.__key)]]"
|
||||
on-tap="_handleActionTap"></gr-button>
|
||||
@@ -78,11 +80,14 @@ limitations under the License.
|
||||
// TODO(davido): Add the rest of the change actions.
|
||||
var ChangeActions = {
|
||||
ABANDON: 'abandon',
|
||||
DELETE: '/',
|
||||
RESTORE: 'restore',
|
||||
};
|
||||
|
||||
// TODO(andybons): Add the rest of the revision actions.
|
||||
var RevisionActions = {
|
||||
DELETE: '/',
|
||||
PUBLISH: 'publish',
|
||||
REBASE: 'rebase',
|
||||
SUBMIT: 'submit',
|
||||
};
|
||||
@@ -128,6 +133,7 @@ limitations under the License.
|
||||
this.hidden =
|
||||
revisionActions.rebase == null &&
|
||||
revisionActions.submit == null &&
|
||||
revisionActions.publish == null &&
|
||||
actions.abandon == null &&
|
||||
actions.restore == null;
|
||||
},
|
||||
@@ -142,13 +148,14 @@ limitations under the License.
|
||||
});
|
||||
},
|
||||
|
||||
_computeActionValues: function(actions, k) {
|
||||
_computeActionValues: function(actions, type) {
|
||||
var result = [];
|
||||
var values = this._getValuesFor(
|
||||
k == 'change' ? ChangeActions : RevisionActions);
|
||||
type == 'change' ? ChangeActions : RevisionActions);
|
||||
for (var a in actions) {
|
||||
if (values.indexOf(a) == -1) { continue; }
|
||||
actions[a].__key = a;
|
||||
actions[a].__type = type;
|
||||
result.push(actions[a]);
|
||||
}
|
||||
return result;
|
||||
@@ -166,24 +173,34 @@ limitations under the License.
|
||||
},
|
||||
|
||||
_computeButtonClass: function(action) {
|
||||
return action == 'submit' ? 'primary' : '';
|
||||
if ([RevisionActions.SUBMIT,
|
||||
RevisionActions.PUBLISH].indexOf(action) != -1) {
|
||||
return 'primary';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
|
||||
_handleActionTap: function(e) {
|
||||
e.preventDefault();
|
||||
var el = Polymer.dom(e).rootTarget;
|
||||
var key = el.getAttribute('data-action-key');
|
||||
if (this._getValuesFor(RevisionActions).indexOf(key) > -1) {
|
||||
var type = el.getAttribute('data-action-type');
|
||||
if (type == 'revision') {
|
||||
if (key == RevisionActions.REBASE) {
|
||||
this._showRebaseDialog();
|
||||
return;
|
||||
}
|
||||
this._fireRevisionAction('/' + key, this._revisionActions[key]);
|
||||
this._fireRevisionAction(this._prependSlash(key),
|
||||
this._revisionActions[key]);
|
||||
} else {
|
||||
this._fireChangeAction('/' + key, this.actions[key]);
|
||||
this._fireChangeAction(this._prependSlash(key), this.actions[key]);
|
||||
}
|
||||
},
|
||||
|
||||
_prependSlash: function(key) {
|
||||
return key == '/' ? key : '/' + key;
|
||||
},
|
||||
|
||||
_handleConfirmDialogCancel: function() {
|
||||
var dialogEls =
|
||||
Polymer.dom(this.root).querySelectorAll('.confirmDialog');
|
||||
@@ -216,7 +233,12 @@ limitations under the License.
|
||||
_fireChangeAction: function(endpoint, action) {
|
||||
this._send(action.method, {}, endpoint).then(
|
||||
function() {
|
||||
this.fire('reload-change', null, {bubbles: false});
|
||||
// We can’t reload a change that was deleted.
|
||||
if (endpoint == ChangeActions.DELETE) {
|
||||
page.show('/');
|
||||
} else {
|
||||
this.fire('reload-change', null, {bubbles: false});
|
||||
}
|
||||
}.bind(this)).catch(function(err) {
|
||||
alert('Oops. Something went wrong. Check the console and bug the ' +
|
||||
'PolyGerrit team for assistance.');
|
||||
|
||||
Reference in New Issue
Block a user