Merge "Add top level admin dropdown to gr-main-header"
This commit is contained in:
@@ -91,13 +91,16 @@ limitations under the License.
|
|||||||
let links = ADMIN_LINKS.slice(0);
|
let links = ADMIN_LINKS.slice(0);
|
||||||
let expandedSection;
|
let expandedSection;
|
||||||
|
|
||||||
|
const isExernalLink = link => link.url[0] !== '/';
|
||||||
|
|
||||||
// Append top-level links that are defined by plugins.
|
// Append top-level links that are defined by plugins.
|
||||||
links.push(...getAdminMenuLinks().map(link => ({
|
links.push(...getAdminMenuLinks().map(link => ({
|
||||||
url: link.url,
|
url: link.url,
|
||||||
name: link.text,
|
name: link.text,
|
||||||
noBaseUrl: link.url[0] === '/',
|
noBaseUrl: !isExernalLink(link),
|
||||||
view: null,
|
view: null,
|
||||||
viewableToAll: true,
|
viewableToAll: true,
|
||||||
|
target: isExernalLink(link) ? '_blank' : null,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
links = links.filter(filterFn);
|
links = links.filter(filterFn);
|
||||||
|
@@ -93,9 +93,17 @@ limitations under the License.
|
|||||||
|
|
||||||
if (expected.pluginGeneratedLinks) {
|
if (expected.pluginGeneratedLinks) {
|
||||||
for (const link of expected.pluginGeneratedLinks) {
|
for (const link of expected.pluginGeneratedLinks) {
|
||||||
assert.isTrue(!!res.links.find(l => {
|
const linkMatch = res.links.find(l => {
|
||||||
return (l.url === link.url && l.name === link.text);
|
return (l.url === link.url && l.name === link.text);
|
||||||
}));
|
});
|
||||||
|
assert.isTrue(!!linkMatch);
|
||||||
|
|
||||||
|
// External links should open in new tab.
|
||||||
|
if (link.url[0] !== '/') {
|
||||||
|
assert.equal(linkMatch.target, '_blank');
|
||||||
|
} else {
|
||||||
|
assert.isNotOk(linkMatch.target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -162,6 +162,7 @@ limitations under the License.
|
|||||||
noBaseUrl: true,
|
noBaseUrl: true,
|
||||||
view: null,
|
view: null,
|
||||||
viewableToAll: true,
|
viewableToAll: true,
|
||||||
|
target: null,
|
||||||
});
|
});
|
||||||
assert.deepEqual(element._filteredLinks[2], {
|
assert.deepEqual(element._filteredLinks[2], {
|
||||||
url: 'http://external/link/url',
|
url: 'http://external/link/url',
|
||||||
@@ -169,6 +170,7 @@ limitations under the License.
|
|||||||
noBaseUrl: false,
|
noBaseUrl: false,
|
||||||
view: null,
|
view: null,
|
||||||
viewableToAll: true,
|
viewableToAll: true,
|
||||||
|
target: '_blank',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -18,8 +18,10 @@ limitations under the License.
|
|||||||
|
|
||||||
<link rel="import" href="../../../behaviors/docs-url-behavior/docs-url-behavior.html">
|
<link rel="import" href="../../../behaviors/docs-url-behavior/docs-url-behavior.html">
|
||||||
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
|
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
|
||||||
|
<link rel="import" href="../../../behaviors/gr-admin-nav-behavior/gr-admin-nav-behavior.html">
|
||||||
<link rel="import" href="../../plugins/gr-endpoint-decorator/gr-endpoint-decorator.html">
|
<link rel="import" href="../../plugins/gr-endpoint-decorator/gr-endpoint-decorator.html">
|
||||||
<link rel="import" href="../../shared/gr-dropdown/gr-dropdown.html">
|
<link rel="import" href="../../shared/gr-dropdown/gr-dropdown.html">
|
||||||
|
<link rel="import" href="../../shared/gr-js-api-interface/gr-js-api-interface.html">
|
||||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||||
<link rel="import" href="../gr-account-dropdown/gr-account-dropdown.html">
|
<link rel="import" href="../gr-account-dropdown/gr-account-dropdown.html">
|
||||||
<link rel="import" href="../gr-smart-search/gr-smart-search.html">
|
<link rel="import" href="../gr-smart-search/gr-smart-search.html">
|
||||||
@@ -170,12 +172,6 @@ limitations under the License.
|
|||||||
</gr-dropdown>
|
</gr-dropdown>
|
||||||
</li>
|
</li>
|
||||||
</template>
|
</template>
|
||||||
<li>
|
|
||||||
<a
|
|
||||||
class="browse linksTitle"
|
|
||||||
href$="[[_computeRelativeURL('/admin/repos')]]">
|
|
||||||
Browse</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<div class="rightItems">
|
<div class="rightItems">
|
||||||
<gr-smart-search
|
<gr-smart-search
|
||||||
@@ -190,6 +186,7 @@ limitations under the License.
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
|
||||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||||
</template>
|
</template>
|
||||||
<script src="gr-main-header.js"></script>
|
<script src="gr-main-header.js"></script>
|
||||||
|
@@ -93,7 +93,8 @@
|
|||||||
},
|
},
|
||||||
_links: {
|
_links: {
|
||||||
type: Array,
|
type: Array,
|
||||||
computed: '_computeLinks(_defaultLinks, _userLinks, _docBaseUrl)',
|
computed: '_computeLinks(_defaultLinks, _userLinks, _adminLinks, ' +
|
||||||
|
'_docBaseUrl)',
|
||||||
},
|
},
|
||||||
_loginURL: {
|
_loginURL: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -106,6 +107,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
behaviors: [
|
behaviors: [
|
||||||
|
Gerrit.AdminNavBehavior,
|
||||||
Gerrit.BaseUrlBehavior,
|
Gerrit.BaseUrlBehavior,
|
||||||
Gerrit.DocsUrlBehavior,
|
Gerrit.DocsUrlBehavior,
|
||||||
],
|
],
|
||||||
@@ -149,7 +151,7 @@
|
|||||||
return '//' + window.location.host + this.getBaseUrl() + path;
|
return '//' + window.location.host + this.getBaseUrl() + path;
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeLinks(defaultLinks, userLinks, docBaseUrl) {
|
_computeLinks(defaultLinks, userLinks, adminLinks, docBaseUrl) {
|
||||||
const links = defaultLinks.slice();
|
const links = defaultLinks.slice();
|
||||||
if (userLinks && userLinks.length > 0) {
|
if (userLinks && userLinks.length > 0) {
|
||||||
links.push({
|
links.push({
|
||||||
@@ -165,6 +167,10 @@
|
|||||||
class: 'hideOnMobile',
|
class: 'hideOnMobile',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
links.push({
|
||||||
|
title: 'Browse',
|
||||||
|
links: adminLinks,
|
||||||
|
});
|
||||||
return links;
|
return links;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -186,10 +192,23 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_loadAccount() {
|
_loadAccount() {
|
||||||
return this.$.restAPI.getAccount().then(account => {
|
const promises = [
|
||||||
|
this.$.restAPI.getAccount(),
|
||||||
|
Gerrit.awaitPluginsLoaded(),
|
||||||
|
];
|
||||||
|
|
||||||
|
return Promise.all(promises).then(result => {
|
||||||
|
const account = result[0];
|
||||||
this._account = account;
|
this._account = account;
|
||||||
this.$.accountContainer.classList.toggle('loggedIn', account != null);
|
this.$.accountContainer.classList.toggle('loggedIn', account != null);
|
||||||
this.$.accountContainer.classList.toggle('loggedOut', account == null);
|
this.$.accountContainer.classList.toggle('loggedOut', account == null);
|
||||||
|
|
||||||
|
return this.getAdminLinks(account,
|
||||||
|
this.$.restAPI.getAccountCapabilities.bind(this.$.restAPI),
|
||||||
|
this.$.jsAPI.getAdminMenuLinks.bind(this.$.jsAPI))
|
||||||
|
.then(res => {
|
||||||
|
this._adminLinks = res.links;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -87,15 +87,28 @@ limitations under the License.
|
|||||||
name: 'Facebook',
|
name: 'Facebook',
|
||||||
url: 'https://facebook.com',
|
url: 'https://facebook.com',
|
||||||
}];
|
}];
|
||||||
|
const adminLinks = [{
|
||||||
|
name: 'Repos',
|
||||||
|
url: '/repos',
|
||||||
|
}];
|
||||||
|
|
||||||
// When no admin links are passed, it should use the default.
|
// When no admin links are passed, it should use the default.
|
||||||
assert.deepEqual(element._computeLinks(defaultLinks, []), defaultLinks);
|
assert.deepEqual(element._computeLinks(defaultLinks, [], adminLinks),
|
||||||
assert.deepEqual(
|
|
||||||
element._computeLinks(defaultLinks, userLinks),
|
|
||||||
defaultLinks.concat({
|
defaultLinks.concat({
|
||||||
title: 'Your',
|
title: 'Browse',
|
||||||
links: userLinks,
|
links: adminLinks,
|
||||||
}));
|
}));
|
||||||
|
assert.deepEqual(
|
||||||
|
element._computeLinks(defaultLinks, userLinks, adminLinks),
|
||||||
|
defaultLinks.concat([
|
||||||
|
{
|
||||||
|
title: 'Your',
|
||||||
|
links: userLinks,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Browse',
|
||||||
|
links: adminLinks,
|
||||||
|
}]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('documentation links', () => {
|
test('documentation links', () => {
|
||||||
|
Reference in New Issue
Block a user