Skip to content

Commit

Permalink
Allow defining extraPropertyNames in cmv_grid
Browse files Browse the repository at this point in the history
  • Loading branch information
fergaldoyle committed Feb 16, 2024
1 parent 2830abb commit 94d36a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/controller/grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,15 +529,17 @@ Ext.define('CpsiMapview.controller.grid.Grid', {
* the WFS propertyName so only data to
* be displayed is returned. The idProperty will
* always be returned even if the column is hidden.
* Merge in an extraPropertyNames defined in the viewModel
*/
getVisibleColumns: function () {

var me = this;
var viewModel = me.getViewModel();
var grid = me.getView();
var store = grid.getStore();
var extraPropertyNames = viewModel.get('extraPropertyNames');

var visibleColumnNames, idProperty;

if (!store.isEmptyStore) {
visibleColumnNames = Ext.Array.pluck(grid.getVisibleColumns(), 'dataIndex');
idProperty = store.model.prototype.idField.name;
Expand All @@ -550,7 +552,7 @@ Ext.define('CpsiMapview.controller.grid.Grid', {
// remove any null columns which may have been created by
// selection checkboxes for example
visibleColumnNames = Ext.Array.clean(visibleColumnNames);
store.propertyName = visibleColumnNames.join(',');
store.propertyName = Ext.Array.merge(visibleColumnNames, extraPropertyNames).join(',');
}
},

Expand Down
3 changes: 2 additions & 1 deletion app/model/grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Ext.define('CpsiMapview.model.grid.Grid', {
usePresetFilters: false,
clearFiltersVisible: true,
exportExcelVisible: true,
exportShapefileVisible: true
exportShapefileVisible: true,
extraPropertyNames: []
},

formulas: {
Expand Down
35 changes: 33 additions & 2 deletions test/spec/controller/grid/Grid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ describe('CpsiMapview.controller.grid.Grid', function () {
var menuItems = menu.down('[itemId=columnItem]').menu.items.items;
var orderedTitles = menuItems.map(function (item) {
return item.text;
})
});

// deep array comparison - original order without sorting would be [ 'Test1', 'Test3', 'Test2' ]
// deep array comparison - original order without sorting
// would be [ 'Test1', 'Test3', 'Test2' ]
expect(orderedTitles).to.eql(['Test1', 'Test2', 'Test3']);
});

Expand All @@ -52,5 +53,35 @@ describe('CpsiMapview.controller.grid.Grid', function () {
view.getEl().down('.x-column-header-trigger').dom.click();
});

it('Gets visible columns, adds Id prop and any extra propertyNames', function() {
var store = view.getStore();
var vm = ctrl.getViewModel();

vm.set('extraPropertyNames', ['Extra']);

// emulate a populated store
store.isEmptyStore = false;

// set fixture columns
view.setColumns([{
text: 'Test1',
dataIndex: 'Test1',
}, {
text: 'Test2',
dataIndex: 'Test2',
hidden: true,
}, {
text: 'Test3',
dataIndex: 'Test3',
}]);

ctrl.getVisibleColumns();

// revert back to true to prevent errors in other tests
store.isEmptyStore = true;

expect(store.propertyName).to.be('id,Test1,Test3,Extra');
});

});
});

0 comments on commit 94d36a3

Please sign in to comment.