Skip to content

Commit

Permalink
Merge pull request #149 from carrbrpoa/attributesTable/showOnlySelected
Browse files Browse the repository at this point in the history
Adjustments:
  • Loading branch information
tmcgee authored Jan 12, 2018
2 parents d9acb81 + f7c530c commit 9925415
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 5 deletions.
9 changes: 9 additions & 0 deletions widgets/AttributesTable/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ define([
this.clearFeatures(selection);
},

showOnlySelected: function () {
var selection = this.showOnlySelectedGridRows();
if (!selection) {
return;
}

this.showOnlySelectedFeatures(selection);
},

clearGrowl: function () {
var growl = registry.byId(this.growlID);
if (growl && growl.close) {
Expand Down
5 changes: 5 additions & 0 deletions widgets/AttributesTable/_FeaturesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ define([
topic.publish(this.attributesContainerID + '/tableUpdated', this);
},

showOnlySelectedFeatures: function (specificFeatures) {
this.showOnlySelectedFeatureGraphics(specificFeatures);
topic.publish(this.attributesContainerID + '/tableUpdated', this);
},

clearSelectedFeatures: function () {
if (this.grid && this.grid.clearSelection) {
this.grid.clearSelection();
Expand Down
31 changes: 31 additions & 0 deletions widgets/AttributesTable/_GraphicsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,14 @@ define([
}
},

showOnlySelectedFeatureGraphics: function (specificGraphics) {
this.keepSpecificGraphics(this.featureGraphics, specificGraphics);

this.setToolbarButtons();
topic.publish(this.attributesContainerID + '/tableUpdated', this);
this.zoomToFeatureGraphics();
},

clearSelectedGraphics: function () {
this.clearGraphicsLayer(this.selectedGraphics);
},
Expand Down Expand Up @@ -736,6 +744,29 @@ define([
}
},

keepSpecificGraphics: function (layer, specificGraphics) {
var selectionFilter = [];
for (var key in specificGraphics.selection) {
if (key) {
selectionFilter.push(key);
}
}

var specificGraphicsFound = layer.graphics.filter(function (graphic) {
var idProperty = graphic.attributes[specificGraphics.idProperty];
if (idProperty) {
return selectionFilter.indexOf(idProperty.toString()) < 0;
}
return false;
});

if (specificGraphicsFound.length > 0) {
array.forEach(specificGraphicsFound, function (graphic) {
layer.remove(graphic);
});
}
},

/*******************************
* Remove Graphic Layers
*******************************/
Expand Down
34 changes: 30 additions & 4 deletions widgets/AttributesTable/_GridMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,23 +453,49 @@ define([
return null;
}

var collection = this.grid.get('collection');
var selection = lang.clone(this.grid.get('selection'));
var store = this.grid.get('store');

if (!selection || !store) {
if (!selection || !collection || !collection.data) {
return null;
}

for (var key in selection) {
if (selection.hasOwnProperty(key) && selection[key] === true) {
store.remove(key);
collection.removeSync(key);
}
}

this.grid.refresh();

return {selection: selection, idProperty: this.idProperty};
}
},

showOnlySelectedGridRows: function () {
if (!this.grid) {
return null;
}

var collection = this.grid.get('collection');
var selection = lang.clone(this.grid.get('selection'));

var toKeep = [];

if (!selection || !collection || !collection.data) {
return null;
}

for (var key in selection) {
if (selection.hasOwnProperty(key) && selection[key] === true) {
toKeep.push(lang.clone(collection.getSync(key)));
}
}

collection.setData(toKeep);

this.grid.refresh();

return {selection: selection, idProperty: this.idProperty};
}
});
});
4 changes: 4 additions & 0 deletions widgets/AttributesTable/_ToolbarMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ define([
itemCount += (display === 'none') ? 0 : 1;
domStyle.set(this.attributesTableClearSelectedRecords.domNode, 'display', display);

display = (options.selected && featOptions.selected) ? 'block' : 'none';
itemCount += (display === 'none') ? 0 : 1;
domStyle.set(this.attributesTableShowOnlySelectedRecords.domNode, 'display', display);

//display = (options.show) ? 'block' : 'none';
display = (itemCount > 1) ? 'block' : 'none';
domStyle.set(this.attributesTableClearAll.domNode, 'display', display);
Expand Down
3 changes: 2 additions & 1 deletion widgets/AttributesTable/nls/AttributesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ define({
clearBufferGraphics: 'Clear Buffer',
clearGrid: 'Clear Grid',
clearAll: 'Clear All',
clearSelectedRecords: 'Clear Selected Record(s)'
clearSelectedRecords: 'Clear Selected Record(s)',
showOnlySelectedRecords: 'Show Only Selected Record(s)'
},

'export': {
Expand Down
1 change: 1 addition & 0 deletions widgets/AttributesTable/templates/AttributesTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<div data-dojo-type="dijit/MenuItem" data-dojo-attach-point="attributesTableClearGrid" data-dojo-attach-event="onClick:clearGrid">${i18n.menus.clear.clearGrid}</div>
<div data-dojo-type="dijit/MenuItem" data-dojo-attach-point="attributesTableClearAll" data-dojo-attach-event="onClick:clearAll">${i18n.menus.clear.clearAll}</div>
<div data-dojo-type="dijit/MenuItem" data-dojo-attach-point="attributesTableClearSelectedRecords" data-dojo-attach-event="onClick:clearSelected">${i18n.menus.clear.clearSelectedRecords}</div>
<div data-dojo-type="dijit/MenuItem" data-dojo-attach-point="attributesTableShowOnlySelectedRecords" data-dojo-attach-event="onClick:showOnlySelected">${i18n.menus.clear.showOnlySelectedRecords}</div>
</div>
</div>
<div data-dojo-type="dijit/form/Button" data-dojo-props="iconClass:'fa fa-download fa-fw','class':'attributesTableExportMenu'"data-dojo-attach-point="attributesTableExportButton" data-dojo-attach-event="onClick:openExport">${i18n.menus.export.title}</div>
Expand Down

0 comments on commit 9925415

Please sign in to comment.