Update URL generation for groups

This change brings router abstraction to the group views (details,
members and audit log). The app params for these views are refactored to
use `Gerrit.Nav.View.GROUP` rather than `Gerrit.Nav.View.ADMIN`.

Change-Id: Ifa3e19c509c7f2f72e34bb05279bb3a45057cf2d
This commit is contained in:
Wyatt Allen
2017-10-19 15:06:54 -07:00
parent 3dad636aad
commit c172767012
9 changed files with 140 additions and 40 deletions

View File

@@ -20,6 +20,7 @@ limitations under the License.
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
<link rel="import" href="../../../styles/gr-table-styles.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<link rel="import" href="../../shared/gr-confirm-dialog/gr-confirm-dialog.html">
<link rel="import" href="../../shared/gr-list-view/gr-list-view.html">
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html">

View File

@@ -93,7 +93,7 @@
},
_computeGroupUrl(id) {
return this.getUrl(this._path + '/', id);
return Gerrit.Nav.getUrlForGroup(id);
},
_getCreateGroupCapability() {

View File

@@ -21,6 +21,7 @@ limitations under the License.
<link rel="import" href="../../../styles/gr-menu-page-styles.html">
<link rel="import" href="../../../styles/gr-page-nav-styles.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<link rel="import" href="../../shared/gr-page-nav/gr-page-nav.html">
<link rel="import" href="../../shared/gr-placeholder/gr-placeholder.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">

View File

@@ -148,14 +148,13 @@
linkCopy.subsection = {
name: this._groupName,
view: 'gr-group',
url: `/admin/groups/${this.encodeURL(this._groupId + '', true)}`,
url: Gerrit.Nav.getUrlForGroup(this._groupId),
children: [
{
name: 'Members',
detailType: 'members',
view: 'gr-group-members',
url: `/admin/groups/${this.encodeURL(this._groupId, true)}` +
',members',
url: Gerrit.Nav.getUrlForGroupMembers(this._groupId),
},
],
};
@@ -165,8 +164,7 @@
name: 'Audit Log',
detailType: 'audit-log',
view: 'gr-group-audit-log',
url: '/admin/groups/' +
`${this.encodeURL(this._groupId + '', true)},audit-log`,
url: Gerrit.Nav.getUrlForGroupLog(this._groupId),
}
);
}
@@ -187,19 +185,31 @@
},
_paramsChanged(params) {
this.set('_showGroup', params.adminView === 'gr-group');
this.set('_showGroupAuditLog', params.adminView === 'gr-group-audit-log');
this.set('_showGroupList', params.adminView === 'gr-admin-group-list');
this.set('_showGroupMembers', params.adminView === 'gr-group-members');
this.set('_showProjectCommands',
const isGroupView = params.view === Gerrit.Nav.View.GROUP;
const isAdminView = params.view === Gerrit.Nav.View.ADMIN;
this.set('_showGroup', isGroupView && !params.detail);
this.set('_showGroupAuditLog', isGroupView &&
params.detail === Gerrit.Nav.GroupDetailView.LOG);
this.set('_showGroupMembers', isGroupView &&
params.detail === Gerrit.Nav.GroupDetailView.MEMBERS);
this.set('_showGroupList', isAdminView &&
params.adminView === 'gr-admin-group-list');
this.set('_showProjectCommands', isAdminView &&
params.adminView === 'gr-project-commands');
this.set('_showProjectMain', params.adminView === 'gr-project');
this.set('_showProjectList',
this.set('_showProjectMain', isAdminView &&
params.adminView === 'gr-project');
this.set('_showProjectList', isAdminView &&
params.adminView === 'gr-project-list');
this.set('_showProjectDetailList',
this.set('_showProjectDetailList', isAdminView &&
params.adminView === 'gr-project-detail-list');
this.set('_showPluginList', params.adminView === 'gr-plugin-list');
this.set('_showProjectAccess', params.adminView === 'gr-project-access');
this.set('_showPluginList', isAdminView &&
params.adminView === 'gr-plugin-list');
this.set('_showProjectAccess', isAdminView &&
params.adminView === 'gr-project-access');
if (params.project !== this._projectName) {
this._projectName = params.project || '';
// Reloads the admin menu.

View File

@@ -75,6 +75,7 @@ limitations under the License.
}];
element.params = {
view: 'admin',
adminView: 'gr-project-list',
};
@@ -206,7 +207,7 @@ limitations under the License.
assert.isTrue(element.reload.called);
done();
});
element.params = {group: 1, adminView: 'gr-group'};
element.params = {group: 1, view: Gerrit.Nav.View.GROUP};
element._groupName = 'oldName';
flushAsynchronousOperations();
element.$$('gr-group').fire('name-changed', {name: newName});

View File

@@ -47,6 +47,11 @@ limitations under the License.
// - `leftSide`, optional, Boolean, if a `lineNum` is provided, a value
// of true selects the line from base of the patch range. False by
// default.
//
// - Gerrit.Nav.View.GROUP:
// - `groupId`, required, String, the ID of the group.
// - `detail`, optional, String, the name of the group detail view.
// Takes any value from Gerrit.Nav.GroupDetailView.
window.Gerrit = window.Gerrit || {};
@@ -71,6 +76,12 @@ limitations under the License.
EDIT: 'edit',
SEARCH: 'search',
SETTINGS: 'settings',
GROUP: 'group',
},
GroupDetailView: {
MEMBERS: 'members',
LOG: 'log',
},
/** @type {Function} */
@@ -315,6 +326,41 @@ limitations under the License.
}
this._navigate(relativeUrl);
},
/**
* @param {string} groupId
* @return {string}
*/
getUrlForGroup(groupId) {
return this._getUrlFor({
view: Gerrit.Nav.View.GROUP,
groupId,
});
},
/**
* @param {string} groupId
* @return {string}
*/
getUrlForGroupLog(groupId) {
return this._getUrlFor({
view: Gerrit.Nav.View.GROUP,
groupId,
detail: Gerrit.Nav.GroupDetailView.LOG,
});
},
/**
* @param {string} groupId
* @return {string}
*/
getUrlForGroupMembers(groupId) {
return this._getUrlFor({
view: Gerrit.Nav.View.GROUP,
groupId,
detail: Gerrit.Nav.GroupDetailView.MEMBERS,
});
},
};
})(window);
</script>

