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:
parent
bd626a9faa
commit
706106408c
|
@ -300,6 +300,16 @@
|
||||||
addDetailView: function(detailView) {
|
addDetailView: function(detailView) {
|
||||||
this._detailFileInfoViews.push(detailView);
|
this._detailFileInfoViews.push(detailView);
|
||||||
this._dirty = true;
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3018,6 +3018,21 @@
|
||||||
if (this.breadcrumb) {
|
if (this.breadcrumb) {
|
||||||
this.breadcrumb.addDetailView(detailView);
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,27 @@ describe('OCA.Files.DetailsView tests', function() {
|
||||||
expect(detailsView.$el.find('.tabsContainer').length).toEqual(1);
|
expect(detailsView.$el.find('.tabsContainer').length).toEqual(1);
|
||||||
});
|
});
|
||||||
describe('file info detail view', function() {
|
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() {
|
it('renders registered view', function() {
|
||||||
var testView = new OCA.Files.DetailFileInfoView();
|
var testView = new OCA.Files.DetailFileInfoView();
|
||||||
var testView2 = new OCA.Files.DetailFileInfoView();
|
var testView2 = new OCA.Files.DetailFileInfoView();
|
||||||
|
|
|
@ -2116,10 +2116,12 @@ describe('OCA.Files.FileList tests', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
addTabStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addTabView');
|
addTabStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addTabView');
|
||||||
addDetailStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addDetailView');
|
addDetailStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addDetailView');
|
||||||
|
getDetailsStub = sinon.stub(OCA.Files.DetailsView.prototype, 'getDetailViews');
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
addTabStub.restore();
|
addTabStub.restore();
|
||||||
addDetailStub.restore();
|
addDetailStub.restore();
|
||||||
|
getDetailsStub.restore();
|
||||||
});
|
});
|
||||||
it('forward the registered views to the underlying DetailsView', function() {
|
it('forward the registered views to the underlying DetailsView', function() {
|
||||||
fileList.destroy();
|
fileList.destroy();
|
||||||
|
@ -2133,6 +2135,19 @@ describe('OCA.Files.FileList tests', function() {
|
||||||
// twice because the filelist already registers one by default
|
// twice because the filelist already registers one by default
|
||||||
expect(addDetailStub.calledTwice).toEqual(true);
|
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() {
|
it('does not error when registering panels when not details view configured', function() {
|
||||||
fileList.destroy();
|
fileList.destroy();
|
||||||
fileList = new OCA.Files.FileList($('#app-content-files'), {
|
fileList = new OCA.Files.FileList($('#app-content-files'), {
|
||||||
|
@ -2144,6 +2159,17 @@ describe('OCA.Files.FileList tests', function() {
|
||||||
expect(addTabStub.notCalled).toEqual(true);
|
expect(addTabStub.notCalled).toEqual(true);
|
||||||
expect(addDetailStub.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() {
|
it('triggers file action when clicking on row if no details view configured', function() {
|
||||||
fileList.destroy();
|
fileList.destroy();
|
||||||
|
|
Loading…
Reference in New Issue