]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make possible to know the registered detail views in a details view
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 9 Jun 2017 01:14:23 +0000 (03:14 +0200)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Tue, 13 Jun 2017 14:41:20 +0000 (16:41 +0200)
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 <danxuliu@gmail.com>
apps/files/js/detailsview.js
apps/files/js/filelist.js
apps/files/tests/js/detailsviewSpec.js
apps/files/tests/js/filelistSpec.js

index f04adcf1292e05528177f829ff75de8506d89aa3..e53922ebb69423df3e15e40d9324ebcb44b55017 100644 (file)
                addDetailView: function(detailView) {
                        this._detailFileInfoViews.push(detailView);
                        this._dirty = true;
+               },
+
+               /**
+                * Returns an array with the added DetailFileInfoViews.
+                *
+                * @return Array<OCA.Files.DetailFileInfoView> an array with the added
+                *         DetailFileInfoViews.
+                */
+               getDetailViews: function() {
+                       return [].concat(this._detailFileInfoViews);
                }
        });
 
index 187ede8c0bd715f49b983c596a203cd82b9c6337..b746588889baaf81b45e5ba9aa00b6c291349219 100644 (file)
                        if (this.breadcrumb) {
                                this.breadcrumb.addDetailView(detailView);
                        }
+               },
+
+               /**
+                * Returns the registered detail views.
+                *
+                * @return null|Array<OCA.Files.DetailFileInfoView> 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;
                }
        };
 
index 26a16b31530cce42d5631272805952d9d66f9bb0..0f483728bff103c8d2b7ae18c1cee7de0ffee1e9 100644 (file)
@@ -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();
index 6b403e7fa856adc9b6b1e3732d3cfcef05fa5f81..b7ee9c8554e8a6639b606d981d8f988b426ee195 100644 (file)
@@ -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();