From cb37d118f62433916bc3d0a0c0b2058b45665b07 Mon Sep 17 00:00:00 2001 From: Becky Siegel Date: Wed, 5 Jul 2017 17:05:55 -0700 Subject: [PATCH] Update gr-admin-project-list to use create button Instead of having Create Project in the Side nav, include the button at the top of the list view. Create project now shows in a modal and not a separate page. Change-Id: Ic22330680aa61249df8866f8782c440caf7e4ec5 --- .../gr-admin-create-project.html | 108 ------------------ .../gr-admin-project-list.html | 31 ++++- .../gr-admin-project-list.js | 33 ++++++ .../gr-admin-project-list_test.html | 26 +++++ .../admin/gr-admin-view/gr-admin-view.html | 6 +- .../admin/gr-admin-view/gr-admin-view.js | 11 +- .../gr-admin-view/gr-admin-view_test.html | 4 +- .../gr-create-project-dialog.html | 103 +++++++++++++++++ .../gr-create-project-dialog.js} | 59 +++++----- .../gr-create-project-dialog_test.html} | 47 +++----- .../app/elements/core/gr-router/gr-router.js | 17 --- polygerrit-ui/app/test/index.html | 2 +- 12 files changed, 240 insertions(+), 207 deletions(-) delete mode 100644 polygerrit-ui/app/elements/admin/gr-admin-create-project/gr-admin-create-project.html create mode 100644 polygerrit-ui/app/elements/admin/gr-create-project-dialog/gr-create-project-dialog.html rename polygerrit-ui/app/elements/admin/{gr-admin-create-project/gr-admin-create-project.js => gr-create-project-dialog/gr-create-project-dialog.js} (69%) rename polygerrit-ui/app/elements/admin/{gr-admin-create-project/gr-admin-create-project_test.html => gr-create-project-dialog/gr-create-project-dialog_test.html} (72%) diff --git a/polygerrit-ui/app/elements/admin/gr-admin-create-project/gr-admin-create-project.html b/polygerrit-ui/app/elements/admin/gr-admin-create-project/gr-admin-create-project.html deleted file mode 100644 index 03fb8abc23..0000000000 --- a/polygerrit-ui/app/elements/admin/gr-admin-create-project/gr-admin-create-project.html +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list.html b/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list.html index 45a6e4a586..0f49e58f60 100644 --- a/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list.html +++ b/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list.html @@ -13,25 +13,29 @@ 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. --> + - - - - + + + + + + + +
+ Create Project +
+
+ +
+
+
diff --git a/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list.js b/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list.js index 8cd804fc54..1610456ddb 100644 --- a/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list.js +++ b/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list.js @@ -35,6 +35,11 @@ readOnly: true, value: '/admin/projects', }, + _hasNewProjectName: Boolean, + _createNewCapability: { + type: Boolean, + value: false, + }, _projects: Array, /** @@ -62,6 +67,10 @@ Gerrit.ListViewBehavior, ], + attached() { + this._getCreateProjectCapability(); + }, + _paramsChanged(params) { this._loading = true; this._filter = this.getFilterValue(params); @@ -75,6 +84,18 @@ return this.getUrl(this._path + '/', name); }, + _getCreateProjectCapability() { + return this.$.restAPI.getAccount().then(account => { + if (!account) { return; } + return this.$.restAPI.getAccountCapabilities(['createProject']) + .then(capabilities => { + if (capabilities.createProject) { + this._createNewCapability = true; + } + }); + }); + }, + _getProjects(filter, projectsPerPage, offset) { this._projects = []; return this.$.restAPI.getProjects(filter, projectsPerPage, offset) @@ -92,6 +113,18 @@ }); }, + _handleCreateProject() { + this.$.createNewModal.handleCreateProject(); + }, + + _handleCloseCreate() { + this.$.createOverlay.close(); + }, + + _handleCreateClicked() { + this.$.createOverlay.open(); + }, + _readOnly(item) { return item.state === 'READ_ONLY' ? 'Y' : 'N'; }, diff --git a/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list_test.html b/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list_test.html index 1292bc57e5..ee3f832986 100644 --- a/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list_test.html +++ b/polygerrit-ui/app/elements/admin/gr-admin-project-list/gr-admin-project-list_test.html @@ -137,5 +137,31 @@ limitations under the License. assert.equal(getComputedStyle(element.$.loading).display, 'none'); }); }); + + suite('create new', () => { + test('_handleCreateClicked called when create-click fired', () => { + sandbox.stub(element, '_handleCreateClicked'); + element.$$('gr-list-view').fire('create-clicked'); + assert.isTrue(element._handleCreateClicked.called); + }); + + test('_handleCreateClicked opens modal', () => { + const openStub = sandbox.stub(element.$.createOverlay, 'open'); + element._handleCreateClicked(); + assert.isTrue(openStub.called); + }); + + test('_handleCreateProject called when confirm fired', () => { + sandbox.stub(element, '_handleCreateProject'); + element.$.createDialog.fire('confirm'); + assert.isTrue(element._handleCreateProject.called); + }); + + test('_handleCloseCreate called when cancel fired', () => { + sandbox.stub(element, '_handleCloseCreate'); + element.$.createDialog.fire('cancel'); + assert.isTrue(element._handleCloseCreate.called); + }); + }); }); diff --git a/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.html b/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.html index 74e1f80bec..b48e5c9f14 100644 --- a/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.html +++ b/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.html @@ -23,7 +23,7 @@ limitations under the License. - + @@ -89,9 +89,9 @@ limitations under the License.