Add repo header to project search

Bug: Issue 7921
Change-Id: Iec3d768e49bfc7a06a1ea143ced9967c3f481bd2
This commit is contained in:
Becky Siegel
2018-01-05 14:18:05 -08:00
parent a919cb69c2
commit 20789303ca
8 changed files with 267 additions and 33 deletions

View File

@@ -22,6 +22,7 @@ limitations under the License.
<link rel="import" href="../../shared/gr-icons/gr-icons.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../gr-change-list/gr-change-list.html">
<link rel="import" href="../gr-repo-header/gr-repo-header.html">
<link rel="import" href="../gr-user-header/gr-user-header.html">
<link rel="import" href="../../../styles/shared-styles.html">
@@ -39,7 +40,8 @@ limitations under the License.
gr-change-list {
width: 100%;
}
gr-user-header {
gr-user-header,
gr-repo-header {
border-bottom: 1px solid #ddd;
}
nav {
@@ -71,11 +73,14 @@ limitations under the License.
</style>
<div class="loading" hidden$="[[!_loading]]" hidden>Loading...</div>
<div hidden$="[[_loading]]" hidden>
<gr-repo-header
repo="[[_repo]]"
class$="[[_computeHeaderClass(_repo)]]"></gr-repo-header>
<gr-user-header
user-id="[[_userId]]"
show-dashboard-link
logged-in="[[_loggedIn]]"
class$="[[_computeUserHeaderClass(_userId)]]"></gr-user-header>
class$="[[_computeHeaderClass(_userId)]]"></gr-user-header>
<gr-change-list
account="[[account]]"
changes="{{_changes}}"

View File

@@ -24,6 +24,9 @@
const USER_QUERY_PATTERN = /^owner:\s?("[^"]+"|[^ ]+)$/;
const REPO_QUERY_PATTERN =
/^project:\s?("[^"]+"|[^ ]+)(\sstatus\s?:(open|"open"))?$/;
const LIMIT_OPERATOR_PATTERN = /\blimit:(\d+)/i;
Polymer({
@@ -114,6 +117,12 @@
type: String,
value: null,
},
/** @type {?String} */
_repo: {
type: String,
value: null,
},
},
listeners: {
@@ -227,16 +236,22 @@
},
_changesChanged(changes) {
if (!changes || !changes.length ||
!USER_QUERY_PATTERN.test(this._query)) {
this._userId = null;
this._userId = null;
this._repo = null;
if (!changes || !changes.length) {
return;
}
this._userId = changes[0].owner.email;
if (USER_QUERY_PATTERN.test(this._query) && changes[0].owner.email) {
this._userId = changes[0].owner.email;
return;
}
if (REPO_QUERY_PATTERN.test(this._query)) {
this._repo = changes[0].project;
}
},
_computeUserHeaderClass(userId) {
return userId ? '' : 'hide';
_computeHeaderClass(id) {
return id ? '' : 'hide';
},
_computePage(offset, changesPerPage) {

View File

@@ -156,6 +156,42 @@ limitations under the License.
});
});
test('_userId query without email', done => {
assert.isNull(element._userId);
element._query = 'owner: foo@bar';
element._changes = [{owner: {}}];
flush(() => {
assert.isNull(element._userId);
done();
});
});
test('_repo query', done => {
assert.isNull(element._repo);
element._query = 'project: test-repo';
element._changes = [{owner: {email: 'foo@bar'}, project: 'test-repo'}];
flush(() => {
assert.equal(element._repo, 'test-repo');
element._query = 'foo bar baz';
element._changes = [{owner: {email: 'foo@bar'}}];
assert.isNull(element._repo);
done();
});
});
test('_repo query with open status', done => {
assert.isNull(element._repo);
element._query = 'project:test-repo status:open';
element._changes = [{owner: {email: 'foo@bar'}, project: 'test-repo'}];
flush(() => {
assert.equal(element._repo, 'test-repo');
element._query = 'foo bar baz';
element._changes = [{owner: {email: 'foo@bar'}}];
assert.isNull(element._repo);
done();
});
});
suite('query based navigation', () => {
setup(() => {
sandbox.stub(Gerrit.Nav, 'getUrlForChange', () => '/r/c/1');

View File

@@ -0,0 +1,41 @@
<!--
@license
Copyright (C) 2018 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.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../styles/dashboard-header-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-date-formatter/gr-date-formatter.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<dom-module id="gr-repo-header">
<template>
<style include="shared-styles"></style>
<style include="dashboard-header-styles"></style>
<div class="info">
<h1 class$="name">
[[repo]]
<hr/>
</h1>
<div>
<span>Detail:</span> <a href$="[[_repoUrl]]">Repo settings</a>
</div>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
</template>
<script src="gr-repo-header.js"></script>
</dom-module>

View File

@@ -0,0 +1,39 @@
/**
* @license
* Copyright (C) 2018 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.
*/
(function() {
'use strict';
Polymer({
is: 'gr-repo-header',
properties: {
/** @type {?String} */
repo: {
type: String,
observer: '_repoChanged',
},
_repoUrl: String,
},
_repoChanged(repoName) {
if (!repoName) {
this._repoUrl = null;
return;
}
this._repoUrl = Gerrit.Nav.getUrlForRepo(repoName);
},
});
})();

View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<!--
@license
Copyright (C) 2018 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.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>gr-repo-header</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-repo-header.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-repo-header></gr-repo-header>
</template>
</test-fixture>
<script>
suite('gr-repo-header tests', () => {
let element;
let sandbox;
setup(() => {
sandbox = sinon.sandbox.create();
element = fixture('basic');
});
teardown(() => { sandbox.restore(); });
test('loads and clears account info', done => {
sandbox.stub(element.$.restAPI, 'getAccountDetails')
.returns(Promise.resolve({
name: 'foo',
email: 'bar',
registered_on: '2015-03-12 18:32:08.000000000',
}));
sandbox.stub(element.$.restAPI, 'getAccountStatus')
.returns(Promise.resolve('baz'));
element.userId = 'foo.bar@baz';
flush(() => {
assert.isOk(element._accountDetails);
assert.isOk(element._status);
element.userId = null;
flush(() => {
flushAsynchronousOperations();
assert.isNull(element._accountDetails);
assert.isNull(element._status);
done();
});
});
});
});
</script>

View File

@@ -20,35 +20,13 @@ limitations under the License.
<link rel="import" href="../../shared/gr-avatar/gr-avatar.html">
<link rel="import" href="../../shared/gr-date-formatter/gr-date-formatter.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../../../styles/dashboard-header-styles.html">
<link rel="import" href="../../../styles/shared-styles.html">
<dom-module id="gr-user-header">
<template>
<style include="shared-styles">
:host {
display: block;
height: 9em;
width: 100%;
}
gr-avatar {
display: inline-block;
height: 7em;
left: 1em;
margin: 1em;
top: 1em;
width: 7em;
}
.info {
display: inline-block;
padding: 1em;
vertical-align: top;
}
.info > div > span {
display: inline-block;
font-weight: bold;
text-align: right;
width: 4em;
}
<style include="shared-styles"></style>
<style include="dashboard-header-styles">
.name {
display: inline-block;
}

View File

@@ -0,0 +1,47 @@
<!--
@license
Copyright (C) 2018 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.
-->
<dom-module id="dashboard-header-styles">
<template>
<style>
:host {
display: block;
height: 9em;
width: 100%;
}
gr-avatar {
display: inline-block;
height: 7em;
left: 1em;
margin: 1em;
top: 1em;
width: 7em;
}
.info {
display: inline-block;
padding: 1em;
vertical-align: top;
}
.info > div > span {
display: inline-block;
font-weight: bold;
text-align: right;
width: 4em;
}
</style>
</template>
</dom-module>