Cleanup gr-change-view (remove gr-ajax use)
Bug: Issue 3988 Change-Id: I9a0134ef96ee48a54cac85bd92e3dea88cb7c76f
This commit is contained in:
@@ -18,7 +18,6 @@ limitations under the License.
|
|||||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
||||||
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
|
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
|
||||||
<link rel="import" href="../../shared/gr-account-link/gr-account-link.html">
|
<link rel="import" href="../../shared/gr-account-link/gr-account-link.html">
|
||||||
<link rel="import" href="../../shared/gr-ajax/gr-ajax.html">
|
|
||||||
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
||||||
<link rel="import" href="../../shared/gr-change-star/gr-change-star.html">
|
<link rel="import" href="../../shared/gr-change-star/gr-change-star.html">
|
||||||
<link rel="import" href="../../shared/gr-date-formatter/gr-date-formatter.html">
|
<link rel="import" href="../../shared/gr-date-formatter/gr-date-formatter.html">
|
||||||
@@ -218,22 +217,6 @@ limitations under the License.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<gr-ajax id="detailXHR"
|
|
||||||
url="[[_computeDetailPath(_changeNum)]]"
|
|
||||||
params="[[_computeDetailQueryParams()]]"
|
|
||||||
last-response="{{_change}}"
|
|
||||||
loading="{{_loading}}"></gr-ajax>
|
|
||||||
<gr-ajax id="commentsXHR"
|
|
||||||
url="[[_computeCommentsPath(_changeNum)]]"
|
|
||||||
last-response="{{_comments}}"></gr-ajax>
|
|
||||||
<gr-ajax id="commitInfoXHR"
|
|
||||||
url="[[_computeCommitInfoPath(_changeNum, _patchNum)]]"
|
|
||||||
last-response="{{_commitInfo}}"></gr-ajax>
|
|
||||||
<!-- TODO(andybons): Cache the project config. -->
|
|
||||||
<gr-ajax id="configXHR"
|
|
||||||
auto
|
|
||||||
url="[[_computeProjectConfigPath(_change.project)]]"
|
|
||||||
last-response="{{_projectConfig}}"></gr-ajax>
|
|
||||||
<div class="container loading" hidden$="{{!_loading}}">Loading...</div>
|
<div class="container loading" hidden$="{{!_loading}}">Loading...</div>
|
||||||
<div class="container" hidden$="{{_loading}}">
|
<div class="container" hidden$="{{_loading}}">
|
||||||
<div class="headerContainer">
|
<div class="headerContainer">
|
||||||
|
@@ -225,31 +225,6 @@
|
|||||||
return '(' + status.toLowerCase() + ')';
|
return '(' + status.toLowerCase() + ')';
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeDetailPath: function(changeNum) {
|
|
||||||
return '/changes/' + changeNum + '/detail';
|
|
||||||
},
|
|
||||||
|
|
||||||
_computeCommitInfoPath: function(changeNum, patchNum) {
|
|
||||||
return this.changeBaseURL(changeNum, patchNum) + '/commit?links';
|
|
||||||
},
|
|
||||||
|
|
||||||
_computeCommentsPath: function(changeNum) {
|
|
||||||
return '/changes/' + changeNum + '/comments';
|
|
||||||
},
|
|
||||||
|
|
||||||
_computeProjectConfigPath: function(project) {
|
|
||||||
return '/projects/' + encodeURIComponent(project) + '/config';
|
|
||||||
},
|
|
||||||
|
|
||||||
_computeDetailQueryParams: function() {
|
|
||||||
var options = this.listChangesOptionsToHex(
|
|
||||||
this.ListChangesOption.ALL_REVISIONS,
|
|
||||||
this.ListChangesOption.CHANGE_ACTIONS,
|
|
||||||
this.ListChangesOption.DOWNLOAD_COMMANDS
|
|
||||||
);
|
|
||||||
return {O: options};
|
|
||||||
},
|
|
||||||
|
|
||||||
_computeLatestPatchNum: function(change) {
|
_computeLatestPatchNum: function(change) {
|
||||||
return change.revisions[change.current_revision]._number;
|
return change.revisions[change.current_revision]._number;
|
||||||
},
|
},
|
||||||
@@ -345,13 +320,44 @@
|
|||||||
|
|
||||||
_getDiffDrafts: function() {
|
_getDiffDrafts: function() {
|
||||||
return this.$.restAPI.getDiffDrafts(this._changeNum).then(
|
return this.$.restAPI.getDiffDrafts(this._changeNum).then(
|
||||||
function(drafts) { return this._diffDrafts = drafts; }.bind(this));
|
function(drafts) {
|
||||||
|
return this._diffDrafts = drafts;
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
_getLoggedIn: function() {
|
_getLoggedIn: function() {
|
||||||
return this.$.restAPI.getLoggedIn();
|
return this.$.restAPI.getLoggedIn();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getProjectConfig: function() {
|
||||||
|
return this.$.restAPI.getProjectConfig(this._change.project).then(
|
||||||
|
function(config) {
|
||||||
|
this._projectConfig = config;
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
_getChangeDetail: function() {
|
||||||
|
return this.$.restAPI.getChangeDetail(this._changeNum).then(
|
||||||
|
function(change) {
|
||||||
|
this._change = change;
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
_getComments: function() {
|
||||||
|
return this.$.restAPI.getDiffComments(this._changeNum).then(
|
||||||
|
function(comments) {
|
||||||
|
this._comments = comments;
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
_getCommitInfo: function() {
|
||||||
|
return this.$.restAPI.getChangeCommitInfo(
|
||||||
|
this._changeNum, this._patchNum).then(
|
||||||
|
function(commitInfo) {
|
||||||
|
this._commitInfo = commitInfo;
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
_reloadDiffDrafts: function() {
|
_reloadDiffDrafts: function() {
|
||||||
this._diffDrafts = {};
|
this._diffDrafts = {};
|
||||||
this._getDiffDrafts().then(function() {
|
this._getDiffDrafts().then(function() {
|
||||||
@@ -362,24 +368,31 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_reload: function() {
|
_reload: function() {
|
||||||
|
this._loading = true;
|
||||||
|
|
||||||
this._getLoggedIn().then(function(loggedIn) {
|
this._getLoggedIn().then(function(loggedIn) {
|
||||||
if (!loggedIn) { return; }
|
if (!loggedIn) { return; }
|
||||||
|
|
||||||
this._reloadDiffDrafts();
|
this._reloadDiffDrafts();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
var detailCompletes = this.$.detailXHR.generateRequest().completes;
|
var detailCompletes = this._getChangeDetail().then(function() {
|
||||||
this.$.commentsXHR.generateRequest();
|
this._loading = false;
|
||||||
|
}.bind(this));
|
||||||
|
this._getComments();
|
||||||
|
|
||||||
var reloadPatchNumDependentResources = function() {
|
var reloadPatchNumDependentResources = function() {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
this.$.commitInfoXHR.generateRequest().completes,
|
this._getCommitInfo(),
|
||||||
this.$.actions.reload(),
|
this.$.actions.reload(),
|
||||||
this.$.fileList.reload(),
|
this.$.fileList.reload(),
|
||||||
]);
|
]);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
var reloadDetailDependentResources = function() {
|
var reloadDetailDependentResources = function() {
|
||||||
return this.$.relatedChanges.reload();
|
return Promise.all([
|
||||||
|
this.$.relatedChanges.reload(),
|
||||||
|
this._getProjectConfig(),
|
||||||
|
]);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
this._resetHeaderEl();
|
this._resetHeaderEl();
|
||||||
|
@@ -35,27 +35,12 @@ limitations under the License.
|
|||||||
<script>
|
<script>
|
||||||
suite('gr-change-view tests', function() {
|
suite('gr-change-view tests', function() {
|
||||||
var element;
|
var element;
|
||||||
var server;
|
|
||||||
|
|
||||||
setup(function() {
|
setup(function() {
|
||||||
|
stub('gr-rest-api-interface', {
|
||||||
|
getAccount: function() { return Promise.resolve(null); },
|
||||||
|
});
|
||||||
element = fixture('basic');
|
element = fixture('basic');
|
||||||
element.$.configXHR.auto = false;
|
|
||||||
|
|
||||||
server = sinon.fakeServer.create();
|
|
||||||
// Eat any requests made by elements in this suite.
|
|
||||||
server.respondWith(
|
|
||||||
'GET',
|
|
||||||
/\/changes\/(.*)/,
|
|
||||||
[
|
|
||||||
200,
|
|
||||||
{'Content-Type': 'application/json'},
|
|
||||||
')]}\'\n{}',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
teardown(function() {
|
|
||||||
server.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('keyboard shortcuts', function() {
|
test('keyboard shortcuts', function() {
|
||||||
@@ -66,7 +51,6 @@ limitations under the License.
|
|||||||
'Should navigate to /');
|
'Should navigate to /');
|
||||||
showStub.restore();
|
showStub.restore();
|
||||||
|
|
||||||
|
|
||||||
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
|
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
|
||||||
var overlayEl = element.$.replyOverlay;
|
var overlayEl = element.$.replyOverlay;
|
||||||
assert.isFalse(overlayEl.opened);
|
assert.isFalse(overlayEl.opened);
|
||||||
|
@@ -17,6 +17,54 @@
|
|||||||
var JSON_PREFIX = ')]}\'';
|
var JSON_PREFIX = ')]}\'';
|
||||||
var PARENT_PATCH_NUM = 'PARENT';
|
var PARENT_PATCH_NUM = 'PARENT';
|
||||||
|
|
||||||
|
// Must be kept in sync with the ListChangesOption enum and protobuf.
|
||||||
|
var ListChangesOption = {
|
||||||
|
LABELS: 0,
|
||||||
|
DETAILED_LABELS: 8,
|
||||||
|
|
||||||
|
// Return information on the current patch set of the change.
|
||||||
|
CURRENT_REVISION: 1,
|
||||||
|
ALL_REVISIONS: 2,
|
||||||
|
|
||||||
|
// If revisions are included, parse the commit object.
|
||||||
|
CURRENT_COMMIT: 3,
|
||||||
|
ALL_COMMITS: 4,
|
||||||
|
|
||||||
|
// If a patch set is included, include the files of the patch set.
|
||||||
|
CURRENT_FILES: 5,
|
||||||
|
ALL_FILES: 6,
|
||||||
|
|
||||||
|
// If accounts are included, include detailed account info.
|
||||||
|
DETAILED_ACCOUNTS: 7,
|
||||||
|
|
||||||
|
// Include messages associated with the change.
|
||||||
|
MESSAGES: 9,
|
||||||
|
|
||||||
|
// Include allowed actions client could perform.
|
||||||
|
CURRENT_ACTIONS: 10,
|
||||||
|
|
||||||
|
// Set the reviewed boolean for the caller.
|
||||||
|
REVIEWED: 11,
|
||||||
|
|
||||||
|
// Include download commands for the caller.
|
||||||
|
DOWNLOAD_COMMANDS: 13,
|
||||||
|
|
||||||
|
// Include patch set weblinks.
|
||||||
|
WEB_LINKS: 14,
|
||||||
|
|
||||||
|
// Include consistency check results.
|
||||||
|
CHECK: 15,
|
||||||
|
|
||||||
|
// Include allowed change actions client could perform.
|
||||||
|
CHANGE_ACTIONS: 16,
|
||||||
|
|
||||||
|
// Include a copy of commit messages including review footers.
|
||||||
|
COMMIT_FOOTERS: 17,
|
||||||
|
|
||||||
|
// Include push certificate information along with any patch sets.
|
||||||
|
PUSH_CERTIFICATES: 18
|
||||||
|
};
|
||||||
|
|
||||||
Polymer({
|
Polymer({
|
||||||
is: 'gr-rest-api-interface',
|
is: 'gr-rest-api-interface',
|
||||||
|
|
||||||
@@ -86,6 +134,11 @@
|
|||||||
return this._fetchSharedCacheURL('/config/server/info');
|
return this._fetchSharedCacheURL('/config/server/info');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getProjectConfig: function(project) {
|
||||||
|
return this._fetchSharedCacheURL(
|
||||||
|
'/projects/' + encodeURIComponent(project) + '/config');
|
||||||
|
},
|
||||||
|
|
||||||
getVersion: function() {
|
getVersion: function() {
|
||||||
return this._fetchSharedCacheURL('/config/server/version');
|
return this._fetchSharedCacheURL('/config/server/version');
|
||||||
},
|
},
|
||||||
@@ -135,6 +188,23 @@
|
|||||||
return this._sharedFetchPromises[url];
|
return this._sharedFetchPromises[url];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getChangeDetail: function(changeNum, opt_cancelCondition) {
|
||||||
|
var options = this._listChangesOptionsToHex(
|
||||||
|
ListChangesOption.ALL_REVISIONS,
|
||||||
|
ListChangesOption.CHANGE_ACTIONS,
|
||||||
|
ListChangesOption.DOWNLOAD_COMMANDS
|
||||||
|
);
|
||||||
|
return this.fetchJSON(
|
||||||
|
this._changeBaseURL(changeNum) + '/detail',
|
||||||
|
opt_cancelCondition,
|
||||||
|
{O: options});
|
||||||
|
},
|
||||||
|
|
||||||
|
getChangeCommitInfo: function(changeNum, patchNum) {
|
||||||
|
return this.fetchJSON(
|
||||||
|
this._changeBaseURL(changeNum, patchNum) + '/commit?links');
|
||||||
|
},
|
||||||
|
|
||||||
getChangeFiles: function(changeNum, patchNum) {
|
getChangeFiles: function(changeNum, patchNum) {
|
||||||
return this.fetchJSON(
|
return this.fetchJSON(
|
||||||
this._changeBaseURL(changeNum, patchNum) + '/files');
|
this._changeBaseURL(changeNum, patchNum) + '/files');
|
||||||
@@ -215,7 +285,7 @@
|
|||||||
opt_patchNum, opt_path) {
|
opt_patchNum, opt_path) {
|
||||||
if (!opt_basePatchNum && !opt_patchNum && !opt_path) {
|
if (!opt_basePatchNum && !opt_patchNum && !opt_path) {
|
||||||
return this.fetchJSON(
|
return this.fetchJSON(
|
||||||
this._getDiffCommentsFetchURL(changeNum, '/drafts'));
|
this._getDiffCommentsFetchURL(changeNum, endpoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
function onlyParent(c) { return c.side == PARENT_PATCH_NUM; }
|
function onlyParent(c) { return c.side == PARENT_PATCH_NUM; }
|
||||||
@@ -262,6 +332,14 @@
|
|||||||
return v;
|
return v;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_listChangesOptionsToHex: function() {
|
||||||
|
var v = 0;
|
||||||
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
|
v |= 1 << arguments[i];
|
||||||
|
}
|
||||||
|
return v.toString(16);
|
||||||
|
},
|
||||||
|
|
||||||
_getCookie: function(name) {
|
_getCookie: function(name) {
|
||||||
var key = name + '=';
|
var key = name + '=';
|
||||||
var cookies = document.cookie.split(';');
|
var cookies = document.cookie.split(';');
|
||||||
|
Reference in New Issue
Block a user