Add repo header to project search Bug: Issue 7921 Change-Id: Iec3d768e49bfc7a06a1ea143ced9967c3f481bd2
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.html b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.html index a9c3c6f..8f12f05 100644 --- a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.html +++ b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.html
@@ -22,6 +22,7 @@ <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 @@ gr-change-list { width: 100%; } - gr-user-header { + gr-user-header, + gr-repo-header { border-bottom: 1px solid #ddd; } nav { @@ -71,11 +73,14 @@ </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}}"
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.js b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.js index 1728bc1..ceb4b4d 100644 --- a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.js +++ b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.js
@@ -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) {
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view_test.html b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view_test.html index 2091c7d..3911364 100644 --- a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view_test.html +++ b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view_test.html
@@ -156,6 +156,42 @@ }); }); + 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');
diff --git a/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header.html b/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header.html new file mode 100644 index 0000000..2328725 --- /dev/null +++ b/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header.html
@@ -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>
diff --git a/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header.js b/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header.js new file mode 100644 index 0000000..a3f9a9e --- /dev/null +++ b/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header.js
@@ -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); + }, + }); +})();
diff --git a/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header_test.html b/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header_test.html new file mode 100644 index 0000000..a561e09 --- /dev/null +++ b/polygerrit-ui/app/elements/change-list/gr-repo-header/gr-repo-header_test.html
@@ -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>
diff --git a/polygerrit-ui/app/elements/change-list/gr-user-header/gr-user-header.html b/polygerrit-ui/app/elements/change-list/gr-user-header/gr-user-header.html index 1c19ab2..89e2b7d 100644 --- a/polygerrit-ui/app/elements/change-list/gr-user-header/gr-user-header.html +++ b/polygerrit-ui/app/elements/change-list/gr-user-header/gr-user-header.html
@@ -20,35 +20,13 @@ <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; }
diff --git a/polygerrit-ui/app/styles/dashboard-header-styles.html b/polygerrit-ui/app/styles/dashboard-header-styles.html new file mode 100644 index 0000000..1f06fb0 --- /dev/null +++ b/polygerrit-ui/app/styles/dashboard-header-styles.html
@@ -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>