View File

@@ -204,6 +204,8 @@
url = this._generateDashboardUrl(params);
} else if (params.view === Views.DIFF || params.view === Views.EDIT) {
url = this._generateDiffOrEditUrl(params);
} else if (params.view === Views.GROUP) {
url = this._generateGroupUrl(params);
} else {
throw new Error('Can\'t generate');
}
@@ -313,6 +315,20 @@
}
},
/**
* @param {!Object} params
* @return {string}
*/
_generateGroupUrl(params) {
let url = `/admin/groups/${this.encodeURL(params.groupId + '', true)}`;
if (params.detail === Gerrit.Nav.GroupDetailView.MEMBERS) {
url += ',members';
} else if (params.detail === Gerrit.Nav.GroupDetailView.LOG) {
url += ',audit-log';
}
return url;
},
/**
* Given an object of parameters, potentially including a `patchNum` or a
* `basePatchNum` or both, return a string representation of that range. If
@@ -765,20 +781,25 @@
this._redirect('/admin/groups/' + encodeURIComponent(data.params[0]));
},
_handleGroupRoute(data) {
this._setParams({
view: Gerrit.Nav.View.GROUP,
groupId: data.params[0],
});
},
_handleGroupAuditLogRoute(data) {
this._setParams({
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-group-audit-log',
detailType: 'audit-log',
view: Gerrit.Nav.View.GROUP,
detail: Gerrit.Nav.GroupDetailView.LOG,
groupId: data.params[0],
});
},
_handleGroupMembersRoute(data) {
this._setParams({
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-group-members',
detailType: 'members',
view: Gerrit.Nav.View.GROUP,
detail: Gerrit.Nav.GroupDetailView.MEMBERS,
groupId: data.params[0],
});
},
@@ -810,14 +831,6 @@
});
},
_handleGroupRoute(data) {
this._setParams({
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-group',
groupId: data.params[0],
});
},
_handleProjectCommandsRoute(data) {
this._setParams({
view: Gerrit.Nav.View.ADMIN,

View File

@@ -365,6 +365,36 @@ limitations under the License.
'/dashboard/user?name=query&title=custom%20dashboard');
});
});
suite('groups', () => {
test('group info', () => {
const params = {
view: Gerrit.Nav.View.GROUP,
groupId: 1234,
};
assert.equal(element._generateUrl(params), '/admin/groups/1234');
});
test('group members', () => {
const params = {
view: Gerrit.Nav.View.GROUP,
groupId: 1234,
detail: 'members',
};
assert.equal(element._generateUrl(params),
'/admin/groups/1234,members');
});
test('group audit log', () => {
const params = {
view: Gerrit.Nav.View.GROUP,
groupId: 1234,
detail: 'log',
};
assert.equal(element._generateUrl(params),
'/admin/groups/1234,audit-log');
});
});
});
suite('param normalization', () => {
@@ -804,9 +834,8 @@ limitations under the License.
test('_handleGroupAuditLogRoute', () => {
const data = {params: {0: 1234}};
assertDataToParams(data, '_handleGroupAuditLogRoute', {
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-group-audit-log',
detailType: 'audit-log',
view: Gerrit.Nav.View.GROUP,
detail: 'log',
groupId: 1234,
});
});
@@ -814,9 +843,8 @@ limitations under the License.
test('_handleGroupMembersRoute', () => {
const data = {params: {0: 1234}};
assertDataToParams(data, '_handleGroupMembersRoute', {
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-group-members',
detailType: 'members',
view: Gerrit.Nav.View.GROUP,
detail: 'members',
groupId: 1234,
});
});
@@ -872,8 +900,7 @@ limitations under the License.
test('_handleGroupRoute', () => {
const data = {params: {0: 4321}};
assertDataToParams(data, '_handleGroupRoute', {
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-group',
view: Gerrit.Nav.View.GROUP,
groupId: 4321,
});
});

View File

@@ -138,7 +138,8 @@
this.set('_showChangeView', view === Gerrit.Nav.View.CHANGE);
this.set('_showDiffView', view === Gerrit.Nav.View.DIFF);
this.set('_showSettingsView', view === Gerrit.Nav.View.SETTINGS);
this.set('_showAdminView', view === Gerrit.Nav.View.ADMIN);
this.set('_showAdminView', view === Gerrit.Nav.View.ADMIN ||
view === Gerrit.Nav.View.GROUP);
this.set('_showCLAView', view === Gerrit.Nav.View.AGREEMENTS);
this.set('_showEditorView', view === Gerrit.Nav.View.EDIT);
if (this.params.justRegistered) {