From 706106408c70a3ce9dd4b6569f71d05aa4f588cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 9 Jun 2017 03:14:23 +0200 Subject: [PATCH] Make possible to know the registered detail views in a details view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some cases, an app may need to act on a detail view registered by another app or the core, for example, to add extra elements to the element of the detail view. Signed-off-by: Daniel Calviño Sánchez --- apps/files/js/detailsview.js | 10 ++++++++++ apps/files/js/filelist.js | 15 +++++++++++++++ apps/files/tests/js/detailsviewSpec.js | 21 +++++++++++++++++++++ apps/files/tests/js/filelistSpec.js | 26 ++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/apps/files/js/detailsview.js b/apps/files/js/detailsview.js index f04adcf129..e53922ebb6 100644 --- a/apps/files/js/detailsview.js +++ b/apps/files/js/detailsview.js @@ -300,6 +300,16 @@ addDetailView: function(detailView) { this._detailFileInfoViews.push(detailView); this._dirty = true; + }, + + /** + * Returns an array with the added DetailFileInfoViews. + * + * @return Array an array with the added + * DetailFileInfoViews. + */ + getDetailViews: function() { + return [].concat(this._detailFileInfoViews); } }); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 187ede8c0b..b746588889 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -3018,6 +3018,21 @@ if (this.breadcrumb) { this.breadcrumb.addDetailView(detailView); } + }, + + /** + * Returns the registered detail views. + * + * @return null|Array an array with the + * registered DetailFileInfoViews, or null if the details view + * is not enabled. + */ + getRegisteredDetailViews: function() { + if (this._detailsView) { + return this._detailsView.getDetailViews(); + } + + return null; } }; diff --git a/apps/files/tests/js/detailsviewSpec.js b/apps/files/tests/js/detailsviewSpec.js index 26a16b3153..0f483728bf 100644 --- a/apps/files/tests/js/detailsviewSpec.js +++ b/apps/files/tests/js/detailsviewSpec.js @@ -35,6 +35,27 @@ describe('OCA.Files.DetailsView tests', function() { expect(detailsView.$el.find('.tabsContainer').length).toEqual(1); }); describe('file info detail view', function() { + it('returns registered view', function() { + var testView = new OCA.Files.DetailFileInfoView(); + var testView2 = new OCA.Files.DetailFileInfoView(); + detailsView.addDetailView(testView); + detailsView.addDetailView(testView2); + + detailViews = detailsView.getDetailViews(); + + expect(detailViews).toContain(testView); + expect(detailViews).toContain(testView2); + + // Modify array and check that registered detail views are not + // modified + detailViews.pop(); + detailViews.pop(); + + detailViews = detailsView.getDetailViews(); + + expect(detailViews).toContain(testView); + expect(detailViews).toContain(testView2); + }); it('renders registered view', function() { var testView = new OCA.Files.DetailFileInfoView(); var testView2 = new OCA.Files.DetailFileInfoView(); diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index 6b403e7fa8..b7ee9c8554 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -2116,10 +2116,12 @@ describe('OCA.Files.FileList tests', function() { beforeEach(function() { addTabStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addTabView'); addDetailStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addDetailView'); + getDetailsStub = sinon.stub(OCA.Files.DetailsView.prototype, 'getDetailViews'); }); afterEach(function() { addTabStub.restore(); addDetailStub.restore(); + getDetailsStub.restore(); }); it('forward the registered views to the underlying DetailsView', function() { fileList.destroy(); @@ -2133,6 +2135,19 @@ describe('OCA.Files.FileList tests', function() { // twice because the filelist already registers one by default expect(addDetailStub.calledTwice).toEqual(true); }); + it('forward getting the registered views to the underlying DetailsView', function() { + fileList.destroy(); + fileList = new OCA.Files.FileList($('#app-content-files'), { + detailsViewEnabled: true + }); + var expectedRegisteredDetailsView = []; + getDetailsStub.returns(expectedRegisteredDetailsView); + + var registeredDetailViews = fileList.getRegisteredDetailViews(); + + expect(getDetailsStub.calledOnce).toEqual(true); + expect(registeredDetailViews).toEqual(expectedRegisteredDetailsView); + }); it('does not error when registering panels when not details view configured', function() { fileList.destroy(); fileList = new OCA.Files.FileList($('#app-content-files'), { @@ -2144,6 +2159,17 @@ describe('OCA.Files.FileList tests', function() { expect(addTabStub.notCalled).toEqual(true); expect(addDetailStub.notCalled).toEqual(true); }); + it('returns null when getting the registered views when not details view configured', function() { + fileList.destroy(); + fileList = new OCA.Files.FileList($('#app-content-files'), { + detailsViewEnabled: false + }); + + var registeredDetailViews = fileList.getRegisteredDetailViews(); + + expect(getDetailsStub.notCalled).toEqual(true); + expect(registeredDetailViews).toBeNull(); + }); }); it('triggers file action when clicking on row if no details view configured', function() { fileList.destroy();