Make possible to know the registered detail views in a details view

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>
This commit is contained in:
Daniel Calviño Sánchez 2017-06-09 03:14:23 +02:00
parent 423136d319
commit 0a3d9f25c1
4 changed files with 72 additions and 0 deletions

View File

@ -300,6 +300,16 @@
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);
}
});

View File

@ -3020,6 +3020,21 @@
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;
}
};

View 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();

View 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